Skip to content

Commit

Permalink
Add doc examples about the chunk option of Kino.Text.new/2 and Kino.M…
Browse files Browse the repository at this point in the history
…arkdown.new/2 (#402)
  • Loading branch information
hugobarauna authored Mar 22, 2024
1 parent a4cc274 commit b730990
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
23 changes: 23 additions & 0 deletions lib/kino/markdown.ex
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,29 @@ defmodule Kino.Markdown do
are merged into a single text. This is useful for streaming content.
Defaults to `false`
## 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.Markdown.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.Markdown.new(word, chunk: true) |> Kino.render()
Process.sleep(250)
end
Kino.nothing()
"""
@spec new(binary(), keyword()) :: t()
def new(text, opts \\ []) do
Expand Down
23 changes: 23 additions & 0 deletions lib/kino/text.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,29 @@ defmodule Kino.Text do
are merged into a single text. This is useful for streaming content.
Defaults to `false`
## 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()
"""
@spec new(String.t(), opts) :: t() when opts: [terminal: boolean(), chunk: boolean()]
def new(text, opts \\ []) when is_binary(text) do
Expand Down

0 comments on commit b730990

Please sign in to comment.