rubytext 0.1.22 → 0.1.23
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/.yardoc/checksums +11 -0
- data/lib/.yardoc/complete +0 -0
- data/lib/.yardoc/object_types +0 -0
- data/lib/.yardoc/objects/root.dat +0 -0
- data/lib/.yardoc/proxy_types +0 -0
- data/lib/color.rb +22 -0
- data/lib/doc/RubyText.html +1410 -0
- data/lib/doc/RubyText/Color.html +366 -0
- data/lib/doc/RubyText/Effects.html +658 -0
- data/lib/doc/RubyText/Keys.html +300 -0
- data/lib/doc/RubyText/Settings.html +593 -0
- data/lib/doc/RubyText/Window.html +5074 -0
- data/lib/doc/RubyText/Window/GetString.html +812 -0
- data/lib/doc/WindowIO.html +541 -0
- data/lib/doc/_index.html +195 -0
- data/lib/doc/class_list.html +51 -0
- data/lib/doc/css/common.css +1 -0
- data/lib/doc/css/full_list.css +58 -0
- data/lib/doc/css/style.css +496 -0
- data/lib/doc/file_list.html +51 -0
- data/lib/doc/frames.html +17 -0
- data/lib/doc/index.html +195 -0
- data/lib/doc/js/app.js +314 -0
- data/lib/doc/js/full_list.js +216 -0
- data/lib/doc/js/jquery.js +4 -0
- data/lib/doc/method_list.html +987 -0
- data/lib/doc/top-level-namespace.html +483 -0
- data/lib/effects.rb +15 -1
- data/lib/keys.rb +3 -0
- data/lib/menu.rb +77 -3
- data/lib/navigation.rb +35 -0
- data/lib/output.rb +18 -4
- data/lib/rubytext_version.rb +1 -1
- data/lib/settings.rb +1 -0
- data/lib/window.rb +1 -0
- metadata +28 -2
data/lib/effects.rb
CHANGED
@@ -1,21 +1,31 @@
|
|
1
1
|
|
2
|
+
# Helper method: insert text effects while printing
|
3
|
+
|
2
4
|
def fx(str, *args, bg: nil)
|
3
5
|
eff = RubyText::Effects.new(*args, bg: bg)
|
4
6
|
str.define_singleton_method(:effect) { eff }
|
5
7
|
str # must return str
|
6
8
|
end
|
7
9
|
|
10
|
+
# Hande text effects (bold, normal, reverse, underline)
|
11
|
+
|
8
12
|
class RubyText::Effects # dumb name?
|
13
|
+
|
14
|
+
# Text modes
|
9
15
|
Modes = {bold: Curses::A_BOLD,
|
10
16
|
normal: Curses::A_NORMAL,
|
11
17
|
reverse: Curses::A_REVERSE,
|
12
18
|
under: Curses::A_UNDERLINE}
|
13
19
|
|
20
|
+
# Other text modes "of our own"
|
21
|
+
|
14
22
|
Others = %[:show, :hide] # show/hide cursor; more later??
|
15
23
|
|
16
24
|
attr_reader :value, :fg, :bg
|
17
25
|
|
18
|
-
#
|
26
|
+
# @todo rewrite logic to accommodate color pairs
|
27
|
+
|
28
|
+
# Initialize an Effects object
|
19
29
|
|
20
30
|
def initialize(*args, bg: nil)
|
21
31
|
bits = 0
|
@@ -32,6 +42,8 @@ class RubyText::Effects # dumb name?
|
|
32
42
|
@value = bits
|
33
43
|
end
|
34
44
|
|
45
|
+
# "Turn on" effect to specified window
|
46
|
+
|
35
47
|
def set(win)
|
36
48
|
@old_fg, @old_bg = win.fg, win.bg # Save off current state?
|
37
49
|
attr, fg, bg = self.value, self.fg, self.bg
|
@@ -41,6 +53,8 @@ class RubyText::Effects # dumb name?
|
|
41
53
|
win.set_colors(fg, bg)
|
42
54
|
end
|
43
55
|
|
56
|
+
# "Turn off" effect in specified window
|
57
|
+
|
44
58
|
def reset(win)
|
45
59
|
attr = self.value
|
46
60
|
win.cwin.attroff(attr)
|
data/lib/keys.rb
CHANGED
data/lib/menu.rb
CHANGED
@@ -1,6 +1,13 @@
|
|
1
|
+
# The top-level module
|
2
|
+
|
1
3
|
module RubyText
|
2
4
|
|
5
|
+
# Wrapper for a curses window
|
6
|
+
|
3
7
|
class Window
|
8
|
+
|
9
|
+
# One-line menu at top of window
|
10
|
+
|
4
11
|
def topmenu(items:, curr: 0, fg: Green, bg: Black)
|
5
12
|
r, c = 0, 0
|
6
13
|
high = 1
|
@@ -55,14 +62,16 @@ module RubyText
|
|
55
62
|
next if result.nil?
|
56
63
|
next if result.empty?
|
57
64
|
return result
|
58
|
-
|
65
|
+
else Curses.beep
|
59
66
|
end
|
60
67
|
RubyText.show_cursor
|
61
68
|
end
|
62
69
|
end
|
63
70
|
|
71
|
+
# Simple menu with rows of strings (or Procs)
|
72
|
+
|
64
73
|
def menu(r: :center, c: :center, items:, curr: 0,
|
65
|
-
border: true,
|
74
|
+
border: true, sticky: false,
|
66
75
|
title: nil, fg: Green, bg: Black)
|
67
76
|
RubyText.hide_cursor
|
68
77
|
if items.is_a?(Hash)
|
@@ -111,7 +120,7 @@ module RubyText
|
|
111
120
|
RubyText.show_cursor
|
112
121
|
return [nil, nil]
|
113
122
|
when Enter
|
114
|
-
self.restback(high, wide, r, c)
|
123
|
+
self.restback(high, wide, r, c) unless sticky
|
115
124
|
RubyText.show_cursor
|
116
125
|
choice = results[sel]
|
117
126
|
return [sel, choice] if choice.is_a? String
|
@@ -124,6 +133,8 @@ module RubyText
|
|
124
133
|
end
|
125
134
|
end
|
126
135
|
|
136
|
+
# Menu for multiple selections (buggy/unused?)
|
137
|
+
|
127
138
|
def multimenu(r: :center, c: :center,
|
128
139
|
items:, curr: 0, selected: [],
|
129
140
|
title: nil, sel_fg: Yellow, fg: White, bg: Blue)
|
@@ -175,6 +186,8 @@ module RubyText
|
|
175
186
|
end
|
176
187
|
end
|
177
188
|
|
189
|
+
# Simple yes/no decision
|
190
|
+
|
178
191
|
def yesno
|
179
192
|
# TODO: Accept YyNn
|
180
193
|
r, c = STDSCR.rc
|
@@ -182,6 +195,8 @@ module RubyText
|
|
182
195
|
num == 0
|
183
196
|
end
|
184
197
|
|
198
|
+
# Menu to choose a single setting and retain it
|
199
|
+
|
185
200
|
def radio_menu(r: :center, c: :center, items:, curr: 0,
|
186
201
|
# Handle current value better?
|
187
202
|
border: true,
|
@@ -251,6 +266,11 @@ module RubyText
|
|
251
266
|
end
|
252
267
|
end
|
253
268
|
end
|
269
|
+
end
|
270
|
+
|
271
|
+
module RubyText
|
272
|
+
|
273
|
+
# Two-paned widget with menu on left, informtional area on right
|
254
274
|
|
255
275
|
def self.selector(win: STDSCR, r: 0, c: 0, rows: 10, cols: 20,
|
256
276
|
items:, fg: White, bg: Blue,
|
@@ -301,5 +321,59 @@ module RubyText
|
|
301
321
|
rescue
|
302
322
|
retry
|
303
323
|
end
|
324
|
+
|
325
|
+
# "Menu" for checklists
|
326
|
+
|
327
|
+
def checklist(r: :center, c: :center,
|
328
|
+
items:, curr: 0, selected: [],
|
329
|
+
title: nil, sel_fg: Yellow, fg: White, bg: Blue)
|
330
|
+
RubyText.hide_cursor
|
331
|
+
high = items.size + 2
|
332
|
+
wide = items.map(&:length).max + 8
|
333
|
+
tlen = title.length + 8 rescue 0
|
334
|
+
wide = [wide, tlen].max
|
335
|
+
row, col = self.coords(r, c)
|
336
|
+
row = row - high/2 if r == :center
|
337
|
+
col = col - wide/2 if c == :center
|
338
|
+
r, c = row, col
|
339
|
+
self.saveback(high, wide, r, c)
|
340
|
+
mr, mc = r+self.r0, c+self.c0
|
341
|
+
mwin = RubyText.window(high, wide, r: mr, c: mc,
|
342
|
+
fg: fg, bg: bg, title: title)
|
343
|
+
Curses.stdscr.keypad(true)
|
344
|
+
sel = curr
|
345
|
+
max = items.size - 1
|
346
|
+
loop do
|
347
|
+
RubyText.hide_cursor # FIXME should be unnecessary
|
348
|
+
items.each.with_index do |item, row|
|
349
|
+
mwin.go row, 0
|
350
|
+
style = (sel == row) ? :reverse : :normal
|
351
|
+
color = selected.find {|x| x[0] == row } ? sel_fg : fg
|
352
|
+
label = "[ ]" + item
|
353
|
+
mwin.print fx(label, color, style)
|
354
|
+
end
|
355
|
+
ch = getch
|
356
|
+
case ch
|
357
|
+
when Up
|
358
|
+
sel -= 1 if sel > 0
|
359
|
+
when Down
|
360
|
+
sel += 1 if sel < max
|
361
|
+
when Esc
|
362
|
+
self.restback(high, wide, r, c)
|
363
|
+
RubyText.show_cursor
|
364
|
+
return []
|
365
|
+
when Enter
|
366
|
+
self.restback(high, wide, r, c)
|
367
|
+
RubyText.show_cursor
|
368
|
+
return selected.map {|i| items[i] }
|
369
|
+
when " "
|
370
|
+
selected << [sel, items[sel]]
|
371
|
+
sel += 1 if sel < max
|
372
|
+
else Curses.beep
|
373
|
+
end
|
374
|
+
RubyText.show_cursor
|
375
|
+
end
|
376
|
+
end
|
377
|
+
|
304
378
|
end
|
305
379
|
|
data/lib/navigation.rb
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
+
# Reopening: Coordinate handling (1-based!)
|
2
|
+
|
1
3
|
class RubyText::Window
|
2
4
|
|
5
|
+
# Handle special coordinate names (symbols)
|
6
|
+
|
3
7
|
def coords(r, c)
|
4
8
|
r = case
|
5
9
|
when r == :center
|
@@ -24,10 +28,17 @@ class RubyText::Window
|
|
24
28
|
[r, c]
|
25
29
|
end
|
26
30
|
|
31
|
+
# Go to specified row/column in current window
|
32
|
+
|
27
33
|
def goto(r, c) # only accepts numbers!
|
28
34
|
@cwin.setpos(r, c)
|
35
|
+
@cwin.refresh
|
29
36
|
end
|
30
37
|
|
38
|
+
|
39
|
+
# Go to specified row/column in current window,
|
40
|
+
# execute block, and return cursor
|
41
|
+
|
31
42
|
def go(r0, c0)
|
32
43
|
r, c = coords(r0, c0)
|
33
44
|
save = self.rc
|
@@ -38,60 +49,84 @@ class RubyText::Window
|
|
38
49
|
end
|
39
50
|
end
|
40
51
|
|
52
|
+
# Move cursor up
|
53
|
+
|
41
54
|
def up(n=1)
|
42
55
|
r, c = rc
|
43
56
|
go r-n, c
|
44
57
|
end
|
45
58
|
|
59
|
+
# Move cursor down
|
60
|
+
|
46
61
|
def down(n=1)
|
47
62
|
r, c = rc
|
48
63
|
go r+n, c
|
49
64
|
end
|
50
65
|
|
66
|
+
# Move cursor left
|
67
|
+
|
51
68
|
def left(n=1)
|
52
69
|
r, c = rc
|
53
70
|
go r, c-n
|
54
71
|
end
|
55
72
|
|
73
|
+
# Move cursor right
|
74
|
+
|
56
75
|
def right(n=1)
|
57
76
|
r, c = rc
|
58
77
|
go r, c+n
|
59
78
|
end
|
60
79
|
|
80
|
+
# Move cursor to top of window
|
81
|
+
|
61
82
|
def top
|
62
83
|
r, c = rc
|
63
84
|
go 0, c
|
64
85
|
end
|
65
86
|
|
87
|
+
# Move cursor to bottom of window
|
88
|
+
|
66
89
|
def bottom
|
67
90
|
r, c = rc
|
68
91
|
rmax = self.rows - 1
|
69
92
|
go rmax, c
|
70
93
|
end
|
71
94
|
|
95
|
+
# Move cursor to top of window
|
96
|
+
|
72
97
|
def up!
|
73
98
|
top
|
74
99
|
end
|
75
100
|
|
101
|
+
# Move cursor to bottom of window
|
102
|
+
|
76
103
|
def down!
|
77
104
|
bottom
|
78
105
|
end
|
79
106
|
|
107
|
+
# Move cursor to far left of window
|
108
|
+
|
80
109
|
def left!
|
81
110
|
r, c = rc
|
82
111
|
go r, 0
|
83
112
|
end
|
84
113
|
|
114
|
+
# Move cursor to far left of window
|
115
|
+
|
85
116
|
def right!
|
86
117
|
r, c = rc
|
87
118
|
cmax = self.cols - 1
|
88
119
|
go r, cmax
|
89
120
|
end
|
90
121
|
|
122
|
+
# Move cursor to home (upper left)
|
123
|
+
|
91
124
|
def home
|
92
125
|
go 0, 0
|
93
126
|
end
|
94
127
|
|
128
|
+
# Return current row/column
|
129
|
+
|
95
130
|
def rc
|
96
131
|
[@cwin.cury, @cwin.curx]
|
97
132
|
end
|
data/lib/output.rb
CHANGED
@@ -123,17 +123,31 @@ class RubyText::Window
|
|
123
123
|
$stdscr = STDSCR
|
124
124
|
end
|
125
125
|
|
126
|
+
=begin
|
127
|
+
def go(r0, c0)
|
128
|
+
r, c = coords(r0, c0)
|
129
|
+
save = self.rc
|
130
|
+
goto r, c
|
131
|
+
if block_given?
|
132
|
+
yield
|
133
|
+
goto *save
|
134
|
+
end
|
135
|
+
end
|
136
|
+
=end
|
137
|
+
|
126
138
|
def [](r, c)
|
127
|
-
|
128
|
-
|
129
|
-
|
139
|
+
r0, c0 = self.rc
|
140
|
+
@cwin.setpos(r, c)
|
141
|
+
ch = @cwin.inch
|
142
|
+
@cwin.setpos(r0, c0)
|
130
143
|
ch.chr
|
131
144
|
end
|
132
145
|
|
133
146
|
def []=(r, c, char)
|
147
|
+
r0, c0 = self.rc
|
134
148
|
@cwin.setpos(r, c)
|
135
149
|
@cwin.addch(char[0].ord|Curses::A_NORMAL)
|
136
|
-
@cwin.setpos(
|
150
|
+
@cwin.setpos(r0, c0)
|
137
151
|
@cwin.refresh
|
138
152
|
end
|
139
153
|
|
data/lib/rubytext_version.rb
CHANGED
data/lib/settings.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.23
|
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-
|
11
|
+
date: 2020-03-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -76,7 +76,33 @@ files:
|
|
76
76
|
- examples/updown_etc.rb
|
77
77
|
- examples/win_centering.rb
|
78
78
|
- examples/window_full.rb
|
79
|
+
- lib/.yardoc/checksums
|
80
|
+
- lib/.yardoc/complete
|
81
|
+
- lib/.yardoc/object_types
|
82
|
+
- lib/.yardoc/objects/root.dat
|
83
|
+
- lib/.yardoc/proxy_types
|
79
84
|
- lib/color.rb
|
85
|
+
- lib/doc/RubyText.html
|
86
|
+
- lib/doc/RubyText/Color.html
|
87
|
+
- lib/doc/RubyText/Effects.html
|
88
|
+
- lib/doc/RubyText/Keys.html
|
89
|
+
- lib/doc/RubyText/Settings.html
|
90
|
+
- lib/doc/RubyText/Window.html
|
91
|
+
- lib/doc/RubyText/Window/GetString.html
|
92
|
+
- lib/doc/WindowIO.html
|
93
|
+
- lib/doc/_index.html
|
94
|
+
- lib/doc/class_list.html
|
95
|
+
- lib/doc/css/common.css
|
96
|
+
- lib/doc/css/full_list.css
|
97
|
+
- lib/doc/css/style.css
|
98
|
+
- lib/doc/file_list.html
|
99
|
+
- lib/doc/frames.html
|
100
|
+
- lib/doc/index.html
|
101
|
+
- lib/doc/js/app.js
|
102
|
+
- lib/doc/js/full_list.js
|
103
|
+
- lib/doc/js/jquery.js
|
104
|
+
- lib/doc/method_list.html
|
105
|
+
- lib/doc/top-level-namespace.html
|
80
106
|
- lib/effects.rb
|
81
107
|
- lib/keys.rb
|
82
108
|
- lib/menu.rb
|