rubytext 0.0.77 → 0.0.78
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/examples/crap.rb +16 -0
- data/examples/prog21.rb +9 -7
- data/examples/prog23.rb +19 -0
- data/examples/prog24.rb +13 -0
- data/lib/menu.rb +14 -37
- data/lib/navigation.rb +3 -2
- data/lib/output.rb +22 -8
- data/lib/rubytext.rb +5 -0
- data/lib/version.rb +1 -1
- data/lib/window.rb +21 -0
- metadata +4 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4e354c6fdb94b4939d7c3fbe944b852d783db1235f571b6b882250be184ea531
|
4
|
+
data.tar.gz: 5d1924c94b30a6a54df89a16fdcb0e9ca5885921fc29b6c882a32c9cfc0dd40a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2abaa8f1c0d14fbc306a94b99e971ba72b923b6cc6986408292c1e6c3610e613ad5f3db634322f8338e43c794efebf8f189ad844d886ff17251df29702608914
|
7
|
+
data.tar.gz: 0bd784d37d361c964cd15aa7c3c6f14bd46980ba2509bee9dd8303ed4f6578b4f0c71e6d6a4c2b2c3c9c19053e68814d165c80b6d3fe146acea3fcbb9f26680b
|
data/examples/crap.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubytext'
|
2
|
+
|
3
|
+
RubyText.start
|
4
|
+
|
5
|
+
STDSCR.go 1, 2
|
6
|
+
STDSCR.putch "0"
|
7
|
+
|
8
|
+
STDSCR.putch '1', r: 3, c: 6, fx: RubyText::Effects.new(Red)
|
9
|
+
STDSCR.putch '2', r: 5, c: 10, fx: RubyText::Effects.new(Yellow, :reverse)
|
10
|
+
STDSCR.putch '3', r: 7, c: 14
|
11
|
+
STDSCR.putch '4', r: 9, c: 18, fx: RubyText::Effects.new(Green, :normal)
|
12
|
+
STDSCR.putch '5', r: 11, c: 22, fx: RubyText::Effects.new(Red, :normal)
|
13
|
+
|
14
|
+
STDSCR.home
|
15
|
+
|
16
|
+
getch
|
data/examples/prog21.rb
CHANGED
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
puts "
|
3
|
-
puts "It knows up, down, Enter, and Escape.\n "
|
4
|
-
puts "Press any key to display the menu..."
|
1
|
+
win = RubyText.window(10, 45, 1, 20, fg: Black, bg: Red)
|
2
|
+
win.puts "This very crude menu is also EXPERIMENTAL."
|
3
|
+
win.puts "It knows up, down, Enter, and Escape.\n "
|
4
|
+
win.puts "Press any key to display the menu..."
|
5
|
+
win.puts
|
6
|
+
|
5
7
|
getch
|
6
8
|
|
7
9
|
days = %w[Monday Tuesday Wednesday Thursday Friday]
|
8
|
-
num, day = RubyText.menu(c:
|
10
|
+
num, day = RubyText.menu(win: win, r: 2, c: 5, items: days)
|
9
11
|
|
10
12
|
puts
|
11
13
|
if day.nil?
|
12
|
-
puts "You picked nothing!"
|
14
|
+
win.puts "You picked nothing!"
|
13
15
|
else
|
14
|
-
puts "You picked item #{num} which is #{day.inspect}"
|
16
|
+
win.puts "You picked item #{num} which is #{day.inspect}"
|
15
17
|
end
|
data/examples/prog23.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
puts "\n Methods such as go, rcprint, and putch \n can accept symbols such as"
|
2
|
+
puts " :top :bottom :left :right :center"
|
3
|
+
puts "\n Of course, printing starting at the far right \n can be problematic."
|
4
|
+
|
5
|
+
win = RubyText.window(7, 29, 1, 60, fg: Red, bg: Black)
|
6
|
+
|
7
|
+
win.putch "1", r: :bottom, c: :left; sleep 0.4
|
8
|
+
win.go :center, :left; win.puts "abc"; sleep 0.4
|
9
|
+
win.go :top, :left; win.puts "def"; sleep 0.4
|
10
|
+
win.rcprint :top, :center, "4"; sleep 0.4
|
11
|
+
|
12
|
+
others = [[:top, :right, "5"], [:center, :right, "6"], [:bottom, :right, "7"],
|
13
|
+
[:bottom, :center, "8"], [:center, :center, "9"]]
|
14
|
+
others.each do |args|
|
15
|
+
r, c, ch = *args
|
16
|
+
win.go r,c
|
17
|
+
win.putch(ch)
|
18
|
+
sleep 0.4
|
19
|
+
end
|
data/examples/prog24.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
puts "\n\n\n putch can take optional row/column keyword arguments"
|
2
|
+
puts " as well as 'fx' (text effects)"
|
3
|
+
|
4
|
+
STDSCR.go 1, 55; sleep 0.4
|
5
|
+
STDSCR.putch "0"; sleep 0.4
|
6
|
+
|
7
|
+
STDSCR.putch '1', r: 3, c: 59, fx: RubyText::Effects.new(Red); sleep 0.4
|
8
|
+
STDSCR.putch '2', r: 5, c: 63, fx: RubyText::Effects.new(Yellow, :reverse); sleep 0.4
|
9
|
+
STDSCR.putch '3', r: 7, c: 67; sleep 0.4
|
10
|
+
STDSCR.putch '4', r: 9, c: 71, fx: RubyText::Effects.new(Green, :normal); sleep 0.4
|
11
|
+
STDSCR.putch '5', r: 11, c: 75, fx: RubyText::Effects.new(Red, :normal)
|
12
|
+
|
13
|
+
STDSCR.home
|
data/lib/menu.rb
CHANGED
@@ -1,32 +1,11 @@
|
|
1
1
|
module RubyText
|
2
2
|
|
3
|
-
def self.
|
4
|
-
@pos = STDSCR.rc
|
5
|
-
@save = []
|
6
|
-
0.upto(high-1) do |h|
|
7
|
-
0.upto(wide-1) do |w|
|
8
|
-
@save << STDSCR[h+r, w+c]
|
9
|
-
end
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
|
-
def self.restback(high, wide, r, c)
|
14
|
-
0.upto(high-1) do |h|
|
15
|
-
0.upto(wide-1) do |w|
|
16
|
-
STDSCR[h+r, w+c] = @save.shift
|
17
|
-
end
|
18
|
-
end
|
19
|
-
STDSCR.go *@pos
|
20
|
-
STDSCR.refresh
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.menu(r: 0, c: 0, items:, curr: 0,
|
3
|
+
def self.menu(win: STDSCR, r: 0, c: 0, items:, curr: 0,
|
24
4
|
fg: White, bg: Blue)
|
25
5
|
high = items.size + 2
|
26
6
|
wide = items.map(&:length).max + 4
|
27
|
-
saveback(high, wide, r, c)
|
28
|
-
|
29
|
-
# RubyText.set(:raw)
|
7
|
+
win.saveback(high, wide, r, c)
|
8
|
+
mwin = RubyText.window(high, wide, r+win.r0, c+win.c0, fg: fg, bg: bg)
|
30
9
|
X.stdscr.keypad(true)
|
31
10
|
RubyText.hide_cursor
|
32
11
|
sel = curr
|
@@ -35,9 +14,9 @@ module RubyText
|
|
35
14
|
rev = RubyText::Effects.new(:reverse)
|
36
15
|
loop do
|
37
16
|
items.each.with_index do |item, row|
|
38
|
-
|
17
|
+
mwin.go row, 0
|
39
18
|
style = (sel == row) ? rev : norm
|
40
|
-
|
19
|
+
mwin.print style, " #{item} "
|
41
20
|
end
|
42
21
|
ch = getch
|
43
22
|
case ch
|
@@ -46,25 +25,23 @@ module RubyText
|
|
46
25
|
when X::KEY_DOWN
|
47
26
|
sel += 1 if sel < max
|
48
27
|
when 27
|
49
|
-
restback(high, wide, r, c)
|
28
|
+
win.restback(high, wide, r, c)
|
50
29
|
return [nil, nil]
|
51
30
|
when 10
|
52
|
-
restback(high, wide, r, c)
|
31
|
+
win.restback(high, wide, r, c)
|
53
32
|
return [sel, items[sel]]
|
54
33
|
end
|
55
34
|
end
|
56
35
|
end
|
57
36
|
|
58
|
-
def self.selector(r: 0, c: 0, rows: 10, cols: 20,
|
37
|
+
def self.selector(win: STDSCR, r: 0, c: 0, rows: 10, cols: 20,
|
59
38
|
items:, fg: White, bg: Blue,
|
60
|
-
|
39
|
+
win2:, callback:, enter: nil, quit: "q")
|
61
40
|
high = rows
|
62
41
|
wide = cols
|
63
|
-
saveback(high, wide, r, c)
|
64
|
-
|
65
|
-
win2 = win
|
42
|
+
win.saveback(high, wide, r, c)
|
43
|
+
mwin = RubyText.window(high, wide, r, c, fg: fg, bg: bg)
|
66
44
|
handler = callback
|
67
|
-
# RubyText.set(:raw)
|
68
45
|
X.stdscr.keypad(true)
|
69
46
|
RubyText.hide_cursor
|
70
47
|
norm = RubyText::Effects.new(:normal)
|
@@ -73,11 +50,11 @@ module RubyText
|
|
73
50
|
max = items.size - 1
|
74
51
|
send(handler, sel, items[sel], win2)
|
75
52
|
loop do
|
76
|
-
|
53
|
+
mwin.home
|
77
54
|
items.each.with_index do |item, row|
|
78
|
-
|
55
|
+
mwin.left
|
79
56
|
style = (sel == row) ? rev : norm
|
80
|
-
|
57
|
+
mwin.puts style, " #{item} "
|
81
58
|
end
|
82
59
|
ch = getch
|
83
60
|
case ch
|
data/lib/navigation.rb
CHANGED
data/lib/output.rb
CHANGED
@@ -63,16 +63,27 @@ class RubyText::Window
|
|
63
63
|
self.print *args
|
64
64
|
end
|
65
65
|
|
66
|
+
def _putch(ch)
|
67
|
+
@cwin.addch(ch)
|
68
|
+
end
|
69
|
+
|
66
70
|
def putch(ch, r: nil, c: nil, fx: nil)
|
67
|
-
|
68
|
-
r
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
71
|
+
debug("putch: #{[ch, r, c, fx].inspect}")
|
72
|
+
if r.nil? && c.nil? && fx.nil?
|
73
|
+
_putch(ch)
|
74
|
+
else
|
75
|
+
r0, c0 = self.rc
|
76
|
+
r ||= r0
|
77
|
+
c ||= c0
|
78
|
+
go(r, c) do
|
79
|
+
fx.set(self) if fx
|
80
|
+
val = fx.value rescue 0
|
81
|
+
@cwin.addch(ch.ord|val)
|
82
|
+
# @cwin.addch(ch)
|
83
|
+
end
|
84
|
+
fx.reset(self) if fx
|
74
85
|
end
|
75
|
-
|
86
|
+
@cwin.refresh
|
76
87
|
end
|
77
88
|
|
78
89
|
def crlf # Technically not output...
|
@@ -181,6 +192,9 @@ module WindowIO
|
|
181
192
|
end
|
182
193
|
|
183
194
|
def putch(ch, r: nil, c: nil, fx: nil)
|
195
|
+
r, c = STDSCR.rc
|
196
|
+
r ||= r0
|
197
|
+
c ||= c0
|
184
198
|
STDSCR.putch(ch, r: r, c: c, fx: fx)
|
185
199
|
end
|
186
200
|
end
|
data/lib/rubytext.rb
CHANGED
data/lib/version.rb
CHANGED
data/lib/window.rb
CHANGED
@@ -2,6 +2,7 @@ class RubyText::Window
|
|
2
2
|
Vert, Horiz = X::A_VERTICAL, X::A_HORIZONTAL
|
3
3
|
|
4
4
|
attr_reader :cwin, :rows, :cols, :width, :height, :scrolling
|
5
|
+
attr_reader :r0, :c0
|
5
6
|
attr_accessor :fg, :bg
|
6
7
|
|
7
8
|
# Better to use Window.window IRL
|
@@ -92,6 +93,26 @@ class RubyText::Window
|
|
92
93
|
lines
|
93
94
|
end
|
94
95
|
|
96
|
+
def saveback(high, wide, r, c)
|
97
|
+
@pos = self.rc
|
98
|
+
@save = []
|
99
|
+
0.upto(high-1) do |h|
|
100
|
+
0.upto(wide-1) do |w|
|
101
|
+
@save << self[h+r-1, w+c-1]
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
|
106
|
+
def restback(high, wide, r, c)
|
107
|
+
0.upto(high-1) do |h|
|
108
|
+
0.upto(wide-1) do |w|
|
109
|
+
self[h+r-1, w+c-1] = @save.shift
|
110
|
+
end
|
111
|
+
end
|
112
|
+
self.go *@pos
|
113
|
+
@cwin.refresh
|
114
|
+
end
|
115
|
+
|
95
116
|
def fg=(sym)
|
96
117
|
set_colors(fg, @bg)
|
97
118
|
end
|
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.78
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
@@ -42,6 +42,7 @@ files:
|
|
42
42
|
- bin/rubytext
|
43
43
|
- examples/README
|
44
44
|
- examples/check.rb
|
45
|
+
- examples/crap.rb
|
45
46
|
- examples/demo.rb
|
46
47
|
- examples/ide.rb
|
47
48
|
- examples/multitest.rb
|
@@ -68,6 +69,8 @@ files:
|
|
68
69
|
- examples/prog20a.rb
|
69
70
|
- examples/prog21.rb
|
70
71
|
- examples/prog22.rb
|
72
|
+
- examples/prog23.rb
|
73
|
+
- examples/prog24.rb
|
71
74
|
- examples/showme.rb
|
72
75
|
- examples/slides
|
73
76
|
- lib/color.rb
|