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

Copy Markdown View Source

Where a prompt is shown and where its keys come from.

Three implementations ship with Drafter:

Functions that change what the terminal remembers return the terminal to keep using.

Summary

Types

A key or paste event as Drafter.Terminal.ANSI decodes it.

t()

All the types that implement this protocol.

Functions

Give the terminal back. The terminal must not be used afterwards.

Show frame as the last frame and move below it, so later output follows it.

Show frame in place of the frame drawn before it.

Whether the terminal redraws frames and delivers keys one at a time.

Wait up to timeout for the next event.

Write text where the current frame is, pushing the frame out of the way.

The terminal's size as {columns, rows}.

Types

event()

@type event() :: Drafter.Terminal.ANSI.event()

A key or paste event as Drafter.Terminal.ANSI decodes it.

t()

@type t() :: term()

All the types that implement this protocol.

Functions

close(terminal)

@spec close(t()) :: :ok

Give the terminal back. The terminal must not be used afterwards.

commit(terminal, frame)

@spec commit(t(), Drafter.Prompt.Frame.t()) :: t()

Show frame as the last frame and move below it, so later output follows it.

draw(terminal, frame)

@spec draw(t(), Drafter.Prompt.Frame.t()) :: t()

Show frame in place of the frame drawn before it.

interactive?(terminal)

@spec interactive?(t()) :: boolean()

Whether the terminal redraws frames and delivers keys one at a time.

next_event(terminal, timeout)

@spec next_event(t(), timeout()) :: {event() | :timeout | :closed, t()}

Wait up to timeout for the next event.

Returns the event, :timeout, or :closed when no more input can arrive.

print(terminal, text)

@spec print(t(), iodata()) :: t()

Write text where the current frame is, pushing the frame out of the way.

The frame is erased; draw it again afterwards.

size(terminal)

@spec size(t()) :: {pos_integer(), pos_integer()}

The terminal's size as {columns, rows}.