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.
- checksums.yaml +4 -4
- data/examples/key-codes.rb +5 -5
- data/lib/terminal/ansi/attributes.rb +4 -7
- data/lib/terminal/ansi.rb +31 -42
- data/lib/terminal/detect.rb +21 -21
- data/lib/terminal/input/as_key_event.rb +317 -0
- data/lib/terminal/input.rb +183 -67
- data/lib/terminal/rspec/helper.rb +7 -8
- data/lib/terminal/text/char_width.rb +4 -3
- data/lib/terminal/version.rb +1 -1
- metadata +4 -5
- data/lib/terminal/input/csiu_keys.rb +0 -198
- data/lib/terminal/input/dumb_keys.rb +0 -19
- data/lib/terminal/input/legacy_keys.rb +0 -141
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 357e535e9317609160d54c93a2a106a2a39d86a4c6740e93bbbccc01a2fcd42f
|
4
|
+
data.tar.gz: 746ddada0e50edf61c7220d144d75de46530056138e8a9d1bc1793098fe8a824
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90b2db6aa0cd6d3351ae8b7ec0f8df30a37e7bdad87050def22c47cbf48c94246efe927b15a612adbc713ff8b34971adc973721172da4702a1c7a433446db5e9
|
7
|
+
data.tar.gz: f35bafc5ecc52b59360ecec503e32ed173486fa81b42eec99912ef545d64be888ff01f9d584c3a6f34dd45505d449ece87ae033e61f0bb0e9637d481ddb7f310
|
data/examples/key-codes.rb
CHANGED
@@ -14,9 +14,9 @@ Terminal.hide_cursor
|
|
14
14
|
at_exit { Terminal.show_cursor } # required for some terminals :/
|
15
15
|
|
16
16
|
while true
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
)
|
21
|
-
break puts if
|
17
|
+
event = Terminal.read_key_event or break puts
|
18
|
+
str = "[blue]: [yellow]#{event.raw.inspect}"
|
19
|
+
str << " [bold bright_green]#{event.name}[/]" unless event.simple?
|
20
|
+
Terminal.puts(str)
|
21
|
+
break puts if event.name == 'Esc'
|
22
22
|
end
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Terminal
|
4
4
|
module Ansi
|
5
|
-
|
5
|
+
@attr = {
|
6
6
|
'/' => '',
|
7
7
|
'/b' => '22',
|
8
8
|
'/blink' => '25',
|
@@ -109,7 +109,7 @@ module Terminal
|
|
109
109
|
'uu' => '21'
|
110
110
|
}.freeze
|
111
111
|
|
112
|
-
|
112
|
+
@colors = {
|
113
113
|
'/bg' => '49',
|
114
114
|
'/fg' => '39',
|
115
115
|
'/ul' => '59',
|
@@ -200,10 +200,7 @@ module Terminal
|
|
200
200
|
'yellow' => '33'
|
201
201
|
}.freeze
|
202
202
|
|
203
|
-
|
204
|
-
|
205
|
-
COLORS_S = COLORS.transform_keys(&:to_sym).compare_by_identity.freeze
|
206
|
-
|
207
|
-
private_constant :ATTRIBUTES, :COLORS, :ATTRIBUTES_S, :COLORS_S
|
203
|
+
@attr_sym = @attr.transform_keys(&:to_sym).compare_by_identity.freeze
|
204
|
+
@colors_sym = @colors.transform_keys(&:to_sym).compare_by_identity.freeze
|
208
205
|
end
|
209
206
|
end
|
data/lib/terminal/ansi.rb
CHANGED
@@ -12,7 +12,7 @@ module Terminal
|
|
12
12
|
#
|
13
13
|
# @attribute [r] attributes
|
14
14
|
# @return [Array<Symbol>] all attribute names
|
15
|
-
def attributes =
|
15
|
+
def attributes = @attr_sym.keys
|
16
16
|
|
17
17
|
# Supported 3/4-bit color names.
|
18
18
|
#
|
@@ -20,7 +20,7 @@ module Terminal
|
|
20
20
|
#
|
21
21
|
# @attribute [r] colors
|
22
22
|
# @return [Array<Symbol>] all color names
|
23
|
-
def colors =
|
23
|
+
def colors = @colors_sym.keys
|
24
24
|
|
25
25
|
# Supported basic 24-bit (Kitty compatible) color names.
|
26
26
|
#
|
@@ -99,9 +99,9 @@ module Terminal
|
|
99
99
|
.map do |arg|
|
100
100
|
case arg
|
101
101
|
when String
|
102
|
-
|
102
|
+
@attr[arg] || @colors[arg] || _color(arg) || _invalid(arg)
|
103
103
|
when Symbol
|
104
|
-
|
104
|
+
@attr_sym[arg] || @colors_sym[arg] || _color(arg) ||
|
105
105
|
_invalid(arg)
|
106
106
|
when (0..255)
|
107
107
|
"38;5;#{arg}"
|
@@ -121,7 +121,7 @@ module Terminal
|
|
121
121
|
#
|
122
122
|
# @param str [#to_s] object to be tested
|
123
123
|
# @return [true, false] whether if attributes are found
|
124
|
-
def ansi?(str) =
|
124
|
+
def ansi?(str) = @re_test.match?(str.to_s)
|
125
125
|
|
126
126
|
# Decorate given argument with ANSI attributes and colors.
|
127
127
|
#
|
@@ -156,7 +156,7 @@ module Terminal
|
|
156
156
|
# @return [String] string without ANSI attributes
|
157
157
|
def undecorate(str)
|
158
158
|
str = str.to_s
|
159
|
-
str.index("\e") ? str.gsub(
|
159
|
+
str.index("\e") ? str.gsub(@re_test, '') : str.dup
|
160
160
|
end
|
161
161
|
|
162
162
|
# Try to combine given ANSI attributes and colors.
|
@@ -181,7 +181,7 @@ module Terminal
|
|
181
181
|
return if (attributes = attributes.to_s.split(separator)).empty?
|
182
182
|
"\e[#{
|
183
183
|
attributes
|
184
|
-
.map! {
|
184
|
+
.map! { @attr[_1] || @colors[_1] || _color(_1) || return }
|
185
185
|
.join(';')
|
186
186
|
}m"
|
187
187
|
end
|
@@ -196,9 +196,9 @@ module Terminal
|
|
196
196
|
attributes.all? do |arg|
|
197
197
|
case arg
|
198
198
|
when String
|
199
|
-
|
199
|
+
@attr[arg] || @colors[arg] || _color(arg)
|
200
200
|
when Symbol
|
201
|
-
|
201
|
+
@attr_sym[arg] || @colors_sym[arg] || _color(arg)
|
202
202
|
when (0..767)
|
203
203
|
true
|
204
204
|
end
|
@@ -225,7 +225,7 @@ module Terminal
|
|
225
225
|
def bbcode(str)
|
226
226
|
str = str.to_s
|
227
227
|
return str.dup unless str.index('[')
|
228
|
-
str.gsub(
|
228
|
+
str.gsub(@re_bbcode) do |match_str|
|
229
229
|
match = Regexp.last_match(1) or next match_str
|
230
230
|
next "[#{match[1..]}]" if match[0] == '\\'
|
231
231
|
try_convert(match) || match_str
|
@@ -245,11 +245,11 @@ module Terminal
|
|
245
245
|
def unbbcode(str)
|
246
246
|
str = str.to_s
|
247
247
|
return str.dup unless str.index('[')
|
248
|
-
str.gsub(
|
248
|
+
str.gsub(@re_bbcode) do |match_str|
|
249
249
|
match = Regexp.last_match(1) or next match_str
|
250
250
|
next "[#{match[1..]}]" if match[0] == '\\'
|
251
251
|
next match_str if (match = match.split).empty?
|
252
|
-
next if match.all? {
|
252
|
+
next if match.all? { @attr[_1] || @colors[_1] || _color(_1) }
|
253
253
|
match_str
|
254
254
|
end
|
255
255
|
end
|
@@ -270,17 +270,17 @@ module Terminal
|
|
270
270
|
def plain(str)
|
271
271
|
str = str.to_s
|
272
272
|
unless str.index('[')
|
273
|
-
return str.index("\e") ? str.gsub(
|
273
|
+
return str.index("\e") ? str.gsub(@re_test, '') : str.dup
|
274
274
|
end
|
275
275
|
str =
|
276
|
-
str.gsub(
|
276
|
+
str.gsub(@re_bbcode) do |match_str|
|
277
277
|
match = Regexp.last_match(1) or next match_str
|
278
278
|
next "[#{match[1..]}]" if match[0] == '\\'
|
279
279
|
next match_str if (match = match.split).empty?
|
280
|
-
next if match.all? {
|
280
|
+
next if match.all? { @attr[_1] || @colors[_1] || _color(_1) }
|
281
281
|
match_str
|
282
282
|
end
|
283
|
-
str.index("\e") ? str.gsub!(
|
283
|
+
str.index("\e") ? str.gsub!(@re_test, '') : str
|
284
284
|
end
|
285
285
|
|
286
286
|
# Create nice colored text.
|
@@ -292,14 +292,16 @@ module Terminal
|
|
292
292
|
# @return [String] fancy text
|
293
293
|
def rainbow(str, frequency: 0.3, spread: 0.8, seed: 1.1)
|
294
294
|
pos = -1
|
295
|
+
@pi2_third ||= 2.0 * Math::PI / 3.0
|
296
|
+
@pi4_third ||= 4.0 * Math::PI / 3.0
|
295
297
|
str
|
296
298
|
.to_s
|
297
299
|
.chars
|
298
300
|
.map! do |char|
|
299
301
|
i = (seed + ((pos += 1) / spread)) * frequency
|
300
302
|
"\e[38;2;#{(Math.sin(i) * 255).to_i.abs};" \
|
301
|
-
"#{(Math.sin(i +
|
302
|
-
"#{(Math.sin(i +
|
303
|
+
"#{(Math.sin(i + @pi2_third) * 255).to_i.abs};" \
|
304
|
+
"#{(Math.sin(i + @pi4_third) * 255).to_i.abs}m#{char}"
|
303
305
|
end
|
304
306
|
.join << RESET
|
305
307
|
end
|
@@ -533,7 +535,7 @@ module Terminal
|
|
533
535
|
opts << 'v=0'
|
534
536
|
when 1, :bottom
|
535
537
|
opts << 'v=1'
|
536
|
-
when 2, :centered
|
538
|
+
when 2, :centered
|
537
539
|
opts << 'v=2'
|
538
540
|
end
|
539
541
|
case horizontal
|
@@ -541,7 +543,7 @@ module Terminal
|
|
541
543
|
opts << 'h=0'
|
542
544
|
when 1, :right
|
543
545
|
opts << 'h=1'
|
544
|
-
when 2, :centered
|
546
|
+
when 2, :centered
|
545
547
|
opts << 'h=2'
|
546
548
|
end
|
547
549
|
end
|
@@ -568,39 +570,34 @@ module Terminal
|
|
568
570
|
return(
|
569
571
|
case v.size
|
570
572
|
when 1, 2
|
571
|
-
"#{
|
573
|
+
"#{@cbase[b]};5;#{v.hex}"
|
572
574
|
when 3
|
573
|
-
"#{
|
575
|
+
"#{@cbase[b]};2;#{(v[0] * 2).hex};#{
|
574
576
|
(v[1] * 2).hex
|
575
577
|
};#{(v[2] * 2).hex}"
|
576
578
|
when 6
|
577
|
-
"#{
|
579
|
+
"#{@cbase[b]};2;#{v[0, 2].hex};#{v[2, 2].hex};#{v[4, 2].hex}"
|
578
580
|
end
|
579
581
|
)
|
580
582
|
end
|
581
583
|
b, v = /\A(fg|bg|on|ul)?_?([a-z]{3,}[0-9]{0,3})\z/.match(str)&.captures
|
582
584
|
return unless v
|
583
|
-
name = NAMED_COLORS[v] and return "#{
|
585
|
+
name = NAMED_COLORS[v] and return "#{@cbase[b]};#{name}"
|
584
586
|
end
|
585
587
|
end
|
586
588
|
|
587
|
-
|
589
|
+
@cbase =
|
588
590
|
{ 'bg' => '48', 'on' => '48', 'ul' => '58' }.tap { _1.default = '38' }
|
589
591
|
.freeze
|
590
592
|
|
591
|
-
|
593
|
+
@re_test =
|
592
594
|
/
|
593
595
|
(?:\e\[[\d;:\?]*[ABCDEFGHJKSTfminsuhl])
|
594
596
|
|
|
595
597
|
(?:\e\]\d+(?:;[^\a\e]+)*(?:\a|\e\\))
|
596
598
|
/x
|
597
599
|
|
598
|
-
|
599
|
-
|
600
|
-
PI2_THIRD = 2.0 * Math::PI / 3.0
|
601
|
-
PI4_THIRD = 4.0 * Math::PI / 3.0
|
602
|
-
|
603
|
-
private_constant :COLOR_BASE, :TEST, :BBCODE, :PI2_THIRD, :PI4_THIRD
|
600
|
+
@re_bbcode = /(?:\[((?~[\[\]]))\])/
|
604
601
|
|
605
602
|
require_relative 'ansi/attributes'
|
606
603
|
|
@@ -706,15 +703,7 @@ module Terminal
|
|
706
703
|
# "\eM" reverse "\n"
|
707
704
|
# "\e[6n" report Cursor Position as "ESC \[ row ; col R"
|
708
705
|
# "\e[21t report window’s title as ESC ] l title ESC \"
|
709
|
-
# "\e[?
|
710
|
-
#
|
711
|
-
# 1000: VT200_MOUSE
|
712
|
-
# 1002: BTN_EVENT_MOUSE
|
713
|
-
# 1003: ANY_EVENT_MOUSE
|
714
|
-
# 1004: FOCUS_EVENT_MOUSE
|
715
|
-
# 1005: Xterm’s UTF8
|
716
|
-
# 1006: Xterm’s CSI-style
|
717
|
-
# 1015: Urxvt’s CSI-style
|
718
|
-
# "\e[?Xl" reset mouse mode "X"
|
706
|
+
# "\e[?1004h" report focus lost "\e[O" and focus get "\e[I"
|
707
|
+
# (disable by "\e[?1004l")
|
719
708
|
end
|
720
709
|
end
|
data/lib/terminal/detect.rb
CHANGED
@@ -11,9 +11,6 @@ module Terminal
|
|
11
11
|
|
12
12
|
def colors
|
13
13
|
return 16_777_216 if ENV['COLORTERM'] == 'truecolor'
|
14
|
-
if %i[ghostty iterm kitty rio vscode wezterm tabby].include?(app_by_tp)
|
15
|
-
return 16_777_216
|
16
|
-
end
|
17
14
|
term = ENV['TERM'] or return 8
|
18
15
|
return 16_777_216 if /[+-]direct/.match?(term)
|
19
16
|
match = /[-+](\d+)color/.match(term) and return match[1].to_i
|
@@ -32,24 +29,27 @@ module Terminal
|
|
32
29
|
private
|
33
30
|
|
34
31
|
def app_by_tp
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
32
|
+
tp = ENV['TERM_PROGRAM']
|
33
|
+
return if tp.nil? || (tp = tp.strip).empty?
|
34
|
+
case tp
|
35
|
+
when 'Apple_Terminal'
|
36
|
+
:macos
|
37
|
+
when 'CodeEditApp_Terminal'
|
38
|
+
:code_edit
|
39
|
+
when 'docker_desktop'
|
40
|
+
:docker
|
41
|
+
when 'FluentTerminal'
|
42
|
+
:fluent
|
43
|
+
when 'HyperTerm'
|
44
|
+
:hyper
|
45
|
+
when 'iTerm.app'
|
46
|
+
:iterm
|
47
|
+
when 'WarpTerminal'
|
48
|
+
:warp
|
49
|
+
else
|
50
|
+
tp = tp.tr(' \\/?!', '_').downcase
|
51
|
+
tp.empty? ? nil : tp.to_sym
|
52
|
+
end
|
53
53
|
end
|
54
54
|
|
55
55
|
def app_by_term
|
@@ -0,0 +1,317 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Terminal
|
4
|
+
module AsKeyEvent
|
5
|
+
class << self
|
6
|
+
def [](raw)
|
7
|
+
return KeyEvent.new(raw, *@single_key[raw.ord]) if raw.size == 1
|
8
|
+
return KeyEvent.unknown(raw) if raw[0] != "\e"
|
9
|
+
return esc1(raw, raw[1]) if raw.size == 2 # ESC ?
|
10
|
+
case raw[1]
|
11
|
+
when "\e" # ESC ESC ...
|
12
|
+
return esc_esc(raw)
|
13
|
+
when 'O'
|
14
|
+
if raw.size == 3
|
15
|
+
# ESC O ?
|
16
|
+
return KeyEvent.new(raw, *@ss3[raw[2].ord])
|
17
|
+
end
|
18
|
+
when '[' # ESC [ ...
|
19
|
+
if raw.size == 3
|
20
|
+
# ESC [ ?
|
21
|
+
return KeyEvent.new(raw, *@ss3[raw[2].ord])
|
22
|
+
end
|
23
|
+
if raw.size == 6 && raw[2] == 'M'
|
24
|
+
# ESC [ M b c r
|
25
|
+
return mouse_vt200(raw)
|
26
|
+
end
|
27
|
+
return csi1(raw) if raw.start_with?("\e[1;") # ESC [ 1 ; ...
|
28
|
+
case raw[-1]
|
29
|
+
when '~'
|
30
|
+
return legacy(raw)
|
31
|
+
when 'u'
|
32
|
+
return csi_u(raw)
|
33
|
+
when 'M'
|
34
|
+
return raw[2] == '<' ? mouse_sgr(raw) : mouse_urxvt(raw)
|
35
|
+
when 'm'
|
36
|
+
return mouse_sgr(raw) if raw[2] == '<'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
KeyEvent.unknown(raw)
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def mouse_vt200(raw)
|
45
|
+
# ESC [ M b c r
|
46
|
+
mouse_event(raw, *raw[3..].chars.map! { _1.ord - 32 })
|
47
|
+
end
|
48
|
+
|
49
|
+
def mouse_sgr(raw)
|
50
|
+
# ESC [ < <code> ; <col> ; <row> M
|
51
|
+
# ESC [ < <code> ; <col> ; <row> m
|
52
|
+
return KeyEvent.unknown(raw) if raw.size < 8
|
53
|
+
bcr = raw[3..-2].split(';', 3).map!(&:to_i)
|
54
|
+
bcr.size == 3 ? mouse_event(raw, *bcr) : KeyEvent.unknown(raw)
|
55
|
+
end
|
56
|
+
|
57
|
+
def mouse_urxvt(raw)
|
58
|
+
# ESC [ <code> ; <col> ; <row> M
|
59
|
+
return KeyEvent.unknown(raw) if raw.size < 8
|
60
|
+
bcr = raw[2..-2].split(';', 3).map!(&:to_i)
|
61
|
+
bcr.size == 3 ? mouse_event(raw, *bcr) : KeyEvent.unknown(raw)
|
62
|
+
end
|
63
|
+
|
64
|
+
def mouse_event(raw, btn, col, row)
|
65
|
+
return KeyEvent.unknown(raw) if btn < 0 || col < 1 || row < 1
|
66
|
+
kind = btn & 3
|
67
|
+
ka = btn >= 64 ? @mouse_wheel_kind : @mouse_kind
|
68
|
+
btn -= kind
|
69
|
+
modifier = btn.allbits?(4) ? 1 : 0
|
70
|
+
modifier += 2 if btn.allbits?(8)
|
71
|
+
modifier += 4 if btn.allbits?(16)
|
72
|
+
KeyEvent.new(raw, ka[kind], modifier, [col, row])
|
73
|
+
end
|
74
|
+
|
75
|
+
def csi_u(raw)
|
76
|
+
# ESC [ <code> u
|
77
|
+
# ESC [ <code> ; <modifier> u
|
78
|
+
return KeyEvent.unknown(raw) if raw.size < 4
|
79
|
+
idx = raw.index(';')
|
80
|
+
code = raw[2..(idx ? idx - 1 : -2)].to_i
|
81
|
+
KeyEvent.new(
|
82
|
+
raw,
|
83
|
+
@csiu[code] || code.chr(Encoding::UTF_8),
|
84
|
+
idx ? [raw[(idx + 1)..-2].to_i - 1, 0].max : 0
|
85
|
+
)
|
86
|
+
end
|
87
|
+
|
88
|
+
def legacy(raw)
|
89
|
+
# ESC [ <code> ~
|
90
|
+
# ESC [ <code> ; <modifier> ~
|
91
|
+
return KeyEvent.unknown(raw) if raw.size < 4
|
92
|
+
idx = raw.index(';')
|
93
|
+
KeyEvent.new(
|
94
|
+
raw,
|
95
|
+
@csi[raw[2..(idx ? idx - 1 : -2)].to_i],
|
96
|
+
idx ? [raw[(idx + 1)..-2].to_i - 1, 0].max : 0
|
97
|
+
)
|
98
|
+
end
|
99
|
+
|
100
|
+
def csi1(raw)
|
101
|
+
# ESC [ 1 ; [~ABCDEFHPQRS]
|
102
|
+
# ESC [ 1 ; <modifier> [~ABCDEFHPQRS]
|
103
|
+
return KeyEvent.unknown(raw) if raw.size < 5
|
104
|
+
key, modifier = @ss3[raw[-1].ord]
|
105
|
+
modifier ||= 0
|
106
|
+
return KeyEvent.new(raw, nil, modifier) unless key
|
107
|
+
modifier |= [raw[4..-2].to_i - 1, 0].max if raw.size > 5
|
108
|
+
KeyEvent.new(raw, key, modifier)
|
109
|
+
end
|
110
|
+
|
111
|
+
def esc_esc(raw)
|
112
|
+
return esc1(raw, raw[2]) if raw.size == 3 # ESC ESC ?
|
113
|
+
ret = self[raw[1..]]
|
114
|
+
KeyEvent.new(raw, ret.key, ret.modifier | 2) # ESC ESC ...
|
115
|
+
end
|
116
|
+
|
117
|
+
def esc1(raw, char)
|
118
|
+
key, modifier = @esc1[char.ord]
|
119
|
+
KeyEvent.new(raw, key || char, modifier || 2)
|
120
|
+
end
|
121
|
+
end
|
122
|
+
|
123
|
+
@mouse_kind = %i[
|
124
|
+
MButton1
|
125
|
+
MButton2
|
126
|
+
MButton3
|
127
|
+
MButtonUp
|
128
|
+
MButton4
|
129
|
+
MButton5
|
130
|
+
].freeze
|
131
|
+
|
132
|
+
@mouse_wheel_kind = %i[MWheelDown MWheelUp MWheelRight MWheelLeft].freeze
|
133
|
+
|
134
|
+
@csiu = {
|
135
|
+
0x02 => :Ins,
|
136
|
+
0x09 => :Tab,
|
137
|
+
0x0d => :Enter,
|
138
|
+
0x1b => :Esc,
|
139
|
+
0x20 => :Space,
|
140
|
+
0x7f => :Back,
|
141
|
+
57_376 => :F13,
|
142
|
+
57_377 => :F14,
|
143
|
+
57_378 => :F15,
|
144
|
+
57_379 => :F16,
|
145
|
+
57_380 => :F17,
|
146
|
+
57_381 => :F18,
|
147
|
+
57_382 => :F19,
|
148
|
+
57_383 => :F20,
|
149
|
+
57_384 => :F21,
|
150
|
+
57_385 => :F22,
|
151
|
+
57_386 => :F23,
|
152
|
+
57_387 => :F24,
|
153
|
+
57_388 => :F25,
|
154
|
+
57_389 => :F26,
|
155
|
+
57_390 => :F27,
|
156
|
+
57_391 => :F28,
|
157
|
+
57_392 => :F29,
|
158
|
+
57_393 => :F30,
|
159
|
+
57_394 => :F31,
|
160
|
+
57_395 => :F32,
|
161
|
+
57_396 => :F33,
|
162
|
+
57_397 => :F34,
|
163
|
+
57_398 => :F35,
|
164
|
+
57_399 => :Kp0,
|
165
|
+
57_400 => :Kp1,
|
166
|
+
57_401 => :Kp2,
|
167
|
+
57_402 => :Kp3,
|
168
|
+
57_403 => :Kp4,
|
169
|
+
57_404 => :Kp5,
|
170
|
+
57_405 => :Kp6,
|
171
|
+
57_406 => :Kp7,
|
172
|
+
57_407 => :Kp8,
|
173
|
+
57_408 => :Kp9,
|
174
|
+
57_409 => :KpDecimal,
|
175
|
+
57_410 => :KpDivide,
|
176
|
+
57_411 => :KpMultiply,
|
177
|
+
57_412 => :KpSubtract,
|
178
|
+
57_413 => :KpAdd,
|
179
|
+
57_414 => :Return, # :KpEnter
|
180
|
+
57_415 => :KpEqual,
|
181
|
+
57_416 => :KpSeparator,
|
182
|
+
57_417 => :KpLeft,
|
183
|
+
57_418 => :KpRight,
|
184
|
+
57_419 => :KpUp,
|
185
|
+
57_420 => :KpDown,
|
186
|
+
57_421 => :KpPageUp,
|
187
|
+
57_422 => :KpPageDown,
|
188
|
+
57_423 => :KpHome,
|
189
|
+
57_424 => :KpEnd,
|
190
|
+
57_425 => :KpInsert,
|
191
|
+
57_426 => :KpDelete,
|
192
|
+
57_428 => :MediaPlay,
|
193
|
+
57_429 => :MediaPause,
|
194
|
+
57_430 => :MediaPlayPause,
|
195
|
+
57_431 => :MediaReverse,
|
196
|
+
57_432 => :MediaStop,
|
197
|
+
57_433 => :MediaFastForward,
|
198
|
+
57_434 => :MediaRewind,
|
199
|
+
57_435 => :MediaTrackNext,
|
200
|
+
57_436 => :MediaTrackPrevious,
|
201
|
+
57_437 => :MediaRecord,
|
202
|
+
57_438 => :LowerVolume,
|
203
|
+
57_439 => :RaiseVolume,
|
204
|
+
57_440 => :MuteVolume,
|
205
|
+
57_441 => :LeftShift,
|
206
|
+
57_442 => :LeftControl,
|
207
|
+
57_443 => :LeftAlt,
|
208
|
+
57_444 => :LeftSuper,
|
209
|
+
57_445 => :LeftHyper,
|
210
|
+
57_446 => :LeftMeta,
|
211
|
+
57_447 => :RightShift,
|
212
|
+
57_448 => :RightControl,
|
213
|
+
57_449 => :RightAlt,
|
214
|
+
57_450 => :RightSuper,
|
215
|
+
57_451 => :RightHyper,
|
216
|
+
57_452 => :RightMeta,
|
217
|
+
57_453 => :IsoLevel3Shift,
|
218
|
+
57_454 => :IsoLevel5Shift
|
219
|
+
}.compare_by_identity.freeze
|
220
|
+
|
221
|
+
@csi = {
|
222
|
+
0x02 => :Ins,
|
223
|
+
0x03 => :Del,
|
224
|
+
0x05 => :PageUp,
|
225
|
+
0x06 => :PageDown,
|
226
|
+
0x07 => :Home,
|
227
|
+
0x08 => :End,
|
228
|
+
0x09 => :Tab,
|
229
|
+
0x0b => :F1,
|
230
|
+
0x0c => :F2,
|
231
|
+
0x0d => :F3,
|
232
|
+
0x0e => :F4,
|
233
|
+
0x0f => :F5,
|
234
|
+
0x11 => :F6,
|
235
|
+
0x12 => :F7,
|
236
|
+
0x13 => :F8,
|
237
|
+
0x14 => :F9,
|
238
|
+
0x15 => :F10,
|
239
|
+
0x17 => :F11,
|
240
|
+
0x18 => :F12,
|
241
|
+
0x19 => :F13,
|
242
|
+
0x1a => :F14,
|
243
|
+
0x1b => :F15,
|
244
|
+
0x1c => :F16,
|
245
|
+
0x1d => :F17,
|
246
|
+
0x1e => :F18,
|
247
|
+
0x1f => :F19,
|
248
|
+
0x20 => :F20,
|
249
|
+
0x21 => :F21,
|
250
|
+
0x22 => :F22,
|
251
|
+
0x23 => :F23,
|
252
|
+
0x24 => :F24
|
253
|
+
}.compare_by_identity.freeze
|
254
|
+
|
255
|
+
@ss3 = {
|
256
|
+
0x41 => :Up, # A
|
257
|
+
0x42 => :Down, # B
|
258
|
+
0x43 => :Right, # C
|
259
|
+
0x44 => :Left, # D
|
260
|
+
0x46 => :End, # F
|
261
|
+
0x48 => :Home, # H
|
262
|
+
0x50 => :F1, # P
|
263
|
+
0x51 => :F2, # Q
|
264
|
+
0x52 => :F3, # R
|
265
|
+
0x53 => :F4, # S
|
266
|
+
0x5a => [:Tab, 1] # Z - not widely used
|
267
|
+
}.compare_by_identity.freeze
|
268
|
+
|
269
|
+
@esc1 = {
|
270
|
+
0x08 => [:Back, 2],
|
271
|
+
0x09 => [:Tab, 2],
|
272
|
+
0x10 => ['?', 6],
|
273
|
+
0x0d => [:Enter, 2],
|
274
|
+
0x1b => [:Esc, 2],
|
275
|
+
0x20 => [:Space, 2],
|
276
|
+
0x7f => [:Back, 2]
|
277
|
+
}.compare_by_identity.freeze
|
278
|
+
|
279
|
+
@single_key = {
|
280
|
+
0x00 => [:Space, 4],
|
281
|
+
0x01 => ['a', 4],
|
282
|
+
0x02 => ['b', 4],
|
283
|
+
0x03 => ['c', 4],
|
284
|
+
0x04 => ['d', 4],
|
285
|
+
0x05 => ['e', 4],
|
286
|
+
0x06 => ['f', 4],
|
287
|
+
0x07 => ['g', 4],
|
288
|
+
0x08 => [:Back, 4],
|
289
|
+
0x09 => :Tab,
|
290
|
+
0x0a => ['j', 4],
|
291
|
+
0x0b => ['k', 4],
|
292
|
+
0x0c => ['l', 4],
|
293
|
+
0x0d => :Enter,
|
294
|
+
0x0e => ['n', 4],
|
295
|
+
0x0f => ['o', 4],
|
296
|
+
0x10 => ['p', 4],
|
297
|
+
0x11 => ['q', 4],
|
298
|
+
0x12 => ['r', 4],
|
299
|
+
0x13 => ['s', 4],
|
300
|
+
0x14 => ['t', 4],
|
301
|
+
0x15 => ['u', 4],
|
302
|
+
0x16 => ['v', 4],
|
303
|
+
0x17 => ['w', 4],
|
304
|
+
0x18 => ['x', 4],
|
305
|
+
0x19 => ['y', 4],
|
306
|
+
0x1a => ['z', 4],
|
307
|
+
0x1b => :Esc,
|
308
|
+
0x1c => ['4', 4],
|
309
|
+
0x1d => ['5', 4],
|
310
|
+
0x1e => ['6', 4],
|
311
|
+
0x1f => ['7', 4],
|
312
|
+
0x20 => :Space,
|
313
|
+
0x7f => :Back
|
314
|
+
}.compare_by_identity.freeze
|
315
|
+
end
|
316
|
+
private_constant :AsKeyEvent
|
317
|
+
end
|