class Fancyline::Editor

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

Constant 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

Instance methods inherited from module Fancyline::Drawable

draw(ctx : Context) draw

Constructor Detail

def self.new(fancyline : Fancyline, prompt : String, line : String = "", cursor : Int32 = 0, display_func : String -> String = NOOP_DISPLAY_FUNC) #

[View source]

Instance Method Detail

def apply(completion : Completion) #

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


[View source]
def clear #

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


[View source]
def clear_prompt #

Removes the prompt from the terminal.


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


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


[View source]
def display_func : DisplayFunc #

Function used to transform a line to a displayable string.


[View source]
def display_func=(display_func : DisplayFunc) #

Function used to transform a line to a displayable string.


[View source]
def draw(ctx : Context) #

Drawable compatibility


[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_prompt #

Draws the prompt and line buffer.


[View source]
def empty? : Bool #

Returns true if the line buffer is empty.


[View source]
def fancyline : Fancyline #

The Fancyline instance this editor was built for.


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


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


[View source]
def move_cursor(offset : Int32) #

Moves the cursor in offset direction


[View source]
def prompt : String #

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


[View source]
def prompt=(prompt : String) #

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


[View source]
def put_char(char : Char) #

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


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


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


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


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


[View source]