struct

Term2::Key

Inherits Struct < Value < Object

Key contains information about a keypress.

Keys can represent:

  • Regular characters (type == KeyType::Runes)
  • Special keys like arrows, function keys (type == KeyType::Up, etc.)
  • Control combinations (type == KeyType::CtrlC, etc.)
  • Alt combinations (alt? == true)
  • Pasted text (paste? == true)
case msg
when Term2::KeyMsg
  key = msg.key
  case key.to_s
  when "q" # quit
 then
  when "ctrl+c" # also quit
 then
  when "up" # move up
 then
  end
end

Constructors

new(type : KeyType, runes : Array(Char) = [] of Char, alt : Bool = false, paste : Bool = false)
Source
new(char : Char, alt : Bool = false)
Source
new(str : String, alt : Bool = false)
Source
new(runes : Array(Char), alt : Bool = false, paste : Bool = false)
Source

Instance methods

==(other : Key)
Source
alt?

Whether Alt was held

Source
matches?(pattern : String) : Bool

Check if this key matches a given string representation

Source
paste?

Whether this key came from a paste operation

Source
rune

Get the first rune (for single character keys)

Source
runes

The characters for this key (for KeyType::Runes)

Source
to_s

Returns a friendly string representation for a key

Source
type

The type of key (special key or Runes for regular characters)

Source
type?(key_type : KeyType) : Bool

Check if this is a specific key type

Source