Fancyline::KeyAction
Inherits Reference / Object
Mapping for key actions. Usually accessed through Fancyline#actions.
Constants
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
Initializes the mapping to a clone of the DEFAULT one.
Instance methods
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.