class

Fancyline::Editor

Inherits Fancyline::Drawable / Reference / Object

Editor for a line of input featuring a prompt. Used by Context for the main prompt, but can also used by Widgets to show an editor e.g. in a sub_info middleware.

Use Context#create_editor instead of instantiating this yourself.

Constants

NOOP_DISPLAY_FUNC = ->(x : String) do x end

Default display function

RPROMPT_MARGIN = 1

Minimum space (in characters) between the rprompt and the prompt line. The right-prompt will be hidden if not satisfiable.

Constructors

new(fancyline : Fancyline, prompt : String, line : String = "", cursor : Int32 = 0, display_func : String -> String = NOOP_DISPLAY_FUNC)
Source

Instance methods

apply(completion : Completion)

Applies completion to the string buffer, and adjusts the cursor to be just after the Completion#word.

Source
clear

Clears the line buffer and resets the cursor to its start position.

Source
clear_prompt

Removes the prompt from the terminal.

Source
cursor

Position of the cursor, starting right after the prompt. Legal values are [0..line.size] - Including line.size, just after the line buffer ends.

Source
cursor=(cursor : Int32)

Position of the cursor, starting right after the prompt. Legal values are [0..line.size] - Including line.size, just after the line buffer ends.

Source
display_func

Function used to transform a line to a displayable string.

Source
display_func=(display_func : DisplayFunc)

Function used to transform a line to a displayable string.

Source
draw(ctx : Context)

Drawable compatibility

Source
draw

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

Source
draw_prompt

Draws the prompt and line buffer.

Source
empty?

Returns true if the line buffer is empty.

Source
fancyline

The Fancyline instance this editor was built for.

Source
line

Current line buffer. Modifying it from everywhere outside the Context itself is fine and is done everywhere it's useful. Make sure to also update the #cursor.

Source
line=(line : String)

Current line buffer. Modifying it from everywhere outside the Context itself is fine and is done everywhere it's useful. Make sure to also update the #cursor.

Source
move_cursor(offset : Int32)

Moves the cursor in offset direction

Source
prompt

Prompt, a string shown just before the user input. Used to display relevant, but usually short, information.

Source
prompt=(prompt : String)

Prompt, a string shown just before the user input. Used to display relevant, but usually short, information.

Source
put_char(char : Char)

Writes char at the cursor, moving the cursor onward, as if the user had input it.

Source
remove_at_cursor(count : Int32)

Removes count characters at the cursor position. If count is negative, moves the cursor count times to the left, removing count characters (Backspace functionality). If count is positive, removes the following count characters, but doesn't move the cursor (Delete functionality). The count is automatically clamped to the line size, it can't get out of bounds.

Source
rprompt

Prompt displayed on the right side, which will disappear when the prompt input gets near it. Can be used to display information like current time, or other short data. Popularized by ZSH.

See Fancyline#readline to easily set this property.

Source
rprompt=(rprompt : String | Nil)

Prompt displayed on the right side, which will disappear when the prompt input gets near it. Can be used to display information like current time, or other short data. Popularized by ZSH.

See Fancyline#readline to easily set this property.

Source
word_at_offset(offset = @cursor) : Tuple(String, Int32) | Nil

Looks for a word under, or just before, offset. If found, returns a tuple of the word itself, and its starting position in the current line buffer. If not found, returns nil.

A non-alphanumeric beginning is never considered to be a word.

Source

Nested types