rcurses 3.6.3 → 3.7
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/rcurses/input.rb +99 -144
- data/lib/rcurses.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 455f228b29c7de53d5b6107f084a6b0fe5e28fc73d812ac3d43849ac36df9b7f
|
4
|
+
data.tar.gz: 0d9bbddcc7b69ffeb9e8c72a7a356a47c0dfae3672a67e0e68e83366790ad11c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 050ee4bcb007baa1a2e823acecb4435795ef0f95c5d9c33e9a17c1008d4a4016c003efecf155571c52dc1c8152a1cb4a3123896e8273c1d12de0c56c9b1c26b8
|
7
|
+
data.tar.gz: f5fe2c215b8d8be9f4d7e49be568e22d89b0be7c97daee9e0fdba26a77e33515596786f659f699b9a6dda6c47d8be9db7db00c34df557b35e8a15d4f99845530
|
data/lib/rcurses/input.rb
CHANGED
@@ -1,160 +1,115 @@
|
|
1
1
|
module Rcurses
|
2
2
|
module Input
|
3
3
|
def getchr(t = nil)
|
4
|
+
# 1) Read a byte (with optional timeout)
|
4
5
|
begin
|
5
|
-
# If a timeout is provided, wrap the blocking getch call in Timeout.timeout.
|
6
6
|
c = t ? Timeout.timeout(t) { $stdin.getch } : $stdin.getch
|
7
7
|
rescue Timeout::Error
|
8
8
|
return nil
|
9
9
|
end
|
10
10
|
|
11
|
-
#
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
second_char = $stdin.getc
|
19
|
-
case second_char
|
20
|
-
when '[' # CSI
|
21
|
-
third_char = $stdin.getc
|
22
|
-
case third_char
|
23
|
-
when 'A' then chr = "UP"
|
24
|
-
when 'a' then chr = "S-UP"
|
25
|
-
when 'B' then chr = "DOWN"
|
26
|
-
when 'b' then chr = "S-DOWN"
|
27
|
-
when 'C' then chr = "RIGHT"
|
28
|
-
when 'c' then chr = "S-RIGHT"
|
29
|
-
when 'D' then chr = "LEFT"
|
30
|
-
when 'd' then chr = "S-LEFT"
|
31
|
-
when 'Z' then chr = "S-TAB"
|
32
|
-
when '1'
|
33
|
-
fourth_char = $stdin.getc
|
34
|
-
case fourth_char
|
35
|
-
when '1'
|
36
|
-
fifth_char = $stdin.getc
|
37
|
-
chr = fifth_char == '~' ? "F1" : ""
|
38
|
-
when '2'
|
39
|
-
fifth_char = $stdin.getc
|
40
|
-
chr = fifth_char == '~' ? "F2" : ""
|
41
|
-
when '3'
|
42
|
-
fifth_char = $stdin.getc
|
43
|
-
chr = fifth_char == '~' ? "F3" : ""
|
44
|
-
when '4'
|
45
|
-
fifth_char = $stdin.getc
|
46
|
-
chr = fifth_char == '~' ? "F4" : ""
|
47
|
-
when '5'
|
48
|
-
fifth_char = $stdin.getc
|
49
|
-
chr = fifth_char == '~' ? "F5" : ""
|
50
|
-
when '7'
|
51
|
-
fifth_char = $stdin.getc
|
52
|
-
chr = fifth_char == '~' ? "F6" : ""
|
53
|
-
when '8'
|
54
|
-
fifth_char = $stdin.getc
|
55
|
-
chr = fifth_char == '~' ? "F7" : ""
|
56
|
-
when '9'
|
57
|
-
fifth_char = $stdin.getc
|
58
|
-
chr = fifth_char == '~' ? "F8" : ""
|
59
|
-
end
|
60
|
-
when '2'
|
61
|
-
fourth_char = $stdin.getc
|
62
|
-
case fourth_char
|
63
|
-
when '~' then chr = "INS"
|
64
|
-
when '0'
|
65
|
-
fifth_char = $stdin.getc
|
66
|
-
chr = fifth_char == '~' ? "F9" : ""
|
67
|
-
when '1'
|
68
|
-
fifth_char = $stdin.getc
|
69
|
-
chr = fifth_char == '~' ? "F10" : ""
|
70
|
-
when '3'
|
71
|
-
fifth_char = $stdin.getc
|
72
|
-
chr = fifth_char == '~' ? "F11" : ""
|
73
|
-
when '4'
|
74
|
-
fifth_char = $stdin.getc
|
75
|
-
chr = fifth_char == '~' ? "F12" : ""
|
76
|
-
else chr = ""
|
77
|
-
end
|
78
|
-
when '3'
|
79
|
-
fourth_char = $stdin.getc
|
80
|
-
chr = fourth_char == '~' ? "DEL" : ""
|
81
|
-
when '5'
|
82
|
-
fourth_char = $stdin.getc
|
83
|
-
case fourth_char
|
84
|
-
when '~' then chr = "PgUP"
|
85
|
-
when '^' then chr = "C-PgUP"
|
86
|
-
else chr = ""
|
87
|
-
end
|
88
|
-
when '6'
|
89
|
-
fourth_char = $stdin.getc
|
90
|
-
case fourth_char
|
91
|
-
when '~' then chr = "PgDOWN"
|
92
|
-
when '^' then chr = "C-PgDOWN"
|
93
|
-
else chr = ""
|
94
|
-
end
|
95
|
-
when '1', '7'
|
96
|
-
fourth_char = $stdin.getc
|
97
|
-
case fourth_char
|
98
|
-
when '~' then chr = "HOME"
|
99
|
-
when '^' then chr = "C-HOME"
|
100
|
-
else chr = ""
|
101
|
-
end
|
102
|
-
when '4', '8'
|
103
|
-
fourth_char = $stdin.getc
|
104
|
-
case fourth_char
|
105
|
-
when '~' then chr = "END"
|
106
|
-
when '^' then chr = "C-END"
|
107
|
-
else chr = ""
|
108
|
-
end
|
109
|
-
else
|
110
|
-
chr = ""
|
111
|
-
end
|
112
|
-
when 'O' # Function keys
|
113
|
-
third_char = $stdin.getc
|
114
|
-
case third_char
|
115
|
-
when 'a' then chr = "C-UP"
|
116
|
-
when 'b' then chr = "C-DOWN"
|
117
|
-
when 'c' then chr = "C-RIGHT"
|
118
|
-
when 'd' then chr = "C-LEFT"
|
119
|
-
else chr = ""
|
11
|
+
# 2) If it's ESC, grab any quick trailing bytes
|
12
|
+
seq = c
|
13
|
+
if c == "\e"
|
14
|
+
if IO.select([$stdin], nil, nil, 0.05)
|
15
|
+
begin
|
16
|
+
seq << $stdin.read_nonblock(1024)
|
17
|
+
rescue IO::WaitReadable, EOFError
|
120
18
|
end
|
121
|
-
else
|
122
|
-
chr = ""
|
123
19
|
end
|
124
|
-
# Treat both "\r" and "\n" as Enter
|
125
|
-
when "\r", "\n" then chr = "ENTER"
|
126
|
-
when "\t" then chr = "TAB"
|
127
|
-
when "\u007F", "\b" then chr = "BACK"
|
128
|
-
when "\u0000" then chr = "C-SPACE"
|
129
|
-
when "\u0001" then chr = "C-A"
|
130
|
-
when "\u0002" then chr = "C-B"
|
131
|
-
when "\u0003" then chr = "C-C"
|
132
|
-
when "\u0004" then chr = "C-D"
|
133
|
-
when "\u0005" then chr = "C-E"
|
134
|
-
when "\u0006" then chr = "C-F"
|
135
|
-
when "\u0007" then chr = "C-G"
|
136
|
-
when "\u0008" then chr = "C-H"
|
137
|
-
when "\u000B" then chr = "C-K"
|
138
|
-
when "\u000C" then chr = "C-L"
|
139
|
-
when "\u000D" then chr = "C-M"
|
140
|
-
when "\u000E" then chr = "C-N"
|
141
|
-
when "\u000F" then chr = "C-O"
|
142
|
-
when "\u0010" then chr = "C-P"
|
143
|
-
when "\u0011" then chr = "C-Q"
|
144
|
-
when "\u0012" then chr = "C-R"
|
145
|
-
when "\u0013" then chr = "C-S"
|
146
|
-
when "\u0014" then chr = "C-T"
|
147
|
-
when "\u0015" then chr = "C-U"
|
148
|
-
when "\u0016" then chr = "C-V"
|
149
|
-
when "\u0018" then chr = "C-X"
|
150
|
-
when "\u0019" then chr = "C-Y"
|
151
|
-
when "\u001A" then chr = "C-Z"
|
152
|
-
when "\u0017" then chr = "WBACK" # C-W
|
153
|
-
when /[[:print:]]/ then chr = c
|
154
|
-
else chr = ""
|
155
20
|
end
|
156
21
|
|
157
|
-
|
22
|
+
# 3) Single ESC alone
|
23
|
+
return "ESC" if seq == "\e"
|
24
|
+
|
25
|
+
# 4) ShiftâTAB
|
26
|
+
return "S-TAB" if seq == "\e[Z"
|
27
|
+
|
28
|
+
# 5) Legacy singleâchar shiftâarrows (your old working ones)
|
29
|
+
case seq
|
30
|
+
when "\e[a" then return "S-UP"
|
31
|
+
when "\e[b" then return "S-DOWN"
|
32
|
+
when "\e[c" then return "S-RIGHT"
|
33
|
+
when "\e[d" then return "S-LEFT"
|
34
|
+
end
|
35
|
+
|
36
|
+
# 6) CSI style shiftâarrows (e.g. ESC [1;2A )
|
37
|
+
if m = seq.match(/\A\e\[\d+;2([ABCD])\z/)
|
38
|
+
return { 'A' => "S-UP", 'B' => "S-DOWN", 'C' => "S-RIGHT", 'D' => "S-LEFT" }[m[1]]
|
39
|
+
end
|
40
|
+
|
41
|
+
# 7) Plain arrows
|
42
|
+
if m = seq.match(/\A\e\[([ABCD])\z/)
|
43
|
+
return { 'A' => "UP", 'B' => "DOWN", 'C' => "RIGHT", 'D' => "LEFT" }[m[1]]
|
44
|
+
end
|
45
|
+
|
46
|
+
# 8) CSI + '~' sequences (Ins, Del, Home, End, PgUp, PgDn, F5-F12)
|
47
|
+
if seq.start_with?("\e[") && seq.end_with?("~")
|
48
|
+
num = seq[/\d+(?=~)/].to_i
|
49
|
+
return case num
|
50
|
+
when 1, 7 then "HOME"
|
51
|
+
when 2 then "INS"
|
52
|
+
when 3 then "DEL"
|
53
|
+
when 4, 8 then "END"
|
54
|
+
when 5 then "PgUP"
|
55
|
+
when 6 then "PgDOWN"
|
56
|
+
when 15 then "F5"
|
57
|
+
when 17 then "F6"
|
58
|
+
when 18 then "F7"
|
59
|
+
when 19 then "F8"
|
60
|
+
when 20 then "F9"
|
61
|
+
when 21 then "F10"
|
62
|
+
when 23 then "F11"
|
63
|
+
when 24 then "F12"
|
64
|
+
else ""
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# 9) SS3 function keys F1-F4
|
69
|
+
if seq.start_with?("\eO") && seq.length == 3
|
70
|
+
return case seq[2]
|
71
|
+
when 'P' then "F1"
|
72
|
+
when 'Q' then "F2"
|
73
|
+
when 'R' then "F3"
|
74
|
+
when 'S' then "F4"
|
75
|
+
else ""
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
# 10) Single / Ctrl-char mappings
|
80
|
+
return case seq
|
81
|
+
when "\r", "\n" then "ENTER"
|
82
|
+
when "\t" then "TAB"
|
83
|
+
when "\u007F", "\b" then "BACK"
|
84
|
+
when "\u0000" then "C-SPACE"
|
85
|
+
when "\u0001" then "C-A"
|
86
|
+
when "\u0002" then "C-B"
|
87
|
+
when "\u0003" then "C-C"
|
88
|
+
when "\u0004" then "C-D"
|
89
|
+
when "\u0005" then "C-E"
|
90
|
+
when "\u0006" then "C-F"
|
91
|
+
when "\u0007" then "C-G"
|
92
|
+
when "\u0008" then "C-H"
|
93
|
+
when "\u000B" then "C-K"
|
94
|
+
when "\u000C" then "C-L"
|
95
|
+
when "\u000D" then "C-M"
|
96
|
+
when "\u000E" then "C-N"
|
97
|
+
when "\u000F" then "C-O"
|
98
|
+
when "\u0010" then "C-P"
|
99
|
+
when "\u0011" then "C-Q"
|
100
|
+
when "\u0012" then "C-R"
|
101
|
+
when "\u0013" then "C-S"
|
102
|
+
when "\u0014" then "C-T"
|
103
|
+
when "\u0015" then "C-U"
|
104
|
+
when "\u0016" then "C-V"
|
105
|
+
when "\u0018" then "C-X"
|
106
|
+
when "\u0019" then "C-Y"
|
107
|
+
when "\u001A" then "C-Z"
|
108
|
+
when "\u0017" then "WBACK"
|
109
|
+
when /\A[[:print:]]\z/ then seq
|
110
|
+
else ""
|
111
|
+
end
|
158
112
|
end
|
159
113
|
end
|
160
114
|
end
|
115
|
+
|
data/lib/rcurses.rb
CHANGED
@@ -5,7 +5,7 @@
|
|
5
5
|
# Web_site: http://isene.com/
|
6
6
|
# Github: https://github.com/isene/rcurses
|
7
7
|
# License: Public domain
|
8
|
-
# Version: 3.
|
8
|
+
# Version: 3.7: Better, more solid Input module
|
9
9
|
|
10
10
|
require 'io/console' # Basic gem for rcurses
|
11
11
|
require 'io/wait' # stdin handling
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rcurses
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: '3.7'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Geir Isene
|
@@ -29,8 +29,8 @@ description: 'Create curses applications for the terminal easier than ever. Crea
|
|
29
29
|
up text (in panes or anywhere in the terminal) in bold, italic, underline, reverse
|
30
30
|
color, blink and in any 256 terminal colors for foreground and background. Use a
|
31
31
|
simple editor to let users edit text in panes. Left, right or center align text
|
32
|
-
in panes. Cursor movement around the terminal. New in 3.
|
33
|
-
|
32
|
+
in panes. Cursor movement around the terminal. New in 3.7: Better, more solid Input
|
33
|
+
module.'
|
34
34
|
email: g@isene.com
|
35
35
|
executables: []
|
36
36
|
extensions: []
|