Module: RatatuiRuby::Event::Key::Character
- Included in:
- RatatuiRuby::Event::Key
- Defined in:
- lib/ratatui_ruby/event/key/character.rb
Overview
Methods for handling printable characters.
Instance Method Summary collapse
-
#char ⇒ Object
Returns the key as a printable character (if applicable).
-
#text? ⇒ Boolean
Returns true if the key represents a single printable character.
Instance Method Details
#char ⇒ Object
Returns the key as a printable character (if applicable).
- Printable Characters
-
Returns the character itself (e.g.,
"a","1"," "). - Special Keys
-
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
Returns <tt>nil</tt> (e.g., <tt>"enter"</tt>, <tt>"up"</tt>, <tt>"f1"</tt>). RatatuiRuby::Event::Key.new(code: "a").char # => "a" RatatuiRuby::Event::Key.new(code: "enter").char # => nil– SPDX-SnippetEnd ++
47 48 49 |
# File 'lib/ratatui_ruby/event/key/character.rb', line 47 def char text? ? @code : nil end |
#text? ⇒ Boolean
Returns true if the key represents a single printable character.
– SPDX-SnippetBegin SPDX-FileCopyrightText: 2026 Kerrick Long SPDX-License-Identifier: MIT-0 ++
RatatuiRuby::Event::Key.new(code: "a").text? # => true
RatatuiRuby::Event::Key.new(code: "enter").text? # => false
RatatuiRuby::Event::Key.new(code: "space").text? # => false ("space" is not 1 char, " " is)
– SPDX-SnippetEnd ++
26 27 28 |
# File 'lib/ratatui_ruby/event/key/character.rb', line 26 def text? @code.length == 1 end |