class Fancyline::KeyAction

Overview

Mapping for key actions. Usually accessed through Fancyline#actions.

Defined in:

fancyline/key_action.cr

Constant Summary

DEFAULT = {Key::Control::CtrlC => ->(ctx : Context) do raise(Interrupt.new) end, Key::Control::Return => ->(ctx : Context) do ctx.accept! end, Key::Control::CtrlO => ->(ctx : Context) do ctx.accept! end, Key::Control::Backspace => ->(ctx : Context) do ctx.editor.remove_at_cursor(-1) end, Key::Control::CtrlH => ->(ctx : Context) do ctx.editor.remove_at_cursor(-1) end, Key::Control::Delete => ->(ctx : Context) do ctx.editor.remove_at_cursor(+1) end, Key::Control::Left => ->(ctx : Context) do ctx.editor.move_cursor(-1) end, Key::Control::Right => ->(ctx : Context) do ctx.editor.move_cursor(+1) end, Key::Control::Home => ->(ctx : Context) do ctx.editor.move_cursor(Int32::MIN) end, Key::Control::End => ->(ctx : Context) do ctx.editor.move_cursor(Int32::MAX) end, Key::Control::CtrlA => ->(ctx : Context) do ctx.editor.move_cursor(Int32::MIN) end, Key::Control::CtrlE => ->(ctx : Context) do ctx.editor.move_cursor(Int32::MAX) end, Key::Control::CtrlD => ->(ctx : Context) do if ctx.editor.empty? ctx.reject! end end, Key::Control::CtrlU => ->(ctx : Context) do ctx.editor.clear end, Key::Control::CtrlL => ->(ctx : Context) do ctx.tty.clear_screen end, Key::Control::Up => ->(ctx : Context) do ctx.start_widget(Widget::History.new) end, Key::Control::CtrlR => ->(ctx : Context) do ctx.start_widget(Widget::HistorySearch.new) end, Key::Control::Tab => ->(ctx : Context) do ctx.start_widget(Widget::Completion.new) end} of Key::Control => Handler

Default key bindings. Make sure to bind keys like Key::Control::Return or Key::Control::CtrlC. Else, the user may not have any way to exit a prompt.

Constructors

Instance Method Summary

Constructor Detail

def self.new(mapping : Hash(Fancyline::Key::Control, Fancyline::Context -> _) = DEFAULT.dup) #

Initializes the mapping to a clone of the DEFAULT one.


[View source]

Instance Method Detail

def [](*args, **options) #

Delegates to #mapping.


[View source]
def [](*args, **options, &) #

Delegates to #mapping.


[View source]
def []=(*args, **options) #

Delegates to #mapping.


[View source]
def []?(*args, **options) #

Delegates to #mapping.


[View source]
def []?(*args, **options, &) #

Delegates to #mapping.


[View source]
def mapping : Hash(Key::Control, Handler) #

The key action mapping


[View source]
def mapping=(mapping : Hash(Key::Control, Handler)) #

The key action mapping


[View source]
def set(key : Key::Control, &block : Handler) #

Sets a mapping for key to run the given block upon hitting it. Replaces an existing mapping for key if any exists.


[View source]