rubytext 0.0.82 → 0.0.83

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: 15520eecd3c1ca3278f62731bad2a032a0ac638b02463fea3b5e7af7f9a14ed8
4
- data.tar.gz: 97afb48c6b17f679bebe60c458e9a8530d5ad23a2fd24413fa1fc4da682fbd89
3
+ metadata.gz: 40b5393ec1718ba30f6d37a83e32c45261d502965e5266bcb1e141d1c98e694a
4
+ data.tar.gz: ca37d8485b30ac6e6c2f0eb44f97e6dac1a682a9fd02536e35328ef727ba6bd8
5
5
  SHA512:
6
- metadata.gz: '09cc80674f2b607189d64739230e13c3f4ee4131447b2d402a69a971b022c294b4d6901187f4c1c089269b27cbe3a64c91dc16f767336fa6dfe1119e9f95049f'
7
- data.tar.gz: fc868a9b1c97338be2f87d74b3a884175e9b4c58b6a1d1845c1bedb14b487e8b4e77e4bff4e500e1c318a621e7f8ad8d176ecea5347ee088a3e3b28302e60c2b
6
+ metadata.gz: ba422d281adb72a894c5b0e2d5df0a7d4e05219420571647d2e1ad578c2ac332c3992fefb84a78c1ed49e3d58144bb87fd698ba6e77c56136cf9acd82732d128
7
+ data.tar.gz: 602acfd074380a0828d898b09890f47c967bc422649c43060ec7cb549e861e541f15b1898b147f68f27eebf155b656b1a68fd5792a7b905a552fa2ad140d8f2a
data/lib/version.rb CHANGED
@@ -1,6 +1,6 @@
1
1
 
2
2
  module RubyText
3
- VERSION = "0.0.82"
3
+ VERSION = "0.0.83"
4
4
 
5
5
  Path = File.expand_path(File.join(File.dirname(__FILE__)))
6
6
  end
data/rubytext.gemspec CHANGED
@@ -21,11 +21,11 @@ Gem::Specification.new do |s|
21
21
  main = Find.find("lib").to_a
22
22
  bin = Find.find("bin").to_a
23
23
  ex = Find.find("examples").to_a
24
-
25
24
  misc = %w[./README.md ./rubytext.gemspec]
26
25
  test = Find.find("test").to_a
26
+ tut = Find.find("tutorial").to_a
27
27
 
28
- s.files = main + bin + ex + misc + test
28
+ s.files = main + bin + ex + misc + test + tut
29
29
  s.homepage = 'https://github.com/Hal9000/rubytext'
30
30
  s.license = "Ruby"
31
31
  end
