ncurses-ruby 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
data/Changes ADDED
@@ -0,0 +1,53 @@
1
+ ncurses-ruby-1.1
2
+ * Bugfixes by T. Sutherland in _tracef and _tracedump.
3
+
4
+ ncurses-ruby-1.0
5
+ * Mousemask bugfix from P.Duncan.
6
+ * Solved timing problems that affected visual smoothness of reactions
7
+ to user input
8
+ * Each SCREEN got back its own "halfdelay" and "cbreak" settings
9
+
10
+ ncurses-ruby-0.9.2
11
+ * Preventing getch and wgetch functions from blocking other ruby threads.
12
+ * Previously ncurses-ruby installed two files named "ncurses.rb" and
13
+ "ncurses.so". The "ncurses.so" is now renamed to "ncurses_bin.so"
14
+ to prevent "require 'ncurses'" from accidentally loading only the
15
+ binary file in case that this is found first in ruby's load path.
16
+ * Reintroduced ability to "include" Ncurses functions:
17
+ Use "include Ncurses::Namespace" for that. This is implemented via
18
+ method_missing, so that ncurses functions (some of which have very
19
+ common names) will not hide other functions defined in the extended
20
+ scope. (Any existing method_missing function is properly aliased and
21
+ called after an unsuccessful lookup.)
22
+
23
+ ncurses-ruby-0.9.1
24
+ * Bugfix in *in*str functions (Hiroshi Sainohira)
25
+ * Fix linking error on Mac OS X and some other platforms (Andreas Schwarz)
26
+
27
+ ncurses-ruby-0.9:
28
+ * Forms wrapper contributed by Simon Kaczor
29
+ * ncurses-ruby now also works with ncurses-4.2
30
+ (an old release from 1998, needed for Zaurus-port)
31
+ * First binary package for Sharp Zaurus (arm-linux)
32
+
33
+ ncurses-ruby-0.8:
34
+ * Bugfix: Calls into the ncurses library prior to calling
35
+ Ncurses::initscr or Ncurses::newterm had previously crashed
36
+ the Ruby interpreter.
37
+ Fixed by delaying the binding of most Ncurses functions
38
+ until after Ncurses::initscr or Ncurses::newterm have been
39
+ called.
40
+ * Replaced module functions with singleton functions. This
41
+ means that
42
+ include Ncurses
43
+ initscr
44
+ is no longer possible. Instead, use
45
+ Ncurses.initscr
46
+ Reasons: - Consistency. The shortcut has never been possible
47
+ with all ncurses functions.
48
+ - Namespace pollution. Some ncurses functions have
49
+ too common names.
50
+
51
+ ncurses-ruby-0.7.2:
52
+ * reintroduced Ncurses::pechochar and Ncurses::redrawwin in the ncurses build.
53
+ These had been removed by mistake because they did not work with PDCurses.
data/README ADDED
@@ -0,0 +1,351 @@
1
+ $Id: README,v 1.14 2006/06/19 09:43:58 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
+ (C) 2005 2006 Tobias Herzke <t-peters@users.berlios.de>
8
+
9
+ This module is free software; you can redistribute it and/or
10
+ modify it under the terms of the GNU Lesser General Public
11
+ License as published by the Free Software Foundation; either
12
+ version 2 of the License, or (at your option) any later version.
13
+
14
+ This module is distributed in the hope that it will be useful,
15
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
+ Lesser General Public License for more details.
18
+
19
+ You should have received a copy of the GNU Lesser General Public
20
+ License along with this module; if not, write to the Free Software
21
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
+ ------------------------------------------------------------------------
23
+
24
+ Overview
25
+ ========
26
+
27
+ This README file explains how to use the ncurses ruby interface. It is
28
+ assumed that the reader has a rough understanding of what the ncurses
29
+ library is and how to use it from the C language. It then goes into
30
+ detail, explaining what is covered by the ruby interface, and the
31
+ rules that were followed in translating the C interface into a ruby
32
+ interface.
33
+
34
+ This ncurses interface provides access to the functions, macros,
35
+ global variables and constants of the ncurses library. These are
36
+ mapped to a Ruby Module named "Ncurses": Functions and external
37
+ variables are implemented as singleton functions of the Module
38
+ Ncurses.
39
+
40
+ This README is organized into the following parts:
41
+ - Overview
42
+ - Installation and Usage
43
+ - External Variables
44
+ - Constants
45
+ - Functions (and their Interfaces)
46
+ - Module / Class Hierarchie
47
+ - The WINDOW class
48
+ - The panel Library
49
+ - The form Library
50
+ - The menu Library
51
+ - Ncurses and Ruby Threads
52
+ - Example programs
53
+ - Applications using ncurses-ruby
54
+
55
+ General Ncurses Literature
56
+ --------------------------
57
+
58
+ If you don't know how to use ncurses from C, then please read an
59
+ introduction to ncurses before continuing with this README. Eric
60
+ Raymond has written an introduction that should be part of the ncurses
61
+ development package installed on your computer.
62
+ If you'd like a gentler introduction, then you have two options:
63
+ (1) there is a part of a chapter in "The Linux Programmer's Guide" dealing
64
+ with ncurses, available from www.tldp.org. It is quite old by now,
65
+ but the ncurses interface has not changed since then, regarding the
66
+ scope of covered functions, so it is still a very good read.
67
+ (2) There is also an up-to-date "NCURSES-Programming-HOWTO" in the HOWTO
68
+ collection of the Linux Documentation Project, also available at
69
+ www.tldp.org, which is worth a read.
70
+
71
+ You will also appreciate the extensive man-pages of ncurses, a useful
72
+ reference while coding.
73
+
74
+
75
+ Installation and Usage
76
+ ======================
77
+
78
+ ruby extconf.rb
79
+ make
80
+ make install
81
+
82
+ In your programs:
83
+ require "ncurses.rb"
84
+
85
+ If your programs use the scanw functions (most unlikely) you will have to
86
+ install the scanf library for ruby (http://www.rubyhacker.com/code/scanf).
87
+
88
+ Most ncurses functions are only available after either Ncurses.initscr or
89
+ Ncurses.newterm has returned successfully.
90
+
91
+ External Variables
92
+ ==================
93
+
94
+ External variables are accessed read-only, by module functions taking no
95
+ arguments. They are spelled exactly like their C counterparts. Sometimes, this
96
+ leads to module functions beginning with an uppercase letter (e.g.
97
+ Ncurses.LINES).
98
+
99
+ One of these external variables, ESCDELAY, is also settable with a ruby method
100
+ (Ncurses.ESCDELAY=).
101
+
102
+ Another external variable, Ncurses.RESIZEDELAY is introduced by this wrapper.
103
+ It contains the maximum milliseconds delay with which terminal resizesings are
104
+ recognized.
105
+
106
+ Constants
107
+ =========
108
+ (static C Preprocessor macros)
109
+
110
+ Constants are implemented as module constants in the Ncurses module, if
111
+ possible. Ruby constants can not start with an underscore, so these constants
112
+ have been renamed (they lost the leading underscore). There are,however,
113
+ module functions with the same name as these constants, that also return
114
+ the constant's value, when invoked (e.g. "Ncurses._ENDLINE" returns the value
115
+ of the constant "Ncurses::ENDLINE", which has the same value as the C constant
116
+ "_ENDLINE").
117
+
118
+ Note: The ncurses macros starting with ACS_ are not constants, their value
119
+ depends on the terminal in use. Nevertheless, they are implemented as
120
+ constants of the Ncurses module, but since they depend on the terminal, they
121
+ are not initialized before initscr() has been called. If you need more than
122
+ one terminal in a single program, you can access the ACS_ values through member
123
+ functions of class SCREEN.
124
+
125
+
126
+ Functions (and their Interfaces)
127
+ ================================
128
+
129
+ Functions (also those only implemented by macros in C) can be accessed
130
+ as module functions of the Module Ncurses. They take exactly the same
131
+ arguments as their C counterparts. Some of the C functions return additional
132
+ arguments through pointer arguments. These are implemented as follows:
133
+
134
+
135
+ Functions expecting pointers to integer types
136
+ ---------------------------------------------
137
+
138
+ When the C-function expects a pointer to int, short, chtype, or attr_type,
139
+ You should use a variable containing an empty array as the argument to the ruby
140
+ function. This is because ruby passes these types (ints) "by value" instead of
141
+ "by reference"; but arrays are passed by reference, so that you can see the
142
+ changes to them.
143
+ Attention: some macro-only functions like getsyx accept variables of type int,
144
+ but, being macros, they write values to their arguments. Thus, they also need
145
+ empty array arguments when called from ruby.
146
+ Example:
147
+ color_pair_number = 4
148
+ foreground_color = []
149
+ background_color = []
150
+ if (Ncurses.pair_content(color_pair_number, foreground_color,
151
+ background_color) != Ncurses::ERR)
152
+ "color pair number #{color_pair_number} contains color number " +
153
+ "#{foreground_color[0]} as the foreground color, and color " +
154
+ "number #{background_color[0]} as the background color")
155
+ end
156
+
157
+ There are 2 functions that read a value from the location pointed to by a
158
+ pointer to int, and store another value at those locations. These functions are
159
+ mouse_trafo and wmouse_trafo. When calling these functions, you have to provide
160
+ 2 arrays, each filled with exacly one Integer. The values contained in these
161
+ arrays will then be changed by the ruby module function.
162
+
163
+
164
+ Functions expecting (non-const) pointers to char
165
+ ------------------------------------------------
166
+
167
+ When the C-function expects a pointer to char, you should use a variable
168
+ containing an empty string as the argument to the ruby function.
169
+ Example:
170
+ line2 = ""
171
+ if (Ncurses.mvwinnstr(Ncurses.stdscr, y=2, x=0, line2,
172
+ Ncurses.getmaxx(Ncurses.stdscr)) == Ncurses::ERR)
173
+ raise "could not scan 3rd line"
174
+ else
175
+ Ncurses.beep if line2.index("|")
176
+ end
177
+ The string that the C function would store at the pointer-to-char location
178
+ will be appended to the given string.
179
+
180
+ Functions expecting const pointers to char do not modify the string they
181
+ receive, you can pass any string to them.
182
+
183
+
184
+
185
+ Functions expecting pointers to structs
186
+ ---------------------------------------------------
187
+
188
+ When the C-function expects a pointer to WINDOW, SCREEN, MEVENT,
189
+ PANEL, FORM, FIELD or FIELDTYPE then simply pass it the corresponding,
190
+ already existing ruby object.
191
+
192
+
193
+ scanf style functions expecting various pointers
194
+ ---------------------------------------------------
195
+
196
+ namely scanw, mvscanw, wscanw, mvwscanw. Use an array after the format string.
197
+ The scanned values will be placed there. Remember, you need scanf for ruby
198
+ installed for these functions to work.
199
+
200
+ Module / Class Hierarchie
201
+ =========================
202
+
203
+ module Ncurses
204
+ class WINDOW; end
205
+ class SCREEN; end
206
+ class MEVENT; end
207
+ module Panel
208
+ class PANEL; end
209
+ end
210
+ module Form
211
+ class FORM; end
212
+ class FIELD; end
213
+ class FIELDTYPE; end
214
+ end
215
+ module Menu
216
+ class MENU; end
217
+ class ITEM; end
218
+ end
219
+ end
220
+
221
+
222
+ The WINDOW class
223
+ ================
224
+
225
+ The class WINDOW implements method_missing and tries to map invoked
226
+ methods to Ncurses module functions using a simple heuristic:
227
+
228
+ If the method name starts with "mv", it looks for a Ncurses module
229
+ function that starts with "mvw", and if it exists, adds itself to the
230
+ argument list and calls this function.
231
+ If no such module function exists, or the name of the invoked method
232
+ does not start with "mv", it looks if there is a module function with
233
+ the name "w" + methodname, and if it exists, adds itself again to the
234
+ argument list and calls this function.
235
+ If this module function did not exist either, then, as a last step, it
236
+ invokes a module function with the same name as the method, adding
237
+ itself to the argument list.
238
+
239
+ Example: If you invoke win.mvaddch(y,x,ch) on an Ncurses::WINDOW
240
+ object, it will delegate the method call to
241
+ Ncurses.mvwaddch(win,y,x,ch).
242
+
243
+ Other examples:
244
+
245
+ win.printw("hello") => Ncurses.wprintw(win, "hello")
246
+
247
+ win.getmaxyx(y=[],
248
+ x=[]) => Ncurses.getmaxyx(win,y,x)
249
+
250
+ win.delwin() => Ncurses.delwin(win) # win cannot be used
251
+ # after this call
252
+
253
+
254
+ The panel Library
255
+ =================
256
+
257
+ The panel library has also been wrapped. All panel functions are
258
+ implemented as module functions of the module Ncurses::Panel.
259
+
260
+ Most of these functions are also implemented as methods of class
261
+ Ncurses::Panel::PANEL, once with their original name and once with the
262
+ subword "panel" and an adjacent underscore removed.
263
+
264
+ The form Library
265
+ ================
266
+
267
+ The form library was wrapped inside the Ncurses:Form module. All
268
+ form functions are implemented as module functions on the module
269
+ Ncurses::Form. In addition, all function for which the first
270
+ parameter is one of the objects are also implemented as an instance
271
+ method of the respective class. For example, instead of calling
272
+ post_form(form), you can use form.post_form().
273
+
274
+ Three objects are defined in the Ncurses:Form module:
275
+ 1. FORM
276
+ 2. FIELD
277
+ 3. FIELDTYPE
278
+
279
+ They are wrapping actual ncurses pointers and should be use whenever a
280
+ pointer to one of these types is expected in function calls.
281
+
282
+ All form constants are defined in the module as Ruby constants with
283
+ the same name as the curses constants.
284
+
285
+ Constructors for FORM, FIELD and FIELDTYPE objects are also provided,
286
+ and they expect the same parameters as new_form, new_field and
287
+ new_fieldtype curses functions.
288
+
289
+ Field validation is implemented using Ruby Proc objects. You must
290
+ provide a Ruby block whenever a function pointer is expected in curses
291
+ function arguments. See the example form2.rb for more details.
292
+
293
+ The functions form_userptr and field_userptr are not supported. Use
294
+ form.user_object and field.user_object to store Ruby objects instead.
295
+
296
+ The menu Library
297
+ ================
298
+
299
+ The menu library was wrapped inside the Ncurses:Menu module. All
300
+ menu functions are implemented as module functions in the module
301
+ Ncurses::Menu. In addition, all functions for which the first
302
+ parameter is one of the objects are also implemented as an instance
303
+ method of the respective class. For example, instead of calling
304
+ post_menu(menu), you can use menu.post_menu().
305
+
306
+ Two objects are defined in the Ncurses:Menu module:
307
+ 1. MENU
308
+ 2. ITEM
309
+
310
+ They are wrapping actual ncurses pointers and should be use whenever a
311
+ pointer to one of these types is expected in function calls.
312
+
313
+ All menu constants are defined in the module as Ruby constants with
314
+ the same name as the curses constants.
315
+
316
+ Constructors for MENU and ITEM objects are also provided, and they
317
+ expect the same parameters as new_menu and new_item curses functions.
318
+
319
+ You must provide a Ruby block whenever a function pointer is expected
320
+ in curses function arguments.
321
+
322
+ The functions menu_userptr and item_userptr are not supported. Use
323
+ menu.user_object and item.user_object to store Ruby objects instead.
324
+
325
+ Ncurses and Ruby Threads
326
+ ========================
327
+
328
+ The ncurses library is not thread-safe. Your application must properly
329
+ serialize calls into ncurses.
330
+
331
+ Prior to release 0.9.2, the getch and wgetch calls used to block the
332
+ complete ruby interpreter, all threads. This is no longer so. Other
333
+ threads should now continue to run during blocking calls to getch and
334
+ wgetch.
335
+
336
+ Example programs
337
+ ================
338
+
339
+ Directory "examples" contains a few example programs demonstrating how
340
+ to use the ncurses library with ruby. Be sure to read the file
341
+ "examples/LICENSES_for_examples".
342
+
343
+
344
+ Applications using ncurses-ruby
345
+ ===============================
346
+
347
+ aeditor (v. 0.x) - Pair programming editor, http://metaeditor.sourceforge.net/
348
+ raggle - RSS aggregator, http://www.raggle.org/about/
349
+ ruvi - Editor, http://ruvi.rubyforge.org/
350
+ tpp - text-based presentation program, http://synflood.at/tpp/
351
+ yapo - ports overview for CRUX linux distribution, http://jue.li/crux/yapo/
data/THANKS ADDED
@@ -0,0 +1,15 @@
1
+ $Id: THANKS,v 1.8 2006/06/19 09:39:40 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
12
+ Simon Strandgaard
13
+ Paul Duncan
14
+ Tim Sutherland
15
+ Earle Clubb
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
@@ -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>