Class: Vedeu::Input::Translator
- Inherits:
-
Object
- Object
- Vedeu::Input::Translator
- Defined in:
- lib/vedeu/input/translator.rb
Overview
Translates escape sequences provided by the terminal into symbols which Vedeu can use for various behaviours.
Instance Attribute Summary collapse
- #code ⇒ String readonly protected
Class Method Summary collapse
Instance Method Summary collapse
- #ctrl_letters ⇒ Hash<String => Symbol> private
- #f_keys ⇒ Hash<String => Symbol> private
-
#initialize(code) ⇒ Vedeu::Input::Translator
constructor
Returns a new instance of Vedeu::Input::Translator.
- #specials ⇒ Hash<String => Symbol> private
- #symbols ⇒ Hash<String => Symbol> private
- #translate ⇒ Symbol
Constructor Details
#initialize(code) ⇒ Vedeu::Input::Translator
Returns a new instance of Vedeu::Input::Translator.
20 21 22 |
# File 'lib/vedeu/input/translator.rb', line 20 def initialize(code) @code = code end |
Instance Attribute Details
#code ⇒ String (readonly, protected)
33 34 35 |
# File 'lib/vedeu/input/translator.rb', line 33 def code @code end |
Class Method Details
.translate(code) ⇒ Symbol
12 13 14 |
# File 'lib/vedeu/input/translator.rb', line 12 def self.translate(code) new(code).translate end |
Instance Method Details
#ctrl_letters ⇒ Hash<String => Symbol> (private)
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/vedeu/input/translator.rb', line 43 def ctrl_letters { "\u0001" => :ctrl_a, "\u0002" => :ctrl_b, "\u0003" => :ctrl_c, "\u2404" => :ctrl_c, "\u0004" => :ctrl_d, "\u2403" => :ctrl_d, "\u0005" => :ctrl_e, "\u0006" => :ctrl_f, "\u0007" => :ctrl_g, "\u0008" => :ctrl_h, # "\u0009" => :ctrl_i, # duplicates tab "\u0010" => :ctrl_j, # produces "\n" "\u0011" => :ctrl_k, "\u0012" => :ctrl_l, "\u0013" => :ctrl_m, "\u0014" => :ctrl_n, "\u0015" => :ctrl_o, "\u0016" => :ctrl_p, "\u0017" => :ctrl_q, "\u0018" => :ctrl_r, "\u2412" => :ctrl_r, "\u0019" => :ctrl_s, # "\u0020" => :ctrl_t, # duplicates spacebar "\u0021" => :ctrl_u, "\u0022" => :ctrl_v, "\u0023" => :ctrl_w, "\u0024" => :ctrl_x, "\u0025" => :ctrl_y, "\u0026" => :ctrl_z, } end |
#f_keys ⇒ Hash<String => Symbol> (private)
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
# File 'lib/vedeu/input/translator.rb', line 78 def f_keys { "\eOP" => :f1, "\eOQ" => :f2, "\eOR" => :f3, "\eOS" => :f4, "\e[15~" => :f5, "\e[15;2~" => :shift_f5, "\e[15;5~" => :ctrl_f5, "\e[17~" => :f6, "\e[17;2~" => :shift_f6, "\e[17;5~" => :ctrl_f6, "\e[18~" => :f7, "\e[18;2~" => :shift_f7, "\e[18;5~" => :ctrl_f7, "\e[19~" => :f8, "\e[19;2~" => :shift_f8, "\e[19;5~" => :ctrl_f8, "\e[20~" => :f9, "\e[20;2~" => :shift_f9, "\e[20;5~" => :ctrl_f9, "\e[21~" => :f10, "\e[21;2~" => :shift_f10, "\e[21;5~" => :ctrl_f10, "\e[23~" => :f11, "\e[23;2~" => :shift_f11, "\e[23;5~" => :ctrl_f11, "\e[24~" => :f12, "\e[24;2~" => :shift_f12, "\e[24;5~" => :ctrl_f12, } end |
#specials ⇒ Hash<String => Symbol> (private)
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'lib/vedeu/input/translator.rb', line 120 def specials { "\u007F" => :backspace, "\u2408" => :backspace, "\u23CE" => :carriage_return, "\e[3~" => :delete, "\u232B" => :delete, "\e[B" => :down, "\u2193" => :down, "\e[F" => :end, "\r" => :enter, "\n" => :enter, "\e" => :escape, "\u238B" => :escape, "\e[H" => :home, "\eOH" => :home, "\e[2~" => :insert, "\e[D" => :left, "\u2190" => :left, "\u240A" => :line_feed, "\e[5~" => :page_up, "\e[6~" => :page_down, "\e[1;2R" => :pause_break, "\e[1;2P" => :print_screen, "\e[C" => :right, "\u2192" => :right, "\e[1;2Q" => :scroll_lock, "\e[Z" => :shift_tab, "\t" => :tab, "\u21B9" => :tab, "\e[A" => :up, "\u2191" => :up, } end |
#symbols ⇒ Hash<String => Symbol> (private)
38 39 40 |
# File 'lib/vedeu/input/translator.rb', line 38 def symbols @symbols ||= f_keys.merge!(ctrl_letters).merge!(specials) end |
#translate ⇒ Symbol
25 26 27 |
# File 'lib/vedeu/input/translator.rb', line 25 def translate symbols.fetch(code, code) end |