curses 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6c17d6438dfbef3ba35924c664ab8aa202d00414
4
+ data.tar.gz: 745b122b2d9437e4be4fd9ae0c9dc3b40a100352
5
+ SHA512:
6
+ metadata.gz: c54eab5f46ce78ba30021ffe8b43e5686b60ef6862d7a069f73d62a74e784071bff6b5a59b0d56bf4e64a1fe299983b8bb8ad64bf0c0ae81357be3635f200c78
7
+ data.tar.gz: 8834576b168a77c442aa5bc90b3be8eddc6ab3a8d0ce65aef979346ba40a20992c633222d6c25fa4c8d3af2b6dfd65d0521081e07607fc830102b6b889100f7e
@@ -0,0 +1 @@
1
+ _�S�����uD'/ �q�� ��*�$����|Z<=�;�����+-��ςZ�"�H����NS��;�.iEKB�@�z�}Tȼc�k\d*j�AB$X��B Q���g���U(6��Z<�zR�� ������ó߾��)B�/B[�0~ș�zw�<�Y�K����U�ͣ�8�Ϙ=}Z��OQ�C�0���V�<}.� /~�a�����t����C�/W9�jW&��ub�l���a�q�N����
@@ -0,0 +1 @@
1
+ s��>�Z@�X��R"�}��>]��
data/BSDL ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (C) 1993-2013 Yukihiro Matsumoto. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without
4
+ modification, are permitted provided that the following conditions
5
+ are met:
6
+ 1. Redistributions of source code must retain the above copyright
7
+ notice, this list of conditions and the following disclaimer.
8
+ 2. Redistributions in binary form must reproduce the above copyright
9
+ notice, this list of conditions and the following disclaimer in the
10
+ documentation and/or other materials provided with the distribution.
11
+
12
+ THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
13
+ ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
14
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
15
+ ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
16
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
17
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
18
+ OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
19
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
20
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
21
+ OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
22
+ SUCH DAMAGE.
data/COPYING ADDED
@@ -0,0 +1,56 @@
1
+ Ruby is copyrighted free software by Yukihiro Matsumoto <matz@netlab.jp>.
2
+ You can redistribute it and/or modify it under either the terms of the
3
+ 2-clause BSDL (see the file BSDL), or the conditions below:
4
+
5
+ 1. You may make and give away verbatim copies of the source form of the
6
+ software without restriction, provided that you duplicate all of the
7
+ original copyright notices and associated disclaimers.
8
+
9
+ 2. You may modify your copy of the software in any way, provided that
10
+ you do at least ONE of the following:
11
+
12
+ a) place your modifications in the Public Domain or otherwise
13
+ make them Freely Available, such as by posting said
14
+ modifications to Usenet or an equivalent medium, or by allowing
15
+ the author to include your modifications in the software.
16
+
17
+ b) use the modified software only within your corporation or
18
+ organization.
19
+
20
+ c) give non-standard binaries non-standard names, with
21
+ instructions on where to get the original software distribution.
22
+
23
+ d) make other distribution arrangements with the author.
24
+
25
+ 3. You may distribute the software in object code or binary form,
26
+ provided that you do at least ONE of the following:
27
+
28
+ a) distribute the binaries and library files of the software,
29
+ together with instructions (in the manual page or equivalent)
30
+ on where to get the original distribution.
31
+
32
+ b) accompany the distribution with the machine-readable source of
33
+ the software.
34
+
35
+ c) give non-standard binaries non-standard names, with
36
+ instructions on where to get the original software distribution.
37
+
38
+ d) make other distribution arrangements with the author.
39
+
40
+ 4. You may modify and include the part of the software into any other
41
+ software (possibly commercial). But some files in the distribution
42
+ are not written by the author, so that they are not under these terms.
43
+
44
+ For the list of those files and their copying conditions, see the
45
+ file LEGAL.
46
+
47
+ 5. The scripts and library files supplied as input to or produced as
48
+ output from the software do not automatically fall under the
49
+ copyright of the software, but belong to whomever generated them,
50
+ and may be sold commercially, and may be aggregated with this
51
+ software.
52
+
53
+ 6. THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
54
+ IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
55
+ WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
56
+ PURPOSE.
@@ -0,0 +1,5 @@
1
+ ### 1.0
2
+
3
+ * Major enhancements
4
+ * Birthday!
5
+
@@ -0,0 +1,16 @@
1
+ BSDL
2
+ COPYING
3
+ History.md
4
+ Manifest.txt
5
+ README.md
6
+ Rakefile
7
+ curses.gemspec
8
+ ext/curses/curses.c
9
+ ext/curses/depend
10
+ ext/curses/extconf.rb
11
+ lib/curses.rb
12
+ sample/hello.rb
13
+ sample/mouse.rb
14
+ sample/rain.rb
15
+ sample/view.rb
16
+ sample/view2.rb
@@ -0,0 +1,28 @@
1
+ # curses
2
+
3
+ * https://github.com/ruby/curses
4
+ * https://github.com/ruby/curses/issues
5
+
6
+ ## Description
7
+
8
+ A Ruby binding for curses, ncurses, and PDCurses, formerly part of the Ruby
9
+ standard library. curses is an extension library for text UI applications.
10
+
11
+ ## Install
12
+
13
+ $ gem install curses
14
+
15
+ ## Developers
16
+
17
+ After checking out the source, run:
18
+
19
+ $ rake newb
20
+
21
+ This task will install any missing dependencies, run the tests/specs,
22
+ and generate the RDoc.
23
+
24
+ ## License
25
+
26
+ curses is released under the Ruby and 2-clause BSD licenses. See COPYING for
27
+ details.
28
+
@@ -0,0 +1,43 @@
1
+ # -*- ruby -*-
2
+
3
+ require 'rubygems'
4
+ require 'hoe'
5
+ begin
6
+ require 'rake/extensiontask'
7
+ rescue LoadError => e
8
+ warn "\nmissing #{e.path} (for rake-compiler)" if e.respond_to? :path
9
+ warn "run: rake newb\n\n"
10
+ end
11
+
12
+ Hoe.plugin :git
13
+ Hoe.plugin :minitest
14
+ Hoe.plugin :travis
15
+
16
+ HOE = Hoe.spec 'curses' do
17
+ self.version = '1.0.0'
18
+
19
+ developer 'Eric Hodel', 'drbrain@segment7.net'
20
+ developer 'Shugo Maeda', ''
21
+
22
+ license 'Ruby'
23
+ license 'BSD-2-Clause'
24
+
25
+ self.extra_rdoc_files << 'ext/curses/curses.c'
26
+ self.spec_extras[:extensions] = 'ext/curses/extconf.rb'
27
+
28
+ self.readme_file = 'README.md'
29
+ self.history_file = 'History.md'
30
+
31
+ self.extra_dev_deps << ['rake-compiler', '~> 0.8']
32
+ end
33
+
34
+ if Rake.const_defined? :ExtensionTask then
35
+ Rake::ExtensionTask.new 'curses', HOE.spec do |ext|
36
+ ext.lib_dir = 'lib/curses'
37
+ end
38
+
39
+ task default: :compile
40
+ task test: :compile
41
+ end
42
+
43
+ # vim: syntax=ruby
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ Gem::Specification.new { |s|
3
+ s.name = "curses"
4
+ s.version = "0.0.1"
5
+ s.date = "2013-06-28"
6
+ s.author = "Shugo Maeda"
7
+ s.email = "shugo@ruby-lang.org"
8
+ s.homepage = "http://github.com/shugo/curses"
9
+ s.platform = Gem::Platform::RUBY
10
+ s.summary = "curses binding for Ruby"
11
+ s.files = Dir.glob('{lib,ext,sample}/**/*') + ['README.md', 'COPYING', 'BSDL']
12
+ s.extensions = ["ext/curses/extconf.rb"]
13
+ s.require_path = "lib"
14
+ }
@@ -0,0 +1,4330 @@
1
+ /* -*- C -*-
2
+ * $Id$
3
+ *
4
+ * ext/curses/curses.c
5
+ *
6
+ * by MAEDA Shugo (ender@pic-internet.or.jp)
7
+ * modified by Yukihiro Matsumoto (matz@netlab.co.jp),
8
+ * Toki Yoshinori,
9
+ * Hitoshi Takahashi,
10
+ * and Takaaki Tateishi (ttate@kt.jaist.ac.jp)
11
+ *
12
+ * maintainers:
13
+ * - Takaaki Tateishi (ttate@kt.jaist.ac.jp)
14
+ *
15
+ * documentation:
16
+ * - Vincent Batts (vbatts@hashbangbash.com)
17
+ */
18
+
19
+ #include "ruby.h"
20
+ #include "ruby/io.h"
21
+ #include "ruby/thread.h"
22
+
23
+ #if defined(HAVE_NCURSES_H)
24
+ # include <ncurses.h>
25
+ #elif defined(HAVE_NCURSES_CURSES_H)
26
+ # include <ncurses/curses.h>
27
+ #elif defined(HAVE_CURSES_COLR_CURSES_H)
28
+ # ifdef HAVE_STDARG_PROTOTYPES
29
+ # include <stdarg.h>
30
+ # else
31
+ # include <varargs.h>
32
+ # endif
33
+ # include <curses_colr/curses.h>
34
+ #else
35
+ # include <curses.h>
36
+ # if defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)
37
+ # if !defined(_maxx)
38
+ # define _maxx maxx
39
+ # endif
40
+ # if !defined(_maxy)
41
+ # define _maxy maxy
42
+ # endif
43
+ # if !defined(_begx)
44
+ # define _begx begx
45
+ # endif
46
+ # if !defined(_begy)
47
+ # define _begy begy
48
+ # endif
49
+ # endif
50
+ #endif
51
+
52
+ #ifdef HAVE_INIT_COLOR
53
+ # define USE_COLOR 1
54
+ #endif
55
+
56
+ /* supports only ncurses mouse routines */
57
+ #ifdef NCURSES_MOUSE_VERSION
58
+ # define USE_MOUSE 1
59
+ #endif
60
+
61
+ #define NUM2CH NUM2CHR
62
+ #define CH2FIX CHR2FIX
63
+
64
+ static VALUE mCurses;
65
+ static VALUE mKey;
66
+ static VALUE cWindow;
67
+ static VALUE cPad;
68
+ #ifdef USE_MOUSE
69
+ static VALUE cMouseEvent;
70
+ #endif
71
+
72
+ static VALUE rb_stdscr;
73
+
74
+ struct windata {
75
+ WINDOW *window;
76
+ };
77
+
78
+ static VALUE window_attroff(VALUE obj, VALUE attrs);
79
+ static VALUE window_attron(VALUE obj, VALUE attrs);
80
+ static VALUE window_attrset(VALUE obj, VALUE attrs);
81
+
82
+ static void
83
+ no_window(void)
84
+ {
85
+ rb_raise(rb_eRuntimeError, "already closed window");
86
+ }
87
+
88
+ #define GetWINDOW(obj, winp) do {\
89
+ if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)\
90
+ rb_raise(rb_eSecurityError, "Insecure: operation on untainted window");\
91
+ TypedData_Get_Struct((obj), struct windata, &windata_type, (winp));\
92
+ if ((winp)->window == 0) no_window();\
93
+ } while (0)
94
+
95
+ static void
96
+ window_free(void *p)
97
+ {
98
+ struct windata *winp = p;
99
+ if (winp->window && winp->window != stdscr) delwin(winp->window);
100
+ winp->window = 0;
101
+ xfree(winp);
102
+ }
103
+
104
+ static size_t
105
+ window_memsize(const void *p)
106
+ {
107
+ const struct windata *winp = p;
108
+ size_t size = sizeof(*winp);
109
+ if (!winp) return 0;
110
+ if (winp->window && winp->window != stdscr) size += sizeof(winp->window);
111
+ return size;
112
+ }
113
+
114
+ static const rb_data_type_t windata_type = {
115
+ "windata",
116
+ {0, window_free, window_memsize,}
117
+ };
118
+
119
+ static VALUE
120
+ prep_window(VALUE class, WINDOW *window)
121
+ {
122
+ VALUE obj;
123
+ struct windata *winp;
124
+
125
+ if (window == NULL) {
126
+ rb_raise(rb_eRuntimeError, "failed to create window");
127
+ }
128
+
129
+ obj = rb_obj_alloc(class);
130
+ TypedData_Get_Struct(obj, struct windata, &windata_type, winp);
131
+ winp->window = window;
132
+
133
+ return obj;
134
+ }
135
+
136
+ /*-------------------------- module Curses --------------------------*/
137
+
138
+ /*
139
+ * Document-method: Curses.init_screen
140
+ *
141
+ * Initialize a standard screen
142
+ *
143
+ * see also Curses.stdscr
144
+ */
145
+ static VALUE
146
+ curses_init_screen(void)
147
+ {
148
+ if (rb_stdscr) return rb_stdscr;
149
+ initscr();
150
+ if (stdscr == 0) {
151
+ rb_raise(rb_eRuntimeError, "can't initialize curses");
152
+ }
153
+ clear();
154
+ rb_stdscr = prep_window(cWindow, stdscr);
155
+ return rb_stdscr;
156
+ }
157
+
158
+ /*
159
+ * Document-method: Curses.stdscr
160
+ *
161
+ * The Standard Screen.
162
+ *
163
+ * Upon initializing curses, a default window called stdscr,
164
+ * which is the size of the terminal screen, is created.
165
+ *
166
+ * Many curses functions use this window.
167
+ */
168
+ #define curses_stdscr curses_init_screen
169
+
170
+ /*
171
+ * Document-method: Curses.close_screen
172
+ *
173
+ * A program should always call Curses.close_screen before exiting or
174
+ * escaping from curses mode temporarily. This routine
175
+ * restores tty modes, moves the cursor to the lower
176
+ * left-hand corner of the screen and resets the terminal
177
+ * into the proper non-visual mode.
178
+ *
179
+ * Calling Curses.refresh or Curses.doupdate after a temporary
180
+ * escape causes the program to resume visual mode.
181
+ *
182
+ */
183
+ static VALUE
184
+ curses_close_screen(void)
185
+ {
186
+ curses_stdscr();
187
+ #ifdef HAVE_ISENDWIN
188
+ if (!isendwin())
189
+ #endif
190
+ endwin();
191
+ rb_stdscr = 0;
192
+ return Qnil;
193
+ }
194
+
195
+ /*
196
+ * This is no runtime method,
197
+ * but a function called before the proc ends
198
+ *
199
+ * Similar to Curses.close_screen, except that it also
200
+ * garbage collects/unregisters the Curses.stdscr
201
+ */
202
+ static void
203
+ curses_finalize(VALUE dummy)
204
+ {
205
+ if (stdscr
206
+ #ifdef HAVE_ISENDWIN
207
+ && !isendwin()
208
+ #endif
209
+ )
210
+ endwin();
211
+ rb_stdscr = 0;
212
+ rb_gc_unregister_address(&rb_stdscr);
213
+ }
214
+
215
+ #ifdef HAVE_ISENDWIN
216
+ /*
217
+ * Document-method: Curses.closed?
218
+ *
219
+ * Returns +true+ if the window/screen has been closed,
220
+ * without any subsequent Curses.refresh calls,
221
+ * returns +false+ otherwise.
222
+ */
223
+ static VALUE
224
+ curses_closed(void)
225
+ {
226
+ curses_stdscr();
227
+ if (isendwin()) {
228
+ return Qtrue;
229
+ }
230
+ return Qfalse;
231
+ }
232
+ #else
233
+ #define curses_closed rb_f_notimplement
234
+ #endif
235
+
236
+ /*
237
+ * Document-method: Curses.clear
238
+ *
239
+ * Clears every position on the screen completely,
240
+ * so that a subsequent call by Curses.refresh for the screen/window
241
+ * will be repainted from scratch.
242
+ */
243
+ static VALUE
244
+ curses_clear(VALUE obj)
245
+ {
246
+ curses_stdscr();
247
+ wclear(stdscr);
248
+ return Qnil;
249
+ }
250
+
251
+ /*
252
+ * Document-method: Curses.clrtoeol
253
+ *
254
+ * Clears to the end of line, that the cursor is currently on.
255
+ */
256
+ static VALUE
257
+ curses_clrtoeol(void)
258
+ {
259
+ curses_stdscr();
260
+ clrtoeol();
261
+ return Qnil;
262
+ }
263
+
264
+ /*
265
+ * Document-method: Curses.refresh
266
+ *
267
+ * Refreshes the windows and lines.
268
+ *
269
+ */
270
+ static VALUE
271
+ curses_refresh(VALUE obj)
272
+ {
273
+ curses_stdscr();
274
+ refresh();
275
+ return Qnil;
276
+ }
277
+
278
+ /*
279
+ * Document-method: Curses.doupdate
280
+ *
281
+ * Refreshes the windows and lines.
282
+ *
283
+ * Curses.doupdate allows multiple updates with
284
+ * more efficiency than Curses.refresh alone.
285
+ */
286
+ static VALUE
287
+ curses_doupdate(VALUE obj)
288
+ {
289
+ curses_stdscr();
290
+ #ifdef HAVE_DOUPDATE
291
+ doupdate();
292
+ #else
293
+ refresh();
294
+ #endif
295
+ return Qnil;
296
+ }
297
+
298
+ /*
299
+ * Document-method: Curses.echo
300
+ *
301
+ * Enables characters typed by the user
302
+ * to be echoed by Curses.getch as they are typed.
303
+ */
304
+ static VALUE
305
+ curses_echo(VALUE obj)
306
+ {
307
+ curses_stdscr();
308
+ echo();
309
+ return Qnil;
310
+ }
311
+
312
+ /*
313
+ * Document-method: Curses.noecho
314
+ *
315
+ * Disables characters typed by the user
316
+ * to be echoed by Curses.getch as they are typed.
317
+ */
318
+ static VALUE
319
+ curses_noecho(VALUE obj)
320
+ {
321
+ curses_stdscr();
322
+ noecho();
323
+ return Qnil;
324
+ }
325
+
326
+ /*
327
+ * Document-method: Curses.raw
328
+ *
329
+ * Put the terminal into raw mode.
330
+ *
331
+ * Raw mode is similar to Curses.cbreak mode, in that characters typed
332
+ * are immediately passed through to the user program.
333
+ *
334
+ * The differences are that in raw mode, the interrupt, quit,
335
+ * suspend, and flow control characters are all passed through
336
+ * uninterpreted, instead of generating a signal. The behavior
337
+ * of the BREAK key depends on other bits in the tty driver
338
+ * that are not set by curses.
339
+ */
340
+ static VALUE
341
+ curses_raw(VALUE obj)
342
+ {
343
+ curses_stdscr();
344
+ raw();
345
+ return Qnil;
346
+ }
347
+
348
+ /*
349
+ * Document-method: Curses.noraw
350
+ *
351
+ * Put the terminal out of raw mode.
352
+ *
353
+ * see Curses.raw for more detail
354
+ */
355
+ static VALUE
356
+ curses_noraw(VALUE obj)
357
+ {
358
+ curses_stdscr();
359
+ noraw();
360
+ return Qnil;
361
+ }
362
+
363
+ /*
364
+ * Document-method: Curses.cbreak
365
+ *
366
+ * Put the terminal into cbreak mode.
367
+ *
368
+ * Normally, the tty driver buffers typed characters until
369
+ * a newline or carriage return is typed. The Curses.cbreak
370
+ * routine disables line buffering and erase/kill
371
+ * character-processing (interrupt and flow control characters
372
+ * are unaffected), making characters typed by the user
373
+ * immediately available to the program.
374
+ *
375
+ * The Curses.nocbreak routine returns the terminal to normal (cooked) mode.
376
+ *
377
+ * Initially the terminal may or may not be in cbreak mode,
378
+ * as the mode is inherited; therefore, a program should
379
+ * call Curses.cbreak or Curses.nocbreak explicitly.
380
+ * Most interactive programs using curses set the cbreak mode.
381
+ * Note that Curses.cbreak overrides Curses.raw.
382
+ *
383
+ * see also Curses.raw
384
+ */
385
+ static VALUE
386
+ curses_cbreak(VALUE obj)
387
+ {
388
+ curses_stdscr();
389
+ cbreak();
390
+ return Qnil;
391
+ }
392
+
393
+ /*
394
+ * Document-method: Curses.nocbreak
395
+ *
396
+ * Put the terminal into normal mode (out of cbreak mode).
397
+ *
398
+ * See Curses.cbreak for more detail.
399
+ */
400
+ static VALUE
401
+ curses_nocbreak(VALUE obj)
402
+ {
403
+ curses_stdscr();
404
+ nocbreak();
405
+ return Qnil;
406
+ }
407
+
408
+ /*
409
+ * Document-method: Curses.nl
410
+ *
411
+ * Enable the underlying display device to translate
412
+ * the return key into newline on input, and whether it
413
+ * translates newline into return and line-feed on output
414
+ * (in either case, the call Curses.addch('\n') does the
415
+ * equivalent of return and line feed on the virtual screen).
416
+ *
417
+ * Initially, these translations do occur. If you disable
418
+ * them using Curses.nonl, curses will be able to make better use
419
+ * of the line-feed capability, resulting in faster cursor
420
+ * motion. Also, curses will then be able to detect the return key.
421
+ */
422
+ static VALUE
423
+ curses_nl(VALUE obj)
424
+ {
425
+ curses_stdscr();
426
+ nl();
427
+ return Qnil;
428
+ }
429
+
430
+ /*
431
+ * Document-method: Curses.nl
432
+ *
433
+ * Disable the underlying display device to translate
434
+ * the return key into newline on input
435
+ *
436
+ * See Curses.nl for more detail
437
+ */
438
+ static VALUE
439
+ curses_nonl(VALUE obj)
440
+ {
441
+ curses_stdscr();
442
+ nonl();
443
+ return Qnil;
444
+ }
445
+
446
+ /*
447
+ * Document-method: Curses.beep
448
+ *
449
+ * Sounds an audible alarm on the terminal, if possible;
450
+ * otherwise it flashes the screen (visual bell).
451
+ *
452
+ * see also Curses.flash
453
+ */
454
+ static VALUE
455
+ curses_beep(VALUE obj)
456
+ {
457
+ #ifdef HAVE_BEEP
458
+ curses_stdscr();
459
+ beep();
460
+ #endif
461
+ return Qnil;
462
+ }
463
+
464
+ /*
465
+ * Document-method: Curses.flash
466
+ *
467
+ * Flashes the screen, for visual alarm on the terminal, if possible;
468
+ * otherwise it sounds the alert.
469
+ *
470
+ * see also Curses.beep
471
+ */
472
+ static VALUE
473
+ curses_flash(VALUE obj)
474
+ {
475
+ #ifdef HAVE_FLASH
476
+ curses_stdscr();
477
+ flash();
478
+ #endif
479
+ return Qnil;
480
+ }
481
+
482
+ static int
483
+ curses_char(VALUE c)
484
+ {
485
+ if (FIXNUM_P(c)) {
486
+ return NUM2INT(c);
487
+ }
488
+ else {
489
+ int cc;
490
+
491
+ StringValue(c);
492
+ if (RSTRING_LEN(c) == 0 || RSTRING_LEN(c) > 1) {
493
+ rb_raise(rb_eArgError, "string not corresponding a character");
494
+ }
495
+ cc = RSTRING_PTR(c)[0];
496
+ if (cc > 0x7f) {
497
+ rb_raise(rb_eArgError, "no multibyte string supported (yet)");
498
+ }
499
+ return cc;
500
+ }
501
+ }
502
+
503
+ #ifdef HAVE_UNGETCH
504
+ /*
505
+ * Document-method: Curses.ungetch
506
+ * call-seq: ungetch(ch)
507
+ *
508
+ * Places +ch+ back onto the input queue to be returned by
509
+ * the next call to Curses.getch.
510
+ *
511
+ * There is just one input queue for all windows.
512
+ */
513
+ static VALUE
514
+ curses_ungetch(VALUE obj, VALUE ch)
515
+ {
516
+ int c = curses_char(ch);
517
+ curses_stdscr();
518
+ ungetch(c);
519
+ return Qnil;
520
+ }
521
+ #else
522
+ #define curses_ungetch rb_f_notimplement
523
+ #endif
524
+
525
+ /*
526
+ * Document-method: Curses.setpos
527
+ * call-seq: setpos(y, x)
528
+ *
529
+ * A setter for the position of the cursor,
530
+ * using coordinates +x+ and +y+
531
+ *
532
+ */
533
+ static VALUE
534
+ curses_setpos(VALUE obj, VALUE y, VALUE x)
535
+ {
536
+ curses_stdscr();
537
+ move(NUM2INT(y), NUM2INT(x));
538
+ return Qnil;
539
+ }
540
+
541
+ /*
542
+ * Document-method: Curses.standout
543
+ *
544
+ * Enables the best highlighting mode of the terminal.
545
+ *
546
+ * This is equivalent to Curses:Window.attron(A_STANDOUT)
547
+ *
548
+ * see also Curses::Window.attrset additional information
549
+ */
550
+ static VALUE
551
+ curses_standout(VALUE obj)
552
+ {
553
+ curses_stdscr();
554
+ standout();
555
+ return Qnil;
556
+ }
557
+
558
+ /*
559
+ * Document-method: Curses.standend
560
+ *
561
+ * Enables the Normal display (no highlight)
562
+ *
563
+ * This is equivalent to Curses.attron(A_NORMAL)
564
+ *
565
+ * see also Curses::Window.attrset for additional information.
566
+ */
567
+ static VALUE
568
+ curses_standend(VALUE obj)
569
+ {
570
+ curses_stdscr();
571
+ standend();
572
+ return Qnil;
573
+ }
574
+
575
+ /*
576
+ * Document-method: Curses.inch
577
+ *
578
+ * Returns the character at the current position.
579
+ */
580
+ static VALUE
581
+ curses_inch(VALUE obj)
582
+ {
583
+ curses_stdscr();
584
+ return CH2FIX(inch());
585
+ }
586
+
587
+ /*
588
+ * Document-method: Curses.addch
589
+ * call-seq: addch(ch)
590
+ *
591
+ * Add a character +ch+, with attributes, then advance the cursor.
592
+ *
593
+ * see also the system manual for curs_addch(3)
594
+ */
595
+ static VALUE
596
+ curses_addch(VALUE obj, VALUE ch)
597
+ {
598
+ curses_stdscr();
599
+ addch(NUM2CH(ch));
600
+ return Qnil;
601
+ }
602
+
603
+ /*
604
+ * Document-method: Curses.insch
605
+ * call-seq: insch(ch)
606
+ *
607
+ * Insert a character +ch+, before the cursor.
608
+ *
609
+ */
610
+ static VALUE
611
+ curses_insch(VALUE obj, VALUE ch)
612
+ {
613
+ curses_stdscr();
614
+ insch(NUM2CH(ch));
615
+ return Qnil;
616
+ }
617
+
618
+ /*
619
+ * Document-method: Curses.addstr
620
+ * call-seq: addstr(str)
621
+ *
622
+ * add a string of characters +str+, to the window and advance cursor
623
+ *
624
+ */
625
+ static VALUE
626
+ curses_addstr(VALUE obj, VALUE str)
627
+ {
628
+ StringValue(str);
629
+ str = rb_str_export_locale(str);
630
+ curses_stdscr();
631
+ if (!NIL_P(str)) {
632
+ addstr(StringValueCStr(str));
633
+ }
634
+ return Qnil;
635
+ }
636
+
637
+ static void *
638
+ getch_func(void *arg)
639
+ {
640
+ int *ip = (int *)arg;
641
+ *ip = getch();
642
+ return 0;
643
+ }
644
+
645
+ /*
646
+ * Document-method: Curses.getch
647
+ *
648
+ * Read and returns a character from the window.
649
+ *
650
+ * See Curses::Key to all the function KEY_* available
651
+ *
652
+ */
653
+ static VALUE
654
+ curses_getch(VALUE obj)
655
+ {
656
+ int c;
657
+
658
+ curses_stdscr();
659
+ rb_thread_call_without_gvl(getch_func, &c, RUBY_UBF_IO, 0);
660
+ if (c == EOF) return Qnil;
661
+ if (rb_isprint(c)) {
662
+ char ch = (char)c;
663
+
664
+ return rb_locale_str_new(&ch, 1);
665
+ }
666
+ return UINT2NUM(c);
667
+ }
668
+
669
+ /* This should be big enough.. I hope */
670
+ #define GETSTR_BUF_SIZE 1024
671
+
672
+ static void *
673
+ getstr_func(void *arg)
674
+ {
675
+ char *rtn = (char *)arg;
676
+ #if defined(HAVE_GETNSTR)
677
+ getnstr(rtn,GETSTR_BUF_SIZE-1);
678
+ #else
679
+ getstr(rtn);
680
+ #endif
681
+ return 0;
682
+ }
683
+
684
+ /*
685
+ * Document-method: Curses.getstr
686
+ *
687
+ * This is equivalent to a series f Curses::Window.getch calls
688
+ *
689
+ */
690
+ static VALUE
691
+ curses_getstr(VALUE obj)
692
+ {
693
+ char rtn[GETSTR_BUF_SIZE];
694
+
695
+ curses_stdscr();
696
+ rb_thread_call_without_gvl(getstr_func, rtn, RUBY_UBF_IO, 0);
697
+ return rb_locale_str_new_cstr(rtn);
698
+ }
699
+
700
+ /*
701
+ * Document-method: Curses.delch
702
+ *
703
+ * Delete the character under the cursor
704
+ *
705
+ */
706
+ static VALUE
707
+ curses_delch(VALUE obj)
708
+ {
709
+ curses_stdscr();
710
+ delch();
711
+ return Qnil;
712
+ }
713
+
714
+ /*
715
+ * Document-method: Curses.deleteln
716
+ *
717
+ * Delete the line under the cursor.
718
+ *
719
+ */
720
+ static VALUE
721
+ curses_deleteln(VALUE obj)
722
+ {
723
+ curses_stdscr();
724
+ #if defined(HAVE_DELETELN) || defined(deleteln)
725
+ deleteln();
726
+ #endif
727
+ return Qnil;
728
+ }
729
+
730
+ /*
731
+ * Document-method: Curses.insertln
732
+ *
733
+ * Inserts a line above the cursor, and the bottom line is lost
734
+ *
735
+ */
736
+ static VALUE
737
+ curses_insertln(VALUE obj)
738
+ {
739
+ curses_stdscr();
740
+ #if defined(HAVE_INSERTLN) || defined(insertln)
741
+ insertln();
742
+ #endif
743
+ return Qnil;
744
+ }
745
+
746
+ /*
747
+ * Document-method: Curses.keyname
748
+ * call-seq: keyname(c)
749
+ *
750
+ * Returns the character string corresponding to key +c+
751
+ */
752
+ static VALUE
753
+ curses_keyname(VALUE obj, VALUE c)
754
+ {
755
+ #ifdef HAVE_KEYNAME
756
+ int cc = curses_char(c);
757
+ const char *name;
758
+
759
+ curses_stdscr();
760
+ name = keyname(cc);
761
+ if (name) {
762
+ return rb_str_new_cstr(name);
763
+ }
764
+ else {
765
+ return Qnil;
766
+ }
767
+ #else
768
+ return Qnil;
769
+ #endif
770
+ }
771
+
772
+ /*
773
+ * Document-method: Curses.lines
774
+ *
775
+ * Returns the number of lines on the screen
776
+ */
777
+ static VALUE
778
+ curses_lines(void)
779
+ {
780
+ return INT2FIX(LINES);
781
+ }
782
+
783
+ /*
784
+ * Document-method: Curses.cols
785
+ *
786
+ * Returns the number of columns on the screen
787
+ */
788
+ static VALUE
789
+ curses_cols(void)
790
+ {
791
+ return INT2FIX(COLS);
792
+ }
793
+
794
+ /*
795
+ * Document-method: Curses.curs_set
796
+ * call-seq: curs_set(visibility)
797
+ *
798
+ * Sets Cursor Visibility.
799
+ * 0: invisible
800
+ * 1: visible
801
+ * 2: very visible
802
+ */
803
+ static VALUE
804
+ curses_curs_set(VALUE obj, VALUE visibility)
805
+ {
806
+ #ifdef HAVE_CURS_SET
807
+ int n;
808
+ curses_stdscr();
809
+ return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil;
810
+ #else
811
+ return Qnil;
812
+ #endif
813
+ }
814
+
815
+ /*
816
+ * Document-method: Curses.scrl
817
+ * call-seq: scrl(num)
818
+ *
819
+ * Scrolls the current window Fixnum +num+ lines.
820
+ * The current cursor position is not changed.
821
+ *
822
+ * For positive +num+, it scrolls up.
823
+ *
824
+ * For negative +num+, it scrolls down.
825
+ *
826
+ */
827
+ static VALUE
828
+ curses_scrl(VALUE obj, VALUE n)
829
+ {
830
+ /* may have to raise exception on ERR */
831
+ #ifdef HAVE_SCRL
832
+ curses_stdscr();
833
+ return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse;
834
+ #else
835
+ return Qfalse;
836
+ #endif
837
+ }
838
+
839
+ /*
840
+ * Document-method: Curses.setscrreg
841
+ *
842
+ * call-seq:
843
+ * setscrreg(top, bottom)
844
+ *
845
+ * Set a software scrolling region in a window.
846
+ * +top+ and +bottom+ are lines numbers of the margin.
847
+ *
848
+ * If this option and Curses.scrollok are enabled, an attempt to move off
849
+ * the bottom margin line causes all lines in the scrolling region
850
+ * to scroll one line in the direction of the first line.
851
+ * Only the text of the window is scrolled.
852
+ *
853
+ */
854
+ static VALUE
855
+ curses_setscrreg(VALUE obj, VALUE top, VALUE bottom)
856
+ {
857
+ /* may have to raise exception on ERR */
858
+ #ifdef HAVE_SETSCRREG
859
+ curses_stdscr();
860
+ return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse;
861
+ #else
862
+ return Qfalse;
863
+ #endif
864
+ }
865
+
866
+ /*
867
+ * Document-method: Curses.attroff
868
+ * call-seq: attroff(attrs)
869
+ *
870
+ * Turns on the named attributes +attrs+ without affecting any others.
871
+ *
872
+ * See also Curses::Window.attrset for additional information.
873
+ */
874
+ static VALUE
875
+ curses_attroff(VALUE obj, VALUE attrs)
876
+ {
877
+ curses_stdscr();
878
+ return window_attroff(rb_stdscr,attrs);
879
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
880
+ }
881
+
882
+ /*
883
+ * Document-method: Curses.attron
884
+ * call-seq: attron(attrs)
885
+ *
886
+ * Turns off the named attributes +attrs+
887
+ * without turning any other attributes on or off.
888
+ *
889
+ * See also Curses::Window.attrset for additional information.
890
+ */
891
+ static VALUE
892
+ curses_attron(VALUE obj, VALUE attrs)
893
+ {
894
+ curses_stdscr();
895
+ return window_attron(rb_stdscr,attrs);
896
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
897
+ }
898
+
899
+ /*
900
+ * Document-method: Curses.attrset
901
+ * call-seq: attrset(attrs)
902
+ *
903
+ * Sets the current attributes of the given window to +attrs+.
904
+ *
905
+ * see also Curses::Window.attrset
906
+ *
907
+ */
908
+ static VALUE
909
+ curses_attrset(VALUE obj, VALUE attrs)
910
+ {
911
+ curses_stdscr();
912
+ return window_attrset(rb_stdscr,attrs);
913
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
914
+ }
915
+
916
+ /*
917
+ * Document-method: Curses.bkgdset
918
+ * call-seq: bkgdset(ch)
919
+ *
920
+ * Manipulate the background of the named window
921
+ * with character Integer +ch+
922
+ *
923
+ * The background becomes a property of the character
924
+ * and moves with the character through any scrolling
925
+ * and insert/delete line/character operations.
926
+ *
927
+ * see also the system manual for curs_bkgd(3)
928
+ */
929
+ static VALUE
930
+ curses_bkgdset(VALUE obj, VALUE ch)
931
+ {
932
+ #ifdef HAVE_BKGDSET
933
+ curses_stdscr();
934
+ bkgdset(NUM2CH(ch));
935
+ #endif
936
+ return Qnil;
937
+ }
938
+
939
+ /*
940
+ * call-seq: bkgd(ch)
941
+ *
942
+ * Window background manipulation routines.
943
+ *
944
+ * Set the background property of the current
945
+ * and then apply the character Integer +ch+ setting
946
+ * to every character position in that window.
947
+ *
948
+ * see also the system manual for curs_bkgd(3)
949
+ */
950
+ static VALUE
951
+ curses_bkgd(VALUE obj, VALUE ch)
952
+ {
953
+ #ifdef HAVE_BKGD
954
+ curses_stdscr();
955
+ return (bkgd(NUM2CH(ch)) == OK) ? Qtrue : Qfalse;
956
+ #else
957
+ return Qfalse;
958
+ #endif
959
+ }
960
+
961
+ #if defined(HAVE_USE_DEFAULT_COLORS)
962
+ /*
963
+ * tells the curses library to use terminal's default colors.
964
+ *
965
+ * see also the system manual for default_colors(3)
966
+ */
967
+ static VALUE
968
+ curses_use_default_colors(VALUE obj)
969
+ {
970
+ curses_stdscr();
971
+ use_default_colors();
972
+ return Qnil;
973
+ }
974
+ #else
975
+ #define curses_use_default_colors rb_f_notimplement
976
+ #endif
977
+
978
+ #if defined(HAVE_TABSIZE)
979
+ /*
980
+ * Document-method: Curses.TABSIZE=
981
+ * call-seq: TABSIZE=(value)
982
+ *
983
+ * Sets the TABSIZE to Integer +value+
984
+ */
985
+ static VALUE
986
+ curses_tabsize_set(VALUE obj, VALUE val)
987
+ {
988
+ TABSIZE = NUM2INT(val);
989
+ return INT2NUM(TABSIZE);
990
+ }
991
+ #else
992
+ #define curses_tabsize_set rb_f_notimplement
993
+ #endif
994
+
995
+ #if defined(HAVE_TABSIZE)
996
+ /*
997
+ * Returns the number of positions in a tab.
998
+ */
999
+ static VALUE
1000
+ curses_tabsize_get(VALUE ojb)
1001
+ {
1002
+ return INT2NUM(TABSIZE);
1003
+ }
1004
+ #else
1005
+ #define curses_tabsize_get rb_f_notimplement
1006
+ #endif
1007
+
1008
+ #if defined(HAVE_ESCDELAY)
1009
+ /*
1010
+ * call-seq: Curses.ESCDELAY=(value)
1011
+ *
1012
+ * Sets the ESCDELAY to Integer +value+
1013
+ */
1014
+ static VALUE
1015
+ curses_escdelay_set(VALUE obj, VALUE val)
1016
+ {
1017
+ ESCDELAY = NUM2INT(val);
1018
+ return INT2NUM(ESCDELAY);
1019
+ }
1020
+ #else
1021
+ #define curses_escdelay_set rb_f_notimplement
1022
+ #endif
1023
+
1024
+ #if defined(HAVE_ESCDELAY)
1025
+ /*
1026
+ * Returns the total time, in milliseconds, for which
1027
+ * curses will await a character sequence, e.g., a function key
1028
+ */
1029
+ static VALUE
1030
+ curses_escdelay_get(VALUE obj)
1031
+ {
1032
+ return INT2NUM(ESCDELAY);
1033
+ }
1034
+ #else
1035
+ #define curses_escdelay_get rb_f_notimplement
1036
+ #endif
1037
+
1038
+ /*
1039
+ * Document-method: Curses.resize
1040
+ * call-seq: resize(lines, cols)
1041
+ *
1042
+ * alias for Curses.resizeterm
1043
+ *
1044
+ */
1045
+
1046
+ /*
1047
+ * Document-method: Curses.resizeterm
1048
+ * call-seq: resizeterm(lines, cols)
1049
+ *
1050
+ * Resize the current term to Fixnum +lines+ and Fixnum +cols+
1051
+ *
1052
+ */
1053
+ static VALUE
1054
+ curses_resizeterm(VALUE obj, VALUE lin, VALUE col)
1055
+ {
1056
+ #if defined(HAVE_RESIZETERM)
1057
+ curses_stdscr();
1058
+ return (resizeterm(NUM2INT(lin),NUM2INT(col)) == OK) ? Qtrue : Qfalse;
1059
+ #else
1060
+ return Qnil;
1061
+ #endif
1062
+ }
1063
+
1064
+ #ifdef USE_COLOR
1065
+ /*
1066
+ * Document-method: Curses.start_color
1067
+ *
1068
+ * Initializes the color attributes, for terminals that support it.
1069
+ *
1070
+ * This must be called, in order to use color attributes.
1071
+ * It is good practice to call it just after Curses.init_screen
1072
+ */
1073
+ static VALUE
1074
+ curses_start_color(VALUE obj)
1075
+ {
1076
+ /* may have to raise exception on ERR */
1077
+ curses_stdscr();
1078
+ return (start_color() == OK) ? Qtrue : Qfalse;
1079
+ }
1080
+
1081
+ /*
1082
+ * Document-method: Curses.init_pair
1083
+ * call-seq: init_pair(pair, f, b)
1084
+ *
1085
+ * Changes the definition of a color-pair.
1086
+ *
1087
+ * It takes three arguments: the number of the color-pair to be changed +pair+,
1088
+ * the foreground color number +f+, and the background color number +b+.
1089
+ *
1090
+ * If the color-pair was previously initialized, the screen is
1091
+ * refreshed and all occurrences of that color-pair are changed
1092
+ * to the new definition.
1093
+ *
1094
+ */
1095
+ static VALUE
1096
+ curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b)
1097
+ {
1098
+ /* may have to raise exception on ERR */
1099
+ curses_stdscr();
1100
+ return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
1101
+ }
1102
+
1103
+ /*
1104
+ * Document-method: Curses.init_color
1105
+ * call-seq: init_color(color, r, g, b)
1106
+ *
1107
+ * Changes the definition of a color. It takes four arguments:
1108
+ * * the number of the color to be changed, +color+
1109
+ * * the amount of red, +r+
1110
+ * * the amount of green, +g+
1111
+ * * the amount of blue, +b+
1112
+ *
1113
+ * The value of the first argument must be between 0 and COLORS.
1114
+ * (See the section Colors for the default color index.) Each
1115
+ * of the last three arguments must be a value between 0 and 1000.
1116
+ * When Curses.init_color is used, all occurrences of that color
1117
+ * on the screen immediately change to the new definition.
1118
+ */
1119
+ static VALUE
1120
+ curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b)
1121
+ {
1122
+ /* may have to raise exception on ERR */
1123
+ curses_stdscr();
1124
+ return (init_color(NUM2INT(color),NUM2INT(r),
1125
+ NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
1126
+ }
1127
+
1128
+ /*
1129
+ * Document-method: Curses.has_colors?
1130
+ *
1131
+ * Returns +true+ or +false+ depending on whether the terminal has color capabilities.
1132
+ */
1133
+ static VALUE
1134
+ curses_has_colors(VALUE obj)
1135
+ {
1136
+ curses_stdscr();
1137
+ return has_colors() ? Qtrue : Qfalse;
1138
+ }
1139
+
1140
+ /*
1141
+ * Document-method: Curses.can_change_color?
1142
+ *
1143
+ * Returns +true+ or +false+ depending on whether the terminal can change color attributes
1144
+ */
1145
+ static VALUE
1146
+ curses_can_change_color(VALUE obj)
1147
+ {
1148
+ curses_stdscr();
1149
+ return can_change_color() ? Qtrue : Qfalse;
1150
+ }
1151
+
1152
+ #if defined(HAVE_COLORS)
1153
+ /*
1154
+ * Document-method: Curses.color
1155
+ *
1156
+ * returns COLORS
1157
+ */
1158
+ static VALUE
1159
+ curses_colors(VALUE obj)
1160
+ {
1161
+ return INT2FIX(COLORS);
1162
+ }
1163
+ #else
1164
+ #define curses_colors rb_f_notimplement
1165
+ #endif
1166
+
1167
+ /*
1168
+ * Document-method: Curses.color_content
1169
+ * call-seq: color_content(color)
1170
+ *
1171
+ * Returns an 3 item Array of the RGB values in +color+
1172
+ */
1173
+ static VALUE
1174
+ curses_color_content(VALUE obj, VALUE color)
1175
+ {
1176
+ short r,g,b;
1177
+
1178
+ curses_stdscr();
1179
+ color_content(NUM2INT(color),&r,&g,&b);
1180
+ return rb_ary_new3(3,INT2FIX(r),INT2FIX(g),INT2FIX(b));
1181
+ }
1182
+
1183
+
1184
+ #if defined(HAVE_COLOR_PAIRS)
1185
+ /*
1186
+ * Document-method: Curses.color_pairs
1187
+ *
1188
+ * Returns the COLOR_PAIRS available, if the curses library supports it.
1189
+ */
1190
+ static VALUE
1191
+ curses_color_pairs(VALUE obj)
1192
+ {
1193
+ return INT2FIX(COLOR_PAIRS);
1194
+ }
1195
+ #else
1196
+ #define curses_color_pairs rb_f_notimplement
1197
+ #endif
1198
+
1199
+ /*
1200
+ * Document-method: Curses.pair_content
1201
+ * call-seq: pair_content(pair)
1202
+ *
1203
+ * Returns a 2 item Array, with the foreground and
1204
+ * background color, in +pair+
1205
+ */
1206
+ static VALUE
1207
+ curses_pair_content(VALUE obj, VALUE pair)
1208
+ {
1209
+ short f,b;
1210
+
1211
+ curses_stdscr();
1212
+ pair_content(NUM2INT(pair),&f,&b);
1213
+ return rb_ary_new3(2,INT2FIX(f),INT2FIX(b));
1214
+ }
1215
+
1216
+ /*
1217
+ * Document-method: Curses.color_pair
1218
+ * call-seq: color_pair(attrs)
1219
+ *
1220
+ * Sets the color pair attributes to +attrs+.
1221
+ *
1222
+ * This should be equivalent to Curses.attrset(COLOR_PAIR(+attrs+))
1223
+ *
1224
+ * TODO: validate that equivalency
1225
+ */
1226
+ static VALUE
1227
+ curses_color_pair(VALUE obj, VALUE attrs)
1228
+ {
1229
+ return INT2FIX(COLOR_PAIR(NUM2INT(attrs)));
1230
+ }
1231
+
1232
+ /*
1233
+ * Document-method: Curses.pair_number
1234
+ * call-seq: pair_number(attrs)
1235
+ *
1236
+ * Returns the Fixnum color pair number of attributes +attrs+.
1237
+ */
1238
+ static VALUE
1239
+ curses_pair_number(VALUE obj, VALUE attrs)
1240
+ {
1241
+ curses_stdscr();
1242
+ return INT2FIX(PAIR_NUMBER(NUM2LONG(attrs)));
1243
+ }
1244
+ #endif /* USE_COLOR */
1245
+
1246
+ #ifdef USE_MOUSE
1247
+ struct mousedata {
1248
+ MEVENT *mevent;
1249
+ };
1250
+
1251
+ static void
1252
+ no_mevent(void)
1253
+ {
1254
+ rb_raise(rb_eRuntimeError, "no such mouse event");
1255
+ }
1256
+
1257
+ #define GetMOUSE(obj, data) do {\
1258
+ if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)\
1259
+ rb_raise(rb_eSecurityError, "Insecure: operation on untainted mouse");\
1260
+ TypedData_Get_Struct((obj), struct mousedata, &mousedata_type, (data));\
1261
+ if ((data)->mevent == 0) no_mevent();\
1262
+ } while (0)
1263
+
1264
+ static void
1265
+ curses_mousedata_free(void *p)
1266
+ {
1267
+ struct mousedata *mdata = p;
1268
+ if (mdata->mevent)
1269
+ xfree(mdata->mevent);
1270
+ }
1271
+
1272
+ static size_t
1273
+ curses_mousedata_memsize(const void *p)
1274
+ {
1275
+ const struct mousedata *mdata = p;
1276
+ size_t size = sizeof(*mdata);
1277
+ if (!mdata) return 0;
1278
+ if (mdata->mevent) size += sizeof(mdata->mevent);
1279
+ return size;
1280
+ }
1281
+
1282
+ static const rb_data_type_t mousedata_type = {
1283
+ "mousedata",
1284
+ {0, curses_mousedata_free, curses_mousedata_memsize,}
1285
+ };
1286
+
1287
+ /*
1288
+ * Document-method: Curses.getmouse
1289
+ *
1290
+ * Returns coordinates of the mouse.
1291
+ *
1292
+ * This will read and pop the mouse event data off the queue
1293
+ *
1294
+ * See the BUTTON*, ALL_MOUSE_EVENTS and REPORT_MOUSE_POSITION constants, to examine the mask of the event
1295
+ */
1296
+ static VALUE
1297
+ curses_getmouse(VALUE obj)
1298
+ {
1299
+ struct mousedata *mdata;
1300
+ VALUE val;
1301
+
1302
+ curses_stdscr();
1303
+ val = TypedData_Make_Struct(cMouseEvent,struct mousedata,
1304
+ &mousedata_type,mdata);
1305
+ mdata->mevent = (MEVENT*)xmalloc(sizeof(MEVENT));
1306
+ return (getmouse(mdata->mevent) == OK) ? val : Qnil;
1307
+ }
1308
+
1309
+ /*
1310
+ * Document-method: Curses.ungetmouse
1311
+ *
1312
+ * It pushes a KEY_MOUSE event onto the input queue, and associates with that
1313
+ * event the given state data and screen-relative character-cell coordinates.
1314
+ *
1315
+ * The Curses.ungetmouse function behaves analogously to Curses.ungetch.
1316
+ */
1317
+ static VALUE
1318
+ curses_ungetmouse(VALUE obj, VALUE mevent)
1319
+ {
1320
+ struct mousedata *mdata;
1321
+
1322
+ curses_stdscr();
1323
+ GetMOUSE(mevent,mdata);
1324
+ return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse;
1325
+ }
1326
+
1327
+ /*
1328
+ * Document-method: Curses.mouseinterval
1329
+ * call-seq: mouseinterval(interval)
1330
+ *
1331
+ * The Curses.mouseinterval function sets the maximum time
1332
+ * (in thousands of a second) that can elapse between press
1333
+ * and release events for them to be recognized as a click.
1334
+ *
1335
+ * Use Curses.mouseinterval(0) to disable click resolution.
1336
+ * This function returns the previous interval value.
1337
+ *
1338
+ * Use Curses.mouseinterval(-1) to obtain the interval without
1339
+ * altering it.
1340
+ *
1341
+ * The default is one sixth of a second.
1342
+ */
1343
+ static VALUE
1344
+ curses_mouseinterval(VALUE obj, VALUE interval)
1345
+ {
1346
+ curses_stdscr();
1347
+ return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse;
1348
+ }
1349
+
1350
+ /*
1351
+ * Document-method: Curses.mousemask
1352
+ * call-seq: mousemask(mask)
1353
+ *
1354
+ * Returns the +mask+ of the reportable events
1355
+ */
1356
+ static VALUE
1357
+ curses_mousemask(VALUE obj, VALUE mask)
1358
+ {
1359
+ curses_stdscr();
1360
+ return INT2NUM(mousemask(NUM2UINT(mask),NULL));
1361
+ }
1362
+
1363
+ #define DEFINE_MOUSE_GET_MEMBER(func_name,mem) \
1364
+ static VALUE func_name (VALUE mouse) \
1365
+ { \
1366
+ struct mousedata *mdata; \
1367
+ GetMOUSE(mouse, mdata); \
1368
+ return (UINT2NUM(mdata->mevent -> mem)); \
1369
+ }
1370
+
1371
+ /*
1372
+ * Document-method: Curses::MouseEvent.eid
1373
+ *
1374
+ * Returns the current mouse id
1375
+ */
1376
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_id, id)
1377
+ /*
1378
+ * Document-method: Curses::MouseEvent.x
1379
+ *
1380
+ * Returns the current mouse's X coordinate
1381
+ */
1382
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_x, x)
1383
+ /*
1384
+ * Document-method: Curses::MouseEvent.y
1385
+ *
1386
+ * Returns the current mouse's Y coordinate
1387
+ */
1388
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_y, y)
1389
+ /*
1390
+ * Document-method: Curses::MouseEvent.z
1391
+ *
1392
+ * Returns the current mouse's Z coordinate
1393
+ */
1394
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_z, z)
1395
+ /*
1396
+ * Document-method: Curses::MouseEvent.bstate
1397
+ *
1398
+ * Returns the current mouse's button state. Use this with the button state
1399
+ * constants to determine which buttons were pressed.
1400
+ */
1401
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_bstate, bstate)
1402
+ #undef define_curs_mouse_member
1403
+ #endif /* USE_MOUSE */
1404
+
1405
+ #ifdef HAVE_TIMEOUT
1406
+ /*
1407
+ * Document-method: Curses.timeout=
1408
+ * call-seq: timeout=(delay)
1409
+ *
1410
+ * Sets block and non-blocking reads for the window.
1411
+ * - If delay is negative, blocking read is used (i.e., waits indefinitely for input).
1412
+ * - If delay is zero, then non-blocking read is used (i.e., read returns ERR if no input is waiting).
1413
+ * - If delay is positive, then read blocks for delay milliseconds, and returns ERR if there is still no input.
1414
+ *
1415
+ */
1416
+ static VALUE
1417
+ curses_timeout(VALUE obj, VALUE delay)
1418
+ {
1419
+ curses_stdscr();
1420
+ timeout(NUM2INT(delay));
1421
+ return Qnil;
1422
+ }
1423
+ #else
1424
+ #define curses_timeout rb_f_notimplement
1425
+ #endif
1426
+
1427
+ #ifdef HAVE_DEF_PROG_MODE
1428
+ /*
1429
+ * Document-method: Curses.def_prog_mode
1430
+ *
1431
+ * Save the current terminal modes as the "program"
1432
+ * state for use by the Curses.reset_prog_mode
1433
+ *
1434
+ * This is done automatically by Curses.init_screen
1435
+ */
1436
+ static VALUE
1437
+ curses_def_prog_mode(VALUE obj)
1438
+ {
1439
+ curses_stdscr();
1440
+ return def_prog_mode() == OK ? Qtrue : Qfalse;
1441
+ }
1442
+ #else
1443
+ #define curses_def_prog_mode rb_f_notimplement
1444
+ #endif
1445
+
1446
+ #ifdef HAVE_RESET_PROG_MODE
1447
+ /*
1448
+ * Document-method: Curses.reset_prog_mode
1449
+ *
1450
+ * Reset the current terminal modes to the saved state
1451
+ * by the Curses.def_prog_mode
1452
+ *
1453
+ * This is done automatically by Curses.close_screen
1454
+ */
1455
+ static VALUE
1456
+ curses_reset_prog_mode(VALUE obj)
1457
+ {
1458
+ curses_stdscr();
1459
+ return reset_prog_mode() == OK ? Qtrue : Qfalse;
1460
+ }
1461
+ #else
1462
+ #define curses_reset_prog_mode rb_f_notimplement
1463
+ #endif
1464
+
1465
+ /*-------------------------- class Window --------------------------*/
1466
+
1467
+ /* returns a Curses::Window object */
1468
+ static VALUE
1469
+ window_s_allocate(VALUE class)
1470
+ {
1471
+ struct windata *winp;
1472
+
1473
+ return TypedData_Make_Struct(class, struct windata, &windata_type, winp);
1474
+ }
1475
+
1476
+ /*
1477
+ * Document-method: Curses::Window.new
1478
+ * call-seq: new(height, width, top, left)
1479
+ *
1480
+ * Construct a new Curses::Window with constraints of
1481
+ * +height+ lines, +width+ columns, begin at +top+ line, and begin +left+ most column.
1482
+ *
1483
+ * A new window using full screen is called as
1484
+ * Curses::Window.new(0,0,0,0)
1485
+ *
1486
+ */
1487
+ static VALUE
1488
+ window_initialize(VALUE obj, VALUE h, VALUE w, VALUE top, VALUE left)
1489
+ {
1490
+ struct windata *winp;
1491
+ WINDOW *window;
1492
+
1493
+ curses_init_screen();
1494
+ TypedData_Get_Struct(obj, struct windata, &windata_type, winp);
1495
+ if (winp->window) delwin(winp->window);
1496
+ window = newwin(NUM2INT(h), NUM2INT(w), NUM2INT(top), NUM2INT(left));
1497
+ wclear(window);
1498
+ winp->window = window;
1499
+
1500
+ return obj;
1501
+ }
1502
+
1503
+ /*
1504
+ * Document-method: Curses::Window.subwin
1505
+ * call-seq: subwin(height, width, top, left)
1506
+ *
1507
+ * Construct a new subwindow with constraints of
1508
+ * +height+ lines, +width+ columns, begin at +top+ line, and begin +left+ most column.
1509
+ *
1510
+ */
1511
+ static VALUE
1512
+ window_subwin(VALUE obj, VALUE height, VALUE width, VALUE top, VALUE left)
1513
+ {
1514
+ struct windata *winp;
1515
+ WINDOW *window;
1516
+ VALUE win;
1517
+ int h, w, t, l;
1518
+
1519
+ h = NUM2INT(height);
1520
+ w = NUM2INT(width);
1521
+ t = NUM2INT(top);
1522
+ l = NUM2INT(left);
1523
+ GetWINDOW(obj, winp);
1524
+ window = subwin(winp->window, h, w, t, l);
1525
+ win = prep_window(rb_obj_class(obj), window);
1526
+
1527
+ return win;
1528
+ }
1529
+
1530
+ /*
1531
+ * Document-method: Curses::Window.close
1532
+ *
1533
+ * Deletes the window, and frees the memory
1534
+ */
1535
+ static VALUE
1536
+ window_close(VALUE obj)
1537
+ {
1538
+ struct windata *winp;
1539
+
1540
+ GetWINDOW(obj, winp);
1541
+ delwin(winp->window);
1542
+ winp->window = 0;
1543
+
1544
+ return Qnil;
1545
+ }
1546
+
1547
+ /*
1548
+ * Document-method: Curses::Window.clear
1549
+ *
1550
+ * Clear the window.
1551
+ */
1552
+ static VALUE
1553
+ window_clear(VALUE obj)
1554
+ {
1555
+ struct windata *winp;
1556
+
1557
+ GetWINDOW(obj, winp);
1558
+ wclear(winp->window);
1559
+
1560
+ return Qnil;
1561
+ }
1562
+
1563
+ /*
1564
+ * Document-method: Curses::Window.clrtoeol
1565
+ *
1566
+ * Clear the window to the end of line, that the cursor is currently on.
1567
+ */
1568
+ static VALUE
1569
+ window_clrtoeol(VALUE obj)
1570
+ {
1571
+ struct windata *winp;
1572
+
1573
+ GetWINDOW(obj, winp);
1574
+ wclrtoeol(winp->window);
1575
+
1576
+ return Qnil;
1577
+ }
1578
+
1579
+ /*
1580
+ * Document-method: Curses::Window.refresh
1581
+ *
1582
+ * Refreshes the windows and lines.
1583
+ *
1584
+ */
1585
+ static VALUE
1586
+ window_refresh(VALUE obj)
1587
+ {
1588
+ struct windata *winp;
1589
+
1590
+ GetWINDOW(obj, winp);
1591
+ wrefresh(winp->window);
1592
+
1593
+ return Qnil;
1594
+ }
1595
+
1596
+ /*
1597
+ * Document-method: Curses::Window.noutrefresh
1598
+ *
1599
+ * Refreshes the windows and lines.
1600
+ *
1601
+ * Curses::Window.noutrefresh allows multiple updates with
1602
+ * more efficiency than Curses::Window.refresh alone.
1603
+ */
1604
+ static VALUE
1605
+ window_noutrefresh(VALUE obj)
1606
+ {
1607
+ struct windata *winp;
1608
+
1609
+ GetWINDOW(obj, winp);
1610
+ #ifdef HAVE_DOUPDATE
1611
+ wnoutrefresh(winp->window);
1612
+ #else
1613
+ wrefresh(winp->window);
1614
+ #endif
1615
+
1616
+ return Qnil;
1617
+ }
1618
+
1619
+ /*
1620
+ * Document-method: Curses::Window.move
1621
+ * call-seq: move(y,x)
1622
+ *
1623
+ * Moves the window so that the upper left-hand corner is at position (+y+, +x+)
1624
+ */
1625
+ static VALUE
1626
+ window_move(VALUE obj, VALUE y, VALUE x)
1627
+ {
1628
+ struct windata *winp;
1629
+
1630
+ GetWINDOW(obj, winp);
1631
+ mvwin(winp->window, NUM2INT(y), NUM2INT(x));
1632
+
1633
+ return Qnil;
1634
+ }
1635
+
1636
+ /*
1637
+ * Document-method: Curses::Window.setpos
1638
+ * call-seq: setpos(y, x)
1639
+ *
1640
+ * A setter for the position of the cursor
1641
+ * in the current window,
1642
+ * using coordinates +x+ and +y+
1643
+ *
1644
+ */
1645
+ static VALUE
1646
+ window_setpos(VALUE obj, VALUE y, VALUE x)
1647
+ {
1648
+ struct windata *winp;
1649
+
1650
+ GetWINDOW(obj, winp);
1651
+ wmove(winp->window, NUM2INT(y), NUM2INT(x));
1652
+ return Qnil;
1653
+ }
1654
+
1655
+ /*
1656
+ * Document-method: Curses::Window.cury
1657
+ *
1658
+ * A getter for the current line (Y coord) of the window
1659
+ */
1660
+ static VALUE
1661
+ window_cury(VALUE obj)
1662
+ {
1663
+ struct windata *winp;
1664
+ int RB_UNUSED_VAR(x), y;
1665
+
1666
+ GetWINDOW(obj, winp);
1667
+ getyx(winp->window, y, x);
1668
+ return INT2FIX(y);
1669
+ }
1670
+
1671
+ /*
1672
+ * Document-method: Curses::Window.curx
1673
+ *
1674
+ * A getter for the current column (X coord) of the window
1675
+ */
1676
+ static VALUE
1677
+ window_curx(VALUE obj)
1678
+ {
1679
+ struct windata *winp;
1680
+ int x, RB_UNUSED_VAR(y);
1681
+
1682
+ GetWINDOW(obj, winp);
1683
+ getyx(winp->window, y, x);
1684
+ return INT2FIX(x);
1685
+ }
1686
+
1687
+ /*
1688
+ * Document-method: Curses::Window.maxy
1689
+ *
1690
+ * A getter for the maximum lines for the window
1691
+ */
1692
+ static VALUE
1693
+ window_maxy(VALUE obj)
1694
+ {
1695
+ struct windata *winp;
1696
+
1697
+ GetWINDOW(obj, winp);
1698
+ #if defined(getmaxy)
1699
+ return INT2FIX(getmaxy(winp->window));
1700
+ #elif defined(getmaxyx)
1701
+ {
1702
+ int x, y;
1703
+ getmaxyx(winp->window, y, x);
1704
+ return INT2FIX(y);
1705
+ }
1706
+ #else
1707
+ return INT2FIX(winp->window->_maxy+1);
1708
+ #endif
1709
+ }
1710
+
1711
+ /*
1712
+ * Document-method: Curses::Window.maxx
1713
+ *
1714
+ * A getter for the maximum columns for the window
1715
+ */
1716
+ static VALUE
1717
+ window_maxx(VALUE obj)
1718
+ {
1719
+ struct windata *winp;
1720
+
1721
+ GetWINDOW(obj, winp);
1722
+ #if defined(getmaxx)
1723
+ return INT2FIX(getmaxx(winp->window));
1724
+ #elif defined(getmaxyx)
1725
+ {
1726
+ int x, y;
1727
+ getmaxyx(winp->window, y, x);
1728
+ return INT2FIX(x);
1729
+ }
1730
+ #else
1731
+ return INT2FIX(winp->window->_maxx+1);
1732
+ #endif
1733
+ }
1734
+
1735
+ /*
1736
+ * Document-method: Curses::Window.begy
1737
+ *
1738
+ * A getter for the beginning line (Y coord) of the window
1739
+ */
1740
+ static VALUE
1741
+ window_begy(VALUE obj)
1742
+ {
1743
+ struct windata *winp;
1744
+ int RB_UNUSED_VAR(x), y;
1745
+
1746
+ GetWINDOW(obj, winp);
1747
+ #ifdef getbegyx
1748
+ getbegyx(winp->window, y, x);
1749
+ #else
1750
+ y = winp->window->_begy;
1751
+ #endif
1752
+ return INT2FIX(y);
1753
+ }
1754
+
1755
+ /*
1756
+ * Document-method: Curses::Window.begx
1757
+ *
1758
+ * A getter for the beginning column (X coord) of the window
1759
+ */
1760
+ static VALUE
1761
+ window_begx(VALUE obj)
1762
+ {
1763
+ struct windata *winp;
1764
+ int x, RB_UNUSED_VAR(y);
1765
+
1766
+ GetWINDOW(obj, winp);
1767
+ #ifdef getbegyx
1768
+ getbegyx(winp->window, y, x);
1769
+ #else
1770
+ x = winp->window->_begx;
1771
+ #endif
1772
+ return INT2FIX(x);
1773
+ }
1774
+
1775
+ /*
1776
+ * Document-method: Curses::Window.box
1777
+ * call-seq: box(vert, hor)
1778
+ *
1779
+ * set the characters to frame the window in.
1780
+ * The vertical +vert+ and horizontal +hor+ character.
1781
+ *
1782
+ * win = Curses::Window.new(5,5,5,5)
1783
+ * win.box(?|, ?-)
1784
+ *
1785
+ */
1786
+ static VALUE
1787
+ window_box(int argc, VALUE *argv, VALUE self)
1788
+ {
1789
+ struct windata *winp;
1790
+ VALUE vert, hor, corn;
1791
+
1792
+ rb_scan_args(argc, argv, "21", &vert, &hor, &corn);
1793
+
1794
+ GetWINDOW(self, winp);
1795
+ box(winp->window, NUM2CH(vert), NUM2CH(hor));
1796
+
1797
+ if (!NIL_P(corn)) {
1798
+ int cur_x, cur_y, x, y;
1799
+ chtype c;
1800
+
1801
+ c = NUM2CH(corn);
1802
+ getyx(winp->window, cur_y, cur_x);
1803
+ x = NUM2INT(window_maxx(self)) - 1;
1804
+ y = NUM2INT(window_maxy(self)) - 1;
1805
+ wmove(winp->window, 0, 0);
1806
+ waddch(winp->window, c);
1807
+ wmove(winp->window, y, 0);
1808
+ waddch(winp->window, c);
1809
+ wmove(winp->window, y, x);
1810
+ waddch(winp->window, c);
1811
+ wmove(winp->window, 0, x);
1812
+ waddch(winp->window, c);
1813
+ wmove(winp->window, cur_y, cur_x);
1814
+ }
1815
+
1816
+ return Qnil;
1817
+ }
1818
+
1819
+ /*
1820
+ * Document-method: Curses::Window.standout
1821
+ *
1822
+ * Enables the best highlighting mode of the terminal.
1823
+ *
1824
+ * This is equivalent to Curses::Window.attron(A_STANDOUT)
1825
+ *
1826
+ * see also Curses::Window.attrset
1827
+ */
1828
+ static VALUE
1829
+ window_standout(VALUE obj)
1830
+ {
1831
+ struct windata *winp;
1832
+
1833
+ GetWINDOW(obj, winp);
1834
+ wstandout(winp->window);
1835
+ return Qnil;
1836
+ }
1837
+
1838
+ /*
1839
+ * Document-method: Curses::Window.standend
1840
+ *
1841
+ * Enables the Normal display (no highlight)
1842
+ *
1843
+ * This is equivalent to Curses::Window.attron(A_NORMAL)
1844
+ *
1845
+ * see also Curses::Window.attrset
1846
+ */
1847
+ static VALUE
1848
+ window_standend(VALUE obj)
1849
+ {
1850
+ struct windata *winp;
1851
+
1852
+ GetWINDOW(obj, winp);
1853
+ wstandend(winp->window);
1854
+ return Qnil;
1855
+ }
1856
+
1857
+ /*
1858
+ * Document-method: Curses::Window.inch
1859
+ *
1860
+ * Returns the character at the current position of the window.
1861
+ */
1862
+ static VALUE
1863
+ window_inch(VALUE obj)
1864
+ {
1865
+ struct windata *winp;
1866
+
1867
+ GetWINDOW(obj, winp);
1868
+ return CH2FIX(winch(winp->window));
1869
+ }
1870
+
1871
+ /*
1872
+ * Document-method: Curses::Window.addch
1873
+ * call-seq: addch(ch)
1874
+ *
1875
+ * Add a character +ch+, with attributes, to the window, then advance the cursor.
1876
+ *
1877
+ * see also the system manual for curs_addch(3)
1878
+ */
1879
+ static VALUE
1880
+ window_addch(VALUE obj, VALUE ch)
1881
+ {
1882
+ struct windata *winp;
1883
+
1884
+ GetWINDOW(obj, winp);
1885
+ waddch(winp->window, NUM2CH(ch));
1886
+
1887
+ return Qnil;
1888
+ }
1889
+
1890
+ /*
1891
+ * Document-method: Curses::Window.insch
1892
+ * call-seq: insch(ch)
1893
+ *
1894
+ * Insert a character +ch+, before the cursor, in the current window
1895
+ *
1896
+ */
1897
+ static VALUE
1898
+ window_insch(VALUE obj, VALUE ch)
1899
+ {
1900
+ struct windata *winp;
1901
+
1902
+ GetWINDOW(obj, winp);
1903
+ winsch(winp->window, NUM2CH(ch));
1904
+
1905
+ return Qnil;
1906
+ }
1907
+
1908
+ /*
1909
+ * Document-method: Curses::Window.addstr
1910
+ * call-seq: addstr(str)
1911
+ *
1912
+ * add a string of characters +str+, to the window and advance cursor
1913
+ *
1914
+ */
1915
+ static VALUE
1916
+ window_addstr(VALUE obj, VALUE str)
1917
+ {
1918
+ if (!NIL_P(str)) {
1919
+ struct windata *winp;
1920
+
1921
+ StringValue(str);
1922
+ str = rb_str_export_locale(str);
1923
+ GetWINDOW(obj, winp);
1924
+ waddstr(winp->window, StringValueCStr(str));
1925
+ }
1926
+ return Qnil;
1927
+ }
1928
+
1929
+ /*
1930
+ * Document-method: Curses::Window.<<
1931
+ *
1932
+ * call-seq:
1933
+ * <<(str)
1934
+ *
1935
+ * Add String +str+ to the current string.
1936
+ *
1937
+ * See also Curses::Window.addstr
1938
+ */
1939
+ static VALUE
1940
+ window_addstr2(VALUE obj, VALUE str)
1941
+ {
1942
+ window_addstr(obj, str);
1943
+ return obj;
1944
+ }
1945
+
1946
+ struct wgetch_arg {
1947
+ WINDOW *win;
1948
+ int c;
1949
+ };
1950
+
1951
+ static void *
1952
+ wgetch_func(void *_arg)
1953
+ {
1954
+ struct wgetch_arg *arg = (struct wgetch_arg *)_arg;
1955
+ arg->c = wgetch(arg->win);
1956
+ return 0;
1957
+ }
1958
+
1959
+ /*
1960
+ * Document-method: Curses::Window.getch
1961
+ *
1962
+ * Read and returns a character from the window.
1963
+ *
1964
+ * See Curses::Key to all the function KEY_* available
1965
+ *
1966
+ */
1967
+ static VALUE
1968
+ window_getch(VALUE obj)
1969
+ {
1970
+ struct windata *winp;
1971
+ struct wgetch_arg arg;
1972
+ int c;
1973
+
1974
+ GetWINDOW(obj, winp);
1975
+ arg.win = winp->window;
1976
+ rb_thread_call_without_gvl(wgetch_func, (void *)&arg, RUBY_UBF_IO, 0);
1977
+ c = arg.c;
1978
+ if (c == EOF) return Qnil;
1979
+ if (rb_isprint(c)) {
1980
+ char ch = (char)c;
1981
+
1982
+ return rb_locale_str_new(&ch, 1);
1983
+ }
1984
+ return UINT2NUM(c);
1985
+ }
1986
+
1987
+ struct wgetstr_arg {
1988
+ WINDOW *win;
1989
+ char rtn[GETSTR_BUF_SIZE];
1990
+ };
1991
+
1992
+ static void *
1993
+ wgetstr_func(void *_arg)
1994
+ {
1995
+ struct wgetstr_arg *arg = (struct wgetstr_arg *)_arg;
1996
+ #if defined(HAVE_WGETNSTR)
1997
+ wgetnstr(arg->win, arg->rtn, GETSTR_BUF_SIZE-1);
1998
+ #else
1999
+ wgetstr(arg->win, arg->rtn);
2000
+ #endif
2001
+ return 0;
2002
+ }
2003
+
2004
+ /*
2005
+ * Document-method: Curses::Window.getstr
2006
+ *
2007
+ * This is equivalent to a series f Curses::Window.getch calls
2008
+ *
2009
+ */
2010
+ static VALUE
2011
+ window_getstr(VALUE obj)
2012
+ {
2013
+ struct windata *winp;
2014
+ struct wgetstr_arg arg;
2015
+
2016
+ GetWINDOW(obj, winp);
2017
+ arg.win = winp->window;
2018
+ rb_thread_call_without_gvl(wgetstr_func, (void *)&arg, RUBY_UBF_IO, 0);
2019
+ return rb_locale_str_new_cstr(arg.rtn);
2020
+ }
2021
+
2022
+ /*
2023
+ * Document-method: Curses::Window.delch
2024
+ *
2025
+ * Delete the character under the cursor
2026
+ *
2027
+ */
2028
+ static VALUE
2029
+ window_delch(VALUE obj)
2030
+ {
2031
+ struct windata *winp;
2032
+
2033
+ GetWINDOW(obj, winp);
2034
+ wdelch(winp->window);
2035
+ return Qnil;
2036
+ }
2037
+
2038
+ /*
2039
+ * Document-method: Curses::Window.deleteln
2040
+ *
2041
+ * Delete the line under the cursor.
2042
+ *
2043
+ */
2044
+ static VALUE
2045
+ window_deleteln(VALUE obj)
2046
+ {
2047
+ #if defined(HAVE_WDELETELN) || defined(wdeleteln)
2048
+ struct windata *winp;
2049
+
2050
+ GetWINDOW(obj, winp);
2051
+ wdeleteln(winp->window);
2052
+ #endif
2053
+ return Qnil;
2054
+ }
2055
+
2056
+ /*
2057
+ * Document-method: Curses::Window.insertln
2058
+ *
2059
+ * Inserts a line above the cursor, and the bottom line is lost
2060
+ *
2061
+ */
2062
+ static VALUE
2063
+ window_insertln(VALUE obj)
2064
+ {
2065
+ #if defined(HAVE_WINSERTLN) || defined(winsertln)
2066
+ struct windata *winp;
2067
+
2068
+ GetWINDOW(obj, winp);
2069
+ winsertln(winp->window);
2070
+ #endif
2071
+ return Qnil;
2072
+ }
2073
+
2074
+ /*
2075
+ * Document-method: Curses::Window.scrollok
2076
+ * call-seq: scrollok(bool)
2077
+ *
2078
+ * Controls what happens when the cursor of a window
2079
+ * is moved off the edge of the window or scrolling region,
2080
+ * either as a result of a newline action on the bottom line,
2081
+ * or typing the last character of the last line.
2082
+ *
2083
+ * If disabled, (+bool+ is false), the cursor is left on the bottom line.
2084
+ *
2085
+ * If enabled, (+bool+ is true), the window is scrolled up one line
2086
+ * (Note that to get the physical scrolling effect on the terminal,
2087
+ * it is also necessary to call Curses::Window.idlok)
2088
+ */
2089
+ static VALUE
2090
+ window_scrollok(VALUE obj, VALUE bf)
2091
+ {
2092
+ struct windata *winp;
2093
+
2094
+ GetWINDOW(obj, winp);
2095
+ scrollok(winp->window, RTEST(bf) ? TRUE : FALSE);
2096
+ return Qnil;
2097
+ }
2098
+
2099
+ /*
2100
+ * Document-method: Curses::Window.idlok
2101
+ * call-seq: idlok(bool)
2102
+ *
2103
+ * If +bool+ is +true+ curses considers using the hardware insert/delete
2104
+ * line feature of terminals so equipped.
2105
+ *
2106
+ * If +bool+ is +false+, disables use of line insertion and deletion.
2107
+ * This option should be enabled only if the application needs insert/delete
2108
+ * line, for example, for a screen editor.
2109
+ *
2110
+ * It is disabled by default because insert/delete line tends to be visually
2111
+ * annoying when used in applications where it is not really needed.
2112
+ * If insert/delete line cannot be used, curses redraws the changed portions of all lines.
2113
+ *
2114
+ */
2115
+ static VALUE
2116
+ window_idlok(VALUE obj, VALUE bf)
2117
+ {
2118
+ struct windata *winp;
2119
+
2120
+ GetWINDOW(obj, winp);
2121
+ idlok(winp->window, RTEST(bf) ? TRUE : FALSE);
2122
+ return Qnil;
2123
+ }
2124
+
2125
+ /*
2126
+ * Document-method: Curses::Window.setscrreg
2127
+ * call-seq:
2128
+ * setscrreg(top, bottom)
2129
+ *
2130
+ * Set a software scrolling region in a window.
2131
+ * +top+ and +bottom+ are lines numbers of the margin.
2132
+ *
2133
+ * If this option and Curses::Window.scrollok are enabled, an attempt to move
2134
+ * off the bottom margin line causes all lines in the scrolling region to
2135
+ * scroll one line in the direction of the first line. Only the text of the
2136
+ * window is scrolled.
2137
+ *
2138
+ */
2139
+ static VALUE
2140
+ window_setscrreg(VALUE obj, VALUE top, VALUE bottom)
2141
+ {
2142
+ #ifdef HAVE_WSETSCRREG
2143
+ struct windata *winp;
2144
+ int res;
2145
+
2146
+ GetWINDOW(obj, winp);
2147
+ res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom));
2148
+ /* may have to raise exception on ERR */
2149
+ return (res == OK) ? Qtrue : Qfalse;
2150
+ #else
2151
+ return Qfalse;
2152
+ #endif
2153
+ }
2154
+
2155
+ #if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET)
2156
+ /*
2157
+ * Document-method: Curses::Window.color_set
2158
+ * call-seq: color_set(col)
2159
+ *
2160
+ * Sets the current color of the given window to the
2161
+ * foreground/background combination described by the Fixnum +col+.
2162
+ */
2163
+ static VALUE
2164
+ window_color_set(VALUE obj, VALUE col)
2165
+ {
2166
+ struct windata *winp;
2167
+ int res;
2168
+
2169
+ GetWINDOW(obj, winp);
2170
+ res = wcolor_set(winp->window, NUM2INT(col), NULL);
2171
+ return (res == OK) ? Qtrue : Qfalse;
2172
+ }
2173
+ #endif /* defined(USE_COLOR) && defined(HAVE_WCOLOR_SET) */
2174
+
2175
+ /*
2176
+ * Document-method: Curses::Window.scroll
2177
+ *
2178
+ * Scrolls the current window up one line.
2179
+ */
2180
+ static VALUE
2181
+ window_scroll(VALUE obj)
2182
+ {
2183
+ struct windata *winp;
2184
+
2185
+ GetWINDOW(obj, winp);
2186
+ /* may have to raise exception on ERR */
2187
+ return (scroll(winp->window) == OK) ? Qtrue : Qfalse;
2188
+ }
2189
+
2190
+ /*
2191
+ * Document-method: Curses::Window.scrl
2192
+ * call-seq: scrl(num)
2193
+ *
2194
+ * Scrolls the current window Fixnum +num+ lines.
2195
+ * The current cursor position is not changed.
2196
+ *
2197
+ * For positive +num+, it scrolls up.
2198
+ *
2199
+ * For negative +num+, it scrolls down.
2200
+ *
2201
+ */
2202
+ static VALUE
2203
+ window_scrl(VALUE obj, VALUE n)
2204
+ {
2205
+ #ifdef HAVE_WSCRL
2206
+ struct windata *winp;
2207
+
2208
+ GetWINDOW(obj, winp);
2209
+ /* may have to raise exception on ERR */
2210
+ return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse;
2211
+ #else
2212
+ return Qfalse;
2213
+ #endif
2214
+ }
2215
+
2216
+ /*
2217
+ * Document-method: Curses::Window.attroff
2218
+ * call-seq: attroff(attrs)
2219
+ *
2220
+ * Turns on the named attributes +attrs+ without affecting any others.
2221
+ *
2222
+ * See also Curses::Window.attrset
2223
+ */
2224
+ static VALUE
2225
+ window_attroff(VALUE obj, VALUE attrs)
2226
+ {
2227
+ #ifdef HAVE_WATTROFF
2228
+ struct windata *winp;
2229
+
2230
+ GetWINDOW(obj,winp);
2231
+ return INT2FIX(wattroff(winp->window,NUM2INT(attrs)));
2232
+ #else
2233
+ return Qtrue;
2234
+ #endif
2235
+ }
2236
+
2237
+ /*
2238
+ * Document-method: Curses::Window.attron
2239
+ * call-seq: attron(attrs)
2240
+ *
2241
+ * Turns off the named attributes +attrs+
2242
+ * without turning any other attributes on or off.
2243
+ *
2244
+ * See also Curses::Window.attrset
2245
+ */
2246
+ static VALUE
2247
+ window_attron(VALUE obj, VALUE attrs)
2248
+ {
2249
+ #ifdef HAVE_WATTRON
2250
+ struct windata *winp;
2251
+ VALUE val;
2252
+
2253
+ GetWINDOW(obj,winp);
2254
+ val = INT2FIX(wattron(winp->window,NUM2INT(attrs)));
2255
+ if (rb_block_given_p()) {
2256
+ rb_yield(val);
2257
+ wattroff(winp->window,NUM2INT(attrs));
2258
+ return val;
2259
+ }
2260
+ else{
2261
+ return val;
2262
+ }
2263
+ #else
2264
+ return Qtrue;
2265
+ #endif
2266
+ }
2267
+
2268
+ /*
2269
+ * Document-method: Curses::Window.attrset
2270
+ * call-seq: attrset(attrs)
2271
+ *
2272
+ * Sets the current attributes of the given window to +attrs+.
2273
+ *
2274
+ * The following video attributes, defined in <curses.h>, can
2275
+ * be passed to the routines Curses::Window.attron, Curses::Window.attroff,
2276
+ * and Curses::Window.attrset, or OR'd with the characters passed to addch.
2277
+ * A_NORMAL Normal display (no highlight)
2278
+ * A_STANDOUT Best highlighting mode of the terminal.
2279
+ * A_UNDERLINE Underlining
2280
+ * A_REVERSE Reverse video
2281
+ * A_BLINK Blinking
2282
+ * A_DIM Half bright
2283
+ * A_BOLD Extra bright or bold
2284
+ * A_PROTECT Protected mode
2285
+ * A_INVIS Invisible or blank mode
2286
+ * A_ALTCHARSET Alternate character set
2287
+ * A_CHARTEXT Bit-mask to extract a character
2288
+ * COLOR_PAIR(n) Color-pair number n
2289
+ *
2290
+ * TODO: provide some examples here.
2291
+ *
2292
+ * see also system manual curs_attr(3)
2293
+ */
2294
+ static VALUE
2295
+ window_attrset(VALUE obj, VALUE attrs)
2296
+ {
2297
+ #ifdef HAVE_WATTRSET
2298
+ struct windata *winp;
2299
+
2300
+ GetWINDOW(obj,winp);
2301
+ return INT2FIX(wattrset(winp->window,NUM2INT(attrs)));
2302
+ #else
2303
+ return Qtrue;
2304
+ #endif
2305
+ }
2306
+
2307
+ /*
2308
+ * Document-method: Curses::Window.bkgdset
2309
+ * call-seq: bkgdset(ch)
2310
+ *
2311
+ * Manipulate the background of the current window
2312
+ * with character Integer +ch+
2313
+ *
2314
+ * see also Curses.bkgdset
2315
+ */
2316
+ static VALUE
2317
+ window_bkgdset(VALUE obj, VALUE ch)
2318
+ {
2319
+ #ifdef HAVE_WBKGDSET
2320
+ struct windata *winp;
2321
+
2322
+ GetWINDOW(obj,winp);
2323
+ wbkgdset(winp->window, NUM2CH(ch));
2324
+ #endif
2325
+ return Qnil;
2326
+ }
2327
+
2328
+ /*
2329
+ * Document-method: Curses::Window.bkgd
2330
+ * call-seq: bkgd(ch)
2331
+ *
2332
+ * Set the background of the current window
2333
+ * and apply character Integer +ch+ to every character.
2334
+ *
2335
+ * see also Curses.bkgd
2336
+ */
2337
+ static VALUE
2338
+ window_bkgd(VALUE obj, VALUE ch)
2339
+ {
2340
+ #ifdef HAVE_WBKGD
2341
+ struct windata *winp;
2342
+
2343
+ GetWINDOW(obj,winp);
2344
+ return (wbkgd(winp->window, NUM2CH(ch)) == OK) ? Qtrue : Qfalse;
2345
+ #else
2346
+ return Qfalse;
2347
+ #endif
2348
+ }
2349
+
2350
+ /*
2351
+ * Document-method: Curses::Window.getbkgd
2352
+ *
2353
+ * Returns an Integer (+ch+) for the character property in the current window.
2354
+ */
2355
+ static VALUE
2356
+ window_getbkgd(VALUE obj)
2357
+ {
2358
+ #ifdef HAVE_WGETBKGD
2359
+ chtype c;
2360
+ struct windata *winp;
2361
+
2362
+ GetWINDOW(obj,winp);
2363
+ return (c = getbkgd(winp->window) != ERR) ? CH2FIX(c) : Qnil;
2364
+ #else
2365
+ return Qnil;
2366
+ #endif
2367
+ }
2368
+
2369
+ /*
2370
+ * Document-method: Curses::Window.resize
2371
+ * call-seq: resize(lines, cols)
2372
+ *
2373
+ * Resize the current window to Fixnum +lines+ and Fixnum +cols+
2374
+ *
2375
+ */
2376
+ static VALUE
2377
+ window_resize(VALUE obj, VALUE lin, VALUE col)
2378
+ {
2379
+ #if defined(HAVE_WRESIZE)
2380
+ struct windata *winp;
2381
+
2382
+ GetWINDOW(obj,winp);
2383
+ return wresize(winp->window, NUM2INT(lin), NUM2INT(col)) == OK ? Qtrue : Qfalse;
2384
+ #else
2385
+ return Qnil;
2386
+ #endif
2387
+ }
2388
+
2389
+
2390
+ #ifdef HAVE_KEYPAD
2391
+ /*
2392
+ * Document-method: Curses::Window.keypad=
2393
+ * call-seq:
2394
+ * keypad=(bool)
2395
+ *
2396
+ * See Curses::Window.keypad
2397
+ */
2398
+
2399
+ /*
2400
+ * Document-method: Curses::Window.keypad
2401
+ * call-seq:
2402
+ * keypad(bool)
2403
+ *
2404
+ * Enables the keypad of the user's terminal.
2405
+ *
2406
+ * If enabled (+bool+ is +true+), the user can press a function key
2407
+ * (such as an arrow key) and wgetch returns a single value representing
2408
+ * the function key, as in KEY_LEFT. If disabled (+bool+ is +false+),
2409
+ * curses does not treat function keys specially and the program has to
2410
+ * interpret the escape sequences itself. If the keypad in the terminal
2411
+ * can be turned on (made to transmit) and off (made to work locally),
2412
+ * turning on this option causes the terminal keypad to be turned on when
2413
+ * Curses::Window.getch is called.
2414
+ *
2415
+ * The default value for keypad is false.
2416
+ *
2417
+ */
2418
+ static VALUE
2419
+ window_keypad(VALUE obj, VALUE val)
2420
+ {
2421
+ struct windata *winp;
2422
+
2423
+ GetWINDOW(obj,winp);
2424
+ /* keypad() of NetBSD's libcurses returns no value */
2425
+ #if defined(__NetBSD__) && !defined(NCURSES_VERSION)
2426
+ keypad(winp->window,(RTEST(val) ? TRUE : FALSE));
2427
+ return Qnil;
2428
+ #else
2429
+ /* may have to raise exception on ERR */
2430
+ return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
2431
+ Qtrue : Qfalse;
2432
+ #endif
2433
+ }
2434
+ #else
2435
+ #define window_keypad rb_f_notimplement
2436
+ #endif
2437
+
2438
+ #ifdef HAVE_NODELAY
2439
+ /*
2440
+ * Document-method: Curses::Window.nodelay
2441
+ * call-seq:
2442
+ * window.nodelay = bool
2443
+ *
2444
+ * When in no-delay mode Curses::Window#getch is a non-blocking call. If no
2445
+ * input is ready #getch returns ERR.
2446
+ *
2447
+ * When in delay mode (+bool+ is +false+ which is the default),
2448
+ * Curses::Window#getch blocks until a key is pressed.
2449
+ *
2450
+ */
2451
+ static VALUE
2452
+ window_nodelay(VALUE obj, VALUE val)
2453
+ {
2454
+ struct windata *winp;
2455
+ GetWINDOW(obj,winp);
2456
+
2457
+ /* nodelay() of NetBSD's libcurses returns no value */
2458
+ #if defined(__NetBSD__) && !defined(NCURSES_VERSION)
2459
+ nodelay(winp->window, RTEST(val) ? TRUE : FALSE);
2460
+ return Qnil;
2461
+ #else
2462
+ return nodelay(winp->window,RTEST(val) ? TRUE : FALSE) == OK ? Qtrue : Qfalse;
2463
+ #endif
2464
+ }
2465
+ #else
2466
+ #define window_nodelay rb_f_notimplement
2467
+ #endif
2468
+
2469
+ #ifdef HAVE_WTIMEOUT
2470
+ /*
2471
+ * Document-method: Curses::Window.timeout=
2472
+ * call-seq: timeout=(delay)
2473
+ *
2474
+ * Sets block and non-blocking reads for the window.
2475
+ * - If delay is negative, blocking read is used (i.e., waits indefinitely for input).
2476
+ * - If delay is zero, then non-blocking read is used (i.e., read returns ERR if no input is waiting).
2477
+ * - If delay is positive, then read blocks for delay milliseconds, and returns ERR if there is still no input.
2478
+ *
2479
+ */
2480
+ static VALUE
2481
+ window_timeout(VALUE obj, VALUE delay)
2482
+ {
2483
+ struct windata *winp;
2484
+ GetWINDOW(obj,winp);
2485
+
2486
+ wtimeout(winp->window,NUM2INT(delay));
2487
+ return Qnil;
2488
+ }
2489
+ #else
2490
+ #define window_timeout rb_f_notimplement
2491
+ #endif
2492
+
2493
+ /*--------------------------- class Pad ----------------------------*/
2494
+
2495
+ #ifdef HAVE_NEWPAD
2496
+ /*
2497
+ * Document-method: Curses::Pad.new
2498
+ *
2499
+ * call-seq:
2500
+ * new(height, width)
2501
+ *
2502
+ * Construct a new Curses::Pad with constraints of +height+ lines, +width+
2503
+ * columns
2504
+ *
2505
+ */
2506
+ static VALUE
2507
+ pad_initialize(VALUE obj, VALUE h, VALUE w)
2508
+ {
2509
+ struct windata *padp;
2510
+ WINDOW *window;
2511
+
2512
+ curses_init_screen();
2513
+ TypedData_Get_Struct(obj, struct windata, &windata_type, padp);
2514
+ if (padp->window) delwin(padp->window);
2515
+ window = newpad(NUM2INT(h), NUM2INT(w));
2516
+ wclear(window);
2517
+ padp->window = window;
2518
+
2519
+ return obj;
2520
+ }
2521
+
2522
+ #if 1
2523
+ #define pad_subpad window_subwin
2524
+ #else
2525
+ /*
2526
+ * Document-method: Curses::Pad.subpad
2527
+ * call-seq:
2528
+ * subpad(height, width, begin_x, begin_y)
2529
+ *
2530
+ * Construct a new subpad with constraints of +height+ lines, +width+ columns,
2531
+ * begin at +begin_x+ line, and +begin_y+ columns on the pad.
2532
+ *
2533
+ */
2534
+ static VALUE
2535
+ pad_subpad(VALUE obj, VALUE height, VALUE width, VALUE begin_x, VALUE begin_y)
2536
+ {
2537
+ struct windata *padp;
2538
+ WINDOW *subpad;
2539
+ VALUE pad;
2540
+ int h, w, x, y;
2541
+
2542
+ h = NUM2INT(height);
2543
+ w = NUM2INT(width);
2544
+ x = NUM2INT(begin_x);
2545
+ y = NUM2INT(begin_y);
2546
+ GetWINDOW(obj, padp);
2547
+ subpad = subwin(padp->window, h, w, x, y);
2548
+ pad = prep_window(rb_obj_class(obj), subpad);
2549
+
2550
+ return pad;
2551
+ }
2552
+ #endif
2553
+
2554
+ /*
2555
+ * Document-method: Curses::Pad.refresh
2556
+ *
2557
+ * call-seq:
2558
+ * pad.refresh(pad_minrow, pad_mincol, screen_minrow, screen_mincol, screen_maxrow, screen_maxcol)
2559
+ *
2560
+ * Refreshes the pad. +pad_minrow+ and pad_mincol+ define the upper-left
2561
+ * corner of the rectangle to be displayed. +screen_minrow+, +screen_mincol+,
2562
+ * +screen_maxrow+, +screen_maxcol+ define the edges of the rectangle to be
2563
+ * displayed on the screen.
2564
+ *
2565
+ */
2566
+ static VALUE
2567
+ pad_refresh(VALUE obj, VALUE pminrow, VALUE pmincol, VALUE sminrow,
2568
+ VALUE smincol, VALUE smaxrow, VALUE smaxcol)
2569
+ {
2570
+ struct windata *padp;
2571
+ int pmr, pmc, smr, smc, sxr, sxc;
2572
+
2573
+ pmr = NUM2INT(pminrow);
2574
+ pmc = NUM2INT(pmincol);
2575
+ smr = NUM2INT(sminrow);
2576
+ smc = NUM2INT(smincol);
2577
+ sxr = NUM2INT(smaxrow);
2578
+ sxc = NUM2INT(smaxcol);
2579
+
2580
+ GetWINDOW(obj, padp);
2581
+ prefresh(padp->window, pmr, pmc, smr, smc, sxr, sxc);
2582
+
2583
+ return Qnil;
2584
+ }
2585
+
2586
+ /*
2587
+ * Document-method: Curses::Pad.noutrefresh
2588
+ *
2589
+ * call-seq:
2590
+ * pad.noutrefresh(pad_minrow, pad_mincol, screen_minrow, screen_mincol, screen_maxrow, screen_maxcol)
2591
+ *
2592
+ * Refreshes the pad. +pad_minrow+ and pad_mincol+ define the upper-left
2593
+ * corner of the rectangle to be displayed. +screen_minrow+, +screen_mincol+,
2594
+ * +screen_maxrow+, +screen_maxcol+ define the edges of the rectangle to be
2595
+ * displayed on the screen.
2596
+ *
2597
+ */
2598
+ static VALUE
2599
+ pad_noutrefresh(VALUE obj, VALUE pminrow, VALUE pmincol, VALUE sminrow,
2600
+ VALUE smincol, VALUE smaxrow, VALUE smaxcol)
2601
+ {
2602
+ struct windata *padp;
2603
+ int pmr, pmc, smr, smc, sxr, sxc;
2604
+
2605
+ pmr = NUM2INT(pminrow);
2606
+ pmc = NUM2INT(pmincol);
2607
+ smr = NUM2INT(sminrow);
2608
+ smc = NUM2INT(smincol);
2609
+ sxr = NUM2INT(smaxrow);
2610
+ sxc = NUM2INT(smaxcol);
2611
+
2612
+ GetWINDOW(obj, padp);
2613
+ #ifdef HAVE_DOUPDATE
2614
+ pnoutrefresh(padp->window, pmr, pmc, smr, smc, sxr, sxc);
2615
+ #else
2616
+ prefresh(padp->window, pmr, pmc, smr, smc, sxr, sxc);
2617
+ #endif
2618
+
2619
+ return Qnil;
2620
+ }
2621
+ #endif /* HAVE_NEWPAD */
2622
+
2623
+ /*------------------------- Initialization -------------------------*/
2624
+
2625
+ /*
2626
+ * Document-module: Curses
2627
+ *
2628
+ * == Description
2629
+ * An implementation of the CRT screen handling and optimization library.
2630
+ *
2631
+ * == Structures and such
2632
+ *
2633
+ * === Classes
2634
+ *
2635
+ * * Curses::Window - class with the means to draw a window or box
2636
+ * * Curses::MouseEvent - class for collecting mouse events
2637
+ *
2638
+ * === Modules
2639
+ *
2640
+ * Curses:: The curses implementation
2641
+ * Curses::Key:: Collection of constants for keypress events
2642
+ *
2643
+ * == Examples
2644
+ *
2645
+ * * hello.rb
2646
+ * :include: sample/hello.rb
2647
+ *
2648
+ *
2649
+ * * rain.rb
2650
+ * :include: sample/rain.rb
2651
+ *
2652
+ *
2653
+ */
2654
+ void
2655
+ Init_curses(void)
2656
+ {
2657
+ mCurses = rb_define_module("Curses");
2658
+
2659
+ /*
2660
+ * Document-module: Curses::Key
2661
+ *
2662
+ *
2663
+ * a container for the KEY_* values.
2664
+ *
2665
+ * See also system manual for getch(3)
2666
+ *
2667
+ */
2668
+ mKey = rb_define_module_under(mCurses, "Key");
2669
+
2670
+ rb_gc_register_address(&rb_stdscr);
2671
+
2672
+ #ifdef USE_MOUSE
2673
+ /*
2674
+ * Document-class: Curses::MouseEvent
2675
+ *
2676
+ * == Description
2677
+ *
2678
+ * Curses::MouseEvent
2679
+ *
2680
+ * == Example
2681
+ *
2682
+ * * mouse.rb
2683
+ * :include: sample/mouse.rb
2684
+ *
2685
+ */
2686
+ cMouseEvent = rb_define_class_under(mCurses,"MouseEvent",rb_cObject);
2687
+ rb_undef_method(CLASS_OF(cMouseEvent),"new");
2688
+ rb_define_method(cMouseEvent, "eid", curs_mouse_id, 0);
2689
+ rb_define_method(cMouseEvent, "x", curs_mouse_x, 0);
2690
+ rb_define_method(cMouseEvent, "y", curs_mouse_y, 0);
2691
+ rb_define_method(cMouseEvent, "z", curs_mouse_z, 0);
2692
+ rb_define_method(cMouseEvent, "bstate", curs_mouse_bstate, 0);
2693
+ #endif /* USE_MOUSE */
2694
+
2695
+ rb_define_module_function(mCurses, "ESCDELAY=", curses_escdelay_set, 1);
2696
+ rb_define_module_function(mCurses, "ESCDELAY", curses_escdelay_get, 0);
2697
+ rb_define_module_function(mCurses, "TABSIZE", curses_tabsize_get, 0);
2698
+ rb_define_module_function(mCurses, "TABSIZE=", curses_tabsize_set, 1);
2699
+
2700
+ rb_define_module_function(mCurses, "use_default_colors", curses_use_default_colors, 0);
2701
+ rb_define_module_function(mCurses, "init_screen", curses_init_screen, 0);
2702
+ rb_define_module_function(mCurses, "close_screen", curses_close_screen, 0);
2703
+ rb_define_module_function(mCurses, "closed?", curses_closed, 0);
2704
+ rb_define_module_function(mCurses, "stdscr", curses_stdscr, 0);
2705
+ rb_define_module_function(mCurses, "refresh", curses_refresh, 0);
2706
+ rb_define_module_function(mCurses, "doupdate", curses_doupdate, 0);
2707
+ rb_define_module_function(mCurses, "clear", curses_clear, 0);
2708
+ rb_define_module_function(mCurses, "clrtoeol", curses_clrtoeol, 0);
2709
+ rb_define_module_function(mCurses, "echo", curses_echo, 0);
2710
+ rb_define_module_function(mCurses, "noecho", curses_noecho, 0);
2711
+ rb_define_module_function(mCurses, "raw", curses_raw, 0);
2712
+ rb_define_module_function(mCurses, "noraw", curses_noraw, 0);
2713
+ rb_define_module_function(mCurses, "cbreak", curses_cbreak, 0);
2714
+ rb_define_module_function(mCurses, "nocbreak", curses_nocbreak, 0);
2715
+ rb_define_module_function(mCurses, "crmode", curses_cbreak, 0);
2716
+ rb_define_module_function(mCurses, "nocrmode", curses_nocbreak, 0);
2717
+ rb_define_module_function(mCurses, "nl", curses_nl, 0);
2718
+ rb_define_module_function(mCurses, "nonl", curses_nonl, 0);
2719
+ rb_define_module_function(mCurses, "beep", curses_beep, 0);
2720
+ rb_define_module_function(mCurses, "flash", curses_flash, 0);
2721
+ rb_define_module_function(mCurses, "ungetch", curses_ungetch, 1);
2722
+ rb_define_module_function(mCurses, "setpos", curses_setpos, 2);
2723
+ rb_define_module_function(mCurses, "standout", curses_standout, 0);
2724
+ rb_define_module_function(mCurses, "standend", curses_standend, 0);
2725
+ rb_define_module_function(mCurses, "inch", curses_inch, 0);
2726
+ rb_define_module_function(mCurses, "addch", curses_addch, 1);
2727
+ rb_define_module_function(mCurses, "insch", curses_insch, 1);
2728
+ rb_define_module_function(mCurses, "addstr", curses_addstr, 1);
2729
+ rb_define_module_function(mCurses, "getch", curses_getch, 0);
2730
+ rb_define_module_function(mCurses, "getstr", curses_getstr, 0);
2731
+ rb_define_module_function(mCurses, "delch", curses_delch, 0);
2732
+ rb_define_module_function(mCurses, "deleteln", curses_deleteln, 0);
2733
+ rb_define_module_function(mCurses, "insertln", curses_insertln, 0);
2734
+ rb_define_module_function(mCurses, "keyname", curses_keyname, 1);
2735
+ rb_define_module_function(mCurses, "lines", curses_lines, 0);
2736
+ rb_define_module_function(mCurses, "cols", curses_cols, 0);
2737
+ rb_define_module_function(mCurses, "curs_set", curses_curs_set, 1);
2738
+ rb_define_module_function(mCurses, "scrl", curses_scrl, 1);
2739
+ rb_define_module_function(mCurses, "setscrreg", curses_setscrreg, 2);
2740
+ rb_define_module_function(mCurses, "attroff", curses_attroff, 1);
2741
+ rb_define_module_function(mCurses, "attron", curses_attron, 1);
2742
+ rb_define_module_function(mCurses, "attrset", curses_attrset, 1);
2743
+ rb_define_module_function(mCurses, "bkgdset", curses_bkgdset, 1);
2744
+ rb_define_module_function(mCurses, "bkgd", curses_bkgd, 1);
2745
+ rb_define_module_function(mCurses, "resizeterm", curses_resizeterm, 2);
2746
+ rb_define_module_function(mCurses, "resize", curses_resizeterm, 2);
2747
+ #ifdef USE_COLOR
2748
+ rb_define_module_function(mCurses, "start_color", curses_start_color, 0);
2749
+ rb_define_module_function(mCurses, "init_pair", curses_init_pair, 3);
2750
+ rb_define_module_function(mCurses, "init_color", curses_init_color, 4);
2751
+ rb_define_module_function(mCurses, "has_colors?", curses_has_colors, 0);
2752
+ rb_define_module_function(mCurses, "can_change_color?",
2753
+ curses_can_change_color, 0);
2754
+ rb_define_module_function(mCurses, "colors", curses_colors, 0);
2755
+ rb_define_module_function(mCurses, "color_content", curses_color_content, 1);
2756
+ rb_define_module_function(mCurses, "color_pairs", curses_color_pairs, 0);
2757
+ rb_define_module_function(mCurses, "pair_content", curses_pair_content, 1);
2758
+ rb_define_module_function(mCurses, "color_pair", curses_color_pair, 1);
2759
+ rb_define_module_function(mCurses, "pair_number", curses_pair_number, 1);
2760
+ #endif /* USE_COLOR */
2761
+ #ifdef USE_MOUSE
2762
+ rb_define_module_function(mCurses, "getmouse", curses_getmouse, 0);
2763
+ rb_define_module_function(mCurses, "ungetmouse", curses_ungetmouse, 1);
2764
+ rb_define_module_function(mCurses, "mouseinterval", curses_mouseinterval, 1);
2765
+ rb_define_module_function(mCurses, "mousemask", curses_mousemask, 1);
2766
+ #endif /* USE_MOUSE */
2767
+
2768
+ rb_define_module_function(mCurses, "timeout=", curses_timeout, 1);
2769
+ rb_define_module_function(mCurses, "def_prog_mode", curses_def_prog_mode, 0);
2770
+ rb_define_module_function(mCurses, "reset_prog_mode", curses_reset_prog_mode, 0);
2771
+
2772
+ {
2773
+ VALUE version;
2774
+ #if defined(HAVE_FUNC_CURSES_VERSION)
2775
+ /* ncurses and PDcurses */
2776
+ version = rb_str_new2(curses_version());
2777
+ #elif defined(HAVE_VAR_CURSES_VERSION)
2778
+ /* SVR4 curses has an undocumented and undeclared variable, curses_version.
2779
+ * It contains a string, "SVR4". */
2780
+ RUBY_EXTERN char *curses_version;
2781
+ version = rb_sprintf("curses (%s)", curses_version);
2782
+ #else
2783
+ /* BSD curses, perhaps. NetBSD 5 still use it. */
2784
+ version = rb_str_new2("curses (unknown)");
2785
+ #endif
2786
+ /*
2787
+ * Identifies curses library version.
2788
+ *
2789
+ * - "ncurses 5.9.20110404"
2790
+ * - "PDCurses 3.4 - Public Domain 2008"
2791
+ * - "curses (SVR4)" (System V curses)
2792
+ * - "curses (unknown)" (The original BSD curses? NetBSD maybe.)
2793
+ *
2794
+ */
2795
+ rb_define_const(mCurses, "VERSION", version);
2796
+ }
2797
+
2798
+ /*
2799
+ * Document-class: Curses::Window
2800
+ *
2801
+ * == Description
2802
+ *
2803
+ * The means by which to create and manage frames or windows.
2804
+ * While there may be more than one window at a time, only one window
2805
+ * will receive input.
2806
+ *
2807
+ * == Usage
2808
+ *
2809
+ * require 'curses'
2810
+ *
2811
+ * Curses.init_screen()
2812
+ *
2813
+ * my_str = "LOOK! PONIES!"
2814
+ * bwin = Curses::Window.new( 10, (my_str.length + 10),
2815
+ * (Curses.lines - 10) / 2,
2816
+ * (Curses.cols - (my_str.length + 10)) / 2 )
2817
+ * bwin.box("\\", "/")
2818
+ * bwin.refresh
2819
+ * win = bwin.subwin( 6, my_str.length + 6,
2820
+ * (Curses.lines - 6) / 2,
2821
+ * (Curses.cols - (my_str.length + 6)) / 2 )
2822
+ * win.setpos(2,3)
2823
+ * win.addstr(my_str)
2824
+ * # or even
2825
+ * win << "\nORLY"
2826
+ * win << "\nYES!! " + my_str
2827
+ * win.refresh
2828
+ * win.getch
2829
+ * win.close
2830
+ *
2831
+ */
2832
+ cWindow = rb_define_class_under(mCurses, "Window", rb_cData);
2833
+ rb_define_alloc_func(cWindow, window_s_allocate);
2834
+ rb_define_method(cWindow, "initialize", window_initialize, 4);
2835
+ rb_define_method(cWindow, "subwin", window_subwin, 4);
2836
+ rb_define_method(cWindow, "close", window_close, 0);
2837
+ rb_define_method(cWindow, "clear", window_clear, 0);
2838
+ rb_define_method(cWindow, "clrtoeol", window_clrtoeol, 0);
2839
+ rb_define_method(cWindow, "refresh", window_refresh, 0);
2840
+ rb_define_method(cWindow, "noutrefresh", window_noutrefresh, 0);
2841
+ rb_define_method(cWindow, "box", window_box, -1);
2842
+ rb_define_method(cWindow, "move", window_move, 2);
2843
+ rb_define_method(cWindow, "setpos", window_setpos, 2);
2844
+ #if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET)
2845
+ rb_define_method(cWindow, "color_set", window_color_set, 1);
2846
+ #endif /* USE_COLOR && HAVE_WCOLOR_SET */
2847
+ rb_define_method(cWindow, "cury", window_cury, 0);
2848
+ rb_define_method(cWindow, "curx", window_curx, 0);
2849
+ rb_define_method(cWindow, "maxy", window_maxy, 0);
2850
+ rb_define_method(cWindow, "maxx", window_maxx, 0);
2851
+ rb_define_method(cWindow, "begy", window_begy, 0);
2852
+ rb_define_method(cWindow, "begx", window_begx, 0);
2853
+ rb_define_method(cWindow, "standout", window_standout, 0);
2854
+ rb_define_method(cWindow, "standend", window_standend, 0);
2855
+ rb_define_method(cWindow, "inch", window_inch, 0);
2856
+ rb_define_method(cWindow, "addch", window_addch, 1);
2857
+ rb_define_method(cWindow, "insch", window_insch, 1);
2858
+ rb_define_method(cWindow, "addstr", window_addstr, 1);
2859
+ rb_define_method(cWindow, "<<", window_addstr2, 1);
2860
+ rb_define_method(cWindow, "getch", window_getch, 0);
2861
+ rb_define_method(cWindow, "getstr", window_getstr, 0);
2862
+ rb_define_method(cWindow, "delch", window_delch, 0);
2863
+ rb_define_method(cWindow, "deleteln", window_deleteln, 0);
2864
+ rb_define_method(cWindow, "insertln", window_insertln, 0);
2865
+ rb_define_method(cWindow, "scroll", window_scroll, 0);
2866
+ rb_define_method(cWindow, "scrollok", window_scrollok, 1);
2867
+ rb_define_method(cWindow, "idlok", window_idlok, 1);
2868
+ rb_define_method(cWindow, "setscrreg", window_setscrreg, 2);
2869
+ rb_define_method(cWindow, "scrl", window_scrl, 1);
2870
+ rb_define_method(cWindow, "resize", window_resize, 2);
2871
+ rb_define_method(cWindow, "keypad", window_keypad, 1);
2872
+ rb_define_method(cWindow, "keypad=", window_keypad, 1);
2873
+
2874
+ rb_define_method(cWindow, "attroff", window_attroff, 1);
2875
+ rb_define_method(cWindow, "attron", window_attron, 1);
2876
+ rb_define_method(cWindow, "attrset", window_attrset, 1);
2877
+ rb_define_method(cWindow, "bkgdset", window_bkgdset, 1);
2878
+ rb_define_method(cWindow, "bkgd", window_bkgd, 1);
2879
+ rb_define_method(cWindow, "getbkgd", window_getbkgd, 0);
2880
+
2881
+ rb_define_method(cWindow, "nodelay=", window_nodelay, 1);
2882
+ rb_define_method(cWindow, "timeout=", window_timeout, 1);
2883
+
2884
+ #ifdef HAVE_NEWPAD
2885
+ /*
2886
+ * Document-class: Curses::Pad
2887
+ *
2888
+ * == Description
2889
+ *
2890
+ * A Pad is like a Window but allows for scrolling of contents that cannot
2891
+ * fit on the screen. Pads do not refresh automatically, use Pad#refresh
2892
+ * or Pad#noutrefresh instead.
2893
+ *
2894
+ */
2895
+ cPad = rb_define_class_under(mCurses, "Pad", cWindow);
2896
+ /* inherits alloc_func from cWindow */
2897
+ rb_define_method(cPad, "initialize", pad_initialize, 2);
2898
+ rb_define_method(cPad, "subpad", pad_subpad, 4);
2899
+ rb_define_method(cPad, "refresh", pad_refresh, 6);
2900
+ rb_define_method(cPad, "noutrefresh", pad_noutrefresh, 6);
2901
+ rb_undef_method(cPad, "subwin");
2902
+ #endif
2903
+
2904
+ #define rb_curses_define_const(c) rb_define_const(mCurses,#c,UINT2NUM(c))
2905
+
2906
+ #ifdef USE_COLOR
2907
+ /* Document-const: A_ATTRIBUTES
2908
+ *
2909
+ * Character attribute mask:
2910
+ * Bit-mask to extract attributes
2911
+ *
2912
+ * See Curses.inch or Curses::Window.inch
2913
+ */
2914
+ rb_curses_define_const(A_ATTRIBUTES);
2915
+ #ifdef A_NORMAL
2916
+ /* Document-const: A_NORMAL
2917
+ *
2918
+ * Attribute mask:
2919
+ * Normal display (no highlight)
2920
+ *
2921
+ * See Curses.attrset
2922
+ */
2923
+ rb_curses_define_const(A_NORMAL);
2924
+ #endif
2925
+ /* Document-const: A_STANDOUT
2926
+ *
2927
+ * Attribute mask:
2928
+ * Best highlighting mode of the terminal.
2929
+ *
2930
+ * See Curses.attrset
2931
+ */
2932
+ rb_curses_define_const(A_STANDOUT);
2933
+ /* Document-const: A_UNDERLINE
2934
+ *
2935
+ * Attribute mask:
2936
+ * Underlining
2937
+ *
2938
+ * See Curses.attrset
2939
+ */
2940
+ rb_curses_define_const(A_UNDERLINE);
2941
+ /* Document-const: A_REVERSE
2942
+ *
2943
+ * Attribute mask:
2944
+ * Reverse video
2945
+ *
2946
+ * See Curses.attrset
2947
+ */
2948
+ rb_curses_define_const(A_REVERSE);
2949
+ /* Document-const: A_BLINK
2950
+ *
2951
+ * Attribute mask:
2952
+ * Blinking
2953
+ *
2954
+ * See Curses.attrset
2955
+ */
2956
+ rb_curses_define_const(A_BLINK);
2957
+ /* Document-const: A_DIM
2958
+ *
2959
+ * Attribute mask:
2960
+ * Half bright
2961
+ *
2962
+ * See Curses.attrset
2963
+ */
2964
+ rb_curses_define_const(A_DIM);
2965
+ /* Document-const: A_BOLD
2966
+ *
2967
+ * Attribute mask:
2968
+ * Extra bright or bold
2969
+ *
2970
+ * See Curses.attrset
2971
+ */
2972
+ rb_curses_define_const(A_BOLD);
2973
+ /* Document-const: A_PROTECT
2974
+ *
2975
+ * Attribute mask:
2976
+ * Protected mode
2977
+ *
2978
+ * See Curses.attrset
2979
+ */
2980
+ rb_curses_define_const(A_PROTECT);
2981
+ #ifdef A_INVIS /* for NetBSD */
2982
+ /* Document-const: A_INVIS
2983
+ *
2984
+ * Attribute mask:
2985
+ * Invisible or blank mode
2986
+ *
2987
+ * See Curses.attrset
2988
+ */
2989
+ rb_curses_define_const(A_INVIS);
2990
+ #endif
2991
+ /* Document-const: A_ALTCHARSET
2992
+ *
2993
+ * Attribute mask:
2994
+ * Alternate character set
2995
+ *
2996
+ * See Curses.attrset
2997
+ */
2998
+ rb_curses_define_const(A_ALTCHARSET);
2999
+ /* Document-const: A_CHARTEXT
3000
+ *
3001
+ * Attribute mask:
3002
+ * Bit-mask to extract a character
3003
+ *
3004
+ * See Curses.attrset
3005
+ */
3006
+ rb_curses_define_const(A_CHARTEXT);
3007
+ #ifdef A_HORIZONTAL
3008
+ /* Document-const: A_HORIZONTAL
3009
+ *
3010
+ * Attribute mask:
3011
+ * horizontal highlight
3012
+ *
3013
+ * Check system curs_attr(3x) for support
3014
+ */
3015
+ rb_curses_define_const(A_HORIZONTAL);
3016
+ #endif
3017
+ #ifdef A_LEFT
3018
+ /* Document-const: A_LEFT
3019
+ *
3020
+ * Attribute mask:
3021
+ * left highlight
3022
+ *
3023
+ * Check system curs_attr(3x) for support
3024
+ */
3025
+ rb_curses_define_const(A_LEFT);
3026
+ #endif
3027
+ #ifdef A_LOW
3028
+ /* Document-const: A_LOW
3029
+ *
3030
+ * Attribute mask:
3031
+ * low highlight
3032
+ *
3033
+ * Check system curs_attr(3x) for support
3034
+ */
3035
+ rb_curses_define_const(A_LOW);
3036
+ #endif
3037
+ #ifdef A_RIGHT
3038
+ /* Document-const: A_RIGHT
3039
+ *
3040
+ * Attribute mask:
3041
+ * right highlight
3042
+ *
3043
+ * Check system curs_attr(3x) for support
3044
+ */
3045
+ rb_curses_define_const(A_RIGHT);
3046
+ #endif
3047
+ #ifdef A_TOP
3048
+ /* Document-const: A_TOP
3049
+ *
3050
+ * Attribute mask:
3051
+ * top highlight
3052
+ *
3053
+ * Check system curs_attr(3x) for support
3054
+ */
3055
+ rb_curses_define_const(A_TOP);
3056
+ #endif
3057
+ #ifdef A_VERTICAL
3058
+ /* Document-const: A_VERTICAL
3059
+ *
3060
+ * Attribute mask:
3061
+ * vertical highlight
3062
+ *
3063
+ * Check system curs_attr(3x) for support
3064
+ */
3065
+ rb_curses_define_const(A_VERTICAL);
3066
+ #endif
3067
+ /* Document-const: A_COLOR
3068
+ *
3069
+ * Character attribute mask:
3070
+ * Bit-mask to extract color-pair field information
3071
+ *
3072
+ * See Curses.inch or Curses::Window.inch
3073
+ */
3074
+ rb_curses_define_const(A_COLOR);
3075
+
3076
+ #ifdef COLORS
3077
+ /*
3078
+ * Document-const: Curses::COLORS
3079
+ *
3080
+ * Number of the colors available
3081
+ */
3082
+ rb_curses_define_const(COLORS);
3083
+ #endif
3084
+ /*
3085
+ * Document-const: Curses::COLOR_BLACK
3086
+ *
3087
+ * Value of the color black
3088
+ */
3089
+ rb_curses_define_const(COLOR_BLACK);
3090
+ /*
3091
+ * Document-const: COLOR_RED
3092
+ *
3093
+ * Value of the color red
3094
+ */
3095
+ rb_curses_define_const(COLOR_RED);
3096
+ /*
3097
+ * Document-const: COLOR_GREEN
3098
+ *
3099
+ * Value of the color green
3100
+ */
3101
+ rb_curses_define_const(COLOR_GREEN);
3102
+ /*
3103
+ * Document-const: COLOR_YELLOW
3104
+ *
3105
+ * Value of the color yellow
3106
+ */
3107
+ rb_curses_define_const(COLOR_YELLOW);
3108
+ /*
3109
+ * Document-const: COLOR_BLUE
3110
+ *
3111
+ * Value of the color blue
3112
+ */
3113
+ rb_curses_define_const(COLOR_BLUE);
3114
+ /*
3115
+ * Document-const: COLOR_MAGENTA
3116
+ *
3117
+ * Value of the color magenta
3118
+ */
3119
+ rb_curses_define_const(COLOR_MAGENTA);
3120
+ /*
3121
+ * Document-const: COLOR_CYAN
3122
+ *
3123
+ * Value of the color cyan
3124
+ */
3125
+ rb_curses_define_const(COLOR_CYAN);
3126
+ /*
3127
+ * Document-const: COLOR_WHITE
3128
+ *
3129
+ * Value of the color white
3130
+ */
3131
+ rb_curses_define_const(COLOR_WHITE);
3132
+ #endif /* USE_COLOR */
3133
+ #ifdef USE_MOUSE
3134
+ #ifdef BUTTON1_PRESSED
3135
+ /* Document-const: BUTTON1_PRESSED
3136
+ *
3137
+ * Mouse event mask:
3138
+ * mouse button 1 down
3139
+ *
3140
+ * See Curses.getmouse
3141
+ */
3142
+ rb_curses_define_const(BUTTON1_PRESSED);
3143
+ #endif
3144
+ #ifdef BUTTON1_RELEASED
3145
+ /* Document-const: BUTTON1_RELEASED
3146
+ *
3147
+ * Mouse event mask:
3148
+ * mouse button 1 up
3149
+ *
3150
+ * See Curses.getmouse
3151
+ */
3152
+ rb_curses_define_const(BUTTON1_RELEASED);
3153
+ #endif
3154
+ #ifdef BUTTON1_CLICKED
3155
+ /* Document-const: BUTTON1_CLICKED
3156
+ *
3157
+ * Mouse event mask:
3158
+ * mouse button 1 clicked
3159
+ *
3160
+ * See Curses.getmouse
3161
+ */
3162
+ rb_curses_define_const(BUTTON1_CLICKED);
3163
+ #endif
3164
+ #ifdef BUTTON1_DOUBLE_CLICKED
3165
+ /* Document-const: BUTTON1_DOUBLE_CLICKED
3166
+ *
3167
+ * Mouse event mask:
3168
+ * mouse button 1 double clicked
3169
+ *
3170
+ * See Curses.getmouse
3171
+ */
3172
+ rb_curses_define_const(BUTTON1_DOUBLE_CLICKED);
3173
+ #endif
3174
+ #ifdef BUTTON1_TRIPLE_CLICKED
3175
+ /* Document-const: BUTTON1_TRIPLE_CLICKED
3176
+ *
3177
+ * Mouse event mask:
3178
+ * mouse button 1 triple clicked
3179
+ *
3180
+ * See Curses.getmouse
3181
+ */
3182
+ rb_curses_define_const(BUTTON1_TRIPLE_CLICKED);
3183
+ #endif
3184
+ #ifdef BUTTON2_PRESSED
3185
+ /* Document-const: BUTTON2_PRESSED
3186
+ *
3187
+ * Mouse event mask:
3188
+ * mouse button 2 down
3189
+ *
3190
+ * See Curses.getmouse
3191
+ */
3192
+ rb_curses_define_const(BUTTON2_PRESSED);
3193
+ #endif
3194
+ #ifdef BUTTON2_RELEASED
3195
+ /* Document-const: BUTTON2_RELEASED
3196
+ *
3197
+ * Mouse event mask:
3198
+ * mouse button 2 up
3199
+ *
3200
+ * See Curses.getmouse
3201
+ */
3202
+ rb_curses_define_const(BUTTON2_RELEASED);
3203
+ #endif
3204
+ #ifdef BUTTON2_CLICKED
3205
+ /* Document-const: BUTTON2_CLICKED
3206
+ *
3207
+ * Mouse event mask:
3208
+ * mouse button 2 clicked
3209
+ *
3210
+ * See Curses.getmouse
3211
+ */
3212
+ rb_curses_define_const(BUTTON2_CLICKED);
3213
+ #endif
3214
+ #ifdef BUTTON2_DOUBLE_CLICKED
3215
+ /* Document-const: BUTTON2_DOUBLE_CLICKED
3216
+ *
3217
+ * Mouse event mask:
3218
+ * mouse button 2 double clicked
3219
+ *
3220
+ * See Curses.getmouse
3221
+ */
3222
+ rb_curses_define_const(BUTTON2_DOUBLE_CLICKED);
3223
+ #endif
3224
+ #ifdef BUTTON2_TRIPLE_CLICKED
3225
+ /* Document-const: BUTTON2_TRIPLE_CLICKED
3226
+ *
3227
+ * Mouse event mask:
3228
+ * mouse button 2 triple clicked
3229
+ *
3230
+ * See Curses.getmouse
3231
+ */
3232
+ rb_curses_define_const(BUTTON2_TRIPLE_CLICKED);
3233
+ #endif
3234
+ #ifdef BUTTON3_PRESSED
3235
+ /* Document-const: BUTTON3_PRESSED
3236
+ *
3237
+ * Mouse event mask:
3238
+ * mouse button 3 down
3239
+ *
3240
+ * See Curses.getmouse
3241
+ */
3242
+ rb_curses_define_const(BUTTON3_PRESSED);
3243
+ #endif
3244
+ #ifdef BUTTON3_RELEASED
3245
+ /* Document-const: BUTTON3_RELEASED
3246
+ *
3247
+ * Mouse event mask:
3248
+ * mouse button 3 up
3249
+ *
3250
+ * See Curses.getmouse
3251
+ */
3252
+ rb_curses_define_const(BUTTON3_RELEASED);
3253
+ #endif
3254
+ #ifdef BUTTON3_CLICKED
3255
+ /* Document-const: BUTTON3_CLICKED
3256
+ *
3257
+ * Mouse event mask:
3258
+ * mouse button 3 clicked
3259
+ *
3260
+ * See Curses.getmouse
3261
+ */
3262
+ rb_curses_define_const(BUTTON3_CLICKED);
3263
+ #endif
3264
+ #ifdef BUTTON3_DOUBLE_CLICKED
3265
+ /* Document-const: BUTTON3_DOUBLE_CLICKED
3266
+ *
3267
+ * Mouse event mask:
3268
+ * mouse button 3 double clicked
3269
+ *
3270
+ * See Curses.getmouse
3271
+ */
3272
+ rb_curses_define_const(BUTTON3_DOUBLE_CLICKED);
3273
+ #endif
3274
+ #ifdef BUTTON3_TRIPLE_CLICKED
3275
+ /* Document-const: BUTTON3_TRIPLE_CLICKED
3276
+ *
3277
+ * Mouse event mask:
3278
+ * mouse button 3 triple clicked
3279
+ *
3280
+ * See Curses.getmouse
3281
+ */
3282
+ rb_curses_define_const(BUTTON3_TRIPLE_CLICKED);
3283
+ #endif
3284
+ #ifdef BUTTON4_PRESSED
3285
+ /* Document-const: BUTTON4_PRESSED
3286
+ *
3287
+ * Mouse event mask:
3288
+ * mouse button 4 down
3289
+ *
3290
+ * See Curses.getmouse
3291
+ */
3292
+ rb_curses_define_const(BUTTON4_PRESSED);
3293
+ #endif
3294
+ #ifdef BUTTON4_RELEASED
3295
+ /* Document-const: BUTTON4_RELEASED
3296
+ *
3297
+ * Mouse event mask:
3298
+ * mouse button 4 up
3299
+ *
3300
+ * See Curses.getmouse
3301
+ */
3302
+ rb_curses_define_const(BUTTON4_RELEASED);
3303
+ #endif
3304
+ #ifdef BUTTON4_CLICKED
3305
+ /* Document-const: BUTTON4_CLICKED
3306
+ *
3307
+ * Mouse event mask:
3308
+ * mouse button 4 clicked
3309
+ *
3310
+ * See Curses.getmouse
3311
+ */
3312
+ rb_curses_define_const(BUTTON4_CLICKED);
3313
+ #endif
3314
+ #ifdef BUTTON4_DOUBLE_CLICKED
3315
+ /* Document-const: BUTTON4_DOUBLE_CLICKED
3316
+ *
3317
+ * Mouse event mask:
3318
+ * mouse button 4 double clicked
3319
+ *
3320
+ * See Curses.getmouse
3321
+ */
3322
+ rb_curses_define_const(BUTTON4_DOUBLE_CLICKED);
3323
+ #endif
3324
+ #ifdef BUTTON4_TRIPLE_CLICKED
3325
+ /* Document-const: BUTTON4_TRIPLE_CLICKED
3326
+ *
3327
+ * Mouse event mask:
3328
+ * mouse button 4 triple clicked
3329
+ *
3330
+ * See Curses.getmouse
3331
+ */
3332
+ rb_curses_define_const(BUTTON4_TRIPLE_CLICKED);
3333
+ #endif
3334
+ #ifdef BUTTON_SHIFT
3335
+ /* Document-const: BUTTON_SHIFT
3336
+ *
3337
+ * Mouse event mask:
3338
+ * shift was down during button state change
3339
+ *
3340
+ * See Curses.getmouse
3341
+ */
3342
+ rb_curses_define_const(BUTTON_SHIFT);
3343
+ #endif
3344
+ #ifdef BUTTON_CTRL
3345
+ /* Document-const: BUTTON_CTRL
3346
+ *
3347
+ * Mouse event mask:
3348
+ * control was down during button state change
3349
+ *
3350
+ * See Curses.getmouse
3351
+ */
3352
+ rb_curses_define_const(BUTTON_CTRL);
3353
+ #endif
3354
+ #ifdef BUTTON_ALT
3355
+ /* Document-const: BUTTON_ALT
3356
+ *
3357
+ * Mouse event mask:
3358
+ * alt was down during button state change
3359
+ *
3360
+ * See Curses.getmouse
3361
+ */
3362
+ rb_curses_define_const(BUTTON_ALT);
3363
+ #endif
3364
+ #ifdef ALL_MOUSE_EVENTS
3365
+ /* Document-const: ALL_MOUSE_EVENTS
3366
+ *
3367
+ * Mouse event mask:
3368
+ * report all button state changes
3369
+ *
3370
+ * See Curses.getmouse
3371
+ */
3372
+ rb_curses_define_const(ALL_MOUSE_EVENTS);
3373
+ #endif
3374
+ #ifdef REPORT_MOUSE_POSITION
3375
+ /* Document-const: REPORT_MOUSE_POSITION
3376
+ *
3377
+ * Mouse event mask:
3378
+ * report mouse movement
3379
+ *
3380
+ * See Curses.getmouse
3381
+ */
3382
+ rb_curses_define_const(REPORT_MOUSE_POSITION);
3383
+ #endif
3384
+ #endif /* USE_MOUSE */
3385
+
3386
+ #if defined(KEY_MOUSE) && defined(USE_MOUSE)
3387
+ /* Document-const: KEY_MOUSE
3388
+ * Mouse event read
3389
+ */
3390
+ /* Document-const: MOUSE
3391
+ * Mouse event read
3392
+ */
3393
+ rb_curses_define_const(KEY_MOUSE);
3394
+ rb_define_const(mKey, "MOUSE", INT2NUM(KEY_MOUSE));
3395
+ #endif
3396
+ #ifdef KEY_MIN
3397
+ /* Document-const: KEY_MIN
3398
+ * The minimum allowed curses key value.
3399
+ */
3400
+ /* Document-const: MIN
3401
+ * The minimum allowed curses key value.
3402
+ */
3403
+ rb_curses_define_const(KEY_MIN);
3404
+ rb_define_const(mKey, "MIN", INT2NUM(KEY_MIN));
3405
+ #endif
3406
+ #ifdef KEY_BREAK
3407
+ /* Document-const: KEY_BREAK
3408
+ * Break key
3409
+ */
3410
+ /* Document-const: BREAK
3411
+ * Break key
3412
+ */
3413
+ rb_curses_define_const(KEY_BREAK);
3414
+ rb_define_const(mKey, "BREAK", INT2NUM(KEY_BREAK));
3415
+ #endif
3416
+ #ifdef KEY_DOWN
3417
+ /* Document-const: KEY_DOWN
3418
+ * the down arrow key
3419
+ */
3420
+ /* Document-const: DOWN
3421
+ * the down arrow key
3422
+ */
3423
+ rb_curses_define_const(KEY_DOWN);
3424
+ rb_define_const(mKey, "DOWN", INT2NUM(KEY_DOWN));
3425
+ #endif
3426
+ #ifdef KEY_UP
3427
+ /* Document-const: KEY_UP
3428
+ * the up arrow key
3429
+ */
3430
+ /* Document-const: UP
3431
+ * the up arrow key
3432
+ */
3433
+ rb_curses_define_const(KEY_UP);
3434
+ rb_define_const(mKey, "UP", INT2NUM(KEY_UP));
3435
+ #endif
3436
+ #ifdef KEY_LEFT
3437
+ /* Document-const: KEY_LEFT
3438
+ * the left arrow key
3439
+ */
3440
+ /* Document-const: LEFT
3441
+ * the left arrow key
3442
+ */
3443
+ rb_curses_define_const(KEY_LEFT);
3444
+ rb_define_const(mKey, "LEFT", INT2NUM(KEY_LEFT));
3445
+ #endif
3446
+ #ifdef KEY_RIGHT
3447
+ /* Document-const: KEY_RIGHT
3448
+ * the right arrow key
3449
+ */
3450
+ /* Document-const: RIGHT
3451
+ * the right arrow key
3452
+ */
3453
+ rb_curses_define_const(KEY_RIGHT);
3454
+ rb_define_const(mKey, "RIGHT", INT2NUM(KEY_RIGHT));
3455
+ #endif
3456
+ #ifdef KEY_HOME
3457
+ /* Document-const: KEY_HOME
3458
+ * Home key (upward+left arrow)
3459
+ */
3460
+ /* Document-const: HOME
3461
+ * Home key (upward+left arrow)
3462
+ */
3463
+ rb_curses_define_const(KEY_HOME);
3464
+ rb_define_const(mKey, "HOME", INT2NUM(KEY_HOME));
3465
+ #endif
3466
+ #ifdef KEY_BACKSPACE
3467
+ /* Document-const: KEY_BACKSPACE
3468
+ * Backspace
3469
+ */
3470
+ /* Document-const: BACKSPACE
3471
+ * Backspace
3472
+ */
3473
+ rb_curses_define_const(KEY_BACKSPACE);
3474
+ rb_define_const(mKey, "BACKSPACE", INT2NUM(KEY_BACKSPACE));
3475
+ #endif
3476
+ #ifdef KEY_F
3477
+ /* KEY_F(n) : 0 <= n <= 63 */
3478
+ {
3479
+ int i;
3480
+ char c[8];
3481
+ for (i=0; i<64; i++) {
3482
+ sprintf(c, "KEY_F%d", i);
3483
+ rb_define_const(mCurses, c, INT2NUM(KEY_F(i)));
3484
+ sprintf(c, "F%d", i);
3485
+ rb_define_const(mKey, c, INT2NUM(KEY_F(i)));
3486
+ }
3487
+ }
3488
+ #endif
3489
+ #ifdef KEY_DL
3490
+ /* Document-const: KEY_DL
3491
+ * Delete line
3492
+ */
3493
+ /* Document-const: DL
3494
+ * Delete line
3495
+ */
3496
+ rb_curses_define_const(KEY_DL);
3497
+ rb_define_const(mKey, "DL", INT2NUM(KEY_DL));
3498
+ #endif
3499
+ #ifdef KEY_IL
3500
+ /* Document-const: KEY_IL
3501
+ * Insert line
3502
+ */
3503
+ /* Document-const: IL
3504
+ * Insert line
3505
+ */
3506
+ rb_curses_define_const(KEY_IL);
3507
+ rb_define_const(mKey, "IL", INT2NUM(KEY_IL));
3508
+ #endif
3509
+ #ifdef KEY_DC
3510
+ /* Document-const: KEY_DC
3511
+ * Delete character
3512
+ */
3513
+ /* Document-const: DC
3514
+ * Delete character
3515
+ */
3516
+ rb_curses_define_const(KEY_DC);
3517
+ rb_define_const(mKey, "DC", INT2NUM(KEY_DC));
3518
+ #endif
3519
+ #ifdef KEY_IC
3520
+ /* Document-const: KEY_IC
3521
+ * Insert char or enter insert mode
3522
+ */
3523
+ /* Document-const: IC
3524
+ * Insert char or enter insert mode
3525
+ */
3526
+ rb_curses_define_const(KEY_IC);
3527
+ rb_define_const(mKey, "IC", INT2NUM(KEY_IC));
3528
+ #endif
3529
+ #ifdef KEY_EIC
3530
+ /* Document-const: KEY_EIC
3531
+ * Enter insert char mode
3532
+ */
3533
+ /* Document-const: EIC
3534
+ * Enter insert char mode
3535
+ */
3536
+ rb_curses_define_const(KEY_EIC);
3537
+ rb_define_const(mKey, "EIC", INT2NUM(KEY_EIC));
3538
+ #endif
3539
+ #ifdef KEY_CLEAR
3540
+ /* Document-const: KEY_CLEAR
3541
+ * Clear Screen
3542
+ */
3543
+ /* Document-const: CLEAR
3544
+ * Clear Screen
3545
+ */
3546
+ rb_curses_define_const(KEY_CLEAR);
3547
+ rb_define_const(mKey, "CLEAR", INT2NUM(KEY_CLEAR));
3548
+ #endif
3549
+ #ifdef KEY_EOS
3550
+ /* Document-const: KEY_EOS
3551
+ * Clear to end of screen
3552
+ */
3553
+ /* Document-const: EOS
3554
+ * Clear to end of screen
3555
+ */
3556
+ rb_curses_define_const(KEY_EOS);
3557
+ rb_define_const(mKey, "EOS", INT2NUM(KEY_EOS));
3558
+ #endif
3559
+ #ifdef KEY_EOL
3560
+ /* Document-const: KEY_EOL
3561
+ * Clear to end of line
3562
+ */
3563
+ /* Document-const: EOL
3564
+ * Clear to end of line
3565
+ */
3566
+ rb_curses_define_const(KEY_EOL);
3567
+ rb_define_const(mKey, "EOL", INT2NUM(KEY_EOL));
3568
+ #endif
3569
+ #ifdef KEY_SF
3570
+ /* Document-const: KEY_SF
3571
+ * Scroll 1 line forward
3572
+ */
3573
+ /* Document-const: SF
3574
+ * Scroll 1 line forward
3575
+ */
3576
+ rb_curses_define_const(KEY_SF);
3577
+ rb_define_const(mKey, "SF", INT2NUM(KEY_SF));
3578
+ #endif
3579
+ #ifdef KEY_SR
3580
+ /* Document-const: KEY_SR
3581
+ * Scroll 1 line backward (reverse)
3582
+ */
3583
+ /* Document-const: SR
3584
+ * Scroll 1 line backward (reverse)
3585
+ */
3586
+ rb_curses_define_const(KEY_SR);
3587
+ rb_define_const(mKey, "SR", INT2NUM(KEY_SR));
3588
+ #endif
3589
+ #ifdef KEY_NPAGE
3590
+ /* Document-const: KEY_NPAGE
3591
+ * Next page
3592
+ */
3593
+ /* Document-const: NPAGE
3594
+ * Next page
3595
+ */
3596
+ rb_curses_define_const(KEY_NPAGE);
3597
+ rb_define_const(mKey, "NPAGE", INT2NUM(KEY_NPAGE));
3598
+ #endif
3599
+ #ifdef KEY_PPAGE
3600
+ /* Document-const: KEY_PPAGE
3601
+ * Previous page
3602
+ */
3603
+ /* Document-const: PPAGE
3604
+ * Previous page
3605
+ */
3606
+ rb_curses_define_const(KEY_PPAGE);
3607
+ rb_define_const(mKey, "PPAGE", INT2NUM(KEY_PPAGE));
3608
+ #endif
3609
+ #ifdef KEY_STAB
3610
+ /* Document-const: KEY_STAB
3611
+ * Set tab
3612
+ */
3613
+ /* Document-const: STAB
3614
+ * Set tab
3615
+ */
3616
+ rb_curses_define_const(KEY_STAB);
3617
+ rb_define_const(mKey, "STAB", INT2NUM(KEY_STAB));
3618
+ #endif
3619
+ #ifdef KEY_CTAB
3620
+ /* Document-const: KEY_CTAB
3621
+ * Clear tab
3622
+ */
3623
+ /* Document-const: CTAB
3624
+ * Clear tab
3625
+ */
3626
+ rb_curses_define_const(KEY_CTAB);
3627
+ rb_define_const(mKey, "CTAB", INT2NUM(KEY_CTAB));
3628
+ #endif
3629
+ #ifdef KEY_CATAB
3630
+ /* Document-const: KEY_CATAB
3631
+ * Clear all tabs
3632
+ */
3633
+ /* Document-const: CATAB
3634
+ * Clear all tabs
3635
+ */
3636
+ rb_curses_define_const(KEY_CATAB);
3637
+ rb_define_const(mKey, "CATAB", INT2NUM(KEY_CATAB));
3638
+ #endif
3639
+ #ifdef KEY_ENTER
3640
+ /* Document-const: KEY_ENTER
3641
+ * Enter or send
3642
+ */
3643
+ /* Document-const: ENTER
3644
+ * Enter or send
3645
+ */
3646
+ rb_curses_define_const(KEY_ENTER);
3647
+ rb_define_const(mKey, "ENTER", INT2NUM(KEY_ENTER));
3648
+ #endif
3649
+ #ifdef KEY_SRESET
3650
+ /* Document-const: KEY_SRESET
3651
+ * Soft (partial) reset
3652
+ */
3653
+ /* Document-const: SRESET
3654
+ * Soft (partial) reset
3655
+ */
3656
+ rb_curses_define_const(KEY_SRESET);
3657
+ rb_define_const(mKey, "SRESET", INT2NUM(KEY_SRESET));
3658
+ #endif
3659
+ #ifdef KEY_RESET
3660
+ /* Document-const: KEY_RESET
3661
+ * Reset or hard reset
3662
+ */
3663
+ /* Document-const: RESET
3664
+ * Reset or hard reset
3665
+ */
3666
+ rb_curses_define_const(KEY_RESET);
3667
+ rb_define_const(mKey, "RESET", INT2NUM(KEY_RESET));
3668
+ #endif
3669
+ #ifdef KEY_PRINT
3670
+ /* Document-const: KEY_PRINT
3671
+ * Print or copy
3672
+ */
3673
+ /* Document-const: PRINT
3674
+ * Print or copy
3675
+ */
3676
+ rb_curses_define_const(KEY_PRINT);
3677
+ rb_define_const(mKey, "PRINT", INT2NUM(KEY_PRINT));
3678
+ #endif
3679
+ #ifdef KEY_LL
3680
+ /* Document-const: KEY_LL
3681
+ * Home down or bottom (lower left)
3682
+ */
3683
+ /* Document-const: LL
3684
+ * Home down or bottom (lower left)
3685
+ */
3686
+ rb_curses_define_const(KEY_LL);
3687
+ rb_define_const(mKey, "LL", INT2NUM(KEY_LL));
3688
+ #endif
3689
+ #ifdef KEY_A1
3690
+ /* Document-const: KEY_A1
3691
+ * Upper left of keypad
3692
+ */
3693
+ /* Document-const: A1
3694
+ * Upper left of keypad
3695
+ */
3696
+ rb_curses_define_const(KEY_A1);
3697
+ rb_define_const(mKey, "A1", INT2NUM(KEY_A1));
3698
+ #endif
3699
+ #ifdef KEY_A3
3700
+ /* Document-const: KEY_A3
3701
+ * Upper right of keypad
3702
+ */
3703
+ /* Document-const: A3
3704
+ * Upper right of keypad
3705
+ */
3706
+ rb_curses_define_const(KEY_A3);
3707
+ rb_define_const(mKey, "A3", INT2NUM(KEY_A3));
3708
+ #endif
3709
+ #ifdef KEY_B2
3710
+ /* Document-const: KEY_B2
3711
+ * Center of keypad
3712
+ */
3713
+ /* Document-const: B2
3714
+ * Center of keypad
3715
+ */
3716
+ rb_curses_define_const(KEY_B2);
3717
+ rb_define_const(mKey, "B2", INT2NUM(KEY_B2));
3718
+ #endif
3719
+ #ifdef KEY_C1
3720
+ /* Document-const: KEY_C1
3721
+ * Lower left of keypad
3722
+ */
3723
+ /* Document-const: C1
3724
+ * Lower left of keypad
3725
+ */
3726
+ rb_curses_define_const(KEY_C1);
3727
+ rb_define_const(mKey, "C1", INT2NUM(KEY_C1));
3728
+ #endif
3729
+ #ifdef KEY_C3
3730
+ /* Document-const: KEY_C3
3731
+ * Lower right of keypad
3732
+ */
3733
+ /* Document-const: C3
3734
+ * Lower right of keypad
3735
+ */
3736
+ rb_curses_define_const(KEY_C3);
3737
+ rb_define_const(mKey, "C3", INT2NUM(KEY_C3));
3738
+ #endif
3739
+ #ifdef KEY_BTAB
3740
+ /* Document-const: BTAB
3741
+ * Back tab key
3742
+ */
3743
+ /* Document-const: KEY_BTAB
3744
+ * Back tab key
3745
+ */
3746
+ rb_curses_define_const(KEY_BTAB);
3747
+ rb_define_const(mKey, "BTAB", INT2NUM(KEY_BTAB));
3748
+ #endif
3749
+ #ifdef KEY_BEG
3750
+ /* Document-const: KEY_BEG
3751
+ * Beginning key
3752
+ */
3753
+ /* Document-const: BEG
3754
+ * Beginning key
3755
+ */
3756
+ rb_curses_define_const(KEY_BEG);
3757
+ rb_define_const(mKey, "BEG", INT2NUM(KEY_BEG));
3758
+ #endif
3759
+ #ifdef KEY_CANCEL
3760
+ /* Document-const: KEY_CANCEL
3761
+ * Cancel key
3762
+ */
3763
+ /* Document-const: CANCEL
3764
+ * Cancel key
3765
+ */
3766
+ rb_curses_define_const(KEY_CANCEL);
3767
+ rb_define_const(mKey, "CANCEL", INT2NUM(KEY_CANCEL));
3768
+ #endif
3769
+ #ifdef KEY_CLOSE
3770
+ /* Document-const: KEY_CLOSE
3771
+ * Close key
3772
+ */
3773
+ /* Document-const: CLOSE
3774
+ * Close key
3775
+ */
3776
+ rb_curses_define_const(KEY_CLOSE);
3777
+ rb_define_const(mKey, "CLOSE", INT2NUM(KEY_CLOSE));
3778
+ #endif
3779
+ #ifdef KEY_COMMAND
3780
+ /* Document-const: KEY_COMMAND
3781
+ * Cmd (command) key
3782
+ */
3783
+ /* Document-const: COMMAND
3784
+ * Cmd (command) key
3785
+ */
3786
+ rb_curses_define_const(KEY_COMMAND);
3787
+ rb_define_const(mKey, "COMMAND", INT2NUM(KEY_COMMAND));
3788
+ #endif
3789
+ #ifdef KEY_COPY
3790
+ /* Document-const: KEY_COPY
3791
+ * Copy key
3792
+ */
3793
+ /* Document-const: COPY
3794
+ * Copy key
3795
+ */
3796
+ rb_curses_define_const(KEY_COPY);
3797
+ rb_define_const(mKey, "COPY", INT2NUM(KEY_COPY));
3798
+ #endif
3799
+ #ifdef KEY_CREATE
3800
+ /* Document-const: KEY_CREATE
3801
+ * Create key
3802
+ */
3803
+ /* Document-const: CREATE
3804
+ * Create key
3805
+ */
3806
+ rb_curses_define_const(KEY_CREATE);
3807
+ rb_define_const(mKey, "CREATE", INT2NUM(KEY_CREATE));
3808
+ #endif
3809
+ #ifdef KEY_END
3810
+ /* Document-const: KEY_END
3811
+ * End key
3812
+ */
3813
+ /* Document-const: END
3814
+ * End key
3815
+ */
3816
+ rb_curses_define_const(KEY_END);
3817
+ rb_define_const(mKey, "END", INT2NUM(KEY_END));
3818
+ #endif
3819
+ #ifdef KEY_EXIT
3820
+ /* Document-const: KEY_EXIT
3821
+ * Exit key
3822
+ */
3823
+ /* Document-const: EXIT
3824
+ * Exit key
3825
+ */
3826
+ rb_curses_define_const(KEY_EXIT);
3827
+ rb_define_const(mKey, "EXIT", INT2NUM(KEY_EXIT));
3828
+ #endif
3829
+ #ifdef KEY_FIND
3830
+ /* Document-const: KEY_FIND
3831
+ * Find key
3832
+ */
3833
+ /* Document-const: FIND
3834
+ * Find key
3835
+ */
3836
+ rb_curses_define_const(KEY_FIND);
3837
+ rb_define_const(mKey, "FIND", INT2NUM(KEY_FIND));
3838
+ #endif
3839
+ #ifdef KEY_HELP
3840
+ /* Document-const: KEY_HELP
3841
+ * Help key
3842
+ */
3843
+ /* Document-const: HELP
3844
+ * Help key
3845
+ */
3846
+ rb_curses_define_const(KEY_HELP);
3847
+ rb_define_const(mKey, "HELP", INT2NUM(KEY_HELP));
3848
+ #endif
3849
+ #ifdef KEY_MARK
3850
+ /* Document-const: KEY_MARK
3851
+ * Mark key
3852
+ */
3853
+ /* Document-const: MARK
3854
+ * Mark key
3855
+ */
3856
+ rb_curses_define_const(KEY_MARK);
3857
+ rb_define_const(mKey, "MARK", INT2NUM(KEY_MARK));
3858
+ #endif
3859
+ #ifdef KEY_MESSAGE
3860
+ /* Document-const: KEY_MESSAGE
3861
+ * Message key
3862
+ */
3863
+ /* Document-const: MESSAGE
3864
+ * Message key
3865
+ */
3866
+ rb_curses_define_const(KEY_MESSAGE);
3867
+ rb_define_const(mKey, "MESSAGE", INT2NUM(KEY_MESSAGE));
3868
+ #endif
3869
+ #ifdef KEY_MOVE
3870
+ /* Document-const: KEY_MOVE
3871
+ * Move key
3872
+ */
3873
+ /* Document-const: MOVE
3874
+ * Move key
3875
+ */
3876
+ rb_curses_define_const(KEY_MOVE);
3877
+ rb_define_const(mKey, "MOVE", INT2NUM(KEY_MOVE));
3878
+ #endif
3879
+ #ifdef KEY_NEXT
3880
+ /* Document-const: KEY_NEXT
3881
+ * Next object key
3882
+ */
3883
+ /* Document-const: NEXT
3884
+ * Next object key
3885
+ */
3886
+ rb_curses_define_const(KEY_NEXT);
3887
+ rb_define_const(mKey, "NEXT", INT2NUM(KEY_NEXT));
3888
+ #endif
3889
+ #ifdef KEY_OPEN
3890
+ /* Document-const: KEY_OPEN
3891
+ * Open key
3892
+ */
3893
+ /* Document-const: OPEN
3894
+ * Open key
3895
+ */
3896
+ rb_curses_define_const(KEY_OPEN);
3897
+ rb_define_const(mKey, "OPEN", INT2NUM(KEY_OPEN));
3898
+ #endif
3899
+ #ifdef KEY_OPTIONS
3900
+ /* Document-const: KEY_OPTIONS
3901
+ * Options key
3902
+ */
3903
+ /* Document-const: OPTIONS
3904
+ * Options key
3905
+ */
3906
+ rb_curses_define_const(KEY_OPTIONS);
3907
+ rb_define_const(mKey, "OPTIONS", INT2NUM(KEY_OPTIONS));
3908
+ #endif
3909
+ #ifdef KEY_PREVIOUS
3910
+ /* Document-const: KEY_PREVIOUS
3911
+ * Previous object key
3912
+ */
3913
+ /* Document-const: PREVIOUS
3914
+ * Previous object key
3915
+ */
3916
+ rb_curses_define_const(KEY_PREVIOUS);
3917
+ rb_define_const(mKey, "PREVIOUS", INT2NUM(KEY_PREVIOUS));
3918
+ #endif
3919
+ #ifdef KEY_REDO
3920
+ /* Document-const: KEY_REDO
3921
+ * Redo key
3922
+ */
3923
+ /* Document-const: REDO
3924
+ * Redo key
3925
+ */
3926
+ rb_curses_define_const(KEY_REDO);
3927
+ rb_define_const(mKey, "REDO", INT2NUM(KEY_REDO));
3928
+ #endif
3929
+ #ifdef KEY_REFERENCE
3930
+ /* Document-const: KEY_REFERENCE
3931
+ * Reference key
3932
+ */
3933
+ /* Document-const: REFERENCE
3934
+ * Reference key
3935
+ */
3936
+ rb_curses_define_const(KEY_REFERENCE);
3937
+ rb_define_const(mKey, "REFERENCE", INT2NUM(KEY_REFERENCE));
3938
+ #endif
3939
+ #ifdef KEY_REFRESH
3940
+ /* Document-const: KEY_REFRESH
3941
+ * Refresh key
3942
+ */
3943
+ /* Document-const: REFRESH
3944
+ * Refresh key
3945
+ */
3946
+ rb_curses_define_const(KEY_REFRESH);
3947
+ rb_define_const(mKey, "REFRESH", INT2NUM(KEY_REFRESH));
3948
+ #endif
3949
+ #ifdef KEY_REPLACE
3950
+ /* Document-const: KEY_REPLACE
3951
+ * Replace key
3952
+ */
3953
+ /* Document-const: REPLACE
3954
+ * Replace key
3955
+ */
3956
+ rb_curses_define_const(KEY_REPLACE);
3957
+ rb_define_const(mKey, "REPLACE", INT2NUM(KEY_REPLACE));
3958
+ #endif
3959
+ #ifdef KEY_RESTART
3960
+ /* Document-const: KEY_RESTART
3961
+ * Restart key
3962
+ */
3963
+ /* Document-const: RESTART
3964
+ * Restart key
3965
+ */
3966
+ rb_curses_define_const(KEY_RESTART);
3967
+ rb_define_const(mKey, "RESTART", INT2NUM(KEY_RESTART));
3968
+ #endif
3969
+ #ifdef KEY_RESUME
3970
+ /* Document-const: KEY_RESUME
3971
+ * Resume key
3972
+ */
3973
+ /* Document-const: RESUME
3974
+ * Resume key
3975
+ */
3976
+ rb_curses_define_const(KEY_RESUME);
3977
+ rb_define_const(mKey, "RESUME", INT2NUM(KEY_RESUME));
3978
+ #endif
3979
+ #ifdef KEY_SAVE
3980
+ /* Document-const: KEY_SAVE
3981
+ * Save key
3982
+ */
3983
+ /* Document-const: SAVE
3984
+ * Save key
3985
+ */
3986
+ rb_curses_define_const(KEY_SAVE);
3987
+ rb_define_const(mKey, "SAVE", INT2NUM(KEY_SAVE));
3988
+ #endif
3989
+ #ifdef KEY_SBEG
3990
+ /* Document-const: KEY_SBEG
3991
+ * Shifted beginning key
3992
+ */
3993
+ /* Document-const: SBEG
3994
+ * Shifted beginning key
3995
+ */
3996
+ rb_curses_define_const(KEY_SBEG);
3997
+ rb_define_const(mKey, "SBEG", INT2NUM(KEY_SBEG));
3998
+ #endif
3999
+ #ifdef KEY_SCANCEL
4000
+ /* Document-const: KEY_SCANCEL
4001
+ * Shifted cancel key
4002
+ */
4003
+ /* Document-const: SCANCEL
4004
+ * Shifted cancel key
4005
+ */
4006
+ rb_curses_define_const(KEY_SCANCEL);
4007
+ rb_define_const(mKey, "SCANCEL", INT2NUM(KEY_SCANCEL));
4008
+ #endif
4009
+ #ifdef KEY_SCOMMAND
4010
+ /* Document-const: KEY_SCOMMAND
4011
+ * Shifted command key
4012
+ */
4013
+ /* Document-const: SCOMMAND
4014
+ * Shifted command key
4015
+ */
4016
+ rb_curses_define_const(KEY_SCOMMAND);
4017
+ rb_define_const(mKey, "SCOMMAND", INT2NUM(KEY_SCOMMAND));
4018
+ #endif
4019
+ #ifdef KEY_SCOPY
4020
+ /* Document-const: KEY_SCOPY
4021
+ * Shifted copy key
4022
+ */
4023
+ /* Document-const: SCOPY
4024
+ * Shifted copy key
4025
+ */
4026
+ rb_curses_define_const(KEY_SCOPY);
4027
+ rb_define_const(mKey, "SCOPY", INT2NUM(KEY_SCOPY));
4028
+ #endif
4029
+ #ifdef KEY_SCREATE
4030
+ /* Document-const: KEY_SCREATE
4031
+ * Shifted create key
4032
+ */
4033
+ /* Document-const: SCREATE
4034
+ * Shifted create key
4035
+ */
4036
+ rb_curses_define_const(KEY_SCREATE);
4037
+ rb_define_const(mKey, "SCREATE", INT2NUM(KEY_SCREATE));
4038
+ #endif
4039
+ #ifdef KEY_SDC
4040
+ /* Document-const: KEY_SDC
4041
+ * Shifted delete char key
4042
+ */
4043
+ /* Document-const: SDC
4044
+ * Shifted delete char key
4045
+ */
4046
+ rb_curses_define_const(KEY_SDC);
4047
+ rb_define_const(mKey, "SDC", INT2NUM(KEY_SDC));
4048
+ #endif
4049
+ #ifdef KEY_SDL
4050
+ /* Document-const: KEY_SDL
4051
+ * Shifted delete line key
4052
+ */
4053
+ /* Document-const: SDL
4054
+ * Shifted delete line key
4055
+ */
4056
+ rb_curses_define_const(KEY_SDL);
4057
+ rb_define_const(mKey, "SDL", INT2NUM(KEY_SDL));
4058
+ #endif
4059
+ #ifdef KEY_SELECT
4060
+ /* Document-const: KEY_SELECT
4061
+ * Select key
4062
+ */
4063
+ /* Document-const: SELECT
4064
+ * Select key
4065
+ */
4066
+ rb_curses_define_const(KEY_SELECT);
4067
+ rb_define_const(mKey, "SELECT", INT2NUM(KEY_SELECT));
4068
+ #endif
4069
+ #ifdef KEY_SEND
4070
+ /* Document-const: KEY_SEND
4071
+ * Shifted end key
4072
+ */
4073
+ /* Document-const: SEND
4074
+ * Shifted end key
4075
+ */
4076
+ rb_curses_define_const(KEY_SEND);
4077
+ rb_define_const(mKey, "SEND", INT2NUM(KEY_SEND));
4078
+ #endif
4079
+ #ifdef KEY_SEOL
4080
+ /* Document-const: KEY_SEOL
4081
+ * Shifted clear line key
4082
+ */
4083
+ /* Document-const: SEOL
4084
+ * Shifted clear line key
4085
+ */
4086
+ rb_curses_define_const(KEY_SEOL);
4087
+ rb_define_const(mKey, "SEOL", INT2NUM(KEY_SEOL));
4088
+ #endif
4089
+ #ifdef KEY_SEXIT
4090
+ /* Document-const: KEY_SEXIT
4091
+ * Shifted exit key
4092
+ */
4093
+ /* Document-const: SEXIT
4094
+ * Shifted exit key
4095
+ */
4096
+ rb_curses_define_const(KEY_SEXIT);
4097
+ rb_define_const(mKey, "SEXIT", INT2NUM(KEY_SEXIT));
4098
+ #endif
4099
+ #ifdef KEY_SFIND
4100
+ /* Document-const: KEY_SFIND
4101
+ * Shifted find key
4102
+ */
4103
+ /* Document-const: SFIND
4104
+ * Shifted find key
4105
+ */
4106
+ rb_curses_define_const(KEY_SFIND);
4107
+ rb_define_const(mKey, "SFIND", INT2NUM(KEY_SFIND));
4108
+ #endif
4109
+ #ifdef KEY_SHELP
4110
+ /* Document-const: KEY_SHELP
4111
+ * Shifted help key
4112
+ */
4113
+ /* Document-const: SHELP
4114
+ * Shifted help key
4115
+ */
4116
+ rb_curses_define_const(KEY_SHELP);
4117
+ rb_define_const(mKey, "SHELP", INT2NUM(KEY_SHELP));
4118
+ #endif
4119
+ #ifdef KEY_SHOME
4120
+ /* Document-const: KEY_SHOME
4121
+ * Shifted home key
4122
+ */
4123
+ /* Document-const: SHOME
4124
+ * Shifted home key
4125
+ */
4126
+ rb_curses_define_const(KEY_SHOME);
4127
+ rb_define_const(mKey, "SHOME", INT2NUM(KEY_SHOME));
4128
+ #endif
4129
+ #ifdef KEY_SIC
4130
+ /* Document-const: KEY_SIC
4131
+ * Shifted input key
4132
+ */
4133
+ /* Document-const: SIC
4134
+ * Shifted input key
4135
+ */
4136
+ rb_curses_define_const(KEY_SIC);
4137
+ rb_define_const(mKey, "SIC", INT2NUM(KEY_SIC));
4138
+ #endif
4139
+ #ifdef KEY_SLEFT
4140
+ /* Document-const: KEY_SLEFT
4141
+ * Shifted left arrow key
4142
+ */
4143
+ /* Document-const: SLEFT
4144
+ * Shifted left arrow key
4145
+ */
4146
+ rb_curses_define_const(KEY_SLEFT);
4147
+ rb_define_const(mKey, "SLEFT", INT2NUM(KEY_SLEFT));
4148
+ #endif
4149
+ #ifdef KEY_SMESSAGE
4150
+ /* Document-const: KEY_SMESSAGE
4151
+ * Shifted message key
4152
+ */
4153
+ /* Document-const: SMESSAGE
4154
+ * Shifted message key
4155
+ */
4156
+ rb_curses_define_const(KEY_SMESSAGE);
4157
+ rb_define_const(mKey, "SMESSAGE", INT2NUM(KEY_SMESSAGE));
4158
+ #endif
4159
+ #ifdef KEY_SMOVE
4160
+ /* Document-const: KEY_SMOVE
4161
+ * Shifted move key
4162
+ */
4163
+ /* Document-const: SMOVE
4164
+ * Shifted move key
4165
+ */
4166
+ rb_curses_define_const(KEY_SMOVE);
4167
+ rb_define_const(mKey, "SMOVE", INT2NUM(KEY_SMOVE));
4168
+ #endif
4169
+ #ifdef KEY_SNEXT
4170
+ /* Document-const: KEY_SNEXT
4171
+ * Shifted next key
4172
+ */
4173
+ /* Document-const: SNEXT
4174
+ * Shifted next key
4175
+ */
4176
+ rb_curses_define_const(KEY_SNEXT);
4177
+ rb_define_const(mKey, "SNEXT", INT2NUM(KEY_SNEXT));
4178
+ #endif
4179
+ #ifdef KEY_SOPTIONS
4180
+ /* Document-const: KEY_SOPTIONS
4181
+ * Shifted options key
4182
+ */
4183
+ /* Document-const: SOPTIONS
4184
+ * Shifted options key
4185
+ */
4186
+ rb_curses_define_const(KEY_SOPTIONS);
4187
+ rb_define_const(mKey, "SOPTIONS", INT2NUM(KEY_SOPTIONS));
4188
+ #endif
4189
+ #ifdef KEY_SPREVIOUS
4190
+ /* Document-const: KEY_SPREVIOUS
4191
+ * Shifted previous key
4192
+ */
4193
+ /* Document-const: SPREVIOUS
4194
+ * Shifted previous key
4195
+ */
4196
+ rb_curses_define_const(KEY_SPREVIOUS);
4197
+ rb_define_const(mKey, "SPREVIOUS", INT2NUM(KEY_SPREVIOUS));
4198
+ #endif
4199
+ #ifdef KEY_SPRINT
4200
+ /* Document-const: KEY_SPRINT
4201
+ * Shifted print key
4202
+ */
4203
+ /* Document-const: SPRINT
4204
+ * Shifted print key
4205
+ */
4206
+ rb_curses_define_const(KEY_SPRINT);
4207
+ rb_define_const(mKey, "SPRINT", INT2NUM(KEY_SPRINT));
4208
+ #endif
4209
+ #ifdef KEY_SREDO
4210
+ /* Document-const: KEY_SREDO
4211
+ * Shifted redo key
4212
+ */
4213
+ /* Document-const: SREDO
4214
+ * Shifted redo key
4215
+ */
4216
+ rb_curses_define_const(KEY_SREDO);
4217
+ rb_define_const(mKey, "SREDO", INT2NUM(KEY_SREDO));
4218
+ #endif
4219
+ #ifdef KEY_SREPLACE
4220
+ /* Document-const: KEY_SREPLACE
4221
+ * Shifted replace key
4222
+ */
4223
+ /* Document-const: SREPLACE
4224
+ * Shifted replace key
4225
+ */
4226
+ rb_curses_define_const(KEY_SREPLACE);
4227
+ rb_define_const(mKey, "SREPLACE", INT2NUM(KEY_SREPLACE));
4228
+ #endif
4229
+ #ifdef KEY_SRIGHT
4230
+ /* Document-const: KEY_SRIGHT
4231
+ * Shifted right arrow key
4232
+ */
4233
+ /* Document-const: SRIGHT
4234
+ * Shifted right arrow key
4235
+ */
4236
+ rb_curses_define_const(KEY_SRIGHT);
4237
+ rb_define_const(mKey, "SRIGHT", INT2NUM(KEY_SRIGHT));
4238
+ #endif
4239
+ #ifdef KEY_SRSUME
4240
+ /* Document-const: KEY_SRSUME
4241
+ * Shifted resume key
4242
+ */
4243
+ /* Document-const: SRSUME
4244
+ * Shifted resume key
4245
+ */
4246
+ rb_curses_define_const(KEY_SRSUME);
4247
+ rb_define_const(mKey, "SRSUME", INT2NUM(KEY_SRSUME));
4248
+ #endif
4249
+ #ifdef KEY_SSAVE
4250
+ /* Document-const: KEY_SSAVE
4251
+ * Shifted save key
4252
+ */
4253
+ /* Document-const: SSAVE
4254
+ * Shifted save key
4255
+ */
4256
+ rb_curses_define_const(KEY_SSAVE);
4257
+ rb_define_const(mKey, "SSAVE", INT2NUM(KEY_SSAVE));
4258
+ #endif
4259
+ #ifdef KEY_SSUSPEND
4260
+ /* Document-const: KEY_SSUSPEND
4261
+ * Shifted suspend key
4262
+ */
4263
+ /* Document-const: SSUSPEND
4264
+ * Shifted suspend key
4265
+ */
4266
+ rb_curses_define_const(KEY_SSUSPEND);
4267
+ rb_define_const(mKey, "SSUSPEND", INT2NUM(KEY_SSUSPEND));
4268
+ #endif
4269
+ #ifdef KEY_SUNDO
4270
+ /* Document-const: KEY_SUNDO
4271
+ * Shifted undo key
4272
+ */
4273
+ /* Document-const: SUNDO
4274
+ * Shifted undo key
4275
+ */
4276
+ rb_curses_define_const(KEY_SUNDO);
4277
+ rb_define_const(mKey, "SUNDO", INT2NUM(KEY_SUNDO));
4278
+ #endif
4279
+ #ifdef KEY_SUSPEND
4280
+ /* Document-const: KEY_SUSPEND
4281
+ * Suspend key
4282
+ */
4283
+ /* Document-const: SUSPEND
4284
+ * Suspend key
4285
+ */
4286
+ rb_curses_define_const(KEY_SUSPEND);
4287
+ rb_define_const(mKey, "SUSPEND", INT2NUM(KEY_SUSPEND));
4288
+ #endif
4289
+ #ifdef KEY_UNDO
4290
+ /* Document-const: KEY_UNDO
4291
+ * Undo key
4292
+ */
4293
+ /* Document-const: UNDO
4294
+ * Undo key
4295
+ */
4296
+ rb_curses_define_const(KEY_UNDO);
4297
+ rb_define_const(mKey, "UNDO", INT2NUM(KEY_UNDO));
4298
+ #endif
4299
+ #ifdef KEY_RESIZE
4300
+ /* Document-const: KEY_RESIZE
4301
+ * Screen Resized
4302
+ */
4303
+ /* Document-const: RESIZE
4304
+ * Screen Resized
4305
+ */
4306
+ rb_curses_define_const(KEY_RESIZE);
4307
+ rb_define_const(mKey, "RESIZE", INT2NUM(KEY_RESIZE));
4308
+ #endif
4309
+ #ifdef KEY_MAX
4310
+ /* Document-const: KEY_MAX
4311
+ * The maximum allowed curses key value.
4312
+ */
4313
+ /* Document-const: MAX
4314
+ * The maximum allowed curses key value.
4315
+ */
4316
+ rb_curses_define_const(KEY_MAX);
4317
+ rb_define_const(mKey, "MAX", INT2NUM(KEY_MAX));
4318
+ #endif
4319
+ {
4320
+ int c;
4321
+ char name[] = "KEY_CTRL_x";
4322
+ for (c = 'A'; c <= 'Z'; c++) {
4323
+ name[sizeof(name) - 2] = c;
4324
+ rb_define_const(mCurses, name, INT2FIX(c - 'A' + 1));
4325
+ }
4326
+ }
4327
+ #undef rb_curses_define_const
4328
+
4329
+ rb_set_end_proc(curses_finalize, 0);
4330
+ }