terminal_rb 0.16.1 → 0.16.2
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/lib/terminal/input.rb +19 -28
- data/lib/terminal/rspec/helper.rb +7 -0
- data/lib/terminal/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c1c85e6d14f19a36f2efd995aa90b962ef24deaedeacd6ba5ba0392ae7d87f54
|
|
4
|
+
data.tar.gz: 99a8c94cbb3b79386fb1725378f4f7cfc6e97e1e4b93978cf6e67d0a1d0720a0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4d257376892920c46bd96c60a475953d169409552db6fc75a3e0f5f0613b34fe5bc3a2e18d77c53d05cf2670f0b81a02ba4ce237d83fb4c3299826d1c3e7cce8
|
|
7
|
+
data.tar.gz: 353f4ed0f0da7ad39ce7413335e31d89264e0587e12c450d6028c8fbfc5c30c986136e0babac12a146176d44c810aabdb403b52a13389a3900256f53cd5b96d8
|
data/lib/terminal/input.rb
CHANGED
|
@@ -85,7 +85,7 @@ module Terminal
|
|
|
85
85
|
on_bumb_key_event(&block)
|
|
86
86
|
true
|
|
87
87
|
when :csi_u, :legacy
|
|
88
|
-
on_tty_key_event(mouse, mouse_move, focus, &block)
|
|
88
|
+
on_tty_key_event(mouse_option(mouse, mouse_move, focus), &block)
|
|
89
89
|
true
|
|
90
90
|
else
|
|
91
91
|
false
|
|
@@ -94,36 +94,30 @@ module Terminal
|
|
|
94
94
|
|
|
95
95
|
private
|
|
96
96
|
|
|
97
|
-
def
|
|
97
|
+
def mouse_option(mouse, mouse_move, focus)
|
|
98
|
+
opts = +(mouse ? '1000' : '')
|
|
98
99
|
# highlight: '1001'
|
|
99
100
|
# drag: '1002'
|
|
100
|
-
|
|
101
|
-
|
|
101
|
+
opts << ';1003' if mouse_move
|
|
102
|
+
opts << ';1004' if focus
|
|
102
103
|
# ext: '1005'
|
|
103
104
|
# sgr: '1006'
|
|
104
105
|
# urxvt: '1015'
|
|
105
106
|
# pixel: '1016'
|
|
106
|
-
opts
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
opts << ';1004' if focus
|
|
111
|
-
raw_write("#{opts}h") ? "#{opts}l" : nil
|
|
112
|
-
end
|
|
107
|
+
"\e[?#{opts};1006" unless opts.empty?
|
|
108
|
+
end
|
|
109
|
+
|
|
110
|
+
def on_tty_key_event(opts)
|
|
113
111
|
STDIN.noecho do |stdin|
|
|
112
|
+
opts = raw_write("#{opts}h") ? "#{opts}l" : nil
|
|
114
113
|
while (raw = stdin.getch)
|
|
115
|
-
if raw != "\e"
|
|
116
|
-
yield(KeyEvent[raw]) ? next : break
|
|
117
|
-
end
|
|
114
|
+
(yield(KeyEvent[raw]) ? next : break) if raw != "\e"
|
|
118
115
|
lesci = 0
|
|
119
|
-
while (nc = stdin.read_nonblock(1, exception: false))
|
|
120
|
-
break unless String === nc
|
|
116
|
+
while String === (nc = stdin.read_nonblock(1, exception: false))
|
|
121
117
|
lesci = raw.size if nc == "\e"
|
|
122
118
|
raw << nc
|
|
123
119
|
end
|
|
124
|
-
if lesci < 2
|
|
125
|
-
yield(KeyEvent[raw]) ? next : break
|
|
126
|
-
end
|
|
120
|
+
(yield(KeyEvent[raw]) ? next : break) if lesci < 2
|
|
127
121
|
break unless raw[1..].split("\e").all? { yield(KeyEvent["\e#{_1}"]) }
|
|
128
122
|
end
|
|
129
123
|
end
|
|
@@ -147,16 +141,13 @@ module Terminal
|
|
|
147
141
|
return :legacy if im == 'legacy'
|
|
148
142
|
return :dumb if im == 'dumb' || !STDIN.tty?
|
|
149
143
|
STDIN.noecho do |stdin|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
end
|
|
157
|
-
end
|
|
144
|
+
return :legacy unless raw_write("\e[>1u\e[?u\e[c")
|
|
145
|
+
inp = +''
|
|
146
|
+
inp << stdin.getch until inp.rindex('c')
|
|
147
|
+
return :legacy unless inp.include?("\e[?1u")
|
|
148
|
+
at_exit { raw_write("\e[<u") }
|
|
149
|
+
:csi_u
|
|
158
150
|
end
|
|
159
|
-
:legacy
|
|
160
151
|
rescue Interrupt
|
|
161
152
|
:legacy
|
|
162
153
|
rescue IOError, SystemCallError
|
|
@@ -61,5 +61,12 @@ RSpec.shared_context 'with Terminal.rb' do |ansi: true, application: :kitty, col
|
|
|
61
61
|
allow(Terminal).to receive(:read_key_event) do
|
|
62
62
|
Terminal::KeyEvent[stdin.shift || raise('stdin buffer is empty')]
|
|
63
63
|
end
|
|
64
|
+
|
|
65
|
+
allow(Terminal).to receive(:on_key_event) do |&b|
|
|
66
|
+
while true
|
|
67
|
+
ev = Terminal::KeyEvent[stdin.shift || raise('stdin buffer is empty')]
|
|
68
|
+
b[ev] or break
|
|
69
|
+
end
|
|
70
|
+
end
|
|
64
71
|
end
|
|
65
72
|
end
|
data/lib/terminal/version.rb
CHANGED