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
-
RPROMPT_MARGIN =
1
-
Minimum space (in characters) between the rprompt and the prompt line. The right-prompt will be hidden if not satisfiable.
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.
-
#rprompt : String | Nil
Prompt displayed on the right side, which will disappear when the prompt input gets near it.
-
#rprompt=(rprompt : String | Nil)
Prompt displayed on the right side, which will disappear when the prompt input gets near it.
-
#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.
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.
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.
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.