rubytext 0.1.21 → 0.1.25
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/examples/topmenu.rb +56 -0
- 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/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/GetString.html +812 -0
- data/lib/doc/RubyText/Window.html +5074 -0
- data/lib/doc/RubyText.html +1410 -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 +495 -44
- data/lib/navigation.rb +35 -0
- data/lib/output.rb +27 -8
- data/lib/rubytext_version.rb +1 -1
- data/lib/settings.rb +5 -4
- data/lib/widgets.rb +10 -2
- data/lib/window.rb +1 -1
- metadata +33 -6
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
|
|
@@ -147,7 +161,7 @@ class RubyText::Window
|
|
147
161
|
end
|
148
162
|
|
149
163
|
class GetString
|
150
|
-
def initialize(win = STDSCR, str = "", i = 0, history: [], limit: nil, tab: [])
|
164
|
+
def initialize(win = STDSCR, str = "", i = 0, history: [], limit: nil, tab: [], capture: [])
|
151
165
|
@win = win
|
152
166
|
@r0, @c0 = @win.rc
|
153
167
|
@limit = limit || (@win.cols - @r0 - 1)
|
@@ -249,15 +263,20 @@ class RubyText::Window
|
|
249
263
|
end
|
250
264
|
end
|
251
265
|
|
252
|
-
def gets(history: [], limit: nil, tab: [], default: ""
|
266
|
+
def gets(history: [], limit: nil, tab: [], default: "", capture: [])
|
267
|
+
# needs improvement
|
253
268
|
# echo assumed to be OFF, keypad ON
|
254
269
|
@history = history
|
255
|
-
gs = GetString.new(self, default, history: history, limit: limit, tab: tab
|
270
|
+
gs = GetString.new(self, default, history: history, limit: limit, tab: tab,
|
271
|
+
capture: capture)
|
256
272
|
count = 0
|
257
273
|
loop do
|
258
|
-
count += 1 # Escape
|
274
|
+
count += 1 # Escape and 'capture' chars have special meaning if first char
|
259
275
|
ch = self.getch
|
260
276
|
case ch
|
277
|
+
when *capture
|
278
|
+
return ch if count == 1
|
279
|
+
gs.add(ch)
|
261
280
|
when Escape
|
262
281
|
return Escape if count == 1
|
263
282
|
gs.enter
|
data/lib/rubytext_version.rb
CHANGED
data/lib/settings.rb
CHANGED
@@ -9,7 +9,7 @@ module RubyText
|
|
9
9
|
@current = @defaults.dup
|
10
10
|
@stack = []
|
11
11
|
@stack.push @current # Note: Never let stack be empty
|
12
|
-
set_curses(
|
12
|
+
set_curses(**@current) # Set them for real
|
13
13
|
# FIXME To be continued...
|
14
14
|
end
|
15
15
|
|
@@ -39,7 +39,7 @@ module RubyText
|
|
39
39
|
cursor ||= @current[:cursor]
|
40
40
|
@stack.push @current
|
41
41
|
@current = {raw: raw, echo: echo, cbreak: cbreak, keypad: keypad, cursor: cursor}
|
42
|
-
set_curses(
|
42
|
+
set_curses(**@current)
|
43
43
|
end
|
44
44
|
|
45
45
|
def reset_boolean
|
@@ -57,7 +57,7 @@ module RubyText
|
|
57
57
|
sym0 = val ? sym : str[1..-1].to_sym
|
58
58
|
list[sym0] = val
|
59
59
|
end
|
60
|
-
set_boolean(list)
|
60
|
+
set_boolean(**list)
|
61
61
|
# allow a block here?
|
62
62
|
end
|
63
63
|
|
@@ -101,6 +101,7 @@ module RubyText
|
|
101
101
|
Object.const_set(:STDSCR, main) unless defined? STDSCR
|
102
102
|
$stdscr = STDSCR # FIXME global needed?
|
103
103
|
Object.include(WindowIO)
|
104
|
+
Curses.ESCDELAY = 10
|
104
105
|
@started = true
|
105
106
|
# rescue => err
|
106
107
|
# puts(err.inspect)
|
@@ -129,7 +130,7 @@ module RubyText
|
|
129
130
|
if name[0] == '_'
|
130
131
|
Curses.send(name[1..-1], *args)
|
131
132
|
else
|
132
|
-
raise "#{name} #{args.inspect}" # NoMethodError
|
133
|
+
raise "Missing: #{name} #{args.inspect}" # NoMethodError
|
133
134
|
end
|
134
135
|
end
|
135
136
|
|
data/lib/widgets.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
1
3
|
module RubyText
|
2
4
|
def self.ticker(row: STDSCR.rows-1, col: 0, width: STDSCR.cols,
|
3
5
|
fg: White, bg: Blue, text:, delay: 0.1)
|
@@ -35,14 +37,20 @@ module RubyText
|
|
35
37
|
ret
|
36
38
|
end
|
37
39
|
|
38
|
-
def self.splash(msg)
|
40
|
+
def self.splash(msg = nil)
|
41
|
+
io = StringIO.new("")
|
42
|
+
if msg.nil?
|
43
|
+
yield io
|
44
|
+
msg = io.string
|
45
|
+
end
|
46
|
+
|
39
47
|
lines = msg.split("\n")
|
40
48
|
high = lines.size + 4
|
41
49
|
wide = lines.map {|x| x.length }.max + 4
|
42
50
|
r0 = (STDSCR.rows - high)/2
|
43
51
|
c0 = (STDSCR.cols - wide)/2
|
44
52
|
STDSCR.saveback(high, wide, r0, c0)
|
45
|
-
win = RubyText.window(high, wide, r: r0, c: c0,
|
53
|
+
win = RubyText.window(high, wide, r: r0, c: c0, scroll: true,
|
46
54
|
fg: White, bg: Red, title: "[Press any key]")
|
47
55
|
win.print "\n "
|
48
56
|
win.puts msg
|
data/lib/window.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
1
|
|
2
2
|
module RubyText
|
3
|
-
# TODO add title:?
|
4
3
|
def self.window(high, wide, r: nil, c: nil, border: true,
|
5
4
|
fg: White, bg: Blue, scroll: false, title: nil)
|
6
5
|
r ||= (STDSCR.rows - high)/2
|
7
6
|
c ||= (STDSCR.cols - wide)/2
|
8
7
|
win = RubyText::Window.new(high, wide, r, c, border, fg, bg, scroll)
|
9
8
|
win.add_title(title) if title
|
9
|
+
0.upto(high) {|row| 0.upto(wide) {|col| win[row, col] = " " } }
|
10
10
|
win
|
11
11
|
end
|
12
12
|
end
|
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.25
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-07-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -72,11 +72,38 @@ files:
|
|
72
72
|
- examples/sym_navigate.rb
|
73
73
|
- examples/ticker_threads.rb
|
74
74
|
- examples/topbottom.rb
|
75
|
+
- examples/topmenu.rb
|
75
76
|
- examples/udlr_bang.rb
|
76
77
|
- examples/updown_etc.rb
|
77
78
|
- examples/win_centering.rb
|
78
79
|
- examples/window_full.rb
|
80
|
+
- lib/.yardoc/checksums
|
81
|
+
- lib/.yardoc/complete
|
82
|
+
- lib/.yardoc/object_types
|
83
|
+
- lib/.yardoc/objects/root.dat
|
84
|
+
- lib/.yardoc/proxy_types
|
79
85
|
- lib/color.rb
|
86
|
+
- lib/doc/RubyText.html
|
87
|
+
- lib/doc/RubyText/Color.html
|
88
|
+
- lib/doc/RubyText/Effects.html
|
89
|
+
- lib/doc/RubyText/Keys.html
|
90
|
+
- lib/doc/RubyText/Settings.html
|
91
|
+
- lib/doc/RubyText/Window.html
|
92
|
+
- lib/doc/RubyText/Window/GetString.html
|
93
|
+
- lib/doc/WindowIO.html
|
94
|
+
- lib/doc/_index.html
|
95
|
+
- lib/doc/class_list.html
|
96
|
+
- lib/doc/css/common.css
|
97
|
+
- lib/doc/css/full_list.css
|
98
|
+
- lib/doc/css/style.css
|
99
|
+
- lib/doc/file_list.html
|
100
|
+
- lib/doc/frames.html
|
101
|
+
- lib/doc/index.html
|
102
|
+
- lib/doc/js/app.js
|
103
|
+
- lib/doc/js/full_list.js
|
104
|
+
- lib/doc/js/jquery.js
|
105
|
+
- lib/doc/method_list.html
|
106
|
+
- lib/doc/top-level-namespace.html
|
80
107
|
- lib/effects.rb
|
81
108
|
- lib/keys.rb
|
82
109
|
- lib/menu.rb
|
@@ -119,7 +146,7 @@ homepage: https://github.com/Hal9000/rubytext
|
|
119
146
|
licenses:
|
120
147
|
- Ruby
|
121
148
|
metadata: {}
|
122
|
-
post_install_message:
|
149
|
+
post_install_message:
|
123
150
|
rdoc_options: []
|
124
151
|
require_paths:
|
125
152
|
- lib
|
@@ -134,8 +161,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
134
161
|
- !ruby/object:Gem::Version
|
135
162
|
version: '0'
|
136
163
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
138
|
-
signing_key:
|
164
|
+
rubygems_version: 3.1.2
|
165
|
+
signing_key:
|
139
166
|
specification_version: 4
|
140
167
|
summary: A thick wrapper for Curses
|
141
168
|
test_files: []
|