@@ -0,0 +1,4 @@
1
+ <style>
2
+ pre {font-size: 15}
3
+ tt {font-size: 15}
4
+ </style>
Binary file
@@ -0,0 +1,31 @@
1
+ require 'rubytext'
2
+
3
+ RubyText.start(fg: White, bg: Black)
4
+
5
+ print " "*10
6
+ Colors.each {|col| print "%-8s" % col.to_s.capitalize }
7
+ puts
8
+ puts
9
+
10
+ Colors.each do |col|
11
+ puts " " + col.to_s.capitalize
12
+ puts
13
+ end
14
+
15
+ STDSCR.bottom
16
+
17
+ r0 = 2
18
+ Colors.each do |fg|
19
+ c0 = 10
20
+ Colors.each do |bg|
21
+ win = RubyText.window(1, 7, r0, c0,
22
+ border: false,
23
+ fg: fg, bg: bg)
24
+ win.puts " TEXT "
25
+ c0 += 8
26
+ end
27
+ r0 += 2
28
+ end
29
+
30
+ getch
31
+
@@ -0,0 +1,57 @@
1
+ <style type="text/css">
2
+ <!--
3
+ pre { white-space: pre-wrap; font-family: monospace; color: #ffffff; background-color: #000000; }
4
+ tt { font-size: 15 }
5
+ body { font-family: monospace; color: #ffffff; background-color: #000000; }
6
+ .Constant { color: #ff40ff; }
7
+ .Special { color: #ffff00; }
8
+ .Identifier { color: #00ffff; }
9
+ .Statement { color: #ffff00; }
10
+ .PreProc { color: #ff40ff; }
11
+ .Type { color: #00ff00; }
12
+ -->
13
+ </style>
14
+
15
+ <script type='text/javascript'>
16
+ <!--
17
+
18
+ -->
19
+ </script>
20
+ </head>
21
+ <body>
22
+ <pre id='vimCodeElement'>
23
+ <span class="PreProc">require</span> <span class="Special">'</span><span class="Constant">rubytext</span><span class="Special">'</span>
24
+
25
+ <span class="Type">RubyText</span>.start(<span class="Constant">fg</span>: <span class="Type">White</span>, <span class="Constant">bg</span>: <span class="Type">Black</span>)
26
+
27
+ print <span class="Special">&quot;</span><span class="Constant"> </span><span class="Special">&quot;</span>*<span class="Constant">10</span>
28
+ <span class="Type">Colors</span>.each {|<span class="Identifier">col</span>| print <span class="Special">&quot;</span><span class="Constant">%-8s</span><span class="Special">&quot;</span> % col.to_s.capitalize }
29
+ puts
30
+ puts
31
+
32
+ <span class="Type">Colors</span>.each <span class="Statement">do</span> |<span class="Identifier">col</span>|
33
+ puts <span class="Special">&quot;</span><span class="Constant"> </span><span class="Special">&quot;</span> + col.to_s.capitalize
34
+ puts
35
+ <span class="Statement">end</span>
36
+
37
+ <span class="Type">STDSCR</span>.bottom
38
+
39
+ r0 = <span class="Constant">2</span>
40
+ <span class="Type">Colors</span>.each <span class="Statement">do</span> |<span class="Identifier">fg</span>|
41
+ c0 = <span class="Constant">10</span>
42
+ <span class="Type">Colors</span>.each <span class="Statement">do</span> |<span class="Identifier">bg</span>|
43
+ win = <span class="Type">RubyText</span>.window(<span class="Constant">1</span>, <span class="Constant">7</span>, r0, c0,
44
+ <span class="Constant">border</span>: <span class="Constant">false</span>,
45
+ <span class="Constant">fg</span>: fg, <span class="Constant">bg</span>: bg)
46
+ win.puts <span class="Special">&quot;</span><span class="Constant"> TEXT </span><span class="Special">&quot;</span>
47
+ c0 += <span class="Constant">8</span>
48
+ <span class="Statement">end</span>
49
+ r0 += <span class="Constant">2</span>
50
+ <span class="Statement">end</span>
51
+
52
+ getch
53
+
54
+ </pre>
55
+ </body>
56
+ </html>
57
+ <!-- vim: set foldmethod=manual : -->
data/tutorial/damn.rb ADDED
@@ -0,0 +1,10 @@
1
+
2
+ module Foo
3
+ def foobar
4
+ puts "got here"
5
+ end
6
+ end
7
+
8
+ Object.include Foo
9
+
10
+ foobar
data/tutorial/hw.png ADDED
Binary file
data/tutorial/hw.rb ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubytext'
2
+
3
+ RubyText.start
4
+
5
+ puts "Hello, world!"
6
+
7
+ getch
@@ -0,0 +1,41 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5
+ <title>~/Dropbox/files/rubytext/tutorial/hw.rb.html</title>
6
+ <meta name="Generator" content="Vim/7.4">
7
+ <meta name="plugin-version" content="vim7.4_v2">
8
+ <meta name="syntax" content="ruby">
9
+ <meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
10
+ <meta name="colorscheme" content="darkblue">
11
+ <style type="text/css">
12
+ <!--
13
+ pre { white-space: pre-wrap; font-family: monospace; color: #ffffff; background-color: #000000; font-size: 15}
14
+ tt { font-size: 15 }
15
+ body { font-family: monospace; color: #ffffff; background-color: #000000; }
16
+ .Constant { color: #ff40ff; }
17
+ .Special { color: #ffff00; }
18
+ .PreProc { color: #ff40ff; }
19
+ .Type { color: #00ff00; }
20
+ -->
21
+ </style>
22
+
23
+ <script type='text/javascript'>
24
+ <!--
25
+
26
+ -->
27
+ </script>
28
+ </head>
29
+ <body>
30
+ <pre id='vimCodeElement'>
31
+ <span class="PreProc">require</span> <span class="Special">'</span><span class="Constant">rubytext</span><span class="Special">'</span>
32
+
33
+ <span class="Type">RubyText</span>.start
34
+
35
+ puts <span class="Special">&quot;</span><span class="Constant">Hello, world!</span><span class="Special">&quot;</span>
36
+
37
+ getch
38
+ </pre>
39
+ </body>
40
+ </html>
41
+ <!-- vim: set foldmethod=manual : -->
data/tutorial/meh.html ADDED
@@ -0,0 +1,124 @@
1
+ <style>
2
+ pre {font-size: 15}
3
+ tt {font-size: 15}
4
+ </style>
5
+ <h1>RubyText
6
+ </h1>
7
+ <p>
8
+
9
+ RubyText is a curses wrapper. The modern variant is ncurses, and there are also
10
+ others. This tutorial doesn't cover much of "real" curses, as the aim is to
11
+ wrap it and make it simpler.
12
+ <p>
13
+
14
+ This project is somewhat in its infancy. Once it is a little more mature, I
15
+ hope to produce an Elixir version. (Elixir is not usually used at the desktop,
16
+ but it <i>can</i> be.)
17
+ <p>
18
+
19
+ Let's start at the beginning with the overused "hello world" example.
20
+ <p>
21
+
22
+ <!-- high = 215 hcode = 165 -->
23
+ <iframe frameborder=0
24
+ width=566 height=215
25
+ src='wrap-hw.html'>
26
+ </iframe>
27
+ <p>
28
+
29
+ Here are some things to notice:
30
+ <ul>
31
+ <li>Obviously you have to require the <tt>rubytext</tt> library.</li>
32
+ <li>You have to invoke <tt>RubyText.start</tt> (possibly with parameters).</li>
33
+ <li>When the curses environment is started, things like <tt>puts</tt> are overridden.</li>
34
+ <li>We call <tt>getch</tt> here (get a character) to make the program "pause" so as not to exit before we see anything.</li>
35
+ <li>At program exit, your screen will be restored to normal.</li>
36
+ </ul>
37
+ Here's another example.
38
+ <p>
39
+
40
+ <!-- high = 277 hcode = 465 -->
41
+ <iframe frameborder=0
42
+ width=870 height=465
43
+ src='wrap-stdscr.html'>
44
+ </iframe>
45
+ <p>
46
+
47
+ <h3>The start method
48
+ </h3>
49
+ <p>
50
+
51
+ The <tt>start</tt> method can take a number of parameters, some of which
52
+ are keyword arguments. If you know curses, some of these will be familiar,
53
+ while others provide functionality unrelated to what curses provides.
54
+ <p>
55
+
56
+ <dl>
57
+ <dt><tt>:cbreak</tt> </dt>
58
+ <dd> Like <tt>cbreak</tt> in curses. Inverse is <tt>:_cbreak</tt> (preferred) or <tt>:nocbreak</tt></dd>
59
+ <dt><tt>:raw</tt> </dt>
60
+ <dd> Like <tt>raw</tt> in curses. Inverse is <tt>:_raw</tt> (preferred) or <tt>:noraw</tt></dd>
61
+ <dt><tt>:echo</tt> </dt>
62
+ <dd> Like <tt>echo</tt> in curses. Inverse is <tt>:_echo</tt> (preferred) or <tt>:noecho</tt></dd>
63
+ <dt><tt>:keypad</tt> </dt>
64
+ <dd> Like <tt>keypad</tt> in curses. Inverse is <tt>:_keypad</tt> (preferred) or <tt>:nokeypad</tt></dd>
65
+ <dt><tt>log:</tt> <i>logfile</i> </dt>
66
+ <dd> Log debugging information to specified file.</dd>
67
+ <dt><tt>fg:</tt> <i>foreground</i> </dt>
68
+ <dd> Set foreground color for STDSCR.</dd>
69
+ <dt><tt>bg:</tt> <i>background</i> </dt>
70
+ <dd> Set background color for STDSCR.</dd>
71
+ <dt><tt>scroll:</tt> <i>Boolean</i> </dt>
72
+ <dd> Permit (or disallow) window scrolling for STDSCR.</dd>
73
+ </dl>
74
+ <p>
75
+
76
+ The defaults are as follows:
77
+ <p>
78
+
79
+ <pre>
80
+ RubyText.start(:cbreak, :_raw, :_echo, :keypad, log: "/tmp/rubytext.log",
81
+ fg: White, bg: Blue, scroll: true)
82
+
83
+ # can be abbreviated simply:
84
+
85
+ RubyText.start
86
+ </pre>
87
+ If you're a relative curses newbie (like me), you may have some confusion about
88
+ the <tt>cbreak</tt> and <tt>raw</tt> modes. Let's clear it up a little with these four facts.
89
+ <p>
90
+
91
+ <ul>
92
+ <li>First of all, <i>neither</i> of these permits buffered keyboard input or line editing (such as backspace).</li>
93
+ <li>As for interrupts such as <tt>^C</tt> and <tt>^Z</tt>, <tt>cbreak</tt> <i>permits</i> these (handles them as usual).</li>
94
+ <li>The same interrupts are <i>not</i> honored by <tt>raw</tt>; instead, they are read as characters.</li>
95
+ <li>Finally, <tt>cbreak</tt> mode overrides <tt>raw</tt> mode if they are specified together.</li>
96
+ </ul>
97
+ As to colors, the defaults of <tt>White</tt> and <tt>Blue</tt> are purely arbitrary. They may change.
98
+ <p>
99
+
100
+ The standard curses implementation recognizes eight colors: <tt>Black</tt>, <tt>Blue</tt>, <tt>Cyan</tt>,
101
+ <tt>Green</tt>, <tt>Magenta</tt>, <tt>Red</tt>, <tt>White</tt>, <tt>Yellow</tt>. Each of these constants refers to a symbol
102
+ of the same (lowercased) name. What these colors look like in your own local environment
103
+ may depend on many factors such as your operating system and terminal driver.
104
+ <p>
105
+
106
+ My own environment is iterm on Mac OSX with fairly standard settings. Here is some code
107
+ that will display all 64 possibilities of foreground/background. (Note that curses seems
108
+ to "cheat" when these two are the same, presumably to preserve legibility.)
109
+ <p>
110
+
111
+ <!-- high = 248 hcode = 521 -->
112
+ <iframe frameborder=0
113
+ width=828 height=521
114
+ src='wrap-colortest.html'>
115
+ </iframe>
116
+ <p>
117
+
118
+ <p>
119
+
120
+ That's all for now.
121
+ <p>
122
+
123
+ <p>
124
+
@@ -0,0 +1,52 @@
1
+ MODE buffering? erase/kill? IQSF NOTES
2
+
3
+ cbreak no no yes cbreak overrides raw.
4
+ _cbreak yes yes
5
+ raw no no no reads: interrupt, quit, suspend, flow control
6
+
7
+ Defaults: cbreak, _echo, keypad
8
+
9
+ cbreak routine disables line buffering and erase/kill character-processing
10
+ (interrupt and flow control characters are unaffected), making characters
11
+ typed by the user immediately available to the program.
12
+
13
+ nocbreak returns the terminal to normal (cooked) mode.
14
+
15
+ A program should call cbreak or nocbreak explicitly.
16
+ Most interactive programs using curses set the cbreak mode.
17
+ Note that cbreak overrides raw.
18
+
19
+ The echo and noecho routines control whether characters are echoed by getch
20
+ Echoing by the tty driver is always disabled, but initially getch is in echo mode.
21
+
22
+ most interactive programs disable echoing
23
+
24
+ keypad option enables keypad of user's terminal.
25
+ User can press a function key (e.g. arrow) and getch returns a single
26
+ value e.g. KEY_LEFT.
27
+
28
+ Skip for now:
29
+ halfdelay
30
+ intrflush option
31
+
32
+ Skip?
33
+ nodelay causes getch to be a non-blocking call.
34
+ If no input is ready, getch returns ERR.
35
+
36
+ Skip?
37
+ notimeout(win, TRUE) -- wgetch does not set a timer.
38
+ Differentiate between sequences received from a function key and those typed by a user.
39
+
40
+ raw and noraw --
41
+ Raw mode is similar to cbreak mode -- characters typed are immediately passed through.
42
+ Differences: in raw mode -- the interrupt, quit, suspend, and flow control characters
43
+ are all passed through uninterpreted, instead of generating a signal. The behavior of
44
+ the BREAK key depends on other bits in the tty driver that are not set by curses.
45
+
46
+ Skip!
47
+ noqiflush
48
+
49
+ Skip!
50
+ timeout and wtimeout routines set blocking or non-blocking read for a given window.
51
+
52
+
Binary file
@@ -0,0 +1,22 @@
1
+ require 'rubytext'
2
+
3
+ RubyText.start(fg: Yellow, bg: Blue)
4
+
5
+ puts "This writes by default to STDSCR"
6
+ STDSCR.puts "and this does the same thing.\n "
7
+
8
+ print "Only one line "
9
+ print "of output "
10
+ print "printed "
11
+ puts "here."
12
+
13
+ puts
14
+
15
+ array = [1, 2, 3, 4, 5]
16
+
17
+ puts "p also works:"
18
+ p array
19
+
20
+ puts
21
+
22
+ getch
@@ -0,0 +1,57 @@
1
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
2
+ <html>
3
+ <head>
4
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
5
+ <title>~/Dropbox/files/rubytext/tutorial/stdscr.rb.html</title>
6
+ <meta name="Generator" content="Vim/7.4">
7
+ <meta name="plugin-version" content="vim7.4_v2">
8
+ <meta name="syntax" content="ruby">
9
+ <meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
10
+ <meta name="colorscheme" content="darkblue">
11
+ <style type="text/css">
12
+ <!--
13
+ pre { white-space: pre-wrap; font-family: monospace; color: #ffffff; background-color: #000000; }
14
+ pre {font-size: 16}
15
+ tt {font-size: 16}
16
+ body { font-family: monospace; color: #ffffff; background-color: #000000; }
17
+ .Constant { color: #ff40ff; }
18
+ .Special { color: #ffff00; }
19
+ .PreProc { color: #ff40ff; }
20
+ .Type { color: #00ff00; }
21
+ -->
22
+ </style>
23
+
24
+ <script type='text/javascript'>
25
+ <!--
26
+
27
+ -->
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <pre id='vimCodeElement'>
32
+ <span class="PreProc">require</span> <span class="Special">'</span><span class="Constant">rubytext</span><span class="Special">'</span>
33
+
34
+ <span class="Type">RubyText</span>.start(<span class="Constant">fg</span>: <span class="Type">Yellow</span>, <span class="Constant">bg</span>: <span class="Type">Blue</span>)
35
+
36
+ puts <span class="Special">&quot;</span><span class="Constant">This writes by default to STDSCR</span><span class="Special">&quot;</span>
37
+ <span class="Type">STDSCR</span>.puts <span class="Special">&quot;</span><span class="Constant">and this does the same thing.</span><span class="Special">\n</span><span class="Constant"> </span><span class="Special">&quot;</span>
38
+
39
+ print <span class="Special">&quot;</span><span class="Constant">Only one line </span><span class="Special">&quot;</span>
40
+ print <span class="Special">&quot;</span><span class="Constant">of output </span><span class="Special">&quot;</span>
41
+ print <span class="Special">&quot;</span><span class="Constant">printed </span><span class="Special">&quot;</span>
42
+ puts <span class="Special">&quot;</span><span class="Constant">here.</span><span class="Special">&quot;</span>
43
+
44
+ puts
45
+
46
+ array = [<span class="Constant">1</span>, <span class="Constant">2</span>, <span class="Constant">3</span>, <span class="Constant">4</span>, <span class="Constant">5</span>]
47
+
48
+ puts <span class="Special">&quot;</span><span class="Constant">p also works:</span><span class="Special">&quot;</span>
49
+ p array
50
+
51
+ puts
52
+
53
+ getch
54
+ </pre>
55
+ </body>
56
+ </html>
57
+ <!-- vim: set foldmethod=manual : -->
@@ -0,0 +1,124 @@
1
+ <style>
2
+ pre {font-size: 15}
3
+ tt {font-size: 15}
4
+ </style>
5
+ <h1>RubyText
6
+ </h1>
7
+ <p>
8
+
9
+ RubyText is a curses wrapper. The modern variant is ncurses, and there are also
10
+ others. This tutorial doesn't cover much of "real" curses, as the aim is to
11
+ wrap it and make it simpler.
12
+ <p>
13
+
14
+ This project is somewhat in its infancy. Once it is a little more mature, I
15
+ hope to produce an Elixir version. (Elixir is not usually used at the desktop,
16
+ but it <i>can</i> be.)
17
+ <p>
18
+
19
+ Let's start at the beginning with the overused "hello world" example.
20
+ <p>
21
+
22
+ <!-- high = 215 hcode = 165 -->
23
+ <iframe frameborder=0
24
+ width=566 height=215
25
+ src='wrap-hw.html'>
26
+ </iframe>
27
+ <p>
28
+
29
+ Here are some things to notice:
30
+ <ul>
31
+ <li>Obviously you have to require the <tt>rubytext</tt> library.</li>
32
+ <li>You have to invoke <tt>RubyText.start</tt> (possibly with parameters).</li>
33
+ <li>When the curses environment is started, things like <tt>puts</tt> are overridden.</li>
34
+ <li>We call <tt>getch</tt> here (get a character) to make the program "pause" so as not to exit before we see anything.</li>
35
+ <li>At program exit, your screen will be restored to normal.</li>
36
+ </ul>
37
+ Here's another example.
38
+ <p>
39
+
40
+ <!-- high = 277 hcode = 465 -->
41
+ <iframe frameborder=0
42
+ width=870 height=465
43
+ src='wrap-stdscr.html'>
44
+ </iframe>
45
+ <p>
46
+
47
+ <h3>The start method
48
+ </h3>
49
+ <p>
50
+
51
+ The <tt>start</tt> method can take a number of parameters, some of which
52
+ are keyword arguments. If you know curses, some of these will be familiar,
53
+ while others provide functionality unrelated to what curses provides.
54
+ <p>
55
+
56
+ <dl>
57
+ <dt><tt>:cbreak</tt> </dt>
58
+ <dd> Like <tt>cbreak</tt> in curses. Inverse is <tt>:_cbreak</tt> (preferred) or <tt>:nocbreak</tt></dd>
59
+ <dt><tt>:raw</tt> </dt>
60
+ <dd> Like <tt>raw</tt> in curses. Inverse is <tt>:_raw</tt> (preferred) or <tt>:noraw</tt></dd>
61
+ <dt><tt>:echo</tt> </dt>
62
+ <dd> Like <tt>echo</tt> in curses. Inverse is <tt>:_echo</tt> (preferred) or <tt>:noecho</tt></dd>
63
+ <dt><tt>:keypad</tt> </dt>
64
+ <dd> Like <tt>keypad</tt> in curses. Inverse is <tt>:_keypad</tt> (preferred) or <tt>:nokeypad</tt></dd>
65
+ <dt><tt>log:</tt> <i>logfile</i> </dt>
66
+ <dd> Log debugging information to specified file.</dd>
67
+ <dt><tt>fg:</tt> <i>foreground</i> </dt>
68
+ <dd> Set foreground color for STDSCR.</dd>
69
+ <dt><tt>bg:</tt> <i>background</i> </dt>
70
+ <dd> Set background color for STDSCR.</dd>
71
+ <dt><tt>scroll:</tt> <i>Boolean</i> </dt>
72
+ <dd> Permit (or disallow) window scrolling for STDSCR.</dd>
73
+ </dl>
74
+ <p>
75
+
76
+ The defaults are as follows:
77
+ <p>
78
+
79
+ <pre>
80
+ RubyText.start(:cbreak, :_raw, :_echo, :keypad, log: "/tmp/rubytext.log",
81
+ fg: White, bg: Blue, scroll: true)
82
+
83
+ # can be abbreviated simply:
84
+
85
+ RubyText.start
86
+ </pre>
87
+ If you're a relative curses newbie (like me), you may have some confusion about
88
+ the <tt>cbreak</tt> and <tt>raw</tt> modes. Let's clear it up a little with these four facts.
89
+ <p>
90
+
91
+ <ul>
92
+ <li>First of all, <i>neither</i> of these permits buffered keyboard input or line editing (such as backspace).</li>
93
+ <li>As for interrupts such as <tt>^C</tt> and <tt>^Z</tt>, <tt>cbreak</tt> <i>permits</i> these (handles them as usual).</li>
94
+ <li>The same interrupts are <i>not</i> honored by <tt>raw</tt>; instead, they are read as characters.</li>
95
+ <li>Finally, <tt>cbreak</tt> mode overrides <tt>raw</tt> mode if they are specified together.</li>
96
+ </ul>
97
+ As to colors, the defaults of <tt>White</tt> and <tt>Blue</tt> are purely arbitrary. They may change.
98
+ <p>
99
+
100
+ The standard curses implementation recognizes eight colors: <tt>Black</tt>, <tt>Blue</tt>, <tt>Cyan</tt>,
101
+ <tt>Green</tt>, <tt>Magenta</tt>, <tt>Red</tt>, <tt>White</tt>, <tt>Yellow</tt>. Each of these constants refers to a symbol
102
+ of the same (lowercased) name. What these colors look like in your own local environment
103
+ may depend on many factors such as your operating system and terminal driver.
104
+ <p>
105
+
106
+ My own environment is iterm on Mac OSX with fairly standard settings. Here is some code
107
+ that will display all 64 possibilities of foreground/background. (Note that curses seems
108
+ to "cheat" when these two are the same, presumably to preserve legibility.)
109
+ <p>
110
+
111
+ <!-- high = 248 hcode = 521 -->
112
+ <iframe frameborder=0
113
+ width=828 height=521
114
+ src='wrap-colortest.html'>
115
+ </iframe>
116
+ <p>
117
+
118
+ <p>
119
+
120
+ That's all for now.
121
+ <p>
122
+
123
+ <p>
124
+
@@ -0,0 +1,129 @@
1
+ .mixin bookish
2
+
3
+ .copy basic.css
4
+
5
+ .h1 RubyText
6
+
7
+ RubyText is a curses wrapper. The modern variant is ncurses, and there are also
8
+ others. This tutorial doesn't cover much of "real" curses, as the aim is to
9
+ wrap it and make it simpler.
10
+
11
+ This project is somewhat in its infancy. Once it is a little more mature, I
12
+ hope to produce an Elixir version. (Elixir is not usually used at the desktop,
13
+ but it _can be.)
14
+
15
+ .def example
16
+ arg, ppl = _args
17
+ ppl ||= 20
18
+ file = arg + ".rb.html"
19
+ sshot = arg + ".png"
20
+ code = File.read(file) # HTML from vim
21
+ lines = code.split("\n")
22
+ n0 = lines.find_index {|x| x =~ /^<pre/ }
23
+ n1 = lines.find_index {|x| x =~ /^<.pre>/ }
24
+ nlines = n1 - n0 - 1
25
+ # hw.png PNG 283x190 283x190+0+0 8-bit sRGB 5443B 0.000u 0:00.000
26
+ img_data = `identify #{sshot}` # depends on imagemagick
27
+ wimg, himg = img_data.split[2].split("x")
28
+ wide = (wimg.to_i * 2).to_i
29
+ high = himg.to_i + 25
30
+ hcode = nlines*ppl.to_i + 25
31
+ hmax = [high, hcode].max # Code may be longer than screenshot height
32
+ _puts "<!-- high = #{high} hcode = #{hcode} -->"
33
+ File.open("wrap-#{arg}.html", "w") do |f|
34
+ f.puts "<table width=100% cellpadding=2><tr><td width=50% valign=top>"
35
+ f.puts code
36
+ f.puts "</td><td width=50% valign=top><img src=#{sshot} valign=top></td></tr></table>"
37
+ end
38
+ _puts <<-HTML
39
+ <iframe frameborder=0
40
+ width=#{wide} height=#{hmax}
41
+ src='wrap-#{arg}.html'>
42
+ </iframe>
43
+ HTML
44
+ .end
45
+
46
+ Let's start at the beginning with the overused "hello world" example.
47
+
48
+ .example hw
49
+
50
+ Here are some things to notice:
51
+ .list
52
+ Obviously you have to require the `rubytext library.
53
+ You have to invoke `RubyText.start (possibly with parameters).
54
+ When the curses environment is started, things like `puts are overridden.
55
+ We call `getch here (get a character) to make the program "pause" so as not to exit before we see anything.
56
+ At program exit, your screen will be restored to normal.
57
+ .end
58
+
59
+ Here's another example.
60
+
61
+ .example stdscr
62
+
63
+ .h3 The start method
64
+
65
+ The `start method can take a number of parameters, some of which
66
+ are keyword arguments. If you know curses, some of these will be familiar,
67
+ while others provide functionality unrelated to what curses provides.
68
+
69
+ .dlist |
70
+ `:cbreak | Like `cbreak in curses. Inverse is `:\_cbreak (preferred) or `:nocbreak
71
+ `:raw | Like `raw in curses. Inverse is `:\_raw (preferred) or `:noraw
72
+ `:echo | Like `echo in curses. Inverse is `:\_echo (preferred) or `:noecho
73
+ `:keypad | Like `keypad in curses. Inverse is `:\_keypad (preferred) or `:nokeypad
74
+ `log: _logfile | Log debugging information to specified file.
75
+ `fg: _foreground | Set foreground color for STDSCR.
76
+ `bg: _background | Set background color for STDSCR.
77
+ `scroll: _Boolean | Permit (or disallow) window scrolling for STDSCR.
78
+ .end
79
+
80
+
81
+ The defaults are as follows:
82
+
83
+ .mono
84
+ RubyText.start(:cbreak, :_raw, :_echo, :keypad, log: "/tmp/rubytext.log",
85
+ fg: White, bg: Blue, scroll: true)
86
+
87
+ # can be abbreviated simply:
88
+
89
+ RubyText.start
90
+ .end
91
+
92
+ .comment
93
+ Skip?
94
+ nodelay causes getch to be a non-blocking call.
95
+ If no input is ready, getch returns ERR.
96
+
97
+ Skip?
98
+ notimeout(win, TRUE) -- wgetch does not set a timer.
99
+ Differentiate between sequences received from a function key and those typed by a user.
100
+ .end
101
+
102
+ If you're a relative curses newbie (like me), you may have some confusion about
103
+ the `cbreak and `raw modes. Let's clear it up a little with these four facts.
104
+
105
+ .list
106
+ First of all, _neither of these permits buffered keyboard input or line editing (such as backspace).
107
+ As for interrupts such as `^C and ``^Z, `cbreak _permits these (handles them as usual).
108
+ The same interrupts are _not honored by `[raw]; instead, they are read as characters.
109
+ Finally, `cbreak mode overrides `raw mode if they are specified together.
110
+ .end
111
+
112
+ As for colors: The defaults of `White and `Blue are purely arbitrary. They may change.
113
+
114
+ The standard curses implementation recognizes eight colors: ``Black, ``Blue, ``Cyan,
115
+ ``Green, ``Magenta, ``Red, ``White, ``Yellow. Each of these constants refers to a symbol
116
+ of the same (lowercased) name. What these colors look like in your own local environment
117
+ may depend on many factors such as your operating system and terminal driver.
118
+
119
+ My own environment is iterm on Mac OSX with fairly standard settings. Here is some code
120
+ that will display all 64 possibilities of foreground/background. (Note that curses seems
121
+ to "cheat" when these two are the same, presumably to preserve legibility.)
122
+
123
+ .example colortest 16
124
+
125
+
126
+ That's all for now.
127
+
128
+
129
+ .cleanup toc.tmp
@@ -0,0 +1,59 @@
1
+ <table width=100% cellpadding=2><tr><td width=50% valign=top>
2
+ <style type="text/css">
3
+ <!--
4
+ pre { white-space: pre-wrap; font-family: monospace; color: #ffffff; background-color: #000000; }
5
+ tt { font-size: 15 }
6
+ body { font-family: monospace; color: #ffffff; background-color: #000000; }
7
+ .Constant { color: #ff40ff; }
8
+ .Special { color: #ffff00; }
9
+ .Identifier { color: #00ffff; }
10
+ .Statement { color: #ffff00; }
11
+ .PreProc { color: #ff40ff; }
12
+ .Type { color: #00ff00; }
13
+ -->
14
+ </style>
15
+
16
+ <script type='text/javascript'>
17
+ <!--
18
+
19
+ -->
20
+ </script>
21
+ </head>
22
+ <body>
23
+ <pre id='vimCodeElement'>
24
+ <span class="PreProc">require</span> <span class="Special">'</span><span class="Constant">rubytext</span><span class="Special">'</span>
25
+
26
+ <span class="Type">RubyText</span>.start(<span class="Constant">fg</span>: <span class="Type">White</span>, <span class="Constant">bg</span>: <span class="Type">Black</span>)
27
+
28
+ print <span class="Special">&quot;</span><span class="Constant"> </span><span class="Special">&quot;</span>*<span class="Constant">10</span>
29
+ <span class="Type">Colors</span>.each {|<span class="Identifier">col</span>| print <span class="Special">&quot;</span><span class="Constant">%-8s</span><span class="Special">&quot;</span> % col.to_s.capitalize }
30
+ puts
31
+ puts
32
+
33
+ <span class="Type">Colors</span>.each <span class="Statement">do</span> |<span class="Identifier">col</span>|
34
+ puts <span class="Special">&quot;</span><span class="Constant"> </span><span class="Special">&quot;</span> + col.to_s.capitalize
35
+ puts
36
+ <span class="Statement">end</span>
37
+
38
+ <span class="Type">STDSCR</span>.bottom
39
+
40
+ r0 = <span class="Constant">2</span>
41
+ <span class="Type">Colors</span>.each <span class="Statement">do</span> |<span class="Identifier">fg</span>|
42
+ c0 = <span class="Constant">10</span>
43
+ <span class="Type">Colors</span>.each <span class="Statement">do</span> |<span class="Identifier">bg</span>|
44
+ win = <span class="Type">RubyText</span>.window(<span class="Constant">1</span>, <span class="Constant">7</span>, r0, c0,
45
+ <span class="Constant">border</span>: <span class="Constant">false</span>,
46
+ <span class="Constant">fg</span>: fg, <span class="Constant">bg</span>: bg)
47
+ win.puts <span class="Special">&quot;</span><span class="Constant"> TEXT </span><span class="Special">&quot;</span>
48
+ c0 += <span class="Constant">8</span>
49
+ <span class="Statement">end</span>
50
+ r0 += <span class="Constant">2</span>
51
+ <span class="Statement">end</span>
52
+
53
+ getch
54
+
55
+ </pre>
56
+ </body>
57
+ </html>
58
+ <!-- vim: set foldmethod=manual : -->
59
+ </td><td width=50% valign=top><img src=colortest.png valign=top></td></tr></table>
@@ -0,0 +1,43 @@
1
+ <table width=100% cellpadding=2><tr><td width=50% valign=top>
2
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
6
+ <title>~/Dropbox/files/rubytext/tutorial/hw.rb.html</title>
7
+ <meta name="Generator" content="Vim/7.4">
8
+ <meta name="plugin-version" content="vim7.4_v2">
9
+ <meta name="syntax" content="ruby">
10
+ <meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
11
+ <meta name="colorscheme" content="darkblue">
12
+ <style type="text/css">
13
+ <!--
14
+ pre { white-space: pre-wrap; font-family: monospace; color: #ffffff; background-color: #000000; font-size: 15}
15
+ tt { font-size: 15 }
16
+ body { font-family: monospace; color: #ffffff; background-color: #000000; }
17
+ .Constant { color: #ff40ff; }
18
+ .Special { color: #ffff00; }
19
+ .PreProc { color: #ff40ff; }
20
+ .Type { color: #00ff00; }
21
+ -->
22
+ </style>
23
+
24
+ <script type='text/javascript'>
25
+ <!--
26
+
27
+ -->
28
+ </script>
29
+ </head>
30
+ <body>
31
+ <pre id='vimCodeElement'>
32
+ <span class="PreProc">require</span> <span class="Special">'</span><span class="Constant">rubytext</span><span class="Special">'</span>
33
+
34
+ <span class="Type">RubyText</span>.start
35
+
36
+ puts <span class="Special">&quot;</span><span class="Constant">Hello, world!</span><span class="Special">&quot;</span>
37
+
38
+ getch
39
+ </pre>
40
+ </body>
41
+ </html>
42
+ <!-- vim: set foldmethod=manual : -->
43
+ </td><td width=50% valign=top><img src=hw.png valign=top></td></tr></table>
@@ -0,0 +1,59 @@
1
+ <table width=100% cellpadding=2><tr><td width=50% valign=top>
2
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
3
+ <html>
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html; charset=UTF-8">
6
+ <title>~/Dropbox/files/rubytext/tutorial/stdscr.rb.html</title>
7
+ <meta name="Generator" content="Vim/7.4">
8
+ <meta name="plugin-version" content="vim7.4_v2">
9
+ <meta name="syntax" content="ruby">
10
+ <meta name="settings" content="use_css,pre_wrap,no_foldcolumn,expand_tabs,prevent_copy=">
11
+ <meta name="colorscheme" content="darkblue">
12
+ <style type="text/css">
13
+ <!--
14
+ pre { white-space: pre-wrap; font-family: monospace; color: #ffffff; background-color: #000000; }
15
+ pre {font-size: 16}
16
+ tt {font-size: 16}
17
+ body { font-family: monospace; color: #ffffff; background-color: #000000; }
18
+ .Constant { color: #ff40ff; }
19
+ .Special { color: #ffff00; }
20
+ .PreProc { color: #ff40ff; }
21
+ .Type { color: #00ff00; }
22
+ -->
23
+ </style>
24
+
25
+ <script type='text/javascript'>
26
+ <!--
27
+
28
+ -->
29
+ </script>
30
+ </head>
31
+ <body>
32
+ <pre id='vimCodeElement'>
33
+ <span class="PreProc">require</span> <span class="Special">'</span><span class="Constant">rubytext</span><span class="Special">'</span>
34
+
35
+ <span class="Type">RubyText</span>.start(<span class="Constant">fg</span>: <span class="Type">Yellow</span>, <span class="Constant">bg</span>: <span class="Type">Blue</span>)
36
+
37
+ puts <span class="Special">&quot;</span><span class="Constant">This writes by default to STDSCR</span><span class="Special">&quot;</span>
38
+ <span class="Type">STDSCR</span>.puts <span class="Special">&quot;</span><span class="Constant">and this does the same thing.</span><span class="Special">\n</span><span class="Constant"> </span><span class="Special">&quot;</span>
39
+
40
+ print <span class="Special">&quot;</span><span class="Constant">Only one line </span><span class="Special">&quot;</span>
41
+ print <span class="Special">&quot;</span><span class="Constant">of output </span><span class="Special">&quot;</span>
42
+ print <span class="Special">&quot;</span><span class="Constant">printed </span><span class="Special">&quot;</span>
43
+ puts <span class="Special">&quot;</span><span class="Constant">here.</span><span class="Special">&quot;</span>
44
+
45
+ puts
46
+
47
+ array = [<span class="Constant">1</span>, <span class="Constant">2</span>, <span class="Constant">3</span>, <span class="Constant">4</span>, <span class="Constant">5</span>]
48
+
49
+ puts <span class="Special">&quot;</span><span class="Constant">p also works:</span><span class="Special">&quot;</span>
50
+ p array
51
+
52
+ puts
53
+
54
+ getch
55
+ </pre>
56
+ </body>
57
+ </html>
58
+ <!-- vim: set foldmethod=manual : -->
59
+ </td><td width=50% valign=top><img src=stdscr.png valign=top></td></tr></table>
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.82
4
+ version: 0.0.83
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hal Fulton
@@ -85,6 +85,24 @@ files:
85
85
  - lib/widgets.rb
86
86
  - lib/window.rb
87
87
  - test/auto.rb
88
+ - tutorial/basic.css
89
+ - tutorial/colortest.png
90
+ - tutorial/colortest.rb
91
+ - tutorial/colortest.rb.html
92
+ - tutorial/damn.rb
93
+ - tutorial/hw.png
94
+ - tutorial/hw.rb
95
+ - tutorial/hw.rb.html
96
+ - tutorial/meh.html
97
+ - tutorial/modes.txt
98
+ - tutorial/stdscr.png
99
+ - tutorial/stdscr.rb
100
+ - tutorial/stdscr.rb.html
101
+ - tutorial/tutorial.html
102
+ - tutorial/tutorial.lt3
103
+ - tutorial/wrap-colortest.html
104
+ - tutorial/wrap-hw.html
105
+ - tutorial/wrap-stdscr.html
88
106
  homepage: https://github.com/Hal9000/rubytext
89
107
  licenses:
90
108
  - Ruby