rubytext 0.0.54 → 0.0.55
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/README.md +278 -6
- data/lib/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e76b63a284c3e46a82ebdbffe93539688f3e05e5ba07c3bcd1b3134a8e4e3f6
|
4
|
+
data.tar.gz: ec46b8c22012c818b4d920758e7dee6e07fdc10aa791a987293cadb011f8e3a0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ffe47e4511c9a9156fb6c0e93853b3bfa83f9c8b48c76db46f42eabb8f849227aa25a0c682231948eca23f0150602f6122db7d7a37914d1a1378b05d8d386529
|
7
|
+
data.tar.gz: 38bd6f8a6757d99f292dcd2731d0bd57d3275047aca5aadf5977c47b30b9f771912f648847594933c23a637b99c8175630191b1f9423177459a85908ca1c5da7
|
data/README.md
CHANGED
@@ -43,7 +43,7 @@ directory and the `showme.rb` script.
|
|
43
43
|
|
44
44
|
A simple window:
|
45
45
|
```ruby
|
46
|
-
require 'rubytext
|
46
|
+
require 'rubytext'
|
47
47
|
win = RubyText.window(6, 25, 2, 34,
|
48
48
|
# 6 rows, 25 cols; upper left at 2,4
|
49
49
|
fg: Blue, bg: White) # foreground, background
|
@@ -53,7 +53,7 @@ win.puts "This is a window..."
|
|
53
53
|
|
54
54
|
How `output` works. This name may change.
|
55
55
|
```ruby
|
56
|
-
require 'rubytext
|
56
|
+
require 'rubytext'
|
57
57
|
win = RubyText.window(9, 36, 2, 6, fg: White, bg: Red)
|
58
58
|
|
59
59
|
win.output do
|
@@ -65,7 +65,7 @@ end
|
|
65
65
|
|
66
66
|
Windows are bordered by default.
|
67
67
|
```ruby
|
68
|
-
require 'rubytext
|
68
|
+
require 'rubytext'
|
69
69
|
win = RubyText.window(9, 35, 3, 7, border: false, fg: Black, bg: Green)
|
70
70
|
|
71
71
|
win.puts "A window doesn't have to"
|
@@ -74,7 +74,7 @@ win.puts "have a border."
|
|
74
74
|
|
75
75
|
Using `puts` will wrap around the window automagically.
|
76
76
|
```ruby
|
77
|
-
require 'rubytext
|
77
|
+
require 'rubytext'
|
78
78
|
win = RubyText.window(8, 39, 4, 9, fg: Black, bg: Blue)
|
79
79
|
|
80
80
|
win.puts "If your text is longer than " +
|
@@ -86,7 +86,7 @@ win.puts "Scrolling is not yet supported."
|
|
86
86
|
|
87
87
|
Scrolling is not yet implemented.
|
88
88
|
```ruby
|
89
|
-
require 'rubytext
|
89
|
+
require 'rubytext'
|
90
90
|
win = RubyText.window(10, 70, 2, 14, fg: Yellow, bg: Black)
|
91
91
|
|
92
92
|
win.output do
|
@@ -103,7 +103,7 @@ end
|
|
103
103
|
|
104
104
|
You can use `print` and `p` as well as `puts`.
|
105
105
|
```ruby
|
106
|
-
require 'rubytext
|
106
|
+
require 'rubytext'
|
107
107
|
win = RubyText.window(10, 60, 2, 14, fg: Blue, bg: Black)
|
108
108
|
|
109
109
|
win.output do
|
@@ -119,5 +119,277 @@ win.output do
|
|
119
119
|
end
|
120
120
|
```
|
121
121
|
|
122
|
+
You can still use `puts` (etc.) with files, but watch for `STDOUT` and `STDERR`.
|
123
|
+
```ruby
|
124
|
+
require 'rubytext'
|
125
|
+
win = RubyText.window(10, 50, 0, 5, fg: Yellow, bg: Blue)
|
126
|
+
|
127
|
+
win.output do
|
128
|
+
puts "Of course, #puts and #print are unaffected \nfor other receivers."
|
129
|
+
|
130
|
+
out = File.new("/tmp/junk", "w")
|
131
|
+
out.puts "Nothing to see here."
|
132
|
+
sleep 2
|
133
|
+
|
134
|
+
print "\nHowever, if you print to STDOUT or STDERR \nwithout redirection, "
|
135
|
+
STDOUT.print "you will have some "
|
136
|
+
STDERR.print "unexpected/undefined results "
|
137
|
+
puts " in more ways than one."
|
138
|
+
end
|
139
|
+
|
140
|
+
```
|
141
|
+
|
142
|
+
Use `[]=` to stuff single characters into a window (like an array).
|
143
|
+
```ruby
|
144
|
+
require 'rubytext'
|
145
|
+
win = RubyText.window(11, 50, 0, 5, fg: Yellow, bg: Blue)
|
146
|
+
|
147
|
+
win.puts "We can use the []= method (0-based)"
|
148
|
+
win.puts "to address individual window locations"
|
149
|
+
win.puts "and place characters there.\n "
|
150
|
+
|
151
|
+
sleep 2
|
152
|
+
win[4,22] = "X"; win.refresh
|
153
|
+
|
154
|
+
sleep 2
|
155
|
+
win[8,20] = "y"; win.refresh
|
156
|
+
|
157
|
+
sleep 2
|
158
|
+
win[6,38] = "Z"; win.refresh
|
159
|
+
```
|
160
|
+
|
161
|
+
Likewise use `[]` to retrieve characters from a window.
|
162
|
+
```ruby
|
163
|
+
require 'rubytext'
|
164
|
+
win = RubyText.window(12, 60, 2, 5, fg: Yellow, bg: Blue)
|
165
|
+
|
166
|
+
win.puts "ABCDE Method [] can retrieve characters "
|
167
|
+
win.puts "FGHIJ from a window."
|
168
|
+
win.puts "KLMNO\nPQRST\nUVWZYZ"
|
169
|
+
win.puts
|
170
|
+
|
171
|
+
sleep 2
|
172
|
+
win.puts "(2,2) => '#{win[2,2]}' (0,4) => '#{win[0,4]}'"
|
173
|
+
win.puts "(6,7) => '#{win[6,7]}' (0,15) => '#{win[0,15]}'"
|
174
|
+
```
|
175
|
+
|
176
|
+
You can write to `STDSCR` or to a subwindow.
|
177
|
+
```ruby
|
178
|
+
require 'rubytext'
|
179
|
+
win = RubyText.window(6, 30, 2, 5, fg: Yellow, bg: Blue)
|
180
|
+
|
181
|
+
win.puts "You can write to a window..."
|
182
|
+
|
183
|
+
sleep 2
|
184
|
+
9.times { STDSCR.puts }
|
185
|
+
STDSCR.puts "...or you can write to STDSCR (standard screen)"
|
186
|
+
|
187
|
+
sleep 1
|
188
|
+
puts "STDSCR is the default receiver."
|
189
|
+
|
190
|
+
sleep 2
|
191
|
+
STDSCR.go 5, 0
|
192
|
+
puts "Nothing stops you from overwriting a window."
|
193
|
+
|
194
|
+
```
|
195
|
+
|
196
|
+
You can retrieve cursor position and window size.
|
197
|
+
```ruby
|
198
|
+
require 'rubytext'
|
199
|
+
win = RubyText.window(12, 65, 1, 5, fg: Yellow, bg: Blue)
|
200
|
+
|
201
|
+
win.output do
|
202
|
+
puts "You can detect the size and cursor position of any window."
|
203
|
+
puts "\nSTDSCR is #{STDSCR.rows} rows by #{STDSCR.cols} columns"
|
204
|
+
puts "win is #{win.rows} rows by #{win.cols} columns"
|
205
|
+
puts "\nSlightly Heisenbergian report of cursor position:"
|
206
|
+
puts " STDSCR.rc = #{STDSCR.rc.inspect}\n win.rc = #{win.rc.inspect}"
|
207
|
+
puts "\nFor fun, I'll print \"ABC\" to STDSCR..."
|
208
|
+
sleep 2
|
209
|
+
STDSCR.print "ABC"
|
210
|
+
end
|
211
|
+
```
|
212
|
+
|
213
|
+
Move the cursor with `go` (and use a block to jump/return).
|
214
|
+
```ruby
|
215
|
+
require 'rubytext'
|
216
|
+
win = RubyText.window(11, 65, 0, 15, fg: Blue, bg: Black)
|
217
|
+
|
218
|
+
win.puts "The #go method will move the cursor to a specific location."
|
219
|
+
win.go 2, 5
|
220
|
+
win.puts "x <-- The x is at 2,5"
|
221
|
+
|
222
|
+
win.puts "\nWith a block, it will execute the block and then"
|
223
|
+
win.puts "return to its previous location."
|
224
|
+
|
225
|
+
win.print "\n ABC..."
|
226
|
+
sleep 2
|
227
|
+
win.go(8, 20) { win.print "XYZ" }
|
228
|
+
sleep 2
|
229
|
+
win.print "DEF"
|
230
|
+
```
|
231
|
+
|
232
|
+
Use `rcprint` to print at specific coordinates.
|
233
|
+
```ruby
|
234
|
+
require 'rubytext'
|
235
|
+
win = RubyText.window(13, 65, 0, 6, fg: Blue, bg: White)
|
236
|
+
|
237
|
+
win.puts "The #rcprint method will print at the specified"
|
238
|
+
win.puts "row/column, like go(r,c) followed by a print,"
|
239
|
+
win.puts "except that it does NOT move the cursor."
|
240
|
+
|
241
|
+
win.rcprint 4,8, "Simplify,"
|
242
|
+
win.rcprint 6,12, "simplify,"
|
243
|
+
win.rcprint 8,16, "simplify!"
|
244
|
+
|
245
|
+
win.rcprint 10,0, "Later there will be other ways to do this kind of thing."
|
246
|
+
```
|
247
|
+
|
248
|
+
Window navigation: `home`, `up`, `down`, `left`, `right`
|
249
|
+
```ruby
|
250
|
+
require 'rubytext'
|
251
|
+
win = RubyText.window(11, 65, 0, 6, fg: Blue, bg: White)
|
252
|
+
|
253
|
+
win.go 2,0
|
254
|
+
win.puts " Method #home will home the cursor..."
|
255
|
+
win.puts " and #putch will put a character at the current location."
|
256
|
+
sleep 2
|
257
|
+
win.home; win.putch "H"; sleep 2
|
258
|
+
win.rcprint 4,3, "We can also move up/down/left/right..."; sleep 2
|
259
|
+
|
260
|
+
win.go 7, 29; win.putch("+"); sleep 1
|
261
|
+
win.go 7, 29; win.up; win.putch("U"); sleep 1
|
262
|
+
win.go 7, 29; win.down; win.putch("D"); sleep 1
|
263
|
+
win.go 7, 29; win.left; win.putch("L"); sleep 1
|
264
|
+
win.go 7, 29; win.right; win.putch("R"); sleep 1
|
265
|
+
```
|
266
|
+
|
267
|
+
More navigation: `up`, `down`, `left`, `right` with a parameter.
|
268
|
+
```ruby
|
269
|
+
require 'rubytext'
|
270
|
+
win = RubyText.window(11, 65, 1, 6, fg: Blue, bg: White)
|
271
|
+
|
272
|
+
win.puts "Methods up/down/left/right can also take an integer..."
|
273
|
+
|
274
|
+
win.go 4, 29; win.putch("+"); sleep 1
|
275
|
+
win.go 4, 29; win.up(2); win.putch("2"); sleep 1
|
276
|
+
win.go 4, 29; win.down(3); win.putch("3"); sleep 1
|
277
|
+
win.go 4, 29; win.left(4); win.putch("4"); sleep 1
|
278
|
+
win.go 4, 29; win.right(5); win.putch("5"); sleep 1
|
279
|
+
```
|
280
|
+
|
281
|
+
Still more navigation: `up!`, `down!`, `left!`, `right!`
|
282
|
+
```ruby
|
283
|
+
require 'rubytext'
|
284
|
+
win = RubyText.window(11, 65, 1, 6, fg: Blue, bg: White)
|
285
|
+
|
286
|
+
win.go 2,0
|
287
|
+
win.puts "We also have: up!, down!, left!, and right! which can"
|
288
|
+
win.puts "Take us to the edges of the window."
|
289
|
+
|
290
|
+
win.go 5, 21; win.putch("+"); sleep 1
|
291
|
+
win.go 5, 21; win.up!; win.putch("U"); sleep 1
|
292
|
+
win.go 5, 21; win.down!; win.putch("D"); sleep 1
|
293
|
+
win.go 5, 21; win.left!; win.putch("L"); sleep 1
|
294
|
+
win.go 5, 21; win.right!; win.putch("R"); sleep 1
|
295
|
+
```
|
296
|
+
|
297
|
+
And finally, `top` and `bottom`.
|
298
|
+
```ruby
|
299
|
+
require 'rubytext'
|
300
|
+
win = RubyText.window(11, 65, 1, 6, fg: Blue, bg: White)
|
301
|
+
|
302
|
+
win.go 2,0
|
303
|
+
win.puts "#top and #bottom are the same as #up! and #down!"
|
304
|
+
|
305
|
+
win.go 5, 21; win.putch("+"); sleep 1
|
306
|
+
win.go 5, 21; win.top; win.putch("T"); sleep 1
|
307
|
+
win.go 5, 21; win.bottom; win.putch("B"); sleep 1
|
308
|
+
```
|
309
|
+
|
310
|
+
Somewhat useless, but there is a `center` method.
|
311
|
+
```ruby
|
312
|
+
require 'rubytext'
|
313
|
+
win = RubyText.window(15, 65, 1, 6, fg: Green, bg: Blue)
|
314
|
+
|
315
|
+
win.puts "#center will print text centered on the current row"
|
316
|
+
win.puts "and do an implicit CRLF at the end.\n "
|
317
|
+
|
318
|
+
stuff = ["I","can","never","imagine","good sets","of real words",
|
319
|
+
"which can somehow", "produce tree shapes", "|", "|"]
|
320
|
+
|
321
|
+
stuff.each {|str| win.center(str) }
|
322
|
+
|
323
|
+
```
|
324
|
+
|
325
|
+
Changing colors during printing. This syntax will change.
|
326
|
+
```ruby
|
327
|
+
require 'rubytext'
|
328
|
+
win = RubyText.window(12, 65, 0, 6, fg: Green, bg: Blue)
|
329
|
+
|
330
|
+
win.puts "This is EXPERIMENTAL."
|
331
|
+
win.puts "Use a color symbol to change text color temporarily:\n "
|
332
|
+
|
333
|
+
win.puts "This is", :yellow, " another color", :white, " and yet another."
|
334
|
+
win.puts "And this is normal again.\n "
|
335
|
+
|
336
|
+
win.puts "This does mean that you can't print a symbol that is"
|
337
|
+
win.puts "also a color name... you'd need a workaround.\n "
|
338
|
+
|
339
|
+
sym = :red
|
340
|
+
win.puts "The symbol is ", sym.inspect, " which works", sym, " just fine."
|
341
|
+
```
|
342
|
+
|
343
|
+
A simple menu (incomplete, still experimental).
|
344
|
+
```ruby
|
345
|
+
require 'rubytext'
|
346
|
+
puts "This very crude menu is also EXPERIMENTAL."
|
347
|
+
puts "At the moment, it only works inside STDSCR!\n"
|
348
|
+
puts "It knows up, down, Enter, and Escape.\n "
|
349
|
+
puts "Press any key to display the menu..."
|
350
|
+
getch
|
351
|
+
|
352
|
+
days = %w[Monday Tuesday Wednesday Thursday Friday]
|
353
|
+
num, day = RubyText.menu(c: 30, items: days)
|
354
|
+
|
355
|
+
puts
|
356
|
+
if day.nil?
|
357
|
+
puts "You picked nothing!"
|
358
|
+
else
|
359
|
+
puts "You picked item #{num} which is #{day.inspect}"
|
360
|
+
end
|
361
|
+
```
|
362
|
+
|
363
|
+
DESC
|
364
|
+
```ruby
|
365
|
+
require 'rubytext'
|
366
|
+
```
|
367
|
+
|
368
|
+
A marquee or ticker example. This uses threads and is kind of cool.
|
369
|
+
```ruby
|
370
|
+
require 'rubytext'
|
371
|
+
msg = <<~EOS
|
372
|
+
A "ticker" example that actually uses threads. Maybe Curses is not as slow as
|
373
|
+
you thought? PRESS ANY KEY TO EXIT...
|
374
|
+
EOS
|
375
|
+
|
376
|
+
w, h = STDSCR.cols, STDSCR.rows - 1
|
377
|
+
threads = []
|
378
|
+
|
379
|
+
r = RubyText
|
380
|
+
t1 = -> { r.ticker(text: msg, row: h-8, col: 20, width: w-40, delay: 0.02, fg: Red, bg: Black) }
|
381
|
+
t2 = -> { r.ticker(text: msg, row: h-6, col: 15, width: w-30, delay: 0.04) }
|
382
|
+
t3 = -> { r.ticker(text: msg, row: h-4, col: 10, width: w-20, delay: 0.06, fg: Black, bg: Green) }
|
383
|
+
t4 = -> { r.ticker(text: msg, row: h-2, col: 5, width: w-10, delay: 0.08, bg: Black) }
|
384
|
+
t5 = -> { r.ticker(text: msg) } # All defaults -- goes at bottom
|
385
|
+
|
386
|
+
threads << Thread.new { t1.call } << Thread.new { t2.call } << Thread.new { t3.call } <<
|
387
|
+
Thread.new { t4.call } << Thread.new { t5.call }
|
388
|
+
|
389
|
+
threads << Thread.new { getch; exit } # quitter thread...
|
390
|
+
threads.each {|t| t.join }
|
391
|
+
```
|
392
|
+
|
393
|
+
|
122
394
|
*More later...*
|
123
395
|
|
data/lib/version.rb
CHANGED