rubytext 0.1.12 → 0.1.13

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b6036e0b122b120c698646243dd7679e7a6b0991687d958a01e66be56119ad1a
4
- data.tar.gz: ede2e0e43159005799fe9de6679858037cc3e1b6d3883583611ff87e2dfbed36
3
+ metadata.gz: b868f42a2da112076a37ef66415e924ce33bef38ac256306cbd6bdb9ca2d88e3
4
+ data.tar.gz: 55f82c3d30480238dfc9fbbf715664eaffadc8f7f9c647f6db5b004d1cfbc30d
5
5
  SHA512:
6
- metadata.gz: 28124389eeef71e3cad064680fc1347649fba40cbf61a06ed0bea1d67fc2aaedd6679cc6c2db3196e03677596f3c7f7fc1172c6e17cc84852b730165db6ef166
7
- data.tar.gz: 1fda7e185b9d33a85629fd6eb9d3c84e4a651001d5f002b4e504bd81682f1aba8aa273d3f00bc2ac0ee46a6593c2c83d5ad3c05f31d96ad530e8a36976d96246
6
+ metadata.gz: 70986013ad4d13935141752c05b75a81f174305c19294f02f5b0830c941eac365e1f809d3c99aef1ae03d150e6d8877d69111521b6598a06ca46d541090afb8f
7
+ data.tar.gz: cab9b4fab8e0e6a3053e3c48da250866a4db55bfba81c877a674e1696fcf8c043d0ad63d97199ec9e54fdd15cdc9fa5f3dbea2c6ae3bd3599a9c828321346e4b
data/README.md CHANGED
@@ -5,21 +5,21 @@ stages. Unlike some similar projects, it is a "thick" wrapper;
5
5
  I am adding functionality that does not always correspond directly
6
6
  to the curses world.
7
7
 
8
- Install the `rubytext` gem and then run the demo or the slides
9
- or both.
8
+ Install the `rubytext` gem and then run demo code or the examples
9
+ or whatever you want:
10
10
 
11
11
  ```
12
12
  $ gem install rubytext
13
13
  $ rubytext demo # 2-minute demo
14
- $ rubytext slides # Longer "slideshow"
15
14
  $ rubytext tutorial # (On OS/X) opens tutorial.html
15
+ $ rubytext slides # Longer "slideshow" (run all examples)
16
16
  ```
17
17
 
18
18
  You can also use the `example` subcommand:
19
19
 
20
20
  ```
21
- $ rubytext example # list all examples
22
- $ rubytext example progname # run 'prog' example
21
+ $ rubytext example # list all examples
22
+ $ rubytext example progname # run 'progname' example
23
23
  ```
24
24
 
25
25
  When you specify the example name, there is no need to
@@ -53,6 +53,7 @@ Here are some of the programs from the `rubytext slides` set of demos. See the `
53
53
  directory and the `showme.rb` script.
54
54
 
55
55
  A simple window:
56
+
56
57
  ```ruby
57
58
  require 'rubytext'
