Class: UI::EscapeSequenceTranslator

Inherits:
Object
  • Object
show all
Defined in:
lib/ektoplayer/ui/escapesequencetranslator.rb

Constant Summary collapse

KEYS =
{
   ?\r     => ICurses::KEY_ENTER,
   ?\r.ord => ICurses::KEY_ENTER
}

Class Method Summary collapse

Class Method Details

.reg(key, fallback, curses_key) ⇒ Object



10
11
12
13
14
# File 'lib/ektoplayer/ui/escapesequencetranslator.rb', line 10

def self.reg(key, fallback, curses_key)
   code = `tput #{key} 2>/dev/null` rescue ''
   code = fallback if code.empty?
   KEYS[code] = curses_key if not code.empty?
end

.to_curses(key) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/ektoplayer/ui/escapesequencetranslator.rb', line 35

def self.to_curses(key)
   if KEYS.include? key
      KEYS[key]
   elsif key.is_a? Integer
      key
   elsif ((key.is_a? String or key.is_a? Array) and key[0] == 27.chr and key[1] == ?[ and key[2] == ?M)
      ICurses::IMouseEvent.new(bstate: ICurses::BUTTON1_CLICKED, x: key[4].ord - 33, y: key[5].ord - 33)
   elsif key.size == 1
      key.ord rescue nil
   end
end