class

Fancyline::Context

Inherits Reference / Object

Context of a currently running prompt. You usually don't have to instantiate one yourself, but use Fancyline instead.

Context implements most of the user-facing operations like handling user input and rendering the resulting output.

Constructors

new(fancyline : Fancyline, prompt : String)
Source

Instance methods

accept!

Accepts the current input. This will make Fancyline#readline return the line buffer in its current form to the caller.

Source
clear_info

Clears the sub information lines. The cursor position is retained.

Source
create_editor(prompt : String, line = "", cursor = 0) : Editor

Creates a new editor. Can be used by widgets to show an editor. The prompt has to start at the beginning of the output line.

Source
create_editor(prompt : String, line = "", cursor = 0, &block : Editor::DisplayFunc) : Editor

Like #create_editor, but uses the supplied block as display function, allowing the caller to transform an output string before writing it to the screen.

Source
destruct

Clears the sub-lines, moves the cursor onto the next line, and returns the current line buffer if it was accepted.

Source
draw

Draws the context onto the terminal. This method is called by Fancyline#readline after every key-press.

Source
draw_info

Draws the sub information lines. The cursor is assumed to be a line above the target lines. The cursor will be moved back to the line, but placed at an unknown column.

Source
editor

Line editor used by the context

Source
fancyline

The Fancyline instance this context was built from.

Source
handle(char : Char)

Handles an input character, as if the user typed it.

This method should not be called from a widget. Call #handle_control or #put_char directly instead.

Source
handle_control(key : Key::Control)

Handles a control key, as if the user had input it.

Source
reject!

Rejects the input. This will make Fancyline#readline return nil to the caller.

Source
start_widget(widget : Widget) : Bool

Starts widget in this context. If there's already a widget active, returns false. Returns true otherwise and calls Widget#start.

Usually called from a key handler (See #actions).

If a widget decides to not start, it's safe to call #stop_widget from inside Widget#start to directly remove the widget again. This does not affect the result of this method, which will stay to be true.

Source
status

Status of this context. Use #accept! and #reject! to modify it.

Source
stop_widget

If a widget is currently running, stops and removes it. If no widget is running does nothing.

Source
tty

Delegates to Fancyline#tty.

Source
widget

Currently active widget (if any)

Source

Nested types