58
59
  win = RubyText.window(6, 25, r: 2, c: 34,
@@ -64,8 +65,8 @@ win.puts "This is a window..."
64
65
 
65
66
  <img src=readme-images/prog01.png>
66
67
 
67
-
68
68
  How `output` works. This name may change.
69
+
69
70
  ```ruby
70
71
  require 'rubytext'
71
72
  win = RubyText.window(9, 36, r: 2, c: 6, fg: White, bg: Red)
@@ -78,6 +79,7 @@ end
78
79
  ```
79
80
 
80
81
  Windows are bordered by default.
82
+
81
83
  ```ruby
82
84
  require 'rubytext'
83
85
  win = RubyText.window(9, 35, r: 3, c: 7, border: false, fg: Black, bg: Green)
@@ -87,6 +89,7 @@ win.puts "have a border."
87
89
  ```
88
90
 
89
91
  Using `puts` will wrap around the window automagically.
92
+
90
93
  ```ruby
91
94
  require 'rubytext'
92
95
  win = RubyText.window(8, 39, r: 4, c: 9, fg: Black, bg: Blue)
@@ -156,10 +159,10 @@ win.output do
156
159
  STDERR.print "unexpected/undefined results "
157
160
  puts " in more ways than one."
158
161
  end
159
-
160
162
  ```
161
163
 
162
164
  Use `[]=` to stuff single characters into a window (like an array).
165
+
163
166
  ```ruby
164
167
  require 'rubytext'
165
168
  win = RubyText.window(11, 50, r: 0, c: 5, fg: Yellow, bg: Blue)
@@ -179,6 +182,7 @@ win[6,38] = "Z"; win.refresh
179
182
  ```
180
183
 
181
184
  Likewise use `[]` to retrieve characters from a window.
185
+
182
186
  ```ruby
183
187
  require 'rubytext'
184
188
  win = RubyText.window(12, 60, r: 2, c: 5, fg: Yellow, bg: Blue)
@@ -194,6 +198,7 @@ win.puts "(6,7) => '#{win[6,7]}' (0,15) => '#{win[0,15]}'"
194
198
  ```
195
199
 
196
200
  You can write to `STDSCR` or to a subwindow.
201
+
197
202
  ```ruby
198
203
  require 'rubytext'
199
204
  win = RubyText.window(6, 30, r: 2, c: 5, fg: Yellow, bg: Blue)
@@ -210,10 +215,10 @@ puts "STDSCR is the default receiver."
210
215
  sleep 2
211
216
  STDSCR.go 5, 0
212
217
  puts "Nothing stops you from overwriting a window."
213
-
214
218
  ```
215
219
 
216
220
  You can retrieve cursor position and window size.
221
+
217
222
  ```ruby
218
223
  require 'rubytext'
219
224
  win = RubyText.window(12, 65, r: 1, c: 5, fg: Yellow, bg: Blue)
@@ -231,6 +236,7 @@ end
231
236
  ```
232
237
 
233
238
  Move the cursor with `go` (and use a block to jump/return).
239
+
234
240
  ```ruby
235
241
  require 'rubytext'
236
242
  win = RubyText.window(11, 65, r: 0, c: 15, fg: Blue, bg: Black)
@@ -250,6 +256,7 @@ win.print "DEF"
250
256
  ```
251
257
 
252
258
  Use `rcprint` to print at specific coordinates.
259
+
253
260
  ```ruby
254
261
  require 'rubytext'
255
262
  win = RubyText.window(13, 65, r: 0, c: 6, fg: Blue, bg: White)
@@ -266,6 +273,7 @@ win.rcprint 10,0, "Later there will be other ways to do this kind of thing."
266
273
  ```
267
274
 
268
275
  Window navigation: `home`, `up`, `down`, `left`, `right`
276
+
269
277
  ```ruby
270
278
  require 'rubytext'
271
279
  win = RubyText.window(11, 65, r: 0, c: 6, fg: Blue, bg: White)
@@ -285,6 +293,7 @@ win.go 7, 29; win.right; win.putch("R"); sleep 1
285
293
  ```
286
294
 
287
295
  More navigation: `up`, `down`, `left`, `right` with a parameter.
296
+
288
297
  ```ruby
289
298
  require 'rubytext'
290
299
  win = RubyText.window(11, 65, r: 1, c: 6, fg: Blue, bg: White)
@@ -299,6 +308,7 @@ win.go 4, 29; win.right(5); win.putch("5"); sleep 1
299
308
  ```
300
309
 
301
310
  Still more navigation: `up!`, `down!`, `left!`, `right!`
311
+
302
312
  ```ruby
303
313
  require 'rubytext'
304
314
  win = RubyText.window(11, 65, r: 1, c: 6, fg: Blue, bg: White)
@@ -315,6 +325,7 @@ win.go 5, 21; win.right!; win.putch("R"); sleep 1
315
325
  ```
316
326
 
317
327
  And finally, `top` and `bottom`.
328
+
318
329
  ```ruby
319
330
  require 'rubytext'
320
331
  win = RubyText.window(11, 65, r: 1, c: 6, fg: Blue, bg: White)
@@ -328,6 +339,7 @@ win.go 5, 21; win.bottom; win.putch("B"); sleep 1
328
339
  ```
329
340
 
330
341
  Somewhat useless, but there is a `center` method.
342
+
331
343
  ```ruby
332
344
  require 'rubytext'
333
345
  win = RubyText.window(15, 65, r: 1, c: 6, fg: Green, bg: Blue)
@@ -343,6 +355,7 @@ stuff.each {|str| win.center(str) }
343
355
  ```
344
356
 
345
357
  Changing colors during printing. This syntax will change.
358
+
346
359
  ```ruby
347
360
  require 'rubytext'
348
361
  win = RubyText.window(12, 65, r: 0, c: 6, fg: Green, bg: Blue)
@@ -361,6 +374,7 @@ win.puts "The symbol is ", sym.inspect, " which works", sym, " just fine."
361
374
  ```
362
375
 
363
376
  A simple menu (incomplete, still experimental).
377
+
364
378
  ```ruby
365
379
  require 'rubytext'
366
380
  puts "This very crude menu is also EXPERIMENTAL."
@@ -380,12 +394,8 @@ else
380
394
  end
381
395
  ```
382
396
 
383
- DESC
384
- ```ruby
385
- require 'rubytext'
386
- ```
387
-
388
397
  A marquee or ticker example. This uses threads and is kind of cool.
398
+
389
399
  ```ruby
390
400
  require 'rubytext'
391
401
  msg = <<~EOS
@@ -413,6 +423,11 @@ threads.each {|t| t.join }
413
423
  <img src=readme-images/prog22.png>
414
424
 
415
425
 
416
-
417
426
  *More later...*
418
427
 
428
+
429
+ DESC
430
+ ```ruby
431
+ require 'rubytext'
432
+ ```
433
+
data/lib/menu.rb CHANGED
@@ -16,12 +16,6 @@ module RubyText
16
16
  mr, mc = r+self.r0, c+self.c0
17
17
  mwin = RubyText.window(high, wide, r: mr, c: mc,
18
18
  fg: fg, bg: bg, title: title)
19
- # where = self == STDSCR ? [r, c+1] : [r-1, c+1] # wtf?
20
- # unless title.nil?
21
- # self.go(*where) do # same row as corner but farther right
22
- # self.print fx("[ #{title} ]", :bold, fg, bg: bg)
23
- # end
24
- # end
25
19
  Curses.stdscr.keypad(true)
26
20
  sel = curr
27
21
  max = items.size - 1
@@ -53,6 +47,56 @@ module RubyText
53
47
  end
54
48
  end
55
49
 
50
+ def multimenu(r: :center, c: :center,
51
+ items:, curr: 0, selected: [],
52
+ title: nil, sel_fg: Yellow, fg: White, bg: Blue)
53
+ RubyText.hide_cursor
54
+ high = items.size + 2
55
+ wide = items.map(&:length).max + 5
56
+ tlen = title.length + 8 rescue 0
57
+ wide = [wide, tlen].max
58
+ row, col = self.coords(r, c)
59
+ row = row - high/2 if r == :center
60
+ col = col - wide/2 if c == :center
61
+ r, c = row, col
62
+ self.saveback(high, wide, r, c)
63
+ mr, mc = r+self.r0, c+self.c0
64
+ mwin = RubyText.window(high, wide, r: mr, c: mc,
65
+ fg: fg, bg: bg, title: title)
66
+ Curses.stdscr.keypad(true)
67
+ sel = curr
68
+ max = items.size - 1
69
+ loop do
70
+ RubyText.hide_cursor # FIXME should be unnecessary
71
+ items.each.with_index do |item, row|
72
+ mwin.go row, 0
73
+ style = (sel == row) ? :reverse : :normal
74
+ color = selected.include?(row) ? sel_fg : fg
75
+ label = (" "*2 + item + " "*8)[0..wide-1]
76
+ mwin.print fx(label, color, style)
77
+ end
78
+ ch = getch
79
+ case ch
80
+ when Curses::KEY_UP
81
+ sel -= 1 if sel > 0
82
+ when Curses::KEY_DOWN
83
+ sel += 1 if sel < max
84
+ when 27
85
+ self.restback(high, wide, r, c)
86
+ RubyText.show_cursor
87
+ return []
88
+ when 10
89
+ self.restback(high, wide, r, c)
90
+ RubyText.show_cursor
91
+ return selected.map {|i| items[i] }
92
+ when " "
93
+ selected << sel
94
+ sel += 1 if sel < max
95
+ else Curses.beep
96
+ end
97
+ RubyText.show_cursor
98
+ end
99
+ end
56
100
  end
57
101
 
58
102
  def self.selector(win: STDSCR, r: 0, c: 0, rows: 10, cols: 20,
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.1.12"
3
+ VERSION = "0.1.13"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/lib/settings.rb CHANGED
@@ -48,14 +48,17 @@ module RubyText
48
48
  end
49
49
 
50
50
  def set(*syms)
51
+ File.open("/tmp/dammit1", "w") {|f| f.puts "-- set: syms = #{syms.inspect}" }
51
52
  raise ArgumentError unless syms - ValidArgs == []
52
53
  # FIXME - call set_boolean
53
54
  list = {}
54
55
  syms.each do |sym|
55
56
  str = sym.to_s
56
57
  val = str[0] != "_"
57
- list[sym] = val
58
+ sym0 = val ? sym : str[1..-1].to_sym
59
+ list[sym0] = val
58
60
  end
61
+ File.open("/tmp/dammit2", "w") {|f| f.puts "-- list = #{list.inspect}" }
59
62
  set_boolean(list)
60
63
  # allow a block here?
61
64
  end
@@ -90,8 +93,8 @@ module RubyText
90
93
  # $debug ||= File.new(log, "w") if log # FIXME remove global
91
94
 
92
95
  args.each {|arg| raise "#{arg} is not valid" unless Settings::ValidArgs.include?(arg) }
93
- raise "#{fg} is not a color" unless ::Colors.include? fg
94
- raise "#{bg} is not a color" unless ::Colors.include? bg
96
+ raise RTError("#{fg} is not a color") unless ::Colors.include? fg
97
+ raise RTError("#{bg} is not a color") unless ::Colors.include? bg
95
98
 
96
99
  @settings = Settings.new
97
100
  @settings.set(*args) # override defaults
@@ -101,10 +104,10 @@ module RubyText
101
104
  $stdscr = STDSCR # FIXME global needed?
102
105
  Object.include(WindowIO)
103
106
  @started = true
104
- rescue => err
105
- debug(err.inspect)
106
- debug(err.backtrace)
107
- raise RTError("#{err}")
107
+ # rescue => err
108
+ # puts(err.inspect)
109
+ # puts(err.backtrace)
110
+ # raise RTError("#{err}")
108
111
  end
109
112
 
110
113
  def self.stop
data/test/auto.rb CHANGED
@@ -29,15 +29,11 @@ class MyTest < Minitest::Test
29
29
  end
30
30
 
31
31
  def test_002_start_bad_param
32
- assert_raises(RTError) { RubyText.start(:foobar); RubyText.stop }
33
- rescue
34
- RubyText.stop
32
+ assert_raises(RuntimeError) { RubyText.start(:foobar); RubyText.stop }
35
33
  end
36
34
 
37
35
  def test_003_start_bad_color
38
36
  assert_raises(RTError) { RubyText.start(fg: :chartreuse); RubyText.stop }
39
- rescue
40
- RubyText.stop
41
37
  end
42
38
 
43
39
  def test_004_set_reset
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.12
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-01-12 00:00:00.000000000 Z
11
+ date: 2019-01-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: curses