Drafter.Prompt.Terminal.Scripted (drafter v0.6.0)

Copy Markdown View Source

A terminal whose keys come from a list and whose output is kept as text.

Events are handed out in order, and :closed once they run out. Only committed frames and printed text are kept; frames drawn on the way are dropped, so the transcript does not depend on timing.

terminal = Drafter.Prompt.Terminal.Scripted.start([{:key, :y}])
{{:key, :y}, terminal} = Drafter.Prompt.Terminal.next_event(terminal, :infinity)
{:closed, _terminal} = Drafter.Prompt.Terminal.next_event(terminal, :infinity)
Drafter.Prompt.Terminal.Scripted.stop(terminal)

The terminal is a process, so it can be used from any process and by several prompts in a row. Drafter.Prompt.Script wraps it for tests.

Options

  • :size - {columns, rows} reported to prompts. Default {80, 24}.

Summary

Functions

The events not yet handed out.

Start a terminal that will hand out events.

Stop the terminal's process.

Everything committed and printed so far, as plain text.

Types

t()

@type t() :: %Drafter.Prompt.Terminal.Scripted{
  size: {pos_integer(), pos_integer()},
  store: pid()
}

Functions

remaining(scripted)

@spec remaining(t()) :: [Drafter.Prompt.Terminal.event()]

The events not yet handed out.

start(events, opts \\ [])

@spec start(
  [Drafter.Prompt.Terminal.event()],
  keyword()
) :: t()

Start a terminal that will hand out events.

stop(scripted)

@spec stop(t()) :: :ok

Stop the terminal's process.

transcript(scripted)

@spec transcript(t()) :: String.t()

Everything committed and printed so far, as plain text.