ncurses 0.9.1
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.
- data/COPYING +515 -0
- data/Changes +27 -0
- data/MANIFEST +27 -0
- data/README +273 -0
- data/README.windows +35 -0
- data/THANKS +11 -0
- data/TODO +15 -0
- data/VERSION +1 -0
- data/examples/LICENSES_for_examples +26 -0
- data/examples/example.rb +129 -0
- data/examples/form.rb +82 -0
- data/examples/form2.rb +184 -0
- data/examples/hello_ncurses.rb +57 -0
- data/examples/rain.rb +220 -0
- data/examples/read_line.rb +67 -0
- data/examples/tclock.rb +227 -0
- data/examples/test_scanw.rb +27 -0
- data/extconf.rb +130 -0
- data/form_wrap.c +1447 -0
- data/form_wrap.h +62 -0
- data/lib/ncurses.rb +289 -0
- data/make_dist.rb +45 -0
- data/ncurses_wrap.c +2611 -0
- data/ncurses_wrap.h +99 -0
- data/panel_wrap.c +256 -0
- data/panel_wrap.h +32 -0
- metadata +79 -0
data/Changes
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
ncurses-ruby-0.9:
|
2
|
+
* Forms wrapper contributed by Simon Kaczor
|
3
|
+
* ncurses-ruby now also works with ncurses-4.2
|
4
|
+
(an old release from 1998, needed for Zaurus-port)
|
5
|
+
* First binary package for Sharp Zaurus (arm-linux)
|
6
|
+
|
7
|
+
ncurses-ruby-0.8:
|
8
|
+
* Bugfix: Calls into the ncurses library prior to calling
|
9
|
+
Ncurses::initscr or Ncurses::newterm had previously crashed
|
10
|
+
the Ruby interpreter.
|
11
|
+
Fixed by delaying the binding of most Ncurses functions
|
12
|
+
until after Ncurses::initscr or Ncurses::newterm have been
|
13
|
+
called.
|
14
|
+
* Replaced module functions with singleton functions. This
|
15
|
+
means that
|
16
|
+
include Ncurses
|
17
|
+
initscr
|
18
|
+
is no longer possible. Instead, use
|
19
|
+
Ncurses.initscr
|
20
|
+
Reasons: - Consistency. The shortcut has never been possible
|
21
|
+
with all ncurses functions.
|
22
|
+
- Namespace pollution. Some ncurses functions have
|
23
|
+
too common names.
|
24
|
+
|
25
|
+
ncurses-ruby-0.7.2:
|
26
|
+
* reintroduced Ncurses::pechochar and Ncurses::redrawwin in the ncurses build.
|
27
|
+
These had been removed by mistake because they did not work with PDCurses.
|
data/MANIFEST
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
Changes
|
2
|
+
COPYING
|
3
|
+
MANIFEST
|
4
|
+
README
|
5
|
+
README.windows
|
6
|
+
THANKS
|
7
|
+
TODO
|
8
|
+
VERSION
|
9
|
+
examples/example.rb
|
10
|
+
examples/form.rb
|
11
|
+
examples/form2.rb
|
12
|
+
examples/hello_ncurses.rb
|
13
|
+
examples/LICENSES_for_examples
|
14
|
+
examples/rain.rb
|
15
|
+
examples/tclock.rb
|
16
|
+
examples/read_line.rb
|
17
|
+
examples/test_scanw.rb
|
18
|
+
extconf.rb
|
19
|
+
form_wrap.c
|
20
|
+
form_wrap.h
|
21
|
+
make_dist.rb
|
22
|
+
ncurses_wrap.c
|
23
|
+
ncurses_wrap.h
|
24
|
+
lib/ncurses.rb
|
25
|
+
panel_wrap.c
|
26
|
+
panel_wrap.h
|
27
|
+
|
data/README
ADDED
@@ -0,0 +1,273 @@
|
|
1
|
+
$Id: README,v 1.10 2004/05/13 21:54:41 t-peters Exp $
|
2
|
+
------------------------------------------------------------------------
|
3
|
+
This directory contains a ruby module for accessing the FSF's ncurses
|
4
|
+
library.
|
5
|
+
(C) 2002, 2003, 2004 Tobias Peters <t-peters@users.berlios.de>
|
6
|
+
(C) 2004 Simon Kaczor <skaczor@cox.net>
|
7
|
+
|
8
|
+
This module is free software; you can redistribute it and/or
|
9
|
+
modify it under the terms of the GNU Lesser General Public
|
10
|
+
License as published by the Free Software Foundation; either
|
11
|
+
version 2 of the License, or (at your option) any later version.
|
12
|
+
|
13
|
+
This module is distributed in the hope that it will be useful,
|
14
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
15
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16
|
+
Lesser General Public License for more details.
|
17
|
+
|
18
|
+
You should have received a copy of the GNU Lesser General Public
|
19
|
+
License along with this module; if not, write to the Free Software
|
20
|
+
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
21
|
+
------------------------------------------------------------------------
|
22
|
+
|
23
|
+
This wrapper provides access to the functions, macros, global variables and
|
24
|
+
constants of the ncurses library. These are mapped to a Ruby Module named
|
25
|
+
"Ncurses": Functions and external variables are implemented as singleton
|
26
|
+
functions of the Module Ncurses.
|
27
|
+
|
28
|
+
This wrapper can also be used to access the PDCurses library
|
29
|
+
(http://pdcurses.sourceforge.net/). See README.windows for details.
|
30
|
+
|
31
|
+
If you don't know how to use ncurses from C, then stop reading here, and read
|
32
|
+
an introduction to ncurses. Eric Raymond has written an introduction that
|
33
|
+
should be part of the ncurses development package installed on your computer.
|
34
|
+
If you need a gentler introduction, then you have two options:
|
35
|
+
(1) there is a part of a chapter in "The Linux Programmer's Guide" dealing with
|
36
|
+
ncurses, available from www.tldp.org. It is quite old by now,
|
37
|
+
but the ncurses interface has not changed since then, regarding the scope
|
38
|
+
of covered functions, so it is still a very good read.
|
39
|
+
(2) There is also an up-to-date "NCURSES-Programming-HOWTO" in the HOWTO
|
40
|
+
collection of the Linux Documentation Project, also available at
|
41
|
+
www.tldp.org, which is worth a read.
|
42
|
+
|
43
|
+
You will also appreciate the extensive man-pages of ncurses.
|
44
|
+
|
45
|
+
|
46
|
+
Installation and Usage
|
47
|
+
======================
|
48
|
+
|
49
|
+
ruby extconf.rb
|
50
|
+
make
|
51
|
+
make install
|
52
|
+
|
53
|
+
In your programs:
|
54
|
+
require "ncurses.rb"
|
55
|
+
|
56
|
+
If your programs use the scanw functions (most unlikely) you will have to
|
57
|
+
install the scanf library for ruby (http://www.rubyhacker.com/code/scanf).
|
58
|
+
|
59
|
+
Most ncurses functions are only available after either Ncurses.initscr or
|
60
|
+
Ncurses.newterm has returned successfully.
|
61
|
+
|
62
|
+
External Variables
|
63
|
+
==================
|
64
|
+
|
65
|
+
External variables are accessed read-only, by module functions taking no
|
66
|
+
arguments. They are spelled exactly like their C counterparts. Sometimes, this
|
67
|
+
leads to module functions beginning with an uppercase letter (e.g.
|
68
|
+
Ncurses.LINES).
|
69
|
+
|
70
|
+
One of these external variables, ESCDELAY, is also settable with a ruby method
|
71
|
+
(Ncurses.ESCDELAY=).
|
72
|
+
|
73
|
+
|
74
|
+
Constants
|
75
|
+
=========
|
76
|
+
(static C Preprocessor macros)
|
77
|
+
|
78
|
+
Constants are implemented as module constants in the Ncurses module, if
|
79
|
+
possible. Ruby constants can not start with an underscore, so these constants
|
80
|
+
have been renamed (they lost the leading underscore). There are,however,
|
81
|
+
module functions with the same name as these constants, that also return
|
82
|
+
the constant's value, when invoked (e.g. "Ncurses._ENDLINE" returns the value
|
83
|
+
of the constant "Ncurses::ENDLINE", which has the same value as the C constant
|
84
|
+
"_ENDLINE").
|
85
|
+
|
86
|
+
Note: The ncurses macros starting with ACS_ are not constants, their value
|
87
|
+
depends on the terminal in use. Nevertheless, they are implemented as
|
88
|
+
constants of the Ncurses module, but since they depend on the terminal, they
|
89
|
+
are not initialized before initscr() has been called. If you need more than
|
90
|
+
one terminal in a single program, you can access the ACS_ values through member
|
91
|
+
functions of class SCREEN.
|
92
|
+
|
93
|
+
|
94
|
+
Functions
|
95
|
+
=========
|
96
|
+
|
97
|
+
Functions (also those only implemented by macros in C) can also be accessed
|
98
|
+
through module functions of the Module Ncurses. They take exactly the same
|
99
|
+
arguments as their C counterparts. Some of the C functions return additional
|
100
|
+
arguments through pointer arguments. These are implemented as follows:
|
101
|
+
|
102
|
+
|
103
|
+
Functions expecting pointers to integer types
|
104
|
+
---------------------------------------------
|
105
|
+
|
106
|
+
When the C-function expects a pointer to int, short, chtype, or attr_type,
|
107
|
+
You should use a variable containing an empty array as the argument to the ruby
|
108
|
+
function. This is because ruby passes these types (ints) "by value" instead of
|
109
|
+
"by reference"; but arrays are passed by reference, so that you can see the
|
110
|
+
changes to them.
|
111
|
+
Attention: some macro-only functions like getsyx accept variables of type int,
|
112
|
+
but, being macros, they write values to their arguments. Thus, they also need
|
113
|
+
empty array arguments when called from ruby.
|
114
|
+
Example:
|
115
|
+
color_pair_number = 4
|
116
|
+
foreground_color = []
|
117
|
+
background_color = []
|
118
|
+
if (Ncurses.pair_content(color_pair_number, foreground_color,
|
119
|
+
background_color) != Ncurses::ERR)
|
120
|
+
"color pair number #{color_pair_number} contains color number " +
|
121
|
+
"#{foreground_color[0]} as the foreground color, and color " +
|
122
|
+
"number #{background_color[0]} as the background color")
|
123
|
+
end
|
124
|
+
|
125
|
+
There are 2 functions that read a value from the location pointed to by a
|
126
|
+
pointer to int, and store another value at those locations. These functions are
|
127
|
+
mouse_trafo and wmouse_trafo. When calling these functions, you have to provide
|
128
|
+
2 arrays, each filled with exacly one Integer. The values contained in these
|
129
|
+
arrays will then be changed by the ruby module function.
|
130
|
+
|
131
|
+
|
132
|
+
Functions expecting (non-const) pointers to char
|
133
|
+
------------------------------------------------
|
134
|
+
|
135
|
+
When the C-function expects a pointer to char, you should use a variable
|
136
|
+
containing an empty string as the argument to the ruby function.
|
137
|
+
Example:
|
138
|
+
line2 = ""
|
139
|
+
if (Ncurses.mvwinnstr(Ncurses.stdscr, y=2, x=0, line2,
|
140
|
+
Ncurses.getmaxx(Ncurses.stdscr)) == Ncurses::ERR)
|
141
|
+
raise "could not scan 3rd line"
|
142
|
+
else
|
143
|
+
Ncurses.beep if line2.index("|")
|
144
|
+
end
|
145
|
+
The string that the C function would store at the pointer-to-char location
|
146
|
+
will be appended to the given string.
|
147
|
+
|
148
|
+
Functions expecting const pointers to char do not modify the string they
|
149
|
+
receive, you can pass any string to them.
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
Functions expecting pointers to structs
|
154
|
+
---------------------------------------------------
|
155
|
+
|
156
|
+
When the C-function expects a pointer to WINDOW, SCREEN, MEVENT,
|
157
|
+
PANEL, FORM, FIELD or FIELDTYPE then simply pass it the corresponding,
|
158
|
+
already existing ruby object.
|
159
|
+
|
160
|
+
|
161
|
+
scanf style functions expecting various pointers
|
162
|
+
---------------------------------------------------
|
163
|
+
|
164
|
+
namely scanw, mvscanw, wscanw, mvwscanw. Use an array after the format string.
|
165
|
+
The scanned values will be placed there. Remember, you need scanf for ruby
|
166
|
+
installed for these functions to work.
|
167
|
+
|
168
|
+
Module / Class Hierarchie
|
169
|
+
=========================
|
170
|
+
|
171
|
+
module Ncurses
|
172
|
+
class WINDOW; end
|
173
|
+
class SCREEN; end
|
174
|
+
class MEVENT; end
|
175
|
+
module Panel
|
176
|
+
class PANEL; end
|
177
|
+
end
|
178
|
+
module Form
|
179
|
+
class FORM; end
|
180
|
+
class FIELD; end
|
181
|
+
class FIELDTYPE; end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
Where to find the functions
|
187
|
+
===========================
|
188
|
+
|
189
|
+
As stated, all ncurses functions are implemented as module functions in the
|
190
|
+
module Ncurses. If you know how an ncurses function is named in C (example:
|
191
|
+
"mvaddch"), then call the corresponding module functions with the
|
192
|
+
same number of arguments (example: "Ncurses.mvaddch(y,x,ch)")
|
193
|
+
|
194
|
+
The class window implements method_missing and tries to map invoked methods
|
195
|
+
to Ncurses module functions using a simple heuristic:
|
196
|
+
If the method name starts with "mv", it looks for a Ncurses module function
|
197
|
+
that starts with "mvw", and if it exists, adds itself to the argument list
|
198
|
+
and calls this function.
|
199
|
+
If no such module function exists, or the name of the invoked method does not
|
200
|
+
start with "mv", it looks if there is a module function with the name "w" +
|
201
|
+
methodname, and if it exists, adds itself again to the argument list and calls
|
202
|
+
this function.
|
203
|
+
If this module function did not exist either, then, as a last step, it invokes
|
204
|
+
a module function with the same name as the method, adding itself to the
|
205
|
+
argument list.
|
206
|
+
|
207
|
+
Example: If you invoke win.mvaddch(y,x,ch) on an Ncurses::WINDOW object, it
|
208
|
+
will delegate the method call to Ncurses.mvwaddch(win,y,x,ch).
|
209
|
+
|
210
|
+
Other examples:
|
211
|
+
win.delwin() => Ncurses.delwin(win) # win cannot be used
|
212
|
+
# after this call
|
213
|
+
win.printw("hello") => Ncurses.wprintw(win, "hello")
|
214
|
+
win.getmaxyx(y=[],
|
215
|
+
x=[]) => Ncurses.getmaxyx(win,y,x)
|
216
|
+
|
217
|
+
|
218
|
+
Example programs
|
219
|
+
================
|
220
|
+
|
221
|
+
Directory "examples" contains a few example programs demonstrating how to use
|
222
|
+
the library with ruby. Be sure to read the file
|
223
|
+
"examples/LICENSES_for_examples".
|
224
|
+
|
225
|
+
|
226
|
+
Applications using ncurses-ruby
|
227
|
+
===============================
|
228
|
+
|
229
|
+
aeditor - Pair programming editor, http://metaeditor.sourceforge.net/
|
230
|
+
raggle - RSS aggregator, http://www.raggle.org/about/
|
231
|
+
|
232
|
+
The panel library
|
233
|
+
=================
|
234
|
+
|
235
|
+
The panel library has also been wrapped. All panel functions are implemented
|
236
|
+
as module functions of the module Ncurses::Panel.
|
237
|
+
|
238
|
+
Most of these functions are also implemented as methods of class
|
239
|
+
Ncurses::Panel::PANEL, once with their original name and once with the subword
|
240
|
+
"panel" and an adjacent underscore removed.
|
241
|
+
|
242
|
+
The form library
|
243
|
+
================
|
244
|
+
|
245
|
+
The form library was wrapped inside the Ncurses:Form module. All
|
246
|
+
form functions are implemented as module functions on the module
|
247
|
+
Ncurses::Form. In addition, all function for which the first
|
248
|
+
parameter is one of the objects are also implemented as an instance
|
249
|
+
method of that object. For example, instead of calling
|
250
|
+
post_form(form), you can use form.post_form().
|
251
|
+
|
252
|
+
Three objects are defined in the Ncurses:Form module:
|
253
|
+
1. FORM
|
254
|
+
2. FIELD
|
255
|
+
3. FIELDTYPE
|
256
|
+
|
257
|
+
They are wrapping actual ncurses pointers and should be use whenever a
|
258
|
+
pointer to one of these types is expected in function calls.
|
259
|
+
|
260
|
+
All form constants are defined in the module as Ruby constants with
|
261
|
+
the same name as the curses constants.
|
262
|
+
|
263
|
+
Constructors for FORM, FIELD and FIELDTYPE objects are also provided,
|
264
|
+
and they expect the same parameters as new_form, new_field and
|
265
|
+
new_fieldtype curses functions.
|
266
|
+
|
267
|
+
Field validation is implemented using Ruby Proc objects. You must
|
268
|
+
provide a Ruby block whenever a function pointer is expected in curses
|
269
|
+
function arguments. See the example form2.rb for more details.
|
270
|
+
|
271
|
+
The functions form_userptr and field_userptr are not supported. Use
|
272
|
+
form.user_object and field.user_object to store Ruby objects instead.
|
273
|
+
|
data/README.windows
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
$Id: README.windows,v 1.2 2003/03/22 20:00:59 t-peters Exp $
|
2
|
+
------------------------------------------------------------------------
|
3
|
+
|
4
|
+
Ncurses has been ported to the cygwin environment. If you are using the
|
5
|
+
cygwin version of ruby on windows, you can simply use this version of
|
6
|
+
ncurses.
|
7
|
+
|
8
|
+
Instead, if you are using a native windows version of Ruby (compiled with
|
9
|
+
mingw, visual c++, borland c++), then you can use this wrapper with the
|
10
|
+
PDCurses library (http://pdcurses.sourceforge.net/). In this case,
|
11
|
+
ncurses-ruby wraps the subset of curses features that are common to ncurses
|
12
|
+
and PDCurses.
|
13
|
+
|
14
|
+
Here's how to compile ncurses-ruby on windows using PDCurses and MinGW:
|
15
|
+
(For those not familiar enough with the mingw compiler, you can get a
|
16
|
+
precompiled mingw ruby from
|
17
|
+
http://www.ruby-lang.org/~eban/ruby/binaries/mingw/, and a precompiled
|
18
|
+
ncurses-ruby version from this project's download area
|
19
|
+
http://developer.berlios.de/project/filelist.php?group_id=273)
|
20
|
+
|
21
|
+
- compile ruby with mingw 2.0 and install it somewhere. remember to set up
|
22
|
+
the PATH environment correctly.
|
23
|
+
|
24
|
+
- get the sources for PDCurses and compile them using the provided Makefile
|
25
|
+
"win32/mingwin32.mak"
|
26
|
+
|
27
|
+
- next, move the pdcurses header files ("curses.h", "panel.h") into mingw's
|
28
|
+
include directory. Also, move the generated libraries ("pdcurses.a",
|
29
|
+
"panel.a") into mingw's lib directory, while renaming these libraries to
|
30
|
+
"libpdcurses.a" and "libpanel.a"
|
31
|
+
|
32
|
+
- compile and install ncurses-ruby using the commands "ruby extconf.rb",
|
33
|
+
"make", "make install"
|
34
|
+
|
35
|
+
- try out the examples
|
data/THANKS
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
$Id: THANKS,v 1.5 2004/07/31 08:34:17 t-peters Exp $
|
2
|
+
|
3
|
+
A list of people that helped me with ncurses-ruby
|
4
|
+
|
5
|
+
Akinori MUSHA (knu at idaemons dot org)
|
6
|
+
Jan Becvar (jan dot becvar at solnet dot cz)
|
7
|
+
Juergen Daubert
|
8
|
+
Doug Kearns
|
9
|
+
Simon Kaczor (skaczor at cox dut net)
|
10
|
+
Hiroshi Sainohira
|
11
|
+
Andreas Schwarz
|
data/TODO
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
$Id: TODO,v 1.6 2003/03/22 22:55:27 t-peters Exp $
|
2
|
+
|
3
|
+
This is the complete list of functions present in ncurses that have not yet
|
4
|
+
been wrapped by ncurses-ruby:
|
5
|
+
|
6
|
+
terminfo functions: setupterm, setterm, set_curterm, del_curterm, restartterm,
|
7
|
+
tparm, tputs, vidputs
|
8
|
+
|
9
|
+
termcap fuctions: tgetent, tgetflag, tgetnum, tgetstr, tgoto
|
10
|
+
|
11
|
+
ncurses
|
12
|
+
kernel functions: ripoffline
|
13
|
+
|
14
|
+
No sense in
|
15
|
+
wrapping these: vw_printw, vwprintw, vwscanw
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.9.1
|
@@ -0,0 +1,26 @@
|
|
1
|
+
$Id: LICENSES_for_examples,v 1.6 2004/05/13 21:55:17 t-peters Exp $
|
2
|
+
|
3
|
+
Ideally, an example program on how to use a library should be in the public
|
4
|
+
domain.
|
5
|
+
|
6
|
+
Some of the example programs contained in this dircectory have not been put in
|
7
|
+
the public domain, however.
|
8
|
+
|
9
|
+
The reason is because I did not write all programs completely myself -- I've
|
10
|
+
adapted the following example programs from ncurses programs in other
|
11
|
+
programming languages, or I have included example programs contributed by
|
12
|
+
other authors, and I have to respect their original licenses:
|
13
|
+
- rain.rb is adapted from rain.c from the ncurses library distribution.
|
14
|
+
- example.rb is adapted from an example program for the python ncurses binding.
|
15
|
+
- tclock.rb is adapted from tclock.c from the ncurses library distribution.
|
16
|
+
- form.rb anf form2.rb have been written by Simon Kaczor, who has adapted them
|
17
|
+
from sample code from the NCurses Programming HOWTO.
|
18
|
+
|
19
|
+
See the comments in the source files for restrictions imposed on copying and
|
20
|
+
modifying these.
|
21
|
+
|
22
|
+
That said, I suppose you may still look at their source code and learn how
|
23
|
+
ncurses programs generally work, as long as you dont start your own programs
|
24
|
+
by loading the example program into your editor and modify it to your needs.
|
25
|
+
|
26
|
+
Tobias Peters <t-peters@users.berlios.de>
|
data/examples/example.rb
ADDED
@@ -0,0 +1,129 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
# $Id: example.rb,v 1.4 2002/03/04 13:24:29 t-peters Exp $
|
4
|
+
|
5
|
+
# This file provides an example for the usage of the ncurses-ruby module.
|
6
|
+
# Copyright (C) 2002 Tobias Peters <t-peters@users.berlios.de>
|
7
|
+
#
|
8
|
+
# The following license applys only to this file. It is less restrictive
|
9
|
+
# than the license for the rest of the ncurses-ruby distribution.
|
10
|
+
# I've adapted this file from someone else, see below.
|
11
|
+
#
|
12
|
+
# Permission is hereby granted, free of charge, to any person
|
13
|
+
# obtaining a copy of this file
|
14
|
+
# (the "Software"), to deal in the Software without restriction,
|
15
|
+
# including without limitation the rights to use, copy, modify, merge,
|
16
|
+
# publish, distribute, sublicense, and/or sell copies of the Software,
|
17
|
+
# and to permit persons to whom the Software is furnished to do so,
|
18
|
+
# subject to the following conditions:
|
19
|
+
#
|
20
|
+
# The above copyright notice and this permission notice shall be
|
21
|
+
# included in all copies or substantial portions of the Software.
|
22
|
+
#
|
23
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
24
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
25
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
26
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
27
|
+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
28
|
+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
29
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
30
|
+
# SOFTWARE.
|
31
|
+
|
32
|
+
|
33
|
+
|
34
|
+
# this file is adapted from an example of the python ncurses binding
|
35
|
+
# pyncurses (http://pyncurses.sf.net/), which has the following copyright
|
36
|
+
# statement:
|
37
|
+
|
38
|
+
# Copyright (c) 2000 by Harry Henry Gebel
|
39
|
+
#
|
40
|
+
# Permission is hereby granted, free of charge, to any person
|
41
|
+
# obtaining a copy of this software and associated documentation files
|
42
|
+
# (the "Software"), to deal in the Software without restriction,
|
43
|
+
# including without limitation the rights to use, copy, modify, merge,
|
44
|
+
# publish, distribute, sublicense, and/or sell copies of the Software,
|
45
|
+
# and to permit persons to whom the Software is furnished to do so,
|
46
|
+
# subject to the following conditions:
|
47
|
+
#
|
48
|
+
# The above copyright notice and this permission notice shall be
|
49
|
+
# included in all copies or substantial portions of the Software.
|
50
|
+
#
|
51
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
52
|
+
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
53
|
+
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
54
|
+
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
|
55
|
+
# BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
|
56
|
+
# ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
57
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
58
|
+
# SOFTWARE.
|
59
|
+
|
60
|
+
|
61
|
+
|
62
|
+
require "ncurses"
|
63
|
+
|
64
|
+
def moving(scr)
|
65
|
+
scr.clear() # clear screen
|
66
|
+
scr.move(5,5) # move cursor
|
67
|
+
scr.addstr("move(5,5)")
|
68
|
+
scr.refresh() # update screen
|
69
|
+
sleep(2)
|
70
|
+
scr.move(2,2)
|
71
|
+
scr.addstr("move(2,2)")
|
72
|
+
scr.refresh()
|
73
|
+
sleep(2)
|
74
|
+
scr.move(10, 2)
|
75
|
+
scr.addstr("Press a key to continue")
|
76
|
+
scr.getch()
|
77
|
+
end
|
78
|
+
|
79
|
+
def border(scr)
|
80
|
+
scr.clear()
|
81
|
+
scr.border(*([0]*8)) # calls WINDOW#border(0, 0, 0, 0, 0, 0, 0, 0)
|
82
|
+
scr.move(3,3)
|
83
|
+
scr.addstr("Press a key to continue")
|
84
|
+
scr.getch()
|
85
|
+
end
|
86
|
+
|
87
|
+
def two_borders()
|
88
|
+
# make a new window as tall as the screen and half as wide, in the left half
|
89
|
+
# of the screen
|
90
|
+
one = Ncurses::WINDOW.new(0, Ncurses.COLS() / 2, 0, 0)
|
91
|
+
# make one for the right half
|
92
|
+
two = Ncurses::WINDOW.new(0, Ncurses.COLS() - (Ncurses.COLS() / 2),
|
93
|
+
0, Ncurses.COLS() / 2)
|
94
|
+
one.border(*([0]*8))
|
95
|
+
two.border(*([0]*8))
|
96
|
+
one.move(3,3)
|
97
|
+
two.move(2,5)
|
98
|
+
one.addstr("move(3,3)")
|
99
|
+
two.addstr("move(2,5)")
|
100
|
+
two.move(5,3)
|
101
|
+
two.addstr("Press a key to continue")
|
102
|
+
one.noutrefresh() # copy window to virtual screen, don't update real screen
|
103
|
+
two.noutrefresh()
|
104
|
+
Ncurses.doupdate() # update read screen
|
105
|
+
two.getch()
|
106
|
+
end
|
107
|
+
|
108
|
+
begin
|
109
|
+
# initialize ncurses
|
110
|
+
Ncurses.initscr
|
111
|
+
Ncurses.cbreak # provide unbuffered input
|
112
|
+
Ncurses.noecho # turn off input echoing
|
113
|
+
Ncurses.nonl # turn off newline translation
|
114
|
+
Ncurses.stdscr.intrflush(false) # turn off flush-on-interrupt
|
115
|
+
Ncurses.stdscr.keypad(true) # turn on keypad mode
|
116
|
+
|
117
|
+
Ncurses.stdscr.addstr("Press a key to continue") # output string
|
118
|
+
Ncurses.stdscr.getch # get a charachter
|
119
|
+
|
120
|
+
moving(Ncurses.stdscr) # demo of moving cursor
|
121
|
+
border(Ncurses.stdscr) # demo of borders
|
122
|
+
two_borders() # demo of two windows with borders
|
123
|
+
|
124
|
+
ensure
|
125
|
+
Ncurses.echo
|
126
|
+
Ncurses.nocbreak
|
127
|
+
Ncurses.nl
|
128
|
+
Ncurses.endwin
|
129
|
+
end
|