View Source Kino.Text (Kino v0.16.0)
A kino for rendering text content.
For rich text, use Kino.Markdown
.
Examples
Kino.Text.new("Hello!")
[:green, "Hello!"]
|> IO.ANSI.format()
|> IO.iodata_to_binary()
|> Kino.Text.new(terminal: true)
Summary
Functions
Creates a new kino displaying the given text content.
Types
@type style() :: [{:color | :font_weight | :font_size, String.Chars.t()}]
@opaque t()
Functions
@spec new(String.t(), opts) :: t() when opts: [terminal: boolean(), chunk: boolean(), style: style()]
Creates a new kino displaying the given text content.
Options
:terminal
- whether to render the text as if it were printed to standard output, supporting ANSI escape codes. Defaults tofalse
:chunk
- whether this is a part of a larger text. Adjacent chunks are merged into a single text. This is useful for streaming content. Defaults tofalse
:style
- a keyword list of CSS attributes, such asstyle: [color: "#FF0000", font_weight: :bold]
. The currently supported styles are:color
,:font_size
, and:font_weight
. Not supported on terminal outputs.
Examples
Using the :chunk
option
Using a Kino.Frame
.
frame = Kino.Frame.new() |> Kino.render()
for word <- ["who", " let", " the", " dogs", " out"] do
text = Kino.Text.new(word, chunk: true)
Kino.Frame.append(frame, text)
Process.sleep(250)
end
Without using a Kino.Frame
.
for word <- ["who", " let", " the", " dogs", " out"] do
Kino.Text.new(word, chunk: true) |> Kino.render()
Process.sleep(250)
end
Kino.nothing()