class Fancyline::Context

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.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(fancyline : Fancyline, prompt : String) #

[View source]

Instance Method Detail

def accept! #

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


[View source]
def clear_info #

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


[View source]
def 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.


[View source]
def 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.


[View source]
def destruct : String | Nil #

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


[View source]
def draw #

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


[View source]
def 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.


[View source]
def editor : Editor #

Line editor used by the context


[View source]
def fancyline : Fancyline #

The Fancyline instance this context was built from.


[View source]
def 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.


[View source]
def handle_control(key : Key::Control) #

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


[View source]
def reject! #

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


[View source]
def 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.


[View source]
def status : Status #

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


[View source]
def stop_widget #

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


[View source]
def tty : Tty #

Delegates to Fancyline#tty.


[View source]
def widget : Widget | Nil #

Currently active widget (if any)


[View source]