class Fancyline::KeyAction
- Fancyline::KeyAction
- Reference
- Object
Overview
Mapping for key actions. Usually accessed through Fancyline#actions
.
Defined in:
fancyline/key_action.crConstant 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
orKey::Control::CtrlC
. Else, the user may not have any way to exit a prompt.
Constructors
-
.new(mapping : Hash(Fancyline::Key::Control, Fancyline::Context -> _) = DEFAULT.dup)
Initializes the mapping to a clone of the
DEFAULT
one.
Instance Method Summary
-
#[](*args, **options)
Delegates to
#mapping
. -
#[](*args, **options, &)
Delegates to
#mapping
. -
#[]=(*args, **options)
Delegates to
#mapping
. -
#[]?(*args, **options)
Delegates to
#mapping
. -
#[]?(*args, **options, &)
Delegates to
#mapping
. -
#mapping : Hash(Key::Control, Handler)
The key action mapping
-
#mapping=(mapping : Hash(Key::Control, Handler))
The key action mapping
-
#set(key : Key::Control, &block : Handler)
Sets a mapping for key to run the given block upon hitting it.
Constructor Detail
Initializes the mapping to a clone of the DEFAULT
one.
Instance Method Detail
Sets a mapping for key to run the given block upon hitting it. Replaces an existing mapping for key if any exists.