rubytext 0.1.21 → 0.1.22
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/menu.rb +87 -29
- data/lib/output.rb +9 -4
- data/lib/rubytext_version.rb +1 -1
- data/lib/window.rb +0 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc35032215721ae6cc67dcb1a801f94ea6eaabd68716362f62a1f82c84cf9c8e
|
4
|
+
data.tar.gz: 4298fe621d895c5392a2170f0ec29ba043516e4f245d80d80ef5c99cc01e9526
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 210598d6cacdfbe8ae32ef68f9997d094038486068e2fb5b453578aea53cd4b075cc26a1d2f191419b79e22c800989312f8a1c4ffe23f322a3cd74ba3dfe25d3
|
7
|
+
data.tar.gz: 63a08f8589711d9cb0b8c7224aba3fc5630dc474b24d92678c4ab0f3165d95689db0c1bee38a924c3f541a0a86863a83ca0de8a2f80607dc9e63aa73d7c18bb2
|
data/lib/menu.rb
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
module RubyText
|
2
2
|
|
3
3
|
class Window
|
4
|
-
def topmenu(items:, curr: 0,
|
5
|
-
title: nil, fg: Green, bg: Black)
|
4
|
+
def topmenu(items:, curr: 0, fg: Green, bg: Black)
|
6
5
|
r, c = 0, 0
|
7
|
-
border = false
|
8
6
|
high = 1
|
9
7
|
|
10
8
|
RubyText.hide_cursor
|
@@ -16,7 +14,6 @@ module RubyText
|
|
16
14
|
results = items
|
17
15
|
end
|
18
16
|
|
19
|
-
tlen = title.length + 8 rescue 0
|
20
17
|
width = 0 # total width
|
21
18
|
cols = [] # start-column of each item
|
22
19
|
items.each do |item|
|
@@ -26,13 +23,9 @@ module RubyText
|
|
26
23
|
end
|
27
24
|
|
28
25
|
r, c = self.coords(r, c)
|
29
|
-
# puts "topmenu saved"
|
30
|
-
# sleep 2
|
31
26
|
self.saveback(high, width, r, c)
|
32
27
|
mr, mc = r+self.r0, c+self.c0
|
33
|
-
|
34
|
-
mwin = RubyText.window(high, width, r: mr, c: mc, border: border,
|
35
|
-
fg: fg, bg: bg, title: title)
|
28
|
+
mwin = RubyText.window(high, width, r: mr, c: mc, fg: fg, bg: bg, border: false, title: nil)
|
36
29
|
Curses.stdscr.keypad(true)
|
37
30
|
sel = curr
|
38
31
|
max = items.size - 1
|
@@ -45,18 +38,16 @@ module RubyText
|
|
45
38
|
end
|
46
39
|
ch = getch
|
47
40
|
case ch
|
48
|
-
when
|
41
|
+
when Left
|
49
42
|
sel -= 1 if sel > 0
|
50
|
-
when
|
43
|
+
when Right
|
51
44
|
sel += 1 if sel < max
|
52
|
-
when
|
45
|
+
when Esc, " " # spacebar also quits
|
53
46
|
self.restback(high, width, r, c)
|
54
47
|
RubyText.show_cursor
|
55
48
|
return [nil, nil]
|
56
|
-
when
|
49
|
+
when Down, Enter
|
57
50
|
self.restback(high, width, r, c)
|
58
|
-
# puts "topmenu restored"
|
59
|
-
# sleep 2
|
60
51
|
RubyText.show_cursor
|
61
52
|
choice = results[sel]
|
62
53
|
return [sel, choice] if choice.is_a? String
|
@@ -93,8 +84,6 @@ module RubyText
|
|
93
84
|
row = row - high/2 if r == :center
|
94
85
|
col = col - wide/2 if c == :center
|
95
86
|
r, c = row, col
|
96
|
-
# puts "menu2 saved"
|
97
|
-
# sleep 2
|
98
87
|
self.saveback(high, wide, r, c)
|
99
88
|
mr, mc = r+self.r0, c+self.c0
|
100
89
|
title = nil unless border
|
@@ -113,15 +102,15 @@ module RubyText
|
|
113
102
|
end
|
114
103
|
ch = getch
|
115
104
|
case ch
|
116
|
-
when
|
105
|
+
when Up
|
117
106
|
sel -= 1 if sel > 0
|
118
|
-
when
|
107
|
+
when Down
|
119
108
|
sel += 1 if sel < max
|
120
|
-
when
|
109
|
+
when Esc
|
121
110
|
self.restback(high, wide, r, c)
|
122
111
|
RubyText.show_cursor
|
123
112
|
return [nil, nil]
|
124
|
-
when
|
113
|
+
when Enter
|
125
114
|
self.restback(high, wide, r, c)
|
126
115
|
RubyText.show_cursor
|
127
116
|
choice = results[sel]
|
@@ -165,15 +154,15 @@ module RubyText
|
|
165
154
|
end
|
166
155
|
ch = getch
|
167
156
|
case ch
|
168
|
-
when
|
157
|
+
when Up
|
169
158
|
sel -= 1 if sel > 0
|
170
|
-
when
|
159
|
+
when Down
|
171
160
|
sel += 1 if sel < max
|
172
|
-
when
|
161
|
+
when Esc
|
173
162
|
self.restback(high, wide, r, c)
|
174
163
|
RubyText.show_cursor
|
175
164
|
return []
|
176
|
-
when
|
165
|
+
when Enter
|
177
166
|
self.restback(high, wide, r, c)
|
178
167
|
RubyText.show_cursor
|
179
168
|
return selected.map {|i| items[i] }
|
@@ -192,6 +181,75 @@ module RubyText
|
|
192
181
|
num, str = STDSCR.menu(r: r, c: c+6, items: ["yes", "no"])
|
193
182
|
num == 0
|
194
183
|
end
|
184
|
+
|
185
|
+
def radio_menu(r: :center, c: :center, items:, curr: 0,
|
186
|
+
# Handle current value better?
|
187
|
+
border: true,
|
188
|
+
title: nil, fg: Green, bg: Black)
|
189
|
+
RubyText.hide_cursor
|
190
|
+
if items.is_a?(Hash)
|
191
|
+
results = items.values
|
192
|
+
items = items.keys
|
193
|
+
hash_flag = true
|
194
|
+
else
|
195
|
+
results = items
|
196
|
+
end
|
197
|
+
|
198
|
+
high = items.size
|
199
|
+
wide = items.map(&:length).max + 3
|
200
|
+
high += 2 if border
|
201
|
+
wide += 2 if border
|
202
|
+
|
203
|
+
tlen = title.length + 8 rescue 0
|
204
|
+
wide = [wide, tlen].max
|
205
|
+
row, col = self.coords(r, c)
|
206
|
+
row = row - high/2 if r == :center
|
207
|
+
col = col - wide/2 if c == :center
|
208
|
+
r, c = row, col
|
209
|
+
self.saveback(high, wide, r, c)
|
210
|
+
mr, mc = r+self.r0, c+self.c0
|
211
|
+
title = nil unless border
|
212
|
+
mwin = RubyText.window(high, wide, r: mr, c: mc, border: border,
|
213
|
+
fg: fg, bg: bg, title: title)
|
214
|
+
Curses.stdscr.keypad(true)
|
215
|
+
sel = curr
|
216
|
+
max = items.size - 1
|
217
|
+
loop do
|
218
|
+
RubyText.hide_cursor # FIXME should be unnecessary
|
219
|
+
items.each.with_index do |item, row|
|
220
|
+
mark = row == curr ? ">" : " "
|
221
|
+
mwin.go row, 0
|
222
|
+
style = (sel == row) ? :reverse : :normal
|
223
|
+
label = "#{mark} #{item}"
|
224
|
+
mwin.print fx(label, style)
|
225
|
+
end
|
226
|
+
ch = getch
|
227
|
+
case ch
|
228
|
+
when Up
|
229
|
+
sel -= 1 if sel > 0
|
230
|
+
when Down
|
231
|
+
sel += 1 if sel < max
|
232
|
+
when Esc
|
233
|
+
self.restback(high, wide, r, c)
|
234
|
+
RubyText.show_cursor
|
235
|
+
return [nil, nil]
|
236
|
+
when " "
|
237
|
+
mwin[curr, 0] = " "
|
238
|
+
mwin[sel, 0] = ">"
|
239
|
+
curr = sel
|
240
|
+
when Enter
|
241
|
+
self.restback(high, wide, r, c)
|
242
|
+
RubyText.show_cursor
|
243
|
+
choice = results[sel]
|
244
|
+
return [sel, choice] if choice.is_a? String
|
245
|
+
result = choice.call
|
246
|
+
return [nil, nil] if result.nil? || result.empty?
|
247
|
+
return result
|
248
|
+
else Curses.beep
|
249
|
+
end
|
250
|
+
RubyText.show_cursor
|
251
|
+
end
|
252
|
+
end
|
195
253
|
end
|
196
254
|
|
197
255
|
def self.selector(win: STDSCR, r: 0, c: 0, rows: 10, cols: 20,
|
@@ -215,17 +273,17 @@ module RubyText
|
|
215
273
|
end
|
216
274
|
ch = getch
|
217
275
|
case ch
|
218
|
-
when
|
276
|
+
when Up
|
219
277
|
if sel > 0
|
220
278
|
sel -= 1
|
221
279
|
handler.call(sel, items[sel], win2)
|
222
280
|
end
|
223
|
-
when
|
281
|
+
when Down
|
224
282
|
if sel < max
|
225
283
|
sel += 1
|
226
284
|
handler.call(sel, items[sel], win2)
|
227
285
|
end
|
228
|
-
when
|
286
|
+
when Enter
|
229
287
|
if enter
|
230
288
|
del = enter.call(sel, items[sel], win2)
|
231
289
|
if del
|
@@ -233,7 +291,7 @@ module RubyText
|
|
233
291
|
raise
|
234
292
|
end
|
235
293
|
end
|
236
|
-
when
|
294
|
+
when Tab
|
237
295
|
Curses.flash
|
238
296
|
when quit # parameter
|
239
297
|
exit
|
data/lib/output.rb
CHANGED
@@ -147,7 +147,7 @@ class RubyText::Window
|
|
147
147
|
end
|
148
148
|
|
149
149
|
class GetString
|
150
|
-
def initialize(win = STDSCR, str = "", i = 0, history: [], limit: nil, tab: [])
|
150
|
+
def initialize(win = STDSCR, str = "", i = 0, history: [], limit: nil, tab: [], capture: [])
|
151
151
|
@win = win
|
152
152
|
@r0, @c0 = @win.rc
|
153
153
|
@limit = limit || (@win.cols - @r0 - 1)
|
@@ -249,15 +249,20 @@ class RubyText::Window
|
|
249
249
|
end
|
250
250
|
end
|
251
251
|
|
252
|
-
def gets(history: [], limit: nil, tab: [], default: ""
|
252
|
+
def gets(history: [], limit: nil, tab: [], default: "", capture: [])
|
253
|
+
# needs improvement
|
253
254
|
# echo assumed to be OFF, keypad ON
|
254
255
|
@history = history
|
255
|
-
gs = GetString.new(self, default, history: history, limit: limit, tab: tab
|
256
|
+
gs = GetString.new(self, default, history: history, limit: limit, tab: tab,
|
257
|
+
capture: capture)
|
256
258
|
count = 0
|
257
259
|
loop do
|
258
|
-
count += 1 # Escape
|
260
|
+
count += 1 # Escape and 'capture' chars have special meaning if first char
|
259
261
|
ch = self.getch
|
260
262
|
case ch
|
263
|
+
when *capture
|
264
|
+
return ch if count == 1
|
265
|
+
gs.add(ch)
|
261
266
|
when Escape
|
262
267
|
return Escape if count == 1
|
263
268
|
gs.enter
|
data/lib/rubytext_version.rb
CHANGED
data/lib/window.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubytext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-02-
|
11
|
+
date: 2020-02-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|