rubytext 0.0.27 → 0.0.28

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 257ff8769efa6a24875d20ec4b53c863e3152ee8e5cc937f63ef0d7aeb1210d1
4
- data.tar.gz: f0e2cec5b63de75e626874e45eb64cb71d6196215575219741dc45876dc0ec26
3
+ metadata.gz: 94623e9ab70d1b8cc1d743a018fadfbfc036c57532d8fd15bb53a1b1ad24a200
4
+ data.tar.gz: 40c219776d5735a49e03e4362b4212609b7241963b464b69a22fa1747f404cab
5
5
  SHA512:
6
- metadata.gz: 3dcbeea59aa67c98851331d2e7edf027b162fe38c4cff9730d5b22e90fe864b9efe04f5e1df383988a9b852d91f2af5a516a24bb1ba1a2494ca780934e039efb
7
- data.tar.gz: 4a053e7ad294945854e4e816166561076232cabb4a2564292fdbe5050b1a8a2f91f988ab7e2afae1f35fe6a1ab3ebafb54367f9ffa3fbbdd81ae4e0b37fab738
6
+ metadata.gz: 34544c7346c4be72e6d1ffb690785eed028f028e901a595f7941e95d9022db5fb4a2f13387e7b01795201d4ba715f974512a3a080772eea12cdfe188f8901309
7
+ data.tar.gz: af0380bd45ff5f3503aaccffd9f1d5081d5141fd2e360e921f8e7250b6f1175ee97c450e3bfea44b40aad9c0312f0264ebf4c37ac1f207f656675f73bf8f8a70
data/bin/rubytext CHANGED
@@ -2,4 +2,4 @@
2
2
 
3
3
  require 'rubytext'
4
4
 
5
- puts RubyText::Path
5
+ STDOUT.puts RubyText::Path
data/examples/README ADDED
@@ -0,0 +1,6 @@
1
+ Note that the prog*.rb files are only fragments
2
+ and NOT complete programs.
3
+
4
+ They are intended to be run via showme.rb (or all
5
+ in sequence via the 'slides' shell script).
6
+
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
+
@@ -0,0 +1,6 @@
1
+ win = RubyText.window(6, 25, 2, 4,
2
+ # 6 rows, 25 cols; upper left at 2,4
3
+ true, # has a border
4
+ fg: :blue, bg: :white) # foreground, background
5
+
6
+ win.puts "This is a window..."
@@ -0,0 +1,7 @@
1
+ win = RubyText.window(9, 36, 2, 6, true, fg: :white, bg: :red)
2
+
3
+ win.output do
4
+ puts "Because this code uses #output,"
5
+ puts "it doesn't have to specify the"
6
+ puts "window as a receiver each time."
7
+ end
@@ -0,0 +1,4 @@
1
+ win = RubyText.window(9, 35, 3, 7, false, fg: :black, bg: :green)
2
+
3
+ win.puts "A window doesn't have to"
4
+ win.puts "have a border."
@@ -0,0 +1,7 @@
1
+ win = RubyText.window(8, 39, 4, 9, true, fg: :black, bg: :blue)
2
+
3
+ win.puts "If your text is longer than " +
4
+ "the width of the window, by default it will " +
5
+ "wrap around."
6
+
7
+ win.puts "Scrolling is not yet supported."
@@ -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
+
@@ -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
@@ -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
+
@@ -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"
@@ -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]}'"
@@ -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
+
@@ -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)
@@ -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
@@ -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
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.0.27"
3
+ VERSION = "0.0.28"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
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.27
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