rubytext 0.0.37 → 0.0.38
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 +8 -1
- data/examples/ide.rb +23 -22
- data/examples/prog08.rb +5 -5
- data/examples/prog20.rb +13 -0
- data/examples/prog21.rb +14 -0
- data/examples/showme.rb +2 -1
- data/examples/slides +1 -1
- data/lib/rubytext.rb +117 -21
- data/lib/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f76ca1f9288f586dee2ea9270f4213e22561b90009a7bbd6e773de9e024af442
|
4
|
+
data.tar.gz: 00345a5a7fe85aa24966717d612ab6d602d0d1b95b361fd547b1570ab0101e6e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7f675a7b1c5d3f174abec10d03137e309d2401e44a138bd88d4bc389cf577583cbd9b19a225588e1e1640d691367ec4b400fc7245f268427a5f55f2d133d2060
|
7
|
+
data.tar.gz: 4e1101676ff0a27dd3d9cf22b4150d356dcf38a7b4f842f8840c1d5e450ca0d8ca2a23c93772563d6f008fd2104260f4194e119b47cd1d1ac0a3cb3f1258b1c7
|
data/README.md
CHANGED
@@ -5,7 +5,14 @@ RubyText is a curses wrapper that is in the early experimental
|
|
5
5
|
stages. The code has bugs. Running it may cause general bad luck
|
6
6
|
as well as demon infestation.
|
7
7
|
|
8
|
-
|
8
|
+
Install the `rubytext` gem and then run the demo or the slides
|
9
|
+
or both.
|
10
|
+
|
11
|
+
```
|
12
|
+
$ gem install rubytext
|
13
|
+
$ rubytext demo # 2-minute demo
|
14
|
+
$ rubytext slides # longer "slideshow"
|
15
|
+
```
|
9
16
|
|
10
17
|
There is also `examples/ide.rb` ("world's simplest Ruby IDE").
|
11
18
|
It is _very_ dumb. :)
|
data/examples/ide.rb
CHANGED
@@ -7,31 +7,34 @@ end
|
|
7
7
|
|
8
8
|
require 'rubytext'
|
9
9
|
|
10
|
-
|
10
|
+
RubyText.start
|
11
|
+
|
12
|
+
# print " " # FIXME - bug requires this?
|
11
13
|
|
12
14
|
@lib, @code = ARGV
|
13
15
|
|
14
16
|
def menu
|
15
17
|
$debug.puts "Entering menu"
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
18
|
+
@mywin.output do
|
19
|
+
# boxme # FIXME - dumb hack
|
20
|
+
@mywin.clear
|
21
|
+
puts
|
22
|
+
puts " World's Simplest Ruby IDE\n "
|
23
|
+
puts " Lib = #{@lib}"
|
24
|
+
puts " Code = #{@code}"
|
25
|
+
puts
|
26
|
+
puts " 1 Edit lib"
|
27
|
+
puts " 2 Edit code"
|
28
|
+
puts " 3 Run code"
|
29
|
+
puts " 4 pry"
|
30
|
+
puts " 5 Shell"
|
31
|
+
puts " 6 irb"
|
32
|
+
puts " 7 RubyDocs"
|
33
|
+
puts
|
34
|
+
puts " 0 Quit"
|
35
|
+
print "\n Choice = "
|
36
|
+
@mywin.refresh # FIXME - dumb hack
|
37
|
+
end
|
35
38
|
$debug.puts "Exiting menu"
|
36
39
|
end
|
37
40
|
|
@@ -50,9 +53,7 @@ end
|
|
50
53
|
|
51
54
|
loop do
|
52
55
|
menu
|
53
|
-
# $debug.puts "about to call getch"
|
54
56
|
cmd = getch.chr
|
55
|
-
# $debug.puts "called getch - '#{cmd}'"
|
56
57
|
case cmd
|
57
58
|
when "1"; system("vi #{@lib}")
|
58
59
|
when "2"; system("vi #{@code}")
|
data/examples/prog08.rb
CHANGED
@@ -1,14 +1,14 @@
|
|
1
|
-
win = RubyText.window(
|
1
|
+
win = RubyText.window(12, 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.\n "
|
6
6
|
|
7
7
|
sleep 2
|
8
|
-
win[4,
|
8
|
+
win[4,22] = "X"
|
9
9
|
|
10
10
|
sleep 2
|
11
|
-
win[8,
|
11
|
+
win[8,20] = "y"
|
12
12
|
|
13
13
|
sleep 2
|
14
|
-
win[6,
|
14
|
+
win[6,38] = "Z"
|
data/examples/prog20.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
win = RubyText.window(12, 65, 2, 6, true, fg: :green, bg: :blue)
|
2
|
+
|
3
|
+
win.puts "This is EXPERIMENTAL."
|
4
|
+
win.puts "Use a color symbol to change text color temporarily:\n "
|
5
|
+
|
6
|
+
win.puts "This is", :yellow, " another color", :white, " and yet another."
|
7
|
+
win.puts "And this is normal again.\n "
|
8
|
+
|
9
|
+
win.puts "This does mean that you can't print a symbol that is"
|
10
|
+
win.puts "also a color name... you'd need a workaround.\n "
|
11
|
+
|
12
|
+
sym = :red
|
13
|
+
win.puts "The symbol is ", sym.inspect, " which works", sym, " just fine."
|
data/examples/prog21.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
puts "This very crude menu is also EXPERIMENTAL."
|
2
|
+
puts "At the moment, it only works inside STDSCR!\n"
|
3
|
+
puts "It knows up, down, Enter, and Escape.\n "
|
4
|
+
puts "Press any key to display the menu..."
|
5
|
+
getch
|
6
|
+
|
7
|
+
days = %w[Monday Tuesday Wednesday Thursday Friday]
|
8
|
+
picked = RubyText.menu(c: 30, items: days)
|
9
|
+
|
10
|
+
if picked.nil?
|
11
|
+
puts "You picked nothing!"
|
12
|
+
else
|
13
|
+
puts "You picked item #{picked} which is #{days[picked].inspect}"
|
14
|
+
end
|
data/examples/showme.rb
CHANGED
data/examples/slides
CHANGED
data/lib/rubytext.rb
CHANGED
@@ -13,26 +13,28 @@ end
|
|
13
13
|
def fb2cp(fg, bg)
|
14
14
|
fg ||= :blue
|
15
15
|
bg ||= :white
|
16
|
-
|
17
|
-
|
16
|
+
f2 = X.const_get("COLOR_#{fg.upcase}")
|
17
|
+
b2 = X.const_get("COLOR_#{bg.upcase}")
|
18
18
|
cp = $ColorPairs[[fg, bg]]
|
19
|
-
[
|
19
|
+
[f2, b2, cp]
|
20
20
|
end
|
21
21
|
|
22
22
|
module RubyText
|
23
23
|
|
24
|
-
Colors =
|
24
|
+
Colors = [:black, :blue, :cyan, :green, :magenta, :red, :white, :yellow]
|
25
25
|
$ColorPairs = {}
|
26
26
|
num = 0
|
27
|
-
Colors.each do |
|
28
|
-
Colors.each do |
|
29
|
-
fg = X.const_get("COLOR_#{
|
30
|
-
bg = X.const_get("COLOR_#{
|
27
|
+
Colors.each do |fsym|
|
28
|
+
Colors.each do |bsym|
|
29
|
+
fg = X.const_get("COLOR_#{fsym.upcase}")
|
30
|
+
bg = X.const_get("COLOR_#{bsym.upcase}")
|
31
31
|
X.init_pair(num+=1, fg, bg) # FIXME backwards?
|
32
|
-
$ColorPairs[[
|
32
|
+
$ColorPairs[[fsym, bsym]] = num
|
33
33
|
end
|
34
34
|
end
|
35
35
|
|
36
|
+
# $ColorPairs.each_pair {|k, v| STDOUT.puts "#{k.inspect} => #{v}" }
|
37
|
+
|
36
38
|
module Keys
|
37
39
|
Down = 258
|
38
40
|
Up = 259
|
@@ -107,6 +109,10 @@ module RubyText
|
|
107
109
|
end
|
108
110
|
obj
|
109
111
|
end
|
112
|
+
|
113
|
+
def fg=(sym)
|
114
|
+
self.colors(@win, fg, @bg)
|
115
|
+
end
|
110
116
|
end
|
111
117
|
end
|
112
118
|
|
@@ -114,13 +120,36 @@ end
|
|
114
120
|
module RubyText
|
115
121
|
|
116
122
|
def self.set(*args)
|
123
|
+
# Allow a block?
|
124
|
+
standard = [:cbreak, :raw, :echo, :keypad]
|
125
|
+
@flags = [] # FIXME can set/reset individually. hmmm
|
117
126
|
args.each do |arg|
|
118
|
-
|
119
|
-
|
120
|
-
|
127
|
+
if standard.include? arg
|
128
|
+
flag = arg.to_s
|
129
|
+
@flags << arg
|
130
|
+
flag.sub!(/_/, "no")
|
131
|
+
X.send(flag)
|
132
|
+
else
|
133
|
+
@flags << arg
|
134
|
+
case arg
|
135
|
+
when :cursor
|
136
|
+
X.show_cursor
|
137
|
+
when :_cursor, :nocursor
|
138
|
+
X.hide_cursor
|
139
|
+
end
|
140
|
+
end
|
121
141
|
end
|
122
142
|
end
|
123
143
|
|
144
|
+
def save_flags
|
145
|
+
@fstack ||= []
|
146
|
+
@fstack.push @flags
|
147
|
+
end
|
148
|
+
|
149
|
+
def rest_flags
|
150
|
+
@flags = @fstack.pop
|
151
|
+
end
|
152
|
+
|
124
153
|
def self.start(*args, log: nil, fg: nil, bg: nil)
|
125
154
|
$debug = File.new(log, "w") if log
|
126
155
|
Object.const_set(:STDSCR, RubyText::Window.main(fg: fg, bg: bg))
|
@@ -159,12 +188,65 @@ module RubyText
|
|
159
188
|
X.curs_set(2) # Doesn't work?
|
160
189
|
end
|
161
190
|
|
191
|
+
def self.saveback(high, wide, r, c)
|
192
|
+
@pos = STDSCR.rc
|
193
|
+
@save = []
|
194
|
+
0.upto(high) do |h|
|
195
|
+
0.upto(wide) do |w|
|
196
|
+
@save << STDSCR[h+r, w+c]
|
197
|
+
end
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
def self.restback(high, wide, r, c)
|
202
|
+
0.upto(high) do |h|
|
203
|
+
0.upto(wide) do |w|
|
204
|
+
STDSCR[h+r, w+c] = @save.shift
|
205
|
+
end
|
206
|
+
end
|
207
|
+
STDSCR.go *@pos
|
208
|
+
STDSCR.refresh
|
209
|
+
end
|
210
|
+
|
211
|
+
def self.menu(r: 0, c: 0, items:)
|
212
|
+
high = items.size + 2
|
213
|
+
wide = items.map(&:length).max + 2
|
214
|
+
saveback(high, wide, r, c)
|
215
|
+
@mywin = RubyText.window(high, wide, r, c, true, fg: :white, bg: :blue)
|
216
|
+
RubyText.set(:raw)
|
217
|
+
X.stdscr.keypad(true)
|
218
|
+
RubyText.hide_cursor
|
219
|
+
sel = 0
|
220
|
+
max = items.size - 1
|
221
|
+
loop do
|
222
|
+
items.each.with_index do |item, row|
|
223
|
+
@mywin.go row, 0
|
224
|
+
color = sel == row ? :yellow : :white
|
225
|
+
@mywin.puts color, " #{item} "
|
226
|
+
end
|
227
|
+
ch = getch
|
228
|
+
case ch
|
229
|
+
when X::KEY_UP
|
230
|
+
sel -= 1 if sel > 0
|
231
|
+
when X::KEY_DOWN
|
232
|
+
sel += 1 if sel < max
|
233
|
+
when 27
|
234
|
+
restback(high, wide, r, c)
|
235
|
+
return nil
|
236
|
+
when 10
|
237
|
+
restback(high, wide, r, c)
|
238
|
+
return sel
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
162
243
|
end
|
163
244
|
|
164
245
|
class RubyText::Window
|
165
246
|
Vert, Horiz = X::A_VERTICAL, X::A_HORIZONTAL
|
166
247
|
|
167
|
-
attr_reader :win, :rows, :cols, :width, :height
|
248
|
+
attr_reader :win, :rows, :cols, :width, :height
|
249
|
+
attr_writer :fg, :bg
|
168
250
|
|
169
251
|
def initialize(high=nil, wide=nil, r0=1, c0=1, border=false, fg=nil, bg=nil)
|
170
252
|
debug "RT::Win.init: #{[high, wide, r0, c0, border]}"
|
@@ -203,23 +285,37 @@ class RubyText::Window
|
|
203
285
|
self[r, c] = ch[0]
|
204
286
|
end
|
205
287
|
|
288
|
+
def need_crlf?(sym, args)
|
289
|
+
sym != :print && # print doesn't default to crlf
|
290
|
+
args[-1][-1] != "\n" # last char is a literal linefeed
|
291
|
+
end
|
292
|
+
|
206
293
|
def delegate_output(sym, *args)
|
207
294
|
args = [""] if args.empty?
|
208
|
-
debug "delegate: colors are #@fg, #@bg"
|
209
295
|
RubyText::Window.colors(@win, @fg, @bg) # FIXME?
|
210
|
-
# debug "#{sym}: args = #{args.inspect}"
|
211
296
|
if sym == :p
|
212
297
|
args.map!(&:inspect)
|
213
298
|
else
|
214
|
-
args.map!
|
299
|
+
args.map! do |x|
|
300
|
+
if RubyText::Colors.include? x
|
301
|
+
x
|
302
|
+
else
|
303
|
+
x.to_s
|
304
|
+
end
|
305
|
+
end
|
215
306
|
end
|
216
|
-
|
217
|
-
flag =
|
218
|
-
#
|
219
|
-
|
220
|
-
|
307
|
+
# STDOUT.puts "again: #{args.inspect}"
|
308
|
+
flag = need_crlf?(sym, args)
|
309
|
+
# Limitation: Can't print color symbols!
|
310
|
+
args.each do |arg|
|
311
|
+
if arg.is_a? Symbol # must be a color
|
312
|
+
RubyText::Window.colors(@win, arg, @bg) # FIXME?
|
313
|
+
else
|
314
|
+
arg.each_char {|ch| ch == "\n" ? crlf : @win.addch(ch) }
|
315
|
+
end
|
221
316
|
end
|
222
317
|
crlf if flag
|
318
|
+
RubyText::Window.colors(@win, @fg, @bg) # FIXME?
|
223
319
|
@win.refresh
|
224
320
|
end
|
225
321
|
|
data/lib/version.rb
CHANGED
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.0.
|
4
|
+
version: 0.0.38
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-11-
|
11
|
+
date: 2018-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: curses
|
@@ -57,6 +57,8 @@ files:
|
|
57
57
|
- examples/prog17.rb
|
58
58
|
- examples/prog18.rb
|
59
59
|
- examples/prog19.rb
|
60
|
+
- examples/prog20.rb
|
61
|
+
- examples/prog21.rb
|
60
62
|
- examples/showme.rb
|
61
63
|
- examples/slides
|
62
64
|
- lib/rubytext.rb
|