class Fancyline::Editor
- Fancyline::Editor
- Reference
- Object
Overview
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.
Included Modules
Defined in:
fancyline/editor.crConstant Summary
-
NOOP_DISPLAY_FUNC =
->(x : String) do x end
-
Default display function
Constructors
Instance Method Summary
-
#apply(completion : Completion)
Applies completion to the string buffer, and adjusts the cursor to be just after the
Completion#word
. -
#clear
Clears the line buffer and resets the cursor to its start position.
-
#clear_prompt
Removes the prompt from the terminal.
-
#cursor : Int32
Position of the cursor, starting right after the prompt.
-
#cursor=(cursor : Int32)
Position of the cursor, starting right after the prompt.
-
#display_func : DisplayFunc
Function used to transform a line to a displayable string.
-
#display_func=(display_func : DisplayFunc)
Function used to transform a line to a displayable string.
-
#draw(ctx : Context)
Drawable
compatibility -
#draw
Draws the context onto the terminal.
-
#draw_prompt
Draws the prompt and line buffer.
-
#empty? : Bool
Returns
true
if the line buffer is empty. -
#fancyline : Fancyline
The
Fancyline
instance this editor was built for. -
#line : String
Current line buffer.
-
#line=(line : String)
Current line buffer.
-
#move_cursor(offset : Int32)
Moves the cursor in offset direction
-
#prompt : String
Prompt, a string shown just before the user input.
-
#prompt=(prompt : String)
Prompt, a string shown just before the user input.
-
#put_char(char : Char)
Writes char at the cursor, moving the cursor onward, as if the user had input it.
-
#remove_at_cursor(count : Int32)
Removes count characters at the cursor position.
-
#word_at_offset(offset = @cursor) : Tuple(String, Int32) | Nil
Looks for a word under, or just before, offset.
Instance methods inherited from module Fancyline::Drawable
draw(ctx : Context)
draw
Constructor Detail
Instance Method Detail
Applies completion to the string buffer, and adjusts the cursor to be
just after the Completion#word
.
Position of the cursor, starting right after the prompt. Legal values are
[0..line.size]
- Including line.size
, just after the line buffer ends.
Position of the cursor, starting right after the prompt. Legal values are
[0..line.size]
- Including line.size
, just after the line buffer ends.
Function used to transform a line to a displayable string.
Draws the context onto the terminal. This method is called by
Fancyline#readline
after every key-press.
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
.
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
.
Prompt, a string shown just before the user input. Used to display relevant, but usually short, information.
Prompt, a string shown just before the user input. Used to display relevant, but usually short, information.
Writes char at the cursor, moving the cursor onward, as if the user had input it.
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.
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.