rubytext 0.0.66 → 0.0.67
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/wtf.out +0 -0
- data/lib/color.rb +41 -20
- data/lib/output.rb +5 -7
- data/lib/rubytext.rb +0 -4
- data/lib/settings.rb +0 -1
- data/lib/version.rb +1 -1
- data/lib/window.rb +5 -3
- metadata +2 -6
- data/examples/_demo.rb +0 -118
- data/examples/_showme.rb +0 -58
- data/examples/_slides +0 -22
- data/examples/foo +0 -7
- data/lib/_color.rb +0 -69
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a60cfbca3fe7273cfcf397c296efa9ec9f15465e37f6e14c2f4d48d04ba1d2dd
|
4
|
+
data.tar.gz: 9f6064816a1c0e6fbdcd8e43a2a8e6ad46b47e05d7b40128c54619e90aa9db2c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 20bcfd4c010aef7769f1535f5e8ae82d4aa61a564646b92c1d7665dc8a6e475f3c8f4a234f95387fd67aae751387b9c226430a1893c5bb22f336c625dcc97a9d
|
7
|
+
data.tar.gz: 5114876fdb6681991646b0b9b940efa5b7baac99717d909011998457cf147682468729c2cf5be40c4a3ce965786fd02ca56a99d5a41af8bc19455c61229f5116
|
data/examples/wtf.out
ADDED
File without changes
|
data/lib/color.rb
CHANGED
@@ -8,37 +8,58 @@ def fb2cp(fg, bg)
|
|
8
8
|
[f2, b2, cp]
|
9
9
|
end
|
10
10
|
|
11
|
-
|
11
|
+
# Colors are 'global' for now
|
12
|
+
Black, Blue, Cyan, Green, Magenta, Red, White, Yellow =
|
13
|
+
:black, :blue, :cyan, :green, :magenta, :red, :white, :yellow
|
14
|
+
|
15
|
+
class RubyText::Color
|
12
16
|
Colors = [Black, Blue, Cyan, Green, Magenta, Red, White, Yellow]
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
17
|
+
|
18
|
+
def self.sym2const(color) # to curses constant
|
19
|
+
X.const_get("COLOR_#{color.to_s.upcase}")
|
20
|
+
end
|
21
|
+
|
22
|
+
def self.index(color)
|
23
|
+
Colors.find_index(color) # "our" number
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.pair(fg, bg)
|
27
|
+
num = 8*index(fg) + index(bg)
|
28
|
+
X.init_pair(num, sym2const(fg), sym2const(bg))
|
29
|
+
num
|
22
30
|
end
|
23
31
|
end
|
24
32
|
|
25
33
|
class RubyText::Window
|
26
|
-
def self.
|
27
|
-
|
28
|
-
X.init_pair(cp, cfg, cbg)
|
34
|
+
def self.colorize!(win, fg, bg)
|
35
|
+
cp = RubyText::Color.pair(fg, bg)
|
29
36
|
win.color_set(cp)
|
30
|
-
end
|
31
|
-
|
32
|
-
def self.colors!(win, fg, bg)
|
33
|
-
colors(win, fg, bg)
|
34
37
|
num = win.maxx * win.maxy
|
35
|
-
win.setpos
|
38
|
+
win.setpos 0,0
|
36
39
|
win.addstr(' '*num)
|
37
|
-
win.setpos
|
40
|
+
win.setpos 0,0
|
38
41
|
win.refresh
|
39
42
|
end
|
40
43
|
|
44
|
+
def set_colors(fg, bg)
|
45
|
+
cp = RubyText::Color.pair(fg, bg)
|
46
|
+
@cwin.color_set(cp)
|
47
|
+
end
|
48
|
+
|
49
|
+
def colorize!(fg, bg)
|
50
|
+
set_colors(fg, bg)
|
51
|
+
num = @cwin.maxx * @cwin.maxy
|
52
|
+
self.home
|
53
|
+
self.go(0, 0) { @cwin.addstr(' '*num) }
|
54
|
+
@cwin.refresh
|
55
|
+
end
|
56
|
+
|
41
57
|
def fg=(sym)
|
42
|
-
|
58
|
+
set_colors(fg, @bg)
|
59
|
+
end
|
60
|
+
|
61
|
+
def bg=(sym)
|
62
|
+
set_colors(@fg, bg)
|
43
63
|
end
|
44
64
|
end
|
65
|
+
|
data/lib/output.rb
CHANGED
@@ -16,14 +16,14 @@ class RubyText::Window
|
|
16
16
|
# FIXME Please refactor the Hal out of this.
|
17
17
|
|
18
18
|
def special?(arg)
|
19
|
-
RubyText::Colors.include?(arg) ||
|
19
|
+
RubyText::Color::Colors.include?(arg) ||
|
20
20
|
arg.is_a?(RubyText::Effects)
|
21
21
|
end
|
22
22
|
|
23
23
|
def delegate_output(sym, *args)
|
24
24
|
args = [""] if args.empty?
|
25
25
|
args += ["\n"] unless sym == :print
|
26
|
-
|
26
|
+
set_colors(@fg, @bg) # FIXME?
|
27
27
|
if sym == :p
|
28
28
|
args.map!(&:inspect)
|
29
29
|
else
|
@@ -32,14 +32,14 @@ class RubyText::Window
|
|
32
32
|
args.each do |arg|
|
33
33
|
case
|
34
34
|
when arg.is_a?(Symbol) # must be a color
|
35
|
-
|
35
|
+
set_colors(arg, @bg) # FIXME?
|
36
36
|
when arg.is_a?(RubyText::Effects)
|
37
37
|
X.attrset(arg.value)
|
38
38
|
else
|
39
39
|
arg.each_char {|ch| ch == "\n" ? crlf : @cwin.addch(ch) }
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
set_colors(@fg, @bg)
|
43
43
|
@cwin.refresh
|
44
44
|
end
|
45
45
|
|
@@ -127,9 +127,8 @@ class RubyText::Window
|
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
130
|
-
|
130
|
+
# into top level...
|
131
131
|
|
132
|
-
module Kernel
|
133
132
|
def puts(*args) # Doesn't affect STDOUT.puts, etc.
|
134
133
|
$stdscr.puts(*args)
|
135
134
|
end
|
@@ -149,5 +148,4 @@ module Kernel
|
|
149
148
|
def getch
|
150
149
|
X.getch
|
151
150
|
end
|
152
|
-
end
|
153
151
|
|
data/lib/rubytext.rb
CHANGED
data/lib/settings.rb
CHANGED
data/lib/version.rb
CHANGED
data/lib/window.rb
CHANGED
@@ -10,13 +10,13 @@ class RubyText::Window
|
|
10
10
|
@wide, @high, @r0, @c0 = wide, high, r0, c0
|
11
11
|
@border, @fg, @bg = border, fg, bg
|
12
12
|
@cwin = X::Window.new(high, wide, r0, c0)
|
13
|
-
|
13
|
+
colorize!(fg, bg)
|
14
14
|
if @border
|
15
15
|
@cwin.box(Vert, Horiz)
|
16
16
|
@outer = @cwin
|
17
17
|
@outer.refresh
|
18
18
|
@cwin = X::Window.new(high-2, wide-2, r0+1, c0+1)
|
19
|
-
|
19
|
+
colorize!(fg, bg)
|
20
20
|
else
|
21
21
|
@outer = @cwin
|
22
22
|
end
|
@@ -30,10 +30,12 @@ class RubyText::Window
|
|
30
30
|
def self.main(fg: nil, bg: nil, scroll: false)
|
31
31
|
main_win = X.init_screen
|
32
32
|
X.start_color
|
33
|
-
|
33
|
+
self.colorize!(main_win, fg, bg)
|
34
34
|
rows, cols = main_win.maxy, main_win.maxx
|
35
35
|
self.make(main_win, rows, cols, 0, 0, border: false,
|
36
36
|
fg: fg, bg: bg, scroll: scroll)
|
37
|
+
rescue => err
|
38
|
+
File.open("/tmp/main.out", "w") {|f| f.puts err.inspect; f.puts err.backtrace }
|
37
39
|
end
|
38
40
|
|
39
41
|
def self.make(cwin, high, wide, r0, c0, border: true, fg: White, bg: Black, scroll: false)
|
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.67
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
@@ -41,12 +41,8 @@ files:
|
|
41
41
|
- "./rubytext.gemspec"
|
42
42
|
- bin/rubytext
|
43
43
|
- examples/README
|
44
|
-
- examples/_demo.rb
|
45
|
-
- examples/_showme.rb
|
46
|
-
- examples/_slides
|
47
44
|
- examples/check.rb
|
48
45
|
- examples/demo.rb
|
49
|
-
- examples/foo
|
50
46
|
- examples/ide.rb
|
51
47
|
- examples/prog01.rb
|
52
48
|
- examples/prog02.rb
|
@@ -72,7 +68,7 @@ files:
|
|
72
68
|
- examples/prog22.rb
|
73
69
|
- examples/showme.rb
|
74
70
|
- examples/slides
|
75
|
-
-
|
71
|
+
- examples/wtf.out
|
76
72
|
- lib/_window.rb
|
77
73
|
- lib/color.rb
|
78
74
|
- lib/effects.rb
|
data/examples/_demo.rb
DELETED
@@ -1,118 +0,0 @@
|
|
1
|
-
$LOAD_PATH.unshift "lib"
|
2
|
-
|
3
|
-
require 'rubytext'
|
4
|
-
|
5
|
-
def delay(sec, speed=1.0)
|
6
|
-
sleep sec/speed
|
7
|
-
end
|
8
|
-
|
9
|
-
speed = ARGV.first || 1.0
|
10
|
-
speed = speed.to_f
|
11
|
-
delay(speed)
|
12
|
-
|
13
|
-
RubyText.start(log: "mylog.txt", fg: Green, bg: Black)
|
14
|
-
|
15
|
-
print "Here goes... "
|
16
|
-
delay 2
|
17
|
-
|
18
|
-
ymax, xmax = STDSCR.rows, STDSCR.cols
|
19
|
-
|
20
|
-
puts "STDSCR is #{ymax.inspect} by #{xmax.inspect}"
|
21
|
-
delay 2
|
22
|
-
|
23
|
-
print "\nI can write here "
|
24
|
-
delay 2
|
25
|
-
puts "and then continue."
|
26
|
-
|
27
|
-
delay 2
|
28
|
-
print "I can jump away "
|
29
|
-
|
30
|
-
delay 2
|
31
|
-
STDSCR.go(20, 15) { puts "and print somewhere else" }
|
32
|
-
# ^ Same as: rcprint(20, 15, "and print somewhere else" }
|
33
|
-
|
34
|
-
delay 2
|
35
|
-
puts "and then return."
|
36
|
-
|
37
|
-
delay 3
|
38
|
-
print "I can hide the cursor... "
|
39
|
-
delay 1
|
40
|
-
RubyText.hide_cursor
|
41
|
-
delay 1
|
42
|
-
print "then show it again... "
|
43
|
-
delay 1
|
44
|
-
RubyText.show_cursor
|
45
|
-
delay 1
|
46
|
-
print "and hide it again. "
|
47
|
-
delay 1
|
48
|
-
RubyText.hide_cursor
|
49
|
-
delay 3
|
50
|
-
|
51
|
-
puts "\n\nNow watch as I create a window:"
|
52
|
-
|
53
|
-
mywin = RubyText.window(16, 40, 8, 14, fg: :blue, bg: :yellow)
|
54
|
-
|
55
|
-
delay 3
|
56
|
-
mywin.puts "\nNow I'm writing in a window."
|
57
|
-
mywin.puts "\nIts size is #{mywin.rows} rows by #{mywin.cols} cols"
|
58
|
-
mywin.puts "(or #{mywin.height}x#{mywin.width} with the frame).\n "
|
59
|
-
|
60
|
-
delay 4
|
61
|
-
mywin.puts "I always try to honor the borders of my window."
|
62
|
-
|
63
|
-
delay 2
|
64
|
-
mywin.puts "\nWatch as I place 50 random stars here..."
|
65
|
-
|
66
|
-
delay 2
|
67
|
-
|
68
|
-
50.times do
|
69
|
-
r = rand(mywin.rows)
|
70
|
-
c = rand(mywin.cols)
|
71
|
-
delay 0.1
|
72
|
-
mywin.rcprint(r, c, "*")
|
73
|
-
end
|
74
|
-
|
75
|
-
delay 4
|
76
|
-
mywin.output do
|
77
|
-
mywin.clear
|
78
|
-
puts "The window method called 'output'"
|
79
|
-
puts "will temporarily override STDSCR so that (in the code)"
|
80
|
-
puts "we don't have to use the window name over and over for stream I/O."
|
81
|
-
delay 4
|
82
|
-
# STDSCR.rcprint 25, 3, "Of course I can still print here if I want."
|
83
|
-
STDSCR.go 25, 3
|
84
|
-
STDSCR.print "Of course I can still print here if I want."
|
85
|
-
delay 3
|
86
|
-
puts "\nOne moment..."
|
87
|
-
delay 4
|
88
|
-
end
|
89
|
-
|
90
|
-
mywin.output do
|
91
|
-
mywin.clear
|
92
|
-
puts "The []= method allows us to place characters in"
|
93
|
-
puts "the window (without auto-refresh)."
|
94
|
-
puts "\nLet's see the '50 stars' trick again:"
|
95
|
-
delay 5
|
96
|
-
50.times do
|
97
|
-
r = rand(mywin.rows)
|
98
|
-
c = rand(mywin.cols)
|
99
|
-
mywin[r, c] = "*"
|
100
|
-
end
|
101
|
-
mywin.cwin.refresh
|
102
|
-
end
|
103
|
-
|
104
|
-
delay 5
|
105
|
-
mywin.output do
|
106
|
-
mywin.clear
|
107
|
-
mywin.puts "The [] method (zero-based) is still buggy, but let's try it."
|
108
|
-
mywin.puts "XYZ"
|
109
|
-
ch = mywin[2,2]
|
110
|
-
mywin.puts "The char at [2,2] is: #{ch.chr.inspect}"
|
111
|
-
end
|
112
|
-
|
113
|
-
delay 4
|
114
|
-
mywin.puts "\nThat's all for now."
|
115
|
-
delay 1
|
116
|
-
mywin.puts "\nPress any key to exit."
|
117
|
-
|
118
|
-
getch
|
data/examples/_showme.rb
DELETED
@@ -1,58 +0,0 @@
|
|
1
|
-
require 'rubytext'
|
2
|
-
require 'timeout'
|
3
|
-
|
4
|
-
def next_slide
|
5
|
-
RubyText.hide_cursor
|
6
|
-
sleep 0.2
|
7
|
-
Timeout.timeout(999) do
|
8
|
-
STDSCR.go @rmax-1-@upward, 0
|
9
|
-
STDSCR.center "Press any key..."
|
10
|
-
getch
|
11
|
-
end
|
12
|
-
rescue Timeout::Error
|
13
|
-
end
|
14
|
-
|
15
|
-
def show_code(prog, upward=0)
|
16
|
-
text = File.read(prog)
|
17
|
-
nlines = text.split("\n").size
|
18
|
-
|
19
|
-
prog_top = @rmax-nlines-3 - upward.to_i
|
20
|
-
code = RubyText.window(nlines+2, @cmax-2, prog_top, 1,
|
21
|
-
fg: Green, bg: Black)
|
22
|
-
code.puts text
|
23
|
-
|
24
|
-
right = STDSCR.cols - prog.length - 8
|
25
|
-
STDSCR.go prog_top, right
|
26
|
-
STDSCR.print "[ #{prog} ]"
|
27
|
-
STDSCR.go 0,0
|
28
|
-
end
|
29
|
-
|
30
|
-
def check_window
|
31
|
-
if @rmax < 25 || @cmax < 80
|
32
|
-
puts "\n Your window should be 25x80 or larger,"
|
33
|
-
puts " but this one is only #{@rmax}x#{@cmax}."
|
34
|
-
puts " Please resize and run again!"
|
35
|
-
getch
|
36
|
-
exit 1
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
#### Main
|
41
|
-
|
42
|
-
RubyText.start(:cbreak, log: "/tmp/showme.log", fg: White, bg: Black)
|
43
|
-
|
44
|
-
@cmax = STDSCR.cols
|
45
|
-
@rmax = STDSCR.rows
|
46
|
-
|
47
|
-
RubyText.hide_cursor
|
48
|
-
|
49
|
-
check_window
|
50
|
-
|
51
|
-
prog, @upward = ARGV
|
52
|
-
@upward ||= 0
|
53
|
-
|
54
|
-
show_code(prog, @upward)
|
55
|
-
|
56
|
-
require_relative prog
|
57
|
-
|
58
|
-
next_slide # if @upward == 0
|
data/examples/_slides
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
|
3
|
-
mylib = `gem which rubytext`.chomp
|
4
|
-
examples = mylib.sub(%r[/lib/rubytext.rb], "/examples")
|
5
|
-
|
6
|
-
Dir.chdir(examples)
|
7
|
-
|
8
|
-
rc = system("ruby check.rb")
|
9
|
-
exit unless rc
|
10
|
-
|
11
|
-
# FIXME
|
12
|
-
# - use names instead of numbers?
|
13
|
-
# - convert showme into a method?
|
14
|
-
|
15
|
-
1.upto(22) do |n|
|
16
|
-
next if n == 11 # junk this one
|
17
|
-
num = '%02d' % n
|
18
|
-
prog = "prog#{num}.rb"
|
19
|
-
upward = 11 if n == 22 # dumbest hack ever!
|
20
|
-
system("ruby showme.rb #{prog} #{upward}")
|
21
|
-
end
|
22
|
-
|
data/examples/foo
DELETED
@@ -1,7 +0,0 @@
|
|
1
|
-
#<ArgumentError: wrong number of arguments (given 2, expected 1)>
|
2
|
-
/Users/Hal/.rvm/gems/ruby-2.4.2/gems/rubytext-0.0.65/lib/color.rb:30:in `[]'
|
3
|
-
/Users/Hal/.rvm/gems/ruby-2.4.2/gems/rubytext-0.0.65/lib/color.rb:30:in `colors'
|
4
|
-
/Users/Hal/.rvm/gems/ruby-2.4.2/gems/rubytext-0.0.65/lib/color.rb:35:in `colors!'
|
5
|
-
/Users/Hal/.rvm/gems/ruby-2.4.2/gems/rubytext-0.0.65/lib/window.rb:33:in `main'
|
6
|
-
/Users/Hal/.rvm/gems/ruby-2.4.2/gems/rubytext-0.0.65/lib/settings.rb:75:in `start'
|
7
|
-
check.rb:3:in `<main>'
|
data/lib/_color.rb
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
|
2
|
-
def fb2cp(fg, bg)
|
3
|
-
fg ||= Blue
|
4
|
-
bg ||= White
|
5
|
-
f2 = X.const_get("COLOR_#{fg.upcase}")
|
6
|
-
b2 = X.const_get("COLOR_#{bg.upcase}")
|
7
|
-
cp = RubyText::ColorPairs[[fg, bg]]
|
8
|
-
[f2, b2, cp]
|
9
|
-
end
|
10
|
-
|
11
|
-
class RubyText::Color
|
12
|
-
attr_reader :curses
|
13
|
-
|
14
|
-
def self.pair(fg, bg)
|
15
|
-
RubyText::ColorPairs[[fg, bg]]
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize(sym)
|
19
|
-
@color = sym
|
20
|
-
@curses = X.const_get("COLOR_#{sym.upcase}")
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module RubyText
|
25
|
-
Colors = [Black, Blue, Cyan, Green, Magenta, Red, White, Yellow]
|
26
|
-
|
27
|
-
# Initialize all color pairs
|
28
|
-
ColorPairs = {}
|
29
|
-
num = 0
|
30
|
-
color_file = File.new("pairs.out", "w")
|
31
|
-
Colors.each do |fsym|
|
32
|
-
Colors.each do |bsym|
|
33
|
-
cfg, cbg = Color.new(fsym).curses, Color.new(bsym).curses
|
34
|
-
X.init_pair(num+=1, cfg, cbg)
|
35
|
-
ColorPairs[[fsym, bsym]] = num
|
36
|
-
# debug "pair #{num} = #{[fsym, bsym]}"
|
37
|
-
color_file.puts "pair #{num} = #{[fsym, bsym]}"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
color_file.close
|
41
|
-
end
|
42
|
-
|
43
|
-
class RubyText::Window
|
44
|
-
def self.set_colors(cwin, fg, bg)
|
45
|
-
@cfile = File.new("colors-#{rand(1000)}.out", "w")
|
46
|
-
cp = RubyText::Color.pair(fg, bg)
|
47
|
-
@cfile.puts "Setting: #{cp} = pair #{[fg, bg].inspect}"
|
48
|
-
@cfile.close
|
49
|
-
exit
|
50
|
-
cwin.color_set(cp)
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.colorize!(win, fg, bg)
|
54
|
-
set_colors(win, fg, bg)
|
55
|
-
num = win.maxx * win.maxy
|
56
|
-
win.setpos(0, 0)
|
57
|
-
win.addstr(' '*num)
|
58
|
-
win.setpos(0, 0)
|
59
|
-
win.refresh
|
60
|
-
end
|
61
|
-
|
62
|
-
def fg=(sym)
|
63
|
-
self.class.set_colors(@cwin, sym, @bg) # BREAK??
|
64
|
-
end
|
65
|
-
|
66
|
-
def bg=(sym)
|
67
|
-
self.class.set_colors(@cwin, @fg, sym)
|
68
|
-
end
|
69
|
-
end
|