View Source Kino.Frame (Kino v0.7.0)

A placeholder for outputs.

A frame wraps outputs that can be dynamically updated at any time.

Also see Kino.animate/3 which offers a convenience on top of this kino.

examples

Examples

frame = Kino.Frame.new() |> Kino.render()

for i <- 1..100 do
  Kino.Frame.render(frame, i)
  Process.sleep(50)
end

Or with a scheduled task in the background.

frame = Kino.Frame.new() |> Kino.render()

Kino.Frame.periodically(frame, 50, 0, fn i ->
  Kino.Frame.render(frame, i)
  {:cont, i + 1}
end)

Link to this section Summary

Functions

Renders and appends the given term to the frame.

Removes all outputs within the given frame.

Creates a new frame.

Registers a callback to run periodically in the frame process.

Renders the given term within the frame.

Link to this section Types

@opaque t()

Link to this section Functions

@spec append(t(), term()) :: :ok

Renders and appends the given term to the frame.

@spec clear(t()) :: :ok

Removes all outputs within the given frame.

@spec new() :: t()

Creates a new frame.

Link to this function

periodically(frame, interval_ms, acc, fun)

View Source
@spec periodically(t(), pos_integer(), term(), (term() -> {:cont, term()} | :halt)) ::
  :ok

Registers a callback to run periodically in the frame process.

The callback is run every interval_ms milliseconds and receives the accumulated value. The callback should return either of:

  • {:cont, acc} - the continue with the new accumulated value

  • :halt - to no longer schedule callback evaluation

The callback is run for the first time immediately upon registration.

@spec render(t(), term()) :: :ok

Renders the given term within the frame.

This works similarly to Kino.render/1, but the rendered output replaces existing frame contents.