module RatatuiRuby::Event::Key::Dwim
DWIM predicates for common key patterns.
These predicates anticipate what developers intuitively try. Space bars, character categories, Unix signals, and Vim-style navigation.
Public Instance Methods
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 54 def alphanumeric? letter? || digit? end
Returns true if the key is alphanumeric.
Event::Key.new(code: "a").alphanumeric? # => true
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 136 def arrow? ARROW_KEYS.include?(@code) && @modifiers.empty? end
Returns true if key is an arrow key.
Event::Key.new(code: "up").arrow? # => true
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 90 def cancel? (@code == "esc" && @modifiers.empty?) || interrupt? end
Returns true for cancel (Esc or Ctrl+C).
event.cancel? # => true for Esc or Ctrl+C
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 28 def cr? @code == "enter" && @modifiers.empty? end
Returns true if the key is Enter. Alias for carriage return.
event.cr? # => true for enter
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 47 def digit? @code.length == 1 && @code.match?(/\A[0-9]\z/) end
Returns true if the key is a digit (0-9).
Event::Key.new(code: "5").digit? # => true
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 83 def eof? @code == "d" && @modifiers == ["ctrl"] end
Returns true for end-of-file (Ctrl+D).
event.eof? # => true for Ctrl+D
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 76 def interrupt? @code == "c" && @modifiers == ["ctrl"] end
Returns true for interrupt (Ctrl+C).
event.interrupt? # => true for Ctrl+C
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 40 def letter? @code.length == 1 && @code.match?(/\A[A-Za-z]\z/) end
Returns true if the key is a single letter (a-z, A-Z).
Event::Key.new(code: "a").letter? # => true
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 61 def punctuation? return false unless @code.length == 1 !letter? && !digit? && !whitespace? end
Returns true if the key is punctuation.
Event::Key.new(code: "@", modifiers: ["shift"]).punctuation? # => true
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 116 def quit? @code == "\\" && @modifiers == ["ctrl"] end
Returns true for SIGQUIT (Ctrl+).
event.quit? # => true for Ctrl+\
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 97 def sigint? interrupt? end
Returns true for SIGINT (Ctrl+C).
event.sigint? # => true for Ctrl+C
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 19 def space? @code == " " && @modifiers.empty? end
Returns true if the key is a space character.
event.space? # => true for " "
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 106 def suspend? @code == "z" && @modifiers == ["ctrl"] end
Returns true for SIGTSTP (Ctrl+Z) - suspend/stop.
event.suspend? # => true for Ctrl+Z
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 145 def vim? return true if VIM_MOVEMENT_KEYS.include?(@code) && @modifiers.empty? @code == "G" && @modifiers == ["shift"] end
Returns true if key is a Vim movement key.
Event::Key.new(code: "j").vim? # => true
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 186 def vim_bottom? @code == "G" && @modifiers == ["shift"] end
Returns true for Vim go to bottom (G).
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 156 def vim_down? @code == "j" && @modifiers.empty? end
Returns true for Vim down (j).
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 151 def vim_left? @code == "h" && @modifiers.empty? end
Returns true for Vim left (h).
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 166 def vim_right? @code == "l" && @modifiers.empty? end
Returns true for Vim right (l).
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 181 def vim_top? @code == "g" && @modifiers.empty? end
Returns true for Vim go to top (gg pattern, here just g).
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 161 def vim_up? @code == "k" && @modifiers.empty? end
Returns true for Vim up (k).
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 176 def vim_word_backward? @code == "b" && @modifiers.empty? end
Returns true for Vim word backward (b).
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 171 def vim_word_forward? @code == "w" && @modifiers.empty? end
Returns true for Vim word forward (w).
Source
# File lib/ratatui_ruby/event/key/dwim.rb, line 69 def whitespace? @code == " " || @code == "enter" || @code == "tab" end
Returns true if the key is whitespace (space, enter, tab).
Event::Key.new(code: " ").whitespace? # => true