class Fancyline::Context
- Fancyline::Context
- Reference
- Object
Overview
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.
Defined in:
fancyline/context.crConstructors
Instance Method Summary
-
#accept!
Accepts the current input.
-
#clear_info
Clears the sub information lines.
-
#create_editor(prompt : String, line = "", cursor = 0) : Editor
Creates a new editor.
-
#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. -
#destruct : String | Nil
Clears the sub-lines, moves the cursor onto the next line, and returns the current line buffer if it was accepted.
-
#draw
Draws the context onto the terminal.
-
#draw_info
Draws the sub information lines.
-
#editor : Editor
Line editor used by the context
-
#fancyline : Fancyline
The
Fancyline
instance this context was built from. -
#handle(char : Char)
Handles an input character, as if the user typed it.
-
#handle_control(key : Key::Control)
Handles a control key, as if the user had input it.
-
#reject!
Rejects the input.
-
#start_widget(widget : Widget) : Bool
Starts widget in this context.
-
#status : Status
Status of this context.
-
#stop_widget
If a widget is currently running, stops and removes it.
-
#tty : Tty
Delegates to
Fancyline#tty
. -
#widget : Widget | Nil
Currently active widget (if any)
Constructor Detail
Instance Method Detail
Accepts the current input. This will make Fancyline#readline
return
the line buffer in its current form to the caller.
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.
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.
Clears the sub-lines, moves the cursor onto the next line, and returns the current line buffer if it was accepted.
Draws the context onto the terminal. This method is called by
Fancyline#readline
after every key-press.
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.
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.
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
.
If a widget is currently running, stops and removes it. If no widget is running does nothing.