Drafter.Runtime.AppLoop (drafter v0.3.2)

Copy Markdown View Source

The Drafter application event loop.

Owns the receive loop and all message dispatch. Rendering is delegated to Drafter.Runtime.Renderer.

Summary

Functions

Turns the calling process into the application loop, returning when the app stops.

Set the local terminal up, then mount the app and run the loop until it stops.

Mount an app, run its ready hook, and enter the event loop for screen_rect.

Functions

enter_loop(app_module, app_state, screen_rect, timers \\ %{}, widget_hierarchy \\ nil, opts \\ [])

@spec enter_loop(module(), term(), map(), map(), map() | nil, keyword()) :: :ok

Turns the calling process into the application loop, returning when the app stops.

Registers the caller with Drafter.AppRegistry and applies :refresh_rate from opts, then receives and dispatches events until the application returns {:stop, reason} or the session shuts down.

Remote sessions call this directly. A local terminal goes through run/2, which sets the terminal up first.

timers maps a timer id to the :timer reference already running for it, widget_hierarchy is the hierarchy from a prior render or nil for none.

Options

Unlike start/3, this function does not mount the app, so :props is not read here.

run(app_module, opts \\ [])

@spec run(
  module(),
  keyword()
) :: :ok

Set the local terminal up, then mount the app and run the loop until it stops.

Registers with the theme, skin and screen managers, drains any stale input, clears the screen and sizes the compositor to the terminal, then hands off to start/3 with a screen rect covering the whole terminal.

Options

Takes the same options as start/3.

start(app_module, screen_rect, opts \\ [])

@spec start(module(), map(), keyword()) :: :ok

Mount an app, run its ready hook, and enter the event loop for screen_rect.

This is everything run/2 does once the terminal has been set up; a headless run enters here directly. Returns when the loop returns.

screen_rect is a %{x: x, y: y, width: w, height: h} map. The app is rendered once before its ready hook and once after, so intervals registered during the hook are running before the first event is taken.

Options