rubytext 0.0.28 → 0.0.29
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rubytext +13 -2
- data/examples/demo.rb +2 -2
- data/examples/prog08.rb +4 -4
- data/examples/prog10.rb +1 -1
- data/examples/prog11.rb +1 -1
- data/examples/prog12.rb +1 -1
- data/examples/prog14.rb +11 -0
- data/examples/prog15.rb +14 -0
- data/examples/prog16.rb +9 -0
- data/examples/prog17.rb +11 -0
- data/examples/prog18.rb +8 -0
- data/examples/prog19.rb +10 -0
- data/examples/showme.rb +56 -0
- data/examples/slides +10 -12
- data/lib/rubytext.rb +61 -7
- data/lib/version.rb +1 -1
- metadata +8 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3919685b14367cf51dd12193b7e3397fde0843ee965dc7ea202aa8792ff5d973
|
4
|
+
data.tar.gz: d8cf125187b359c15e5ad5eda14652ca4e0e64f14d6394eb3dcee93b70fe61de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5c4118c0b3b8a8827ef56188f77a648e9660fea3f3edef249fa24c4594300637c51b988d7c5329a1cd5fae799a0332f7c4d9659e9e085dfaa99df243166479a
|
7
|
+
data.tar.gz: ea7dd88f236d86fbf4308b4bbd8e9ac0f3395ffd796ef4f651ab3993180bee65e29a331863e4dd0bd5b0cc81e77c314773ff83cae495ba429a19d7710409899a
|
data/bin/rubytext
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require 'rubytext'
|
3
|
+
require 'rubytext' # Remember: Specify STDOUT as needed!
|
4
4
|
|
5
|
-
|
5
|
+
path = RubyText::Path
|
6
|
+
|
7
|
+
cmd = ARGV.first
|
8
|
+
|
9
|
+
case cmd
|
10
|
+
when nil
|
11
|
+
STDOUT.puts "Usage: rubytext [demo|slides]"
|
12
|
+
when "demo"
|
13
|
+
system("ruby #{path}/../examples/demo.rb")
|
14
|
+
when "slides"
|
15
|
+
system("#{path}/../examples/slides")
|
16
|
+
end
|
data/examples/demo.rb
CHANGED
data/examples/prog08.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
win = RubyText.window(10, 50,
|
1
|
+
win = RubyText.window(10, 50, 0, 5, true, fg: :yellow, bg: :blue)
|
2
2
|
|
3
3
|
win.puts "We can use the []= method (0-based)"
|
4
4
|
win.puts "to address individual window locations"
|
5
|
-
win.puts "and place characters there
|
5
|
+
win.puts "and place characters there. [BUG!]\n "
|
6
6
|
|
7
7
|
sleep 2
|
8
8
|
win[4,2] = "X"
|
9
9
|
|
10
10
|
sleep 2
|
11
|
-
win[
|
11
|
+
win[8,10] = "y"
|
12
12
|
|
13
13
|
sleep 2
|
14
|
-
win[
|
14
|
+
win[6,18] = "Z"
|
data/examples/prog10.rb
CHANGED
data/examples/prog11.rb
CHANGED
data/examples/prog12.rb
CHANGED
data/examples/prog14.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
win = RubyText.window(13, 65, 2, 6, true, fg: :blue, bg: :white)
|
2
|
+
|
3
|
+
win.puts "The #rcprint method will print at the specified"
|
4
|
+
win.puts "row/column, like go(r,c) followed by a print,"
|
5
|
+
win.puts "except that it does NOT move the cursor."
|
6
|
+
|
7
|
+
win.rcprint 4,8, "Simplify,"
|
8
|
+
win.rcprint 6,12, "simplify,"
|
9
|
+
win.rcprint 8,16, "simplify!"
|
10
|
+
|
11
|
+
win.rcprint 10,0, "Later there will be other ways to do this kind of thing."
|
data/examples/prog15.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
win = RubyText.window(11, 65, 1, 6, true, fg: :blue, bg: :white)
|
2
|
+
|
3
|
+
win.go 2,0
|
4
|
+
win.puts " Method #home will home the cursor..."
|
5
|
+
win.puts " and #putch will put a character at the current location."
|
6
|
+
sleep 2
|
7
|
+
win.home; win.putch "H"; sleep 2
|
8
|
+
win.rcprint 4,3, "We can also move up/down/left/right..."; sleep 2
|
9
|
+
|
10
|
+
win.go 7, 29; win.putch("+"); sleep 1
|
11
|
+
win.go 7, 29; win.up; win.putch("U"); sleep 1
|
12
|
+
win.go 7, 29; win.down; win.putch("D"); sleep 1
|
13
|
+
win.go 7, 29; win.left; win.putch("L"); sleep 1
|
14
|
+
win.go 7, 29; win.right; win.putch("R"); sleep 1
|
data/examples/prog16.rb
ADDED
@@ -0,0 +1,9 @@
|
|
1
|
+
win = RubyText.window(11, 65, 1, 6, true, fg: :blue, bg: :white)
|
2
|
+
|
3
|
+
win.puts "Methods up/down/left/right can also take an integer..."
|
4
|
+
|
5
|
+
win.go 4, 29; win.putch("+"); sleep 1
|
6
|
+
win.go 4, 29; win.up(2); win.putch("2"); sleep 1
|
7
|
+
win.go 4, 29; win.down(3); win.putch("3"); sleep 1
|
8
|
+
win.go 4, 29; win.left(4); win.putch("4"); sleep 1
|
9
|
+
win.go 4, 29; win.right(5); win.putch("5"); sleep 1
|
data/examples/prog17.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
win = RubyText.window(11, 65, 1, 6, true, fg: :blue, bg: :white)
|
2
|
+
|
3
|
+
win.go 2,0
|
4
|
+
win.puts "We also have: up!, down!, left!, and right! which can"
|
5
|
+
win.puts "Take us to the edges of the window."
|
6
|
+
|
7
|
+
win.go 5, 21; win.putch("+"); sleep 1
|
8
|
+
win.go 5, 21; win.up!; win.putch("U"); sleep 1
|
9
|
+
win.go 5, 21; win.down!; win.putch("D"); sleep 1
|
10
|
+
win.go 5, 21; win.left!; win.putch("L"); sleep 1
|
11
|
+
win.go 5, 21; win.right!; win.putch("R"); sleep 1
|
data/examples/prog18.rb
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
win = RubyText.window(11, 65, 1, 6, true, fg: :blue, bg: :white)
|
2
|
+
|
3
|
+
win.go 2,0
|
4
|
+
win.puts "#top and #bottom are the same as #up! and #down!"
|
5
|
+
|
6
|
+
win.go 5, 21; win.putch("+"); sleep 1
|
7
|
+
win.go 5, 21; win.top; win.putch("T"); sleep 1
|
8
|
+
win.go 5, 21; win.bottom; win.putch("B"); sleep 1
|
data/examples/prog19.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
win = RubyText.window(15, 65, 1, 6, true, fg: :green, bg: :blue)
|
2
|
+
|
3
|
+
win.puts "#center will print text centered on the current row"
|
4
|
+
win.puts "and do an implicit CRLF at the end.\n "
|
5
|
+
|
6
|
+
stuff = ["I","can","never","imagine","good sets","of real words",
|
7
|
+
"which can somehow", "produce tree shapes", "|", "|"]
|
8
|
+
|
9
|
+
stuff.each {|str| win.center(str) }
|
10
|
+
|
data/examples/showme.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'rubytext'
|
2
|
+
require 'timeout'
|
3
|
+
|
4
|
+
def next_slide
|
5
|
+
RubyText.hide_cursor
|
6
|
+
sleep 2
|
7
|
+
Timeout.timeout(999) do
|
8
|
+
STDSCR.go @rmax-1, 0
|
9
|
+
STDSCR.center "Press any key..."
|
10
|
+
getch
|
11
|
+
end
|
12
|
+
rescue Timeout::Error
|
13
|
+
end
|
14
|
+
|
15
|
+
def show_code(prog)
|
16
|
+
text = File.read(prog)
|
17
|
+
nlines = text.split("\n").size
|
18
|
+
|
19
|
+
prog_top = @rmax-nlines-3
|
20
|
+
code = RubyText.window(nlines+2, @cmax-2, prog_top, 1,
|
21
|
+
true, fg: :green, bg: :black)
|
22
|
+
code.puts text
|
23
|
+
|
24
|
+
STDSCR.go prog_top, 61
|
25
|
+
STDSCR.print "[ #{prog} ]"
|
26
|
+
STDSCR.go 0,0
|
27
|
+
end
|
28
|
+
|
29
|
+
def check_window
|
30
|
+
if @rmax < 25 || @cmax < 80
|
31
|
+
puts "\n Your window should be 25x80 or larger,"
|
32
|
+
puts " but this one is only #{rmax}x#{cmax}."
|
33
|
+
puts " Please resize and run again!"
|
34
|
+
getch
|
35
|
+
exit 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
#### Main
|
40
|
+
|
41
|
+
RubyText.start(:cbreak, log: "showme.log", fg: :white, bg: :black)
|
42
|
+
|
43
|
+
@cmax = STDSCR.cols
|
44
|
+
@rmax = STDSCR.rows
|
45
|
+
|
46
|
+
RubyText.hide_cursor
|
47
|
+
|
48
|
+
check_window
|
49
|
+
|
50
|
+
prog = ARGV.first
|
51
|
+
|
52
|
+
show_code(prog)
|
53
|
+
|
54
|
+
require_relative prog
|
55
|
+
|
56
|
+
next_slide
|
data/examples/slides
CHANGED
@@ -3,15 +3,13 @@
|
|
3
3
|
rc = system("ruby examples/check.rb")
|
4
4
|
exit unless rc
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
system("ruby showme.rb
|
14
|
-
|
15
|
-
|
16
|
-
#system("ruby showme.rb examples/prog11.rb")
|
17
|
-
system("ruby showme.rb examples/prog12.rb")
|
6
|
+
# FIXME
|
7
|
+
# - use names instead of numbers?
|
8
|
+
# - convert rt-show into a method?
|
9
|
+
|
10
|
+
1.upto(19) do |n|
|
11
|
+
num = '%02d' % n
|
12
|
+
prog = "examples/prog#{num}.rb"
|
13
|
+
system("ruby examples/showme.rb #{prog}")
|
14
|
+
end
|
15
|
+
|
data/lib/rubytext.rb
CHANGED
@@ -73,7 +73,6 @@ module RubyText
|
|
73
73
|
|
74
74
|
def self.main(fg: nil, bg: nil)
|
75
75
|
@main_win = X.init_screen
|
76
|
-
debug(@main_win.inspect)
|
77
76
|
X.start_color
|
78
77
|
colors!(@main_win, fg, bg)
|
79
78
|
rows, cols = @main_win.maxy, @main_win.maxx
|
@@ -192,9 +191,16 @@ class RubyText::Window
|
|
192
191
|
@win.refresh
|
193
192
|
end
|
194
193
|
|
195
|
-
def center(
|
194
|
+
def center(str)
|
195
|
+
r, c = self.rc
|
196
196
|
n = @win.maxx - str.length
|
197
|
-
|
197
|
+
go r, n/2
|
198
|
+
puts str
|
199
|
+
end
|
200
|
+
|
201
|
+
def putch(ch)
|
202
|
+
r, c = self.rc
|
203
|
+
self[r, c] = ch[0]
|
198
204
|
end
|
199
205
|
|
200
206
|
def delegate_output(sym, *args)
|
@@ -247,9 +253,58 @@ debug "delegate: colors are #@fg, #@bg"
|
|
247
253
|
end
|
248
254
|
end
|
249
255
|
|
250
|
-
def
|
256
|
+
def up(n=1)
|
257
|
+
r, c = rc
|
258
|
+
go r-n, c
|
259
|
+
end
|
260
|
+
|
261
|
+
def down(n=1)
|
262
|
+
r, c = rc
|
263
|
+
go r+n, c
|
264
|
+
end
|
265
|
+
|
266
|
+
def left(n=1)
|
251
267
|
r, c = rc
|
252
|
-
go r
|
268
|
+
go r, c-n
|
269
|
+
end
|
270
|
+
|
271
|
+
def right(n=1)
|
272
|
+
r, c = rc
|
273
|
+
go r, c+n
|
274
|
+
end
|
275
|
+
|
276
|
+
def top
|
277
|
+
r, c = rc
|
278
|
+
go 0, c
|
279
|
+
end
|
280
|
+
|
281
|
+
def bottom
|
282
|
+
r, c = rc
|
283
|
+
rmax = self.rows - 1
|
284
|
+
go rmax, c
|
285
|
+
end
|
286
|
+
|
287
|
+
def up!
|
288
|
+
top
|
289
|
+
end
|
290
|
+
|
291
|
+
def down!
|
292
|
+
bottom
|
293
|
+
end
|
294
|
+
|
295
|
+
def left!
|
296
|
+
r, c = rc
|
297
|
+
go r, 0
|
298
|
+
end
|
299
|
+
|
300
|
+
def right!
|
301
|
+
r, c = rc
|
302
|
+
cmax = self.cols - 1
|
303
|
+
go r, cmax
|
304
|
+
end
|
305
|
+
|
306
|
+
def home
|
307
|
+
go 0, 0
|
253
308
|
end
|
254
309
|
|
255
310
|
def crlf
|
@@ -295,7 +350,7 @@ debug "delegate: colors are #@fg, #@bg"
|
|
295
350
|
|
296
351
|
def []=(r, c, char)
|
297
352
|
@win.setpos(r, c)
|
298
|
-
@win.
|
353
|
+
@win.addch(char[0])
|
299
354
|
@win.refresh
|
300
355
|
end
|
301
356
|
|
@@ -315,7 +370,6 @@ end
|
|
315
370
|
### Stick stuff into Kernel for top level
|
316
371
|
|
317
372
|
module Kernel
|
318
|
-
# private
|
319
373
|
def puts(*args) # Doesn't affect STDOUT.puts, etc.
|
320
374
|
$stdscr.puts(*args)
|
321
375
|
end
|
data/lib/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rubytext
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.29
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
@@ -51,6 +51,13 @@ files:
|
|
51
51
|
- examples/prog11.rb
|
52
52
|
- examples/prog12.rb
|
53
53
|
- examples/prog13.rb
|
54
|
+
- examples/prog14.rb
|
55
|
+
- examples/prog15.rb
|
56
|
+
- examples/prog16.rb
|
57
|
+
- examples/prog17.rb
|
58
|
+
- examples/prog18.rb
|
59
|
+
- examples/prog19.rb
|
60
|
+
- examples/showme.rb
|
54
61
|
- examples/slides
|
55
62
|
- lib/rubytext.rb
|
56
63
|
- lib/version.rb
|