curses 1.1.0-x86-mingw32

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