terminal_rb 0.11.0 → 0.12.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,141 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module Terminal
4
- module LegacyKeys
5
- class << self
6
- def key_name(key)
7
- @key_name[key.ord] if key.size == 1
8
- end
9
-
10
- def translate(esc)
11
- return "Alt+#{@esc1[esc[0].ord] || esc[0]}" if esc.size == 1 # ESC ?
12
- if esc.size == 2 && (esc[0] == 'O' || esc[0] == '[')
13
- return @ss3[esc[1].ord] # ESC O ? || ESC [ ?
14
- end
15
- if esc[0] == "\e" # ESC ESC ...
16
- return "Alt+#{@esc1[esc[1].ord] || esc[1]}" if esc.size == 1
17
- esc.shift
18
- return (name = translate(esc)) ? "Alt+#{name}" : nil
19
- end
20
- return if esc[0] != '[' # ESC [ ...
21
- return csi1(esc) if esc[1] == '1' && esc[2] == ';'
22
- csi(esc) if esc[-1] == '~'
23
- end
24
-
25
- private
26
-
27
- def csi(esc)
28
- # ESC [ <code> ~
29
- # ESC [ <code> ; <modifier> ~
30
- return @csi[esc[1..-2].join.to_i] if (idx = esc.index(';')).nil? # no mod
31
- key = @csi[esc[1..(idx - 1)].join.to_i] or return
32
- return key if (mod = esc[(idx + 1)..-2].join.to_i - 1) < 1 # no mod
33
- (@mods.filter_map { |b, n| n if mod.allbits?(b) } << key).join('+')
34
- end
35
-
36
- def csi1(esc)
37
- # ESC [ 1 ; <modifier> [~ABCDEFHPQRS]
38
- return if esc.size < 5
39
- key = @ss3[esc[-1].ord] or return
40
- return key if (mod = esc[3..-2].join.to_i - 1) < 1 # no mod
41
- (@mods.filter_map { |b, n| n if mod.allbits?(b) } << key).join('+')
42
- end
43
- end
44
-
45
- @csi = {
46
- 0x02 => 'Ins',
47
- 0x03 => 'Del',
48
- 0x05 => 'PageUp',
49
- 0x06 => 'PageDown',
50
- 0x07 => 'Home',
51
- 0x08 => 'End',
52
- 0x09 => 'Tab',
53
- 0x0b => 'F1',
54
- 0x0c => 'F2',
55
- 0x0d => 'F3',
56
- 0x0e => 'F4',
57
- 0x0f => 'F5',
58
- 0x11 => 'F6',
59
- 0x12 => 'F7',
60
- 0x13 => 'F8',
61
- 0x14 => 'F9',
62
- 0x15 => 'F10',
63
- 0x17 => 'F11',
64
- 0x18 => 'F12',
65
- 0x1b => 'Enter'
66
- }.compare_by_identity.freeze
67
-
68
- @ss3 = {
69
- 0x41 => 'Up', # A
70
- 0x42 => 'Down', # B
71
- 0x43 => 'Right', # C
72
- 0x44 => 'Left', # D
73
- 0x46 => 'End', # F
74
- 0x48 => 'Home', # H
75
- 0x50 => 'F1', # P
76
- 0x51 => 'F2', # Q
77
- 0x52 => 'F3', # R
78
- 0x53 => 'F4', # S
79
- 0x5a => 'Shift+Tab' # Z - not widely used
80
- }.compare_by_identity.freeze
81
-
82
- @esc1 = {
83
- 0x08 => 'Back',
84
- 0x09 => 'Tab',
85
- 0x10 => 'Ctrl+?',
86
- 0x0d => 'Enter',
87
- 0x1b => 'Esc',
88
- 0x20 => 'Space',
89
- 0x7f => 'Back'
90
- }.compare_by_identity.freeze
91
-
92
- @key_name = {
93
- 0x00 => 'Ctrl+Space',
94
- 0x01 => 'Ctrl+a',
95
- 0x02 => 'Ctrl+b',
96
- 0x03 => 'Ctrl+c',
97
- 0x04 => 'Ctrl+d',
98
- 0x05 => 'Ctrl+e',
99
- 0x06 => 'Ctrl+f',
100
- 0x07 => 'Ctrl+g',
101
- 0x08 => 'Ctrl+Back',
102
- 0x09 => 'Tab',
103
- 0x0a => 'Ctrl+j',
104
- 0x0b => 'Ctrl+k',
105
- 0x0c => 'Ctrl+l',
106
- 0x0d => 'Enter',
107
- 0x0e => 'Ctrl+n',
108
- 0x0f => 'Ctrl+o',
109
- 0x10 => 'Ctrl+p',
110
- 0x11 => 'Ctrl+q',
111
- 0x12 => 'Ctrl+r',
112
- 0x13 => 'Ctrl+s',
113
- 0x14 => 'Ctrl+t',
114
- 0x15 => 'Ctrl+u',
115
- 0x16 => 'Ctrl+v',
116
- 0x17 => 'Ctrl+w',
117
- 0x18 => 'Ctrl+x',
118
- 0x19 => 'Ctrl+y',
119
- 0x1a => 'Ctrl+z',
120
- 0x1b => 'Esc',
121
- 0x1c => 'Ctrl+4',
122
- 0x1d => 'Ctrl+5',
123
- 0x1e => 'Ctrl+6',
124
- 0x1f => 'Ctrl+7',
125
- 0x20 => 'Space',
126
- 0x7f => 'Back'
127
- }.compare_by_identity.freeze
128
-
129
- @mods = {
130
- 1 => 'Shift',
131
- 2 => 'Alt',
132
- 4 => 'Ctrl',
133
- 8 => 'Super',
134
- 16 => 'Hyper',
135
- 32 => 'Meta',
136
- 64 => 'Caps',
137
- 128 => 'Num'
138
- }.freeze
139
- end
140
- private_constant :LegacyKeys
141
- end