Drafter.Prompt.Region (drafter v0.6.1)

Copy Markdown View Source

Redraws a few lines in place below the shell prompt, without the alternate screen.

A region remembers how many lines it last drew and which of them holds the terminal cursor. Every function returns the bytes to write and the region to keep; nothing here writes to a terminal.

{bytes, region} = Drafter.Prompt.Region.draw(%Drafter.Prompt.Region{}, frame, {80, 24})
{bytes, region} = Drafter.Prompt.Region.leave(region)

The cursor must be at the start of an empty line before the first draw/3. Lines are cut to one column less than the terminal's width and the frame to one line less than its height, so a frame never wraps or scrolls past the top of the screen. Every line break written is \r\n.

Summary

Functions

Erase the frame and leave the cursor where its first line was.

Draw frame over whatever the region drew last.

Move the cursor to the start of the line below the frame and show it.

Types

size()

@type size() :: {pos_integer(), pos_integer()}

t()

@type t() :: %Drafter.Prompt.Region{
  cursor_row: non_neg_integer(),
  height: non_neg_integer()
}

Functions

clear(region)

@spec clear(t()) :: {iodata(), t()}

Erase the frame and leave the cursor where its first line was.

The returned region is empty.

draw(region, frame, arg)

@spec draw(t(), Drafter.Prompt.Frame.t(), size()) :: {iodata(), t()}

Draw frame over whatever the region drew last.

Lines left over from a taller previous frame are erased. The cursor is shown at the frame's cursor position, or hidden at the end of the last line when the frame has none.

leave(region)

@spec leave(t()) :: {iodata(), t()}

Move the cursor to the start of the line below the frame and show it.

The frame stays on screen. The returned region is empty, so the next draw/3 starts a new frame there.