rubytext 0.0.27 → 0.0.28
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/rubytext +1 -1
- data/examples/README +6 -0
- data/examples/check.rb +16 -0
- data/examples/demo.rb +114 -0
- data/examples/ide.rb +71 -0
- data/examples/prog01.rb +6 -0
- data/examples/prog02.rb +7 -0
- data/examples/prog03.rb +4 -0
- data/examples/prog04.rb +7 -0
- data/examples/prog05.rb +12 -0
- data/examples/prog06.rb +13 -0
- data/examples/prog07.rb +15 -0
- data/examples/prog08.rb +14 -0
- data/examples/prog09.rb +10 -0
- data/examples/prog10.rb +15 -0
- data/examples/prog11.rb +14 -0
- data/examples/prog12.rb +12 -0
- data/examples/prog13.rb +14 -0
- data/examples/slides +17 -0
- data/lib/version.rb +1 -1
- data/rubytext.gemspec +2 -1
- metadata +19 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 94623e9ab70d1b8cc1d743a018fadfbfc036c57532d8fd15bb53a1b1ad24a200
|
4
|
+
data.tar.gz: 40c219776d5735a49e03e4362b4212609b7241963b464b69a22fa1747f404cab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34544c7346c4be72e6d1ffb690785eed028f028e901a595f7941e95d9022db5fb4a2f13387e7b01795201d4ba715f974512a3a080772eea12cdfe188f8901309
|
7
|
+
data.tar.gz: af0380bd45ff5f3503aaccffd9f1d5081d5141fd2e360e921f8e7250b6f1175ee97c450e3bfea44b40aad9c0312f0264ebf4c37ac1f207f656675f73bf8f8a70
|
data/bin/rubytext
CHANGED
data/examples/README
ADDED
data/examples/check.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'rubytext'
|
2
|
+
|
3
|
+
RubyText.start(:raw, fg: :white, bg: :black)
|
4
|
+
|
5
|
+
cmax = STDSCR.cols
|
6
|
+
rmax = STDSCR.rows
|
7
|
+
|
8
|
+
RubyText.hide_cursor
|
9
|
+
|
10
|
+
if rmax < 25 || cmax < 80
|
11
|
+
puts "\n Your window should be 25x80 or larger,"
|
12
|
+
puts " but this one is only #{rmax}x#{cmax}."
|
13
|
+
puts " Please resize and run again!"
|
14
|
+
getch
|
15
|
+
exit 1
|
16
|
+
end
|
data/examples/demo.rb
ADDED
@@ -0,0 +1,114 @@
|
|
1
|
+
$LOAD_PATH.unshift "lib"
|
2
|
+
|
3
|
+
require 'rubytext'
|
4
|
+
|
5
|
+
def delay(sec)
|
6
|
+
sleep sec/2.0
|
7
|
+
end
|
8
|
+
|
9
|
+
RubyText.start(log: "mylog.txt", fg: :green, bg: :black)
|
10
|
+
|
11
|
+
print "Here goes... "
|
12
|
+
delay 2
|
13
|
+
|
14
|
+
ymax, xmax = STDSCR.rows, STDSCR.cols
|
15
|
+
|
16
|
+
puts "STDSCR is #{ymax.inspect} by #{xmax.inspect}"
|
17
|
+
delay 2
|
18
|
+
|
19
|
+
print "\nI can write here "
|
20
|
+
delay 2
|
21
|
+
puts "and then continue."
|
22
|
+
|
23
|
+
delay 2
|
24
|
+
print "I can jump away "
|
25
|
+
|
26
|
+
delay 2
|
27
|
+
STDSCR.go(20, 15) { puts "and print somewhere else" }
|
28
|
+
# ^ Same as: rcprint(20, 15, "and print somewhere else" }
|
29
|
+
|
30
|
+
delay 2
|
31
|
+
puts "and then return."
|
32
|
+
|
33
|
+
delay 3
|
34
|
+
print "I can hide the cursor... "
|
35
|
+
delay 1
|
36
|
+
RubyText.hide_cursor
|
37
|
+
delay 1
|
38
|
+
print "then show it again... "
|
39
|
+
delay 1
|
40
|
+
RubyText.show_cursor
|
41
|
+
delay 1
|
42
|
+
print "and hide it again. "
|
43
|
+
delay 1
|
44
|
+
RubyText.hide_cursor
|
45
|
+
delay 3
|
46
|
+
|
47
|
+
puts "\n\nNow watch as I create a window:"
|
48
|
+
|
49
|
+
mywin = RubyText.window(16, 40, 8, 14, true, fg: :blue, bg: :yellow)
|
50
|
+
|
51
|
+
delay 3
|
52
|
+
mywin.puts "\nNow I'm writing in a window."
|
53
|
+
mywin.puts "\nIts size is #{mywin.rows} rows by #{mywin.cols} cols"
|
54
|
+
mywin.puts "(or #{mywin.height}x#{mywin.width} with the frame).\n "
|
55
|
+
|
56
|
+
delay 4
|
57
|
+
mywin.puts "I always try to honor the borders of my window."
|
58
|
+
|
59
|
+
delay 2
|
60
|
+
mywin.puts "\nWatch as I place 50 random stars here..."
|
61
|
+
|
62
|
+
delay 2
|
63
|
+
|
64
|
+
50.times do
|
65
|
+
r = rand(mywin.rows)
|
66
|
+
c = rand(mywin.cols)
|
67
|
+
delay 0.1
|
68
|
+
mywin.rcprint(r, c, "*")
|
69
|
+
end
|
70
|
+
|
71
|
+
delay 4
|
72
|
+
mywin.output do
|
73
|
+
mywin.clear
|
74
|
+
puts "The window method called 'output'"
|
75
|
+
puts "will temporarily override STDSCR so that (in the code)"
|
76
|
+
puts "we don't have to use the window name over and over for stream I/O."
|
77
|
+
delay 4
|
78
|
+
# STDSCR.rcprint 25, 3, "Of course I can still print here if I want."
|
79
|
+
STDSCR.go 25, 3
|
80
|
+
STDSCR.print "Of course I can still print here if I want."
|
81
|
+
delay 3
|
82
|
+
puts "\nOne moment..."
|
83
|
+
delay 4
|
84
|
+
end
|
85
|
+
|
86
|
+
mywin.output do
|
87
|
+
mywin.clear
|
88
|
+
puts "The []= method allows us to place characters in"
|
89
|
+
puts "the window (without auto-refresh)."
|
90
|
+
puts "\nLet's see the '50 stars' trick again:"
|
91
|
+
delay 5
|
92
|
+
50.times do
|
93
|
+
r = rand(mywin.rows)
|
94
|
+
c = rand(mywin.cols)
|
95
|
+
mywin[r, c] = "*"
|
96
|
+
end
|
97
|
+
mywin.win.refresh
|
98
|
+
end
|
99
|
+
|
100
|
+
delay 5
|
101
|
+
mywin.output do
|
102
|
+
mywin.clear
|
103
|
+
mywin.puts "The [] method (zero-based) is still buggy, but let's try it."
|
104
|
+
mywin.puts "XYZ"
|
105
|
+
ch = mywin[2,2]
|
106
|
+
mywin.puts "The char at [2,2] is: #{ch.chr.inspect}"
|
107
|
+
end
|
108
|
+
|
109
|
+
delay 4
|
110
|
+
mywin.puts "\nThat's all for now."
|
111
|
+
delay 1
|
112
|
+
mywin.puts "\nPress any key to exit."
|
113
|
+
|
114
|
+
getch
|
data/examples/ide.rb
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
$LOAD_PATH << "lib"
|
2
|
+
|
3
|
+
if ARGV.size != 2
|
4
|
+
STDERR.puts "Usage: ruby ide.rb libname.rb progname.rb"
|
5
|
+
exit
|
6
|
+
end
|
7
|
+
|
8
|
+
require 'rubytext'
|
9
|
+
|
10
|
+
print " " # FIXME - bug requires this?
|
11
|
+
|
12
|
+
@lib, @code = ARGV
|
13
|
+
|
14
|
+
def menu
|
15
|
+
$debug.puts "Entering menu"
|
16
|
+
m = @mywin
|
17
|
+
m.boxme # FIXME - dumb hack
|
18
|
+
m.clear
|
19
|
+
m.puts
|
20
|
+
m.puts " World's Simplest Ruby IDE\n "
|
21
|
+
m.puts " Lib = #{@lib}"
|
22
|
+
m.puts " Code = #{@code}"
|
23
|
+
m.puts
|
24
|
+
m.puts " 1 Edit lib"
|
25
|
+
m.puts " 2 Edit code"
|
26
|
+
m.puts " 3 Run code"
|
27
|
+
m.puts " 4 pry"
|
28
|
+
m.puts " 5 Shell"
|
29
|
+
m.puts " 6 irb"
|
30
|
+
m.puts " 7 RubyDocs"
|
31
|
+
m.puts
|
32
|
+
m.puts " 0 Quit"
|
33
|
+
m.print "\n Choice = "
|
34
|
+
m.refresh # FIXME - dumb hack
|
35
|
+
$debug.puts "Exiting menu"
|
36
|
+
end
|
37
|
+
|
38
|
+
def shell(str)
|
39
|
+
STDSCR.clear
|
40
|
+
RubyText.show_cursor
|
41
|
+
system("stty sane") # FIXME - dumb hack
|
42
|
+
STDSCR.puts "\n\n When you exit, you will\n return to the IDE.\n "
|
43
|
+
system(str)
|
44
|
+
X.noecho # FIXME Shouldn't have to do this stuff
|
45
|
+
X.stdscr.keypad(true)
|
46
|
+
X.cbreak # by default
|
47
|
+
end
|
48
|
+
|
49
|
+
@mywin = RubyText.window(19, 30, 1, 2, true)
|
50
|
+
|
51
|
+
loop do
|
52
|
+
menu
|
53
|
+
# $debug.puts "about to call getch"
|
54
|
+
cmd = getch.chr
|
55
|
+
# $debug.puts "called getch - '#{cmd}'"
|
56
|
+
case cmd
|
57
|
+
when "1"; system("vi #{@lib}")
|
58
|
+
when "2"; system("vi #{@code}")
|
59
|
+
when "3"; system("tput clear; ruby #{@code}; sleep 5")
|
60
|
+
when "4"; shell("pry")
|
61
|
+
when "5"; shell("bash")
|
62
|
+
when "6"; shell("irb")
|
63
|
+
when "7"; system("open -a Safari http://ruby-doc.org")
|
64
|
+
when "0"; exit
|
65
|
+
else
|
66
|
+
@mywin.rcprint 12, 4, "\n\n No such command '#{cmd}'"
|
67
|
+
sleep 2
|
68
|
+
next
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
data/examples/prog01.rb
ADDED
data/examples/prog02.rb
ADDED
data/examples/prog03.rb
ADDED
data/examples/prog04.rb
ADDED
data/examples/prog05.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
win = RubyText.window(10, 70, 2, 14, true, fg: :yellow, bg: :black)
|
2
|
+
|
3
|
+
win.output do
|
4
|
+
puts "Without scrolling, this is what happens when your window fills up..."
|
5
|
+
puts "This behavior will probably change later."
|
6
|
+
sleep 2
|
7
|
+
puts "Let's print 10 more lines now:"
|
8
|
+
sleep 2
|
9
|
+
|
10
|
+
10.times {|i| puts "Printing line #{i}..."; sleep 0.5 }
|
11
|
+
end
|
12
|
+
|
data/examples/prog06.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
win = RubyText.window(10, 60, 2, 14, true, fg: :blue, bg: :black)
|
2
|
+
|
3
|
+
win.output do
|
4
|
+
puts "The #print and #p methods also act as you expect."
|
5
|
+
|
6
|
+
print "This will all "
|
7
|
+
print "go on a single "
|
8
|
+
puts "line."
|
9
|
+
|
10
|
+
puts
|
11
|
+
array = [1, 2, 3]
|
12
|
+
p array
|
13
|
+
end
|
data/examples/prog07.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
win = RubyText.window(10, 50, 2, 5, true, fg: :yellow, bg: :blue)
|
2
|
+
|
3
|
+
win.output do
|
4
|
+
puts "Of course, #puts and #print are unaffected \nfor other receivers."
|
5
|
+
|
6
|
+
out = File.new("/tmp/junk", "w")
|
7
|
+
out.puts "Nothing to see here."
|
8
|
+
sleep 2
|
9
|
+
|
10
|
+
print "\nHowever, if you print to STDOUT or STDERR \nwithout redirection, "
|
11
|
+
STDOUT.print "you will have some "
|
12
|
+
STDERR.print "unexpected/undefined results "
|
13
|
+
puts " in more ways than one."
|
14
|
+
end
|
15
|
+
|
data/examples/prog08.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
win = RubyText.window(10, 50, 2, 5, true, fg: :yellow, bg: :blue)
|
2
|
+
|
3
|
+
win.puts "We can use the []= method (0-based)"
|
4
|
+
win.puts "to address individual window locations"
|
5
|
+
win.puts "and place characters there.\n "
|
6
|
+
|
7
|
+
sleep 2
|
8
|
+
win[4,2] = "X"
|
9
|
+
|
10
|
+
sleep 2
|
11
|
+
win[6,20] = "y"
|
12
|
+
|
13
|
+
sleep 2
|
14
|
+
win[8,8] = "Z"
|
data/examples/prog09.rb
ADDED
@@ -0,0 +1,10 @@
|
|
1
|
+
win = RubyText.window(12, 60, 2, 5, true, fg: :yellow, bg: :blue)
|
2
|
+
|
3
|
+
win.puts "ABCDE Method [] can retrieve characters "
|
4
|
+
win.puts "FGHIJ from a window."
|
5
|
+
win.puts "KLMNO\nPQRST\nUVWZYZ"
|
6
|
+
win.puts
|
7
|
+
|
8
|
+
sleep 2
|
9
|
+
win.puts "(2,2) => '#{win[2,2]}' (0,4) => '#{win[0,4]}'"
|
10
|
+
win.puts "(6,7) => '#{win[6,7]}' (0,15) => '#{win[0,15]}'"
|
data/examples/prog10.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
win = RubyText.window(6, 30, 2, 5, true, fg: :black, bg: :blue)
|
2
|
+
|
3
|
+
win.puts "You can write to a window..."
|
4
|
+
|
5
|
+
sleep 2
|
6
|
+
9.times { STDSCR.puts }
|
7
|
+
STDSCR.puts "...or you can write to STDSCR (standard screen)"
|
8
|
+
|
9
|
+
sleep 1
|
10
|
+
puts "STDSCR is the default receiver."
|
11
|
+
|
12
|
+
sleep 2
|
13
|
+
STDSCR.go 5, 0
|
14
|
+
puts "Nothing stops you from overwriting a window."
|
15
|
+
|
data/examples/prog11.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
win = RubyText.window(6, 30, 2, 5, true, fg: :black, bg: :blue)
|
2
|
+
|
3
|
+
win.puts "We default to cbreak mode, so that characters are "
|
4
|
+
win.puts "accepted instantly, but control-C still works."
|
5
|
+
sleep 2
|
6
|
+
win.puts "\nIf we set raw mode, control-C is disallowed."
|
7
|
+
|
8
|
+
RubyText.set(:raw)
|
9
|
+
|
10
|
+
win.puts "\nGo ahead, type a ^C."
|
11
|
+
sleep 5
|
12
|
+
|
13
|
+
win.puts "\nI'm still here."
|
14
|
+
RubyText.set(:_raw)
|
data/examples/prog12.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
win = RubyText.window(12, 65, 1, 5, true, fg: :black, bg: :blue)
|
2
|
+
|
3
|
+
win.output do
|
4
|
+
puts "You can detect the size and cursor position of any window."
|
5
|
+
puts "\nSTDSCR is #{STDSCR.rows} rows by #{STDSCR.cols} columns"
|
6
|
+
puts "win is #{win.rows} rows by #{win.cols} columns"
|
7
|
+
puts "\nSlightly Heisenbergian report of cursor position:"
|
8
|
+
puts " STDSCR.rc = #{STDSCR.rc.inspect}\n win.rc = #{win.rc.inspect}"
|
9
|
+
puts "\nFor fun, I'll print \"ABC\" to STDSCR..."
|
10
|
+
sleep 2
|
11
|
+
STDSCR.print "ABC"
|
12
|
+
end
|
data/examples/prog13.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
win = RubyText.window(12, 65, 0, 15, true, fg: :blue, bg: :black)
|
2
|
+
|
3
|
+
win.puts "The #go method will move the cursor to a specific location."
|
4
|
+
win.go 2, 5
|
5
|
+
win.puts "x <-- The x is at 2,5"
|
6
|
+
|
7
|
+
win.puts "\nWith a block, it will execute the block and then"
|
8
|
+
win.puts "return to its previous location."
|
9
|
+
|
10
|
+
win.print "\n ABC..."
|
11
|
+
sleep 2
|
12
|
+
win.go(8, 20) { win.print "XYZ" }
|
13
|
+
sleep 2
|
14
|
+
win.print "DEF"
|
data/examples/slides
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
rc = system("ruby examples/check.rb")
|
4
|
+
exit unless rc
|
5
|
+
|
6
|
+
system("ruby showme.rb examples/prog01.rb")
|
7
|
+
system("ruby showme.rb examples/prog02.rb")
|
8
|
+
system("ruby showme.rb examples/prog03.rb")
|
9
|
+
system("ruby showme.rb examples/prog04.rb")
|
10
|
+
system("ruby showme.rb examples/prog05.rb")
|
11
|
+
system("ruby showme.rb examples/prog06.rb")
|
12
|
+
system("ruby showme.rb examples/prog07.rb")
|
13
|
+
system("ruby showme.rb examples/prog08.rb")
|
14
|
+
system("ruby showme.rb examples/prog09.rb")
|
15
|
+
system("ruby showme.rb examples/prog10.rb")
|
16
|
+
#system("ruby showme.rb examples/prog11.rb")
|
17
|
+
system("ruby showme.rb examples/prog12.rb")
|
data/lib/version.rb
CHANGED
data/rubytext.gemspec
CHANGED
@@ -20,11 +20,12 @@ Gem::Specification.new do |s|
|
|
20
20
|
# Files...
|
21
21
|
main = Find.find("lib").to_a
|
22
22
|
bin = Find.find("bin").to_a
|
23
|
+
ex = Find.find("examples").to_a
|
23
24
|
|
24
25
|
misc = %w[./README.md ./rubytext.gemspec]
|
25
26
|
# test = Find.find("test").to_a
|
26
27
|
|
27
|
-
s.files = main + bin + misc # + test
|
28
|
+
s.files = main + bin + ex + misc # + test
|
28
29
|
s.homepage = 'https://github.com/Hal9000/rubytext'
|
29
30
|
s.license = "Ruby License"
|
30
31
|
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.28
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hal Fulton
|
@@ -34,6 +34,24 @@ files:
|
|
34
34
|
- "./README.md"
|
35
35
|
- "./rubytext.gemspec"
|
36
36
|
- bin/rubytext
|
37
|
+
- examples/README
|
38
|
+
- examples/check.rb
|
39
|
+
- examples/demo.rb
|
40
|
+
- examples/ide.rb
|
41
|
+
- examples/prog01.rb
|
42
|
+
- examples/prog02.rb
|
43
|
+
- examples/prog03.rb
|
44
|
+
- examples/prog04.rb
|
45
|
+
- examples/prog05.rb
|
46
|
+
- examples/prog06.rb
|
47
|
+
- examples/prog07.rb
|
48
|
+
- examples/prog08.rb
|
49
|
+
- examples/prog09.rb
|
50
|
+
- examples/prog10.rb
|
51
|
+
- examples/prog11.rb
|
52
|
+
- examples/prog12.rb
|
53
|
+
- examples/prog13.rb
|
54
|
+
- examples/slides
|
37
55
|
- lib/rubytext.rb
|
38
56
|
- lib/version.rb
|
39
57
|
homepage: https://github.com/Hal9000/rubytext
|