rubysl-curses 1.0.0

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: 479a6a30a2387c020f20b86d3ca3fe635447671b
4
+ data.tar.gz: 832e85d87af5bb831b49a3e4ab497fcddf5598df
5
+ SHA512:
6
+ metadata.gz: ca116304af1d590e23b831b0c921e636c7f1c123de46d89ea673ba20ee147827a608606fb2d07b8248a1c9177fcdca901a655781bb533fc9d7239edd7cd575d9
7
+ data.tar.gz: 991b9a2cb5a29ebf9fc53a626acfdfdf739a1b6ee003a5cd40687f5ae84546817be7e029878e2264af09fdad3fec0b57a2a1436dfaa32054fe454141a85c9af8
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .rbx
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: ruby
2
+ before_install:
3
+ - gem update --system
4
+ - gem --version
5
+ - gem install rubysl-bundler
6
+ script: bundle exec mspec spec
7
+ rvm:
8
+ - rbx-nightly-18mode
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rubysl-curses.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,25 @@
1
+ Copyright (c) 2013, Brian Shirai
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ 1. Redistributions of source code must retain the above copyright notice, this
8
+ list of conditions and the following disclaimer.
9
+ 2. Redistributions in binary form must reproduce the above copyright notice,
10
+ this list of conditions and the following disclaimer in the documentation
11
+ and/or other materials provided with the distribution.
12
+ 3. Neither the name of the library nor the names of its contributors may be
13
+ used to endorse or promote products derived from this software without
14
+ specific prior written permission.
15
+
16
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19
+ DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY DIRECT,
20
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
23
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
24
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
25
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # RubySL::Curses
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rubysl-curses'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install rubysl-curses
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,2134 @@
1
+ /* -*- C -*-
2
+ * $Id: curses.c 25899 2009-11-24 07:02:04Z shyouhei $
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
+
16
+ #include "ruby.h"
17
+ #include "rubyio.h"
18
+
19
+ #if defined(HAVE_NCURSES_H)
20
+ # include <ncurses.h>
21
+ #elif defined(HAVE_NCURSES_CURSES_H)
22
+ # include <ncurses/curses.h>
23
+ #elif defined(HAVE_CURSES_COLR_CURSES_H)
24
+ # ifdef HAVE_STDARG_PROTOTYPES
25
+ # include <stdarg.h>
26
+ # else
27
+ # include <varargs.h>
28
+ # endif
29
+ # include <curses_colr/curses.h>
30
+ #else
31
+ # include <curses.h>
32
+ # if defined(__bsdi__) || defined(__NetBSD__) || defined(__APPLE__)
33
+ # if !defined(_maxx)
34
+ # define _maxx maxx
35
+ # endif
36
+ # if !defined(_maxy)
37
+ # define _maxy maxy
38
+ # endif
39
+ # if !defined(_begx)
40
+ # define _begx begx
41
+ # endif
42
+ # if !defined(_begy)
43
+ # define _begy begy
44
+ # endif
45
+ # endif
46
+ #endif
47
+
48
+ #ifdef HAVE_INIT_COLOR
49
+ # define USE_COLOR 1
50
+ #endif
51
+
52
+ /* supports only ncurses mouse routines */
53
+ #ifdef NCURSES_MOUSE_VERSION
54
+ # define USE_MOUSE 1
55
+ #endif
56
+
57
+ #define NUM2CH NUM2LONG
58
+ #define CH2FIX LONG2FIX
59
+
60
+ static VALUE mCurses;
61
+ static VALUE mKey;
62
+ static VALUE cWindow;
63
+ #ifdef USE_MOUSE
64
+ static VALUE cMouseEvent;
65
+ #endif
66
+
67
+ static VALUE rb_stdscr;
68
+
69
+ struct windata {
70
+ WINDOW *window;
71
+ };
72
+
73
+ #define CHECK(c) c
74
+
75
+ static VALUE window_attroff();
76
+ static VALUE window_attron();
77
+ static VALUE window_attrset();
78
+
79
+ static void
80
+ no_window()
81
+ {
82
+ rb_raise(rb_eRuntimeError, "already closed window");
83
+ }
84
+
85
+ #define GetWINDOW(obj, winp) do {\
86
+ if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)\
87
+ rb_raise(rb_eSecurityError, "Insecure: operation on untainted window");\
88
+ Data_Get_Struct(obj, struct windata, winp);\
89
+ if (winp->window == 0) no_window();\
90
+ } while (0)
91
+
92
+ static void
93
+ free_window(winp)
94
+ struct windata *winp;
95
+ {
96
+ if (winp->window && winp->window != stdscr) delwin(winp->window);
97
+ winp->window = 0;
98
+ free(winp);
99
+ }
100
+
101
+ static VALUE
102
+ prep_window(class, window)
103
+ VALUE class;
104
+ WINDOW *window;
105
+ {
106
+ VALUE obj;
107
+ struct windata *winp;
108
+
109
+ if (window == NULL) {
110
+ rb_raise(rb_eRuntimeError, "failed to create window");
111
+ }
112
+
113
+ obj = rb_obj_alloc(class);
114
+ Data_Get_Struct(obj, struct windata, winp);
115
+ winp->window = window;
116
+
117
+ return obj;
118
+ }
119
+
120
+ /*-------------------------- module Curses --------------------------*/
121
+
122
+ /* def init_screen */
123
+ static VALUE
124
+ curses_init_screen()
125
+ {
126
+ rb_secure(4);
127
+ if (rb_stdscr) return rb_stdscr;
128
+ initscr();
129
+ if (stdscr == 0) {
130
+ rb_raise(rb_eRuntimeError, "can't initialize curses");
131
+ }
132
+ clear();
133
+ rb_stdscr = prep_window(cWindow, stdscr);
134
+ return rb_stdscr;
135
+ }
136
+
137
+ /* def stdscr */
138
+ #define curses_stdscr curses_init_screen
139
+
140
+ /* def close_screen */
141
+ static VALUE
142
+ curses_close_screen()
143
+ {
144
+ curses_stdscr();
145
+ #ifdef HAVE_ISENDWIN
146
+ if (!isendwin())
147
+ #endif
148
+ endwin();
149
+ rb_stdscr = 0;
150
+ return Qnil;
151
+ }
152
+
153
+ static void
154
+ curses_finalize(VALUE dummy)
155
+ {
156
+ if (stdscr
157
+ #ifdef HAVE_ISENDWIN
158
+ && !isendwin()
159
+ #endif
160
+ )
161
+ endwin();
162
+ rb_stdscr = 0;
163
+ rb_gc_unregister_address(&rb_stdscr);
164
+ }
165
+
166
+ /* def closed? */
167
+ static VALUE
168
+ curses_closed()
169
+ {
170
+ #ifdef HAVE_ISENDWIN
171
+ curses_stdscr();
172
+ if (isendwin()) {
173
+ return Qtrue;
174
+ }
175
+ return Qfalse;
176
+ #else
177
+ rb_notimplement();
178
+ #endif
179
+ }
180
+
181
+ /* def clear */
182
+ static VALUE
183
+ curses_clear(obj)
184
+ VALUE obj;
185
+ {
186
+ curses_stdscr();
187
+ wclear(stdscr);
188
+ return Qnil;
189
+ }
190
+
191
+ /* def clrtoeol */
192
+ static VALUE
193
+ curses_clrtoeol()
194
+ {
195
+ curses_stdscr();
196
+ clrtoeol();
197
+ return Qnil;
198
+ }
199
+
200
+ /* def refresh */
201
+ static VALUE
202
+ curses_refresh(obj)
203
+ VALUE obj;
204
+ {
205
+ curses_stdscr();
206
+ refresh();
207
+ return Qnil;
208
+ }
209
+
210
+ /* def doupdate */
211
+ static VALUE
212
+ curses_doupdate(obj)
213
+ VALUE obj;
214
+ {
215
+ curses_stdscr();
216
+ #ifdef HAVE_DOUPDATE
217
+ doupdate();
218
+ #else
219
+ refresh();
220
+ #endif
221
+ return Qnil;
222
+ }
223
+
224
+ /* def echo */
225
+ static VALUE
226
+ curses_echo(obj)
227
+ VALUE obj;
228
+ {
229
+ curses_stdscr();
230
+ echo();
231
+ return Qnil;
232
+ }
233
+
234
+ /* def noecho */
235
+ static VALUE
236
+ curses_noecho(obj)
237
+ VALUE obj;
238
+ {
239
+ curses_stdscr();
240
+ noecho();
241
+ return Qnil;
242
+ }
243
+
244
+ /* def raw */
245
+ static VALUE
246
+ curses_raw(obj)
247
+ VALUE obj;
248
+ {
249
+ curses_stdscr();
250
+ raw();
251
+ return Qnil;
252
+ }
253
+
254
+ /* def noraw */
255
+ static VALUE
256
+ curses_noraw(obj)
257
+ VALUE obj;
258
+ {
259
+ curses_stdscr();
260
+ noraw();
261
+ return Qnil;
262
+ }
263
+
264
+ /* def cbreak */
265
+ static VALUE
266
+ curses_cbreak(obj)
267
+ VALUE obj;
268
+ {
269
+ curses_stdscr();
270
+ cbreak();
271
+ return Qnil;
272
+ }
273
+
274
+ /* def nocbreak */
275
+ static VALUE
276
+ curses_nocbreak(obj)
277
+ VALUE obj;
278
+ {
279
+ curses_stdscr();
280
+ nocbreak();
281
+ return Qnil;
282
+ }
283
+
284
+ /* def nl */
285
+ static VALUE
286
+ curses_nl(obj)
287
+ VALUE obj;
288
+ {
289
+ curses_stdscr();
290
+ nl();
291
+ return Qnil;
292
+ }
293
+
294
+ /* def nonl */
295
+ static VALUE
296
+ curses_nonl(obj)
297
+ VALUE obj;
298
+ {
299
+ curses_stdscr();
300
+ nonl();
301
+ return Qnil;
302
+ }
303
+
304
+ /* def beep */
305
+ static VALUE
306
+ curses_beep(obj)
307
+ VALUE obj;
308
+ {
309
+ #ifdef HAVE_BEEP
310
+ curses_stdscr();
311
+ beep();
312
+ #endif
313
+ return Qnil;
314
+ }
315
+
316
+ /* def flash */
317
+ static VALUE
318
+ curses_flash(obj)
319
+ VALUE obj;
320
+ {
321
+ #ifdef HAVE_FLASH
322
+ curses_stdscr();
323
+ flash();
324
+ #endif
325
+ return Qnil;
326
+ }
327
+
328
+ /* def ungetch */
329
+ static VALUE
330
+ curses_ungetch(obj, ch)
331
+ VALUE obj;
332
+ VALUE ch;
333
+ {
334
+ #ifdef HAVE_UNGETCH
335
+ curses_stdscr();
336
+ ungetch(NUM2INT(ch));
337
+ #else
338
+ rb_notimplement();
339
+ #endif
340
+ return Qnil;
341
+ }
342
+
343
+ /* def setpos(y, x) */
344
+ static VALUE
345
+ curses_setpos(obj, y, x)
346
+ VALUE obj;
347
+ VALUE y;
348
+ VALUE x;
349
+ {
350
+ curses_stdscr();
351
+ move(NUM2INT(y), NUM2INT(x));
352
+ return Qnil;
353
+ }
354
+
355
+ /* def standout */
356
+ static VALUE
357
+ curses_standout(obj)
358
+ VALUE obj;
359
+ {
360
+ curses_stdscr();
361
+ standout();
362
+ return Qnil;
363
+ }
364
+
365
+ /* def standend */
366
+ static VALUE
367
+ curses_standend(obj)
368
+ VALUE obj;
369
+ {
370
+ curses_stdscr();
371
+ standend();
372
+ return Qnil;
373
+ }
374
+
375
+ /* def inch */
376
+ static VALUE
377
+ curses_inch(obj)
378
+ VALUE obj;
379
+ {
380
+ curses_stdscr();
381
+ return CH2FIX(inch());
382
+ }
383
+
384
+ /* def addch(ch) */
385
+ static VALUE
386
+ curses_addch(obj, ch)
387
+ VALUE obj;
388
+ VALUE ch;
389
+ {
390
+ curses_stdscr();
391
+ addch(NUM2CH(ch));
392
+ return Qnil;
393
+ }
394
+
395
+ /* def insch(ch) */
396
+ static VALUE
397
+ curses_insch(obj, ch)
398
+ VALUE obj;
399
+ VALUE ch;
400
+ {
401
+ curses_stdscr();
402
+ insch(NUM2CH(ch));
403
+ return Qnil;
404
+ }
405
+
406
+ /* def addstr(str) */
407
+ static VALUE
408
+ curses_addstr(obj, str)
409
+ VALUE obj;
410
+ VALUE str;
411
+ {
412
+ curses_stdscr();
413
+ if (!NIL_P(str)) {
414
+ addstr(STR2CSTR(str));
415
+ }
416
+ return Qnil;
417
+ }
418
+
419
+ /* def getch */
420
+ static VALUE
421
+ curses_getch(obj)
422
+ VALUE obj;
423
+ {
424
+ rb_read_check(stdin);
425
+ curses_stdscr();
426
+ return UINT2NUM(getch());
427
+ }
428
+
429
+ /* def getstr */
430
+ static VALUE
431
+ curses_getstr(obj)
432
+ VALUE obj;
433
+ {
434
+ char rtn[1024]; /* This should be big enough.. I hope */
435
+
436
+ curses_stdscr();
437
+ rb_read_check(stdin);
438
+ #if defined(HAVE_GETNSTR)
439
+ getnstr(rtn,1023);
440
+ #else
441
+ getstr(rtn);
442
+ #endif
443
+ return rb_tainted_str_new2(rtn);
444
+ }
445
+
446
+ /* def delch */
447
+ static VALUE
448
+ curses_delch(obj)
449
+ VALUE obj;
450
+ {
451
+ curses_stdscr();
452
+ delch();
453
+ return Qnil;
454
+ }
455
+
456
+ /* def delelteln */
457
+ static VALUE
458
+ curses_deleteln(obj)
459
+ VALUE obj;
460
+ {
461
+ curses_stdscr();
462
+ #if defined(HAVE_DELETELN) || defined(deleteln)
463
+ deleteln();
464
+ #endif
465
+ return Qnil;
466
+ }
467
+
468
+ /* def insertln */
469
+ static VALUE
470
+ curses_insertln(obj)
471
+ VALUE obj;
472
+ {
473
+ curses_stdscr();
474
+ #if defined(HAVE_INSERTLN) || defined(insertln)
475
+ insertln();
476
+ #endif
477
+ return Qnil;
478
+ }
479
+
480
+ /* def keyname */
481
+ static VALUE
482
+ curses_keyname(obj, c)
483
+ VALUE obj;
484
+ VALUE c;
485
+ {
486
+ #ifdef HAVE_KEYNAME
487
+ const char *name;
488
+
489
+ curses_stdscr();
490
+ name = keyname(NUM2INT(c));
491
+ if (name) {
492
+ return rb_str_new2(name);
493
+ } else {
494
+ return Qnil;
495
+ }
496
+ #else
497
+ return Qnil;
498
+ #endif
499
+ }
500
+
501
+ static VALUE
502
+ curses_lines()
503
+ {
504
+ return INT2FIX(LINES);
505
+ }
506
+
507
+ static VALUE
508
+ curses_cols()
509
+ {
510
+ return INT2FIX(COLS);
511
+ }
512
+
513
+ static VALUE
514
+ curses_curs_set(VALUE obj, VALUE visibility)
515
+ {
516
+ #ifdef HAVE_CURS_SET
517
+ int n;
518
+ curses_stdscr();
519
+ return (n = curs_set(NUM2INT(visibility)) != ERR) ? INT2FIX(n) : Qnil;
520
+ #else
521
+ return Qnil;
522
+ #endif
523
+ }
524
+
525
+ static VALUE
526
+ curses_scrl(VALUE obj, VALUE n)
527
+ {
528
+ /* may have to raise exception on ERR */
529
+ #ifdef HAVE_SCRL
530
+ curses_stdscr();
531
+ return (scrl(NUM2INT(n)) == OK) ? Qtrue : Qfalse;
532
+ #else
533
+ return Qfalse;
534
+ #endif
535
+ }
536
+
537
+ static VALUE
538
+ curses_setscrreg(VALUE obj, VALUE top, VALUE bottom)
539
+ {
540
+ /* may have to raise exception on ERR */
541
+ #ifdef HAVE_SETSCRREG
542
+ curses_stdscr();
543
+ return (setscrreg(NUM2INT(top), NUM2INT(bottom)) == OK) ? Qtrue : Qfalse;
544
+ #else
545
+ return Qfalse;
546
+ #endif
547
+ }
548
+
549
+ static VALUE
550
+ curses_attroff(VALUE obj, VALUE attrs)
551
+ {
552
+ curses_stdscr();
553
+ return window_attroff(rb_stdscr,attrs);
554
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
555
+ }
556
+
557
+ static VALUE
558
+ curses_attron(VALUE obj, VALUE attrs)
559
+ {
560
+ curses_stdscr();
561
+ return window_attron(rb_stdscr,attrs);
562
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
563
+ }
564
+
565
+ static VALUE
566
+ curses_attrset(VALUE obj, VALUE attrs)
567
+ {
568
+ curses_stdscr();
569
+ return window_attrset(rb_stdscr,attrs);
570
+ /* return INT2FIX(attroff(NUM2INT(attrs))); */
571
+ }
572
+
573
+ static VALUE
574
+ curses_bkgdset(VALUE obj, VALUE ch)
575
+ {
576
+ #ifdef HAVE_BKGDSET
577
+ curses_stdscr();
578
+ bkgdset(NUM2CH(ch));
579
+ #endif
580
+ return Qnil;
581
+ }
582
+
583
+ static VALUE
584
+ curses_bkgd(VALUE obj, VALUE ch)
585
+ {
586
+ #ifdef HAVE_BKGD
587
+ curses_stdscr();
588
+ return (bkgd(NUM2CH(ch)) == OK) ? Qtrue : Qfalse;
589
+ #else
590
+ return Qfalse;
591
+ #endif
592
+ }
593
+
594
+ static VALUE
595
+ curses_resizeterm(VALUE obj, VALUE lin, VALUE col)
596
+ {
597
+ #if defined(HAVE_RESIZETERM)
598
+ curses_stdscr();
599
+ return (resizeterm(NUM2INT(lin),NUM2INT(col)) == OK) ? Qtrue : Qfalse;
600
+ #else
601
+ return Qnil;
602
+ #endif
603
+ }
604
+
605
+ #ifdef USE_COLOR
606
+ static VALUE
607
+ curses_start_color(VALUE obj)
608
+ {
609
+ /* may have to raise exception on ERR */
610
+ curses_stdscr();
611
+ return (start_color() == OK) ? Qtrue : Qfalse;
612
+ }
613
+
614
+ static VALUE
615
+ curses_init_pair(VALUE obj, VALUE pair, VALUE f, VALUE b)
616
+ {
617
+ /* may have to raise exception on ERR */
618
+ curses_stdscr();
619
+ return (init_pair(NUM2INT(pair),NUM2INT(f),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
620
+ }
621
+
622
+ static VALUE
623
+ curses_init_color(VALUE obj, VALUE color, VALUE r, VALUE g, VALUE b)
624
+ {
625
+ /* may have to raise exception on ERR */
626
+ curses_stdscr();
627
+ return (init_color(NUM2INT(color),NUM2INT(r),
628
+ NUM2INT(g),NUM2INT(b)) == OK) ? Qtrue : Qfalse;
629
+ }
630
+
631
+ static VALUE
632
+ curses_has_colors(VALUE obj)
633
+ {
634
+ curses_stdscr();
635
+ return has_colors() ? Qtrue : Qfalse;
636
+ }
637
+
638
+ static VALUE
639
+ curses_can_change_color(VALUE obj)
640
+ {
641
+ curses_stdscr();
642
+ return can_change_color() ? Qtrue : Qfalse;
643
+ }
644
+
645
+ static VALUE
646
+ curses_color_content(VALUE obj, VALUE color)
647
+ {
648
+ short r,g,b;
649
+
650
+ curses_stdscr();
651
+ color_content(NUM2INT(color),&r,&g,&b);
652
+ return rb_ary_new3(3,INT2FIX(r),INT2FIX(g),INT2FIX(b));
653
+ }
654
+
655
+ static VALUE
656
+ curses_pair_content(VALUE obj, VALUE pair)
657
+ {
658
+ short f,b;
659
+
660
+ curses_stdscr();
661
+ pair_content(NUM2INT(pair),&f,&b);
662
+ return rb_ary_new3(2,INT2FIX(f),INT2FIX(b));
663
+ }
664
+
665
+ static VALUE
666
+ curses_color_pair(VALUE obj, VALUE attrs)
667
+ {
668
+ return INT2FIX(COLOR_PAIR(NUM2INT(attrs)));
669
+ }
670
+
671
+ static VALUE
672
+ curses_pair_number(VALUE obj, VALUE attrs)
673
+ {
674
+ curses_stdscr();
675
+ return INT2FIX(PAIR_NUMBER(NUM2INT(attrs)));
676
+ }
677
+ #endif /* USE_COLOR */
678
+
679
+ #ifdef USE_MOUSE
680
+ struct mousedata {
681
+ MEVENT *mevent;
682
+ };
683
+
684
+ static void
685
+ no_mevent()
686
+ {
687
+ rb_raise(rb_eRuntimeError, "no such mouse event");
688
+ }
689
+
690
+ #define GetMOUSE(obj, data) do {\
691
+ if (!OBJ_TAINTED(obj) && rb_safe_level() >= 4)\
692
+ rb_raise(rb_eSecurityError, "Insecure: operation on untainted mouse");\
693
+ Data_Get_Struct(obj, struct mousedata, data);\
694
+ if (data->mevent == 0) no_mevent();\
695
+ } while (0)
696
+
697
+ static void
698
+ curses_mousedata_free(struct mousedata *mdata)
699
+ {
700
+ if (mdata->mevent)
701
+ free(mdata->mevent);
702
+ }
703
+
704
+ static VALUE
705
+ curses_getmouse(VALUE obj)
706
+ {
707
+ struct mousedata *mdata;
708
+ VALUE val;
709
+
710
+ curses_stdscr();
711
+ val = Data_Make_Struct(cMouseEvent,struct mousedata,
712
+ 0,curses_mousedata_free,mdata);
713
+ mdata->mevent = (MEVENT*)xmalloc(sizeof(MEVENT));
714
+ return (getmouse(mdata->mevent) == OK) ? val : Qnil;
715
+ }
716
+
717
+ static VALUE
718
+ curses_ungetmouse(VALUE obj, VALUE mevent)
719
+ {
720
+ struct mousedata *mdata;
721
+
722
+ curses_stdscr();
723
+ GetMOUSE(mevent,mdata);
724
+ return (ungetmouse(mdata->mevent) == OK) ? Qtrue : Qfalse;
725
+ }
726
+
727
+ static VALUE
728
+ curses_mouseinterval(VALUE obj, VALUE interval)
729
+ {
730
+ curses_stdscr();
731
+ return mouseinterval(NUM2INT(interval)) ? Qtrue : Qfalse;
732
+ }
733
+
734
+ static VALUE
735
+ curses_mousemask(VALUE obj, VALUE mask)
736
+ {
737
+ curses_stdscr();
738
+ return INT2NUM(mousemask(NUM2UINT(mask),NULL));
739
+ }
740
+
741
+ #define DEFINE_MOUSE_GET_MEMBER(func_name,mem) \
742
+ static VALUE func_name (VALUE mouse) \
743
+ { \
744
+ struct mousedata *mdata; \
745
+ GetMOUSE(mouse, mdata); \
746
+ return (UINT2NUM(mdata->mevent -> mem)); \
747
+ }
748
+
749
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_id, id)
750
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_x, x)
751
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_y, y)
752
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_z, z)
753
+ DEFINE_MOUSE_GET_MEMBER(curs_mouse_bstate, bstate)
754
+ #undef define_curs_mouse_member
755
+ #endif /* USE_MOUSE */
756
+
757
+ static VALUE
758
+ curses_timeout(VALUE obj, VALUE delay)
759
+ {
760
+ #ifdef HAVE_TIMEOUT
761
+ curses_stdscr();
762
+ timeout(NUM2INT(delay));
763
+ return Qnil;
764
+ #else
765
+ rb_notimplement();
766
+ #endif
767
+ }
768
+
769
+ static VALUE
770
+ curses_def_prog_mode(VALUE obj)
771
+ {
772
+ #ifdef HAVE_DEF_PROG_MODE
773
+ curses_stdscr();
774
+ return def_prog_mode() == OK ? Qtrue : Qfalse;
775
+ #else
776
+ rb_notimplement();
777
+ #endif
778
+ }
779
+
780
+ static VALUE
781
+ curses_reset_prog_mode(VALUE obj)
782
+ {
783
+ #ifdef HAVE_RESET_PROG_MODE
784
+ curses_stdscr();
785
+ return reset_prog_mode() == OK ? Qtrue : Qfalse;
786
+ #else
787
+ rb_notimplement();
788
+ #endif
789
+ }
790
+
791
+ /*-------------------------- class Window --------------------------*/
792
+
793
+ /* def self.allocate */
794
+ static VALUE
795
+ window_s_allocate(VALUE class)
796
+ {
797
+ struct windata *winp;
798
+
799
+ return Data_Make_Struct(class, struct windata, 0, free_window, winp);
800
+ }
801
+
802
+ /* def initialize(h, w, top, left) */
803
+ static VALUE
804
+ window_initialize(obj, h, w, top, left)
805
+ VALUE obj;
806
+ VALUE h;
807
+ VALUE w;
808
+ VALUE top;
809
+ VALUE left;
810
+ {
811
+ struct windata *winp;
812
+ WINDOW *window;
813
+
814
+ rb_secure(4);
815
+ curses_init_screen();
816
+ Data_Get_Struct(obj, struct windata, winp);
817
+ if (winp->window) delwin(winp->window);
818
+ window = newwin(NUM2INT(h), NUM2INT(w), NUM2INT(top), NUM2INT(left));
819
+ wclear(window);
820
+ winp->window = window;
821
+
822
+ return obj;
823
+ }
824
+
825
+ /* def subwin(height, width, top, left) */
826
+ static VALUE
827
+ window_subwin(obj, height, width, top, left)
828
+ VALUE obj;
829
+ VALUE height;
830
+ VALUE width;
831
+ VALUE top;
832
+ VALUE left;
833
+ {
834
+ struct windata *winp;
835
+ WINDOW *window;
836
+ VALUE win;
837
+ int h, w, t, l;
838
+
839
+ h = NUM2INT(height);
840
+ w = NUM2INT(width);
841
+ t = NUM2INT(top);
842
+ l = NUM2INT(left);
843
+ GetWINDOW(obj, winp);
844
+ window = subwin(winp->window, h, w, t, l);
845
+ win = prep_window(rb_obj_class(obj), window);
846
+
847
+ return win;
848
+ }
849
+
850
+ /* def close */
851
+ static VALUE
852
+ window_close(obj)
853
+ VALUE obj;
854
+ {
855
+ struct windata *winp;
856
+
857
+ GetWINDOW(obj, winp);
858
+ delwin(winp->window);
859
+ winp->window = 0;
860
+
861
+ return Qnil;
862
+ }
863
+
864
+ /* def clear */
865
+ static VALUE
866
+ window_clear(obj)
867
+ VALUE obj;
868
+ {
869
+ struct windata *winp;
870
+
871
+ GetWINDOW(obj, winp);
872
+ wclear(winp->window);
873
+
874
+ return Qnil;
875
+ }
876
+
877
+ /* def clrtoeol */
878
+ static VALUE
879
+ window_clrtoeol(obj)
880
+ VALUE obj;
881
+ {
882
+ struct windata *winp;
883
+
884
+ GetWINDOW(obj, winp);
885
+ wclrtoeol(winp->window);
886
+
887
+ return Qnil;
888
+ }
889
+
890
+ /* def refresh */
891
+ static VALUE
892
+ window_refresh(obj)
893
+ VALUE obj;
894
+ {
895
+ struct windata *winp;
896
+
897
+ GetWINDOW(obj, winp);
898
+ wrefresh(winp->window);
899
+
900
+ return Qnil;
901
+ }
902
+
903
+ /* def noutrefresh */
904
+ static VALUE
905
+ window_noutrefresh(obj)
906
+ VALUE obj;
907
+ {
908
+ struct windata *winp;
909
+
910
+ GetWINDOW(obj, winp);
911
+ #ifdef HAVE_DOUPDATE
912
+ wnoutrefresh(winp->window);
913
+ #else
914
+ wrefresh(winp->window);
915
+ #endif
916
+
917
+ return Qnil;
918
+ }
919
+
920
+ /* def move(y, x) */
921
+ static VALUE
922
+ window_move(obj, y, x)
923
+ VALUE obj;
924
+ VALUE y;
925
+ VALUE x;
926
+ {
927
+ struct windata *winp;
928
+
929
+ GetWINDOW(obj, winp);
930
+ mvwin(winp->window, NUM2INT(y), NUM2INT(x));
931
+
932
+ return Qnil;
933
+ }
934
+
935
+ /* def setpos(y, x) */
936
+ static VALUE
937
+ window_setpos(obj, y, x)
938
+ VALUE obj;
939
+ VALUE y;
940
+ VALUE x;
941
+ {
942
+ struct windata *winp;
943
+
944
+ GetWINDOW(obj, winp);
945
+ wmove(winp->window, NUM2INT(y), NUM2INT(x));
946
+ return Qnil;
947
+ }
948
+
949
+ /* def cury */
950
+ static VALUE
951
+ window_cury(obj)
952
+ VALUE obj;
953
+ {
954
+ struct windata *winp;
955
+ int x, y;
956
+
957
+ GetWINDOW(obj, winp);
958
+ getyx(winp->window, y, x);
959
+ return INT2FIX(y);
960
+ }
961
+
962
+ /* def curx */
963
+ static VALUE
964
+ window_curx(obj)
965
+ VALUE obj;
966
+ {
967
+ struct windata *winp;
968
+ int x, y;
969
+
970
+ GetWINDOW(obj, winp);
971
+ getyx(winp->window, y, x);
972
+ return INT2FIX(x);
973
+ }
974
+
975
+ /* def maxy */
976
+ static VALUE
977
+ window_maxy(obj)
978
+ VALUE obj;
979
+ {
980
+ struct windata *winp;
981
+
982
+ GetWINDOW(obj, winp);
983
+ #if defined(getmaxy)
984
+ return INT2FIX(getmaxy(winp->window));
985
+ #elif defined(getmaxyx)
986
+ {
987
+ int x, y;
988
+ getmaxyx(winp->window, y, x);
989
+ return INT2FIX(y);
990
+ }
991
+ #else
992
+ return INT2FIX(winp->window->_maxy+1);
993
+ #endif
994
+ }
995
+
996
+ /* def maxx */
997
+ static VALUE
998
+ window_maxx(obj)
999
+ VALUE obj;
1000
+ {
1001
+ struct windata *winp;
1002
+
1003
+ GetWINDOW(obj, winp);
1004
+ #if defined(getmaxx)
1005
+ return INT2FIX(getmaxx(winp->window));
1006
+ #elif defined(getmaxyx)
1007
+ {
1008
+ int x, y;
1009
+ getmaxyx(winp->window, y, x);
1010
+ return INT2FIX(x);
1011
+ }
1012
+ #else
1013
+ return INT2FIX(winp->window->_maxx+1);
1014
+ #endif
1015
+ }
1016
+
1017
+ /* def begy */
1018
+ static VALUE
1019
+ window_begy(obj)
1020
+ VALUE obj;
1021
+ {
1022
+ struct windata *winp;
1023
+ int x, y;
1024
+
1025
+ GetWINDOW(obj, winp);
1026
+ #ifdef getbegyx
1027
+ getbegyx(winp->window, y, x);
1028
+ return INT2FIX(y);
1029
+ #else
1030
+ return INT2FIX(winp->window->_begy);
1031
+ #endif
1032
+ }
1033
+
1034
+ /* def begx */
1035
+ static VALUE
1036
+ window_begx(obj)
1037
+ VALUE obj;
1038
+ {
1039
+ struct windata *winp;
1040
+ int x, y;
1041
+
1042
+ GetWINDOW(obj, winp);
1043
+ #ifdef getbegyx
1044
+ getbegyx(winp->window, y, x);
1045
+ return INT2FIX(x);
1046
+ #else
1047
+ return INT2FIX(winp->window->_begx);
1048
+ #endif
1049
+ }
1050
+
1051
+ /* def box(vert, hor) */
1052
+ static VALUE
1053
+ window_box(argc, argv, self)
1054
+ int argc;
1055
+ VALUE argv[], self;
1056
+ {
1057
+ struct windata *winp;
1058
+ VALUE vert, hor, corn;
1059
+
1060
+ rb_scan_args(argc, argv, "21", &vert, &hor, &corn);
1061
+
1062
+ GetWINDOW(self, winp);
1063
+ box(winp->window, NUM2CH(vert), NUM2CH(hor));
1064
+
1065
+ if (!NIL_P(corn)) {
1066
+ int cur_x, cur_y, x, y;
1067
+ chtype c;
1068
+
1069
+ c = NUM2CH(corn);
1070
+ getyx(winp->window, cur_y, cur_x);
1071
+ x = NUM2INT(window_maxx(self)) - 1;
1072
+ y = NUM2INT(window_maxy(self)) - 1;
1073
+ wmove(winp->window, 0, 0);
1074
+ waddch(winp->window, c);
1075
+ wmove(winp->window, y, 0);
1076
+ waddch(winp->window, c);
1077
+ wmove(winp->window, y, x);
1078
+ waddch(winp->window, c);
1079
+ wmove(winp->window, 0, x);
1080
+ waddch(winp->window, c);
1081
+ wmove(winp->window, cur_y, cur_x);
1082
+ }
1083
+
1084
+ return Qnil;
1085
+ }
1086
+
1087
+ /* def standout */
1088
+ static VALUE
1089
+ window_standout(obj)
1090
+ VALUE obj;
1091
+ {
1092
+ struct windata *winp;
1093
+
1094
+ GetWINDOW(obj, winp);
1095
+ wstandout(winp->window);
1096
+ return Qnil;
1097
+ }
1098
+
1099
+ /* def standend */
1100
+ static VALUE
1101
+ window_standend(obj)
1102
+ VALUE obj;
1103
+ {
1104
+ struct windata *winp;
1105
+
1106
+ GetWINDOW(obj, winp);
1107
+ wstandend(winp->window);
1108
+ return Qnil;
1109
+ }
1110
+
1111
+ /* def inch */
1112
+ static VALUE
1113
+ window_inch(obj)
1114
+ VALUE obj;
1115
+ {
1116
+ struct windata *winp;
1117
+
1118
+ GetWINDOW(obj, winp);
1119
+ return CH2FIX(winch(winp->window));
1120
+ }
1121
+
1122
+ /* def addch(ch) */
1123
+ static VALUE
1124
+ window_addch(obj, ch)
1125
+ VALUE obj;
1126
+ VALUE ch;
1127
+ {
1128
+ struct windata *winp;
1129
+
1130
+ GetWINDOW(obj, winp);
1131
+ waddch(winp->window, NUM2CH(ch));
1132
+
1133
+ return Qnil;
1134
+ }
1135
+
1136
+ /* def insch(ch) */
1137
+ static VALUE
1138
+ window_insch(obj, ch)
1139
+ VALUE obj;
1140
+ VALUE ch;
1141
+ {
1142
+ struct windata *winp;
1143
+
1144
+ GetWINDOW(obj, winp);
1145
+ winsch(winp->window, NUM2CH(ch));
1146
+
1147
+ return Qnil;
1148
+ }
1149
+
1150
+ /* def addstr(str) */
1151
+ static VALUE
1152
+ window_addstr(obj, str)
1153
+ VALUE obj;
1154
+ VALUE str;
1155
+ {
1156
+ if (!NIL_P(str)) {
1157
+ struct windata *winp;
1158
+
1159
+ GetWINDOW(obj, winp);
1160
+ waddstr(winp->window, STR2CSTR(str));
1161
+ }
1162
+ return Qnil;
1163
+ }
1164
+
1165
+ /* def <<(str) */
1166
+ static VALUE
1167
+ window_addstr2(obj, str)
1168
+ VALUE obj;
1169
+ VALUE str;
1170
+ {
1171
+ window_addstr(obj, str);
1172
+ return obj;
1173
+ }
1174
+
1175
+ /* def getch */
1176
+ static VALUE
1177
+ window_getch(obj)
1178
+ VALUE obj;
1179
+ {
1180
+ struct windata *winp;
1181
+
1182
+ rb_read_check(stdin);
1183
+ GetWINDOW(obj, winp);
1184
+ return UINT2NUM(wgetch(winp->window));
1185
+ }
1186
+
1187
+ /* def getstr */
1188
+ static VALUE
1189
+ window_getstr(obj)
1190
+ VALUE obj;
1191
+ {
1192
+ struct windata *winp;
1193
+ char rtn[1024]; /* This should be big enough.. I hope */
1194
+
1195
+ GetWINDOW(obj, winp);
1196
+ rb_read_check(stdin);
1197
+ #if defined(HAVE_WGETNSTR)
1198
+ wgetnstr(winp->window, rtn, 1023);
1199
+ #else
1200
+ wgetstr(winp->window, rtn);
1201
+ #endif
1202
+ return rb_tainted_str_new2(rtn);
1203
+ }
1204
+
1205
+ /* def delch */
1206
+ static VALUE
1207
+ window_delch(obj)
1208
+ VALUE obj;
1209
+ {
1210
+ struct windata *winp;
1211
+
1212
+ GetWINDOW(obj, winp);
1213
+ wdelch(winp->window);
1214
+ return Qnil;
1215
+ }
1216
+
1217
+ /* def delelteln */
1218
+ static VALUE
1219
+ window_deleteln(obj)
1220
+ VALUE obj;
1221
+ {
1222
+ #if defined(HAVE_WDELETELN) || defined(wdeleteln)
1223
+ struct windata *winp;
1224
+
1225
+ GetWINDOW(obj, winp);
1226
+ wdeleteln(winp->window);
1227
+ #endif
1228
+ return Qnil;
1229
+ }
1230
+
1231
+ /* def insertln */
1232
+ static VALUE
1233
+ window_insertln(obj)
1234
+ VALUE obj;
1235
+ {
1236
+ #if defined(HAVE_WINSERTLN) || defined(winsertln)
1237
+ struct windata *winp;
1238
+
1239
+ GetWINDOW(obj, winp);
1240
+ winsertln(winp->window);
1241
+ #endif
1242
+ return Qnil;
1243
+ }
1244
+
1245
+ static VALUE
1246
+ window_scrollok(VALUE obj, VALUE bf)
1247
+ {
1248
+ struct windata *winp;
1249
+
1250
+ GetWINDOW(obj, winp);
1251
+ scrollok(winp->window, RTEST(bf) ? TRUE : FALSE);
1252
+ return Qnil;
1253
+ }
1254
+
1255
+ static VALUE
1256
+ window_idlok(VALUE obj, VALUE bf)
1257
+ {
1258
+ struct windata *winp;
1259
+
1260
+ GetWINDOW(obj, winp);
1261
+ idlok(winp->window, RTEST(bf) ? TRUE : FALSE);
1262
+ return Qnil;
1263
+ }
1264
+
1265
+ static VALUE
1266
+ window_setscrreg(VALUE obj, VALUE top, VALUE bottom)
1267
+ {
1268
+ #ifdef HAVE_WSETSCRREG
1269
+ struct windata *winp;
1270
+ int res;
1271
+
1272
+ GetWINDOW(obj, winp);
1273
+ res = wsetscrreg(winp->window, NUM2INT(top), NUM2INT(bottom));
1274
+ /* may have to raise exception on ERR */
1275
+ return (res == OK) ? Qtrue : Qfalse;
1276
+ #else
1277
+ return Qfalse;
1278
+ #endif
1279
+ }
1280
+
1281
+ #if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET)
1282
+ static VALUE
1283
+ window_color_set(VALUE obj, VALUE col)
1284
+ {
1285
+ struct windata *winp;
1286
+ int res;
1287
+
1288
+ GetWINDOW(obj, winp);
1289
+ res = wcolor_set(winp->window, NUM2INT(col), NULL);
1290
+ return (res == OK) ? Qtrue : Qfalse;
1291
+ }
1292
+ #endif /* USE_COLOR */
1293
+
1294
+ static VALUE
1295
+ window_scroll(VALUE obj)
1296
+ {
1297
+ struct windata *winp;
1298
+
1299
+ GetWINDOW(obj, winp);
1300
+ /* may have to raise exception on ERR */
1301
+ return (scroll(winp->window) == OK) ? Qtrue : Qfalse;
1302
+ }
1303
+
1304
+ static VALUE
1305
+ window_scrl(VALUE obj, VALUE n)
1306
+ {
1307
+ #ifdef HAVE_WSCRL
1308
+ struct windata *winp;
1309
+
1310
+ GetWINDOW(obj, winp);
1311
+ /* may have to raise exception on ERR */
1312
+ return (wscrl(winp->window,NUM2INT(n)) == OK) ? Qtrue : Qfalse;
1313
+ #else
1314
+ return Qfalse;
1315
+ #endif
1316
+ }
1317
+
1318
+ static VALUE
1319
+ window_attroff(VALUE obj, VALUE attrs)
1320
+ {
1321
+ #ifdef HAVE_WATTROFF
1322
+ struct windata *winp;
1323
+
1324
+ GetWINDOW(obj,winp);
1325
+ return INT2FIX(wattroff(winp->window,NUM2INT(attrs)));
1326
+ #else
1327
+ return Qtrue;
1328
+ #endif
1329
+ }
1330
+
1331
+ static VALUE
1332
+ window_attron(VALUE obj, VALUE attrs)
1333
+ {
1334
+ #ifdef HAVE_WATTRON
1335
+ struct windata *winp;
1336
+ VALUE val;
1337
+
1338
+ GetWINDOW(obj,winp);
1339
+ val = INT2FIX(wattron(winp->window,NUM2INT(attrs)));
1340
+ if( rb_block_given_p() ){
1341
+ rb_yield(val);
1342
+ wattroff(winp->window,NUM2INT(attrs));
1343
+ return val;
1344
+ }
1345
+ else{
1346
+ return val;
1347
+ }
1348
+ #else
1349
+ return Qtrue;
1350
+ #endif
1351
+ }
1352
+
1353
+ static VALUE
1354
+ window_attrset(VALUE obj, VALUE attrs)
1355
+ {
1356
+ #ifdef HAVE_WATTRSET
1357
+ struct windata *winp;
1358
+
1359
+ GetWINDOW(obj,winp);
1360
+ return INT2FIX(wattrset(winp->window,NUM2INT(attrs)));
1361
+ #else
1362
+ return Qtrue;
1363
+ #endif
1364
+ }
1365
+
1366
+ static VALUE
1367
+ window_bkgdset(VALUE obj, VALUE ch)
1368
+ {
1369
+ #ifdef HAVE_WBKGDSET
1370
+ struct windata *winp;
1371
+
1372
+ GetWINDOW(obj,winp);
1373
+ wbkgdset(winp->window, NUM2CH(ch));
1374
+ #endif
1375
+ return Qnil;
1376
+ }
1377
+
1378
+ static VALUE
1379
+ window_bkgd(VALUE obj, VALUE ch)
1380
+ {
1381
+ #ifdef HAVE_WBKGD
1382
+ struct windata *winp;
1383
+
1384
+ GetWINDOW(obj,winp);
1385
+ return (wbkgd(winp->window, NUM2CH(ch)) == OK) ? Qtrue : Qfalse;
1386
+ #else
1387
+ return Qfalse;
1388
+ #endif
1389
+ }
1390
+
1391
+ static VALUE
1392
+ window_getbkgd(VALUE obj)
1393
+ {
1394
+ #ifdef HAVE_WGETBKGD
1395
+ chtype c;
1396
+ struct windata *winp;
1397
+
1398
+ GetWINDOW(obj,winp);
1399
+ return (c = getbkgd(winp->window) != ERR) ? CH2FIX(c) : Qnil;
1400
+ #else
1401
+ return Qnil;
1402
+ #endif
1403
+ }
1404
+
1405
+ static VALUE
1406
+ window_resize(VALUE obj, VALUE lin, VALUE col)
1407
+ {
1408
+ #if defined(HAVE_WRESIZE)
1409
+ struct windata *winp;
1410
+
1411
+ GetWINDOW(obj,winp);
1412
+ return wresize(winp->window, NUM2INT(lin), NUM2INT(col)) == OK ? Qtrue : Qfalse;
1413
+ #else
1414
+ return Qnil;
1415
+ #endif
1416
+ }
1417
+
1418
+
1419
+ static VALUE
1420
+ window_keypad(VALUE obj, VALUE val)
1421
+ {
1422
+ #ifdef HAVE_KEYPAD
1423
+ struct windata *winp;
1424
+
1425
+ GetWINDOW(obj,winp);
1426
+ /* keypad() of NetBSD's libcurses returns no value */
1427
+ #if defined(__NetBSD__) && !defined(NCURSES_VERSION)
1428
+ keypad(winp->window,(RTEST(val) ? TRUE : FALSE));
1429
+ return Qnil;
1430
+ #else
1431
+ /* may have to raise exception on ERR */
1432
+ return (keypad(winp->window,RTEST(val) ? TRUE : FALSE)) == OK ?
1433
+ Qtrue : Qfalse;
1434
+ #endif
1435
+ #else
1436
+ rb_notimplement();
1437
+ #endif /* HAVE_KEYPAD */
1438
+ }
1439
+
1440
+ static VALUE
1441
+ window_nodelay(VALUE obj, VALUE val)
1442
+ {
1443
+ #ifdef HAVE_NODELAY
1444
+ struct windata *winp;
1445
+ GetWINDOW(obj,winp);
1446
+
1447
+ /* nodelay() of NetBSD's libcurses returns no value */
1448
+ #if defined(__NetBSD__) && !defined(NCURSES_VERSION)
1449
+ nodelay(winp->window, RTEST(val) ? TRUE : FALSE);
1450
+ return Qnil;
1451
+ #else
1452
+ return nodelay(winp->window,RTEST(val) ? TRUE : FALSE) == OK ? Qtrue : Qfalse;
1453
+ #endif
1454
+ #else
1455
+ rb_notimplement();
1456
+ #endif
1457
+ }
1458
+
1459
+ static VALUE
1460
+ window_timeout(VALUE obj, VALUE delay)
1461
+ {
1462
+ #ifdef HAVE_WTIMEOUT
1463
+ struct windata *winp;
1464
+ GetWINDOW(obj,winp);
1465
+
1466
+ wtimeout(winp->window,NUM2INT(delay));
1467
+ return Qnil;
1468
+ #else
1469
+ rb_notimplement();
1470
+ #endif
1471
+ }
1472
+
1473
+ /*------------------------- Initialization -------------------------*/
1474
+ void
1475
+ Init_curses()
1476
+ {
1477
+ mCurses = rb_define_module("Curses");
1478
+ mKey = rb_define_module_under(mCurses, "Key");
1479
+
1480
+ rb_gc_register_address(&rb_stdscr);
1481
+
1482
+ #ifdef USE_MOUSE
1483
+ cMouseEvent = rb_define_class_under(mCurses,"MouseEvent",rb_cObject);
1484
+ rb_undef_method(CLASS_OF(cMouseEvent),"new");
1485
+ rb_define_method(cMouseEvent, "eid", curs_mouse_id, 0);
1486
+ rb_define_method(cMouseEvent, "x", curs_mouse_x, 0);
1487
+ rb_define_method(cMouseEvent, "y", curs_mouse_y, 0);
1488
+ rb_define_method(cMouseEvent, "z", curs_mouse_z, 0);
1489
+ rb_define_method(cMouseEvent, "bstate", curs_mouse_bstate, 0);
1490
+ #endif /* USE_MOUSE */
1491
+
1492
+ rb_define_module_function(mCurses, "init_screen", curses_init_screen, 0);
1493
+ rb_define_module_function(mCurses, "close_screen", curses_close_screen, 0);
1494
+ rb_define_module_function(mCurses, "closed?", curses_closed, 0);
1495
+ rb_define_module_function(mCurses, "stdscr", curses_stdscr, 0);
1496
+ rb_define_module_function(mCurses, "refresh", curses_refresh, 0);
1497
+ rb_define_module_function(mCurses, "doupdate", curses_doupdate, 0);
1498
+ rb_define_module_function(mCurses, "clear", curses_clear, 0);
1499
+ rb_define_module_function(mCurses, "clrtoeol", curses_clrtoeol, 0);
1500
+ rb_define_module_function(mCurses, "echo", curses_echo, 0);
1501
+ rb_define_module_function(mCurses, "noecho", curses_noecho, 0);
1502
+ rb_define_module_function(mCurses, "raw", curses_raw, 0);
1503
+ rb_define_module_function(mCurses, "noraw", curses_noraw, 0);
1504
+ rb_define_module_function(mCurses, "cbreak", curses_cbreak, 0);
1505
+ rb_define_module_function(mCurses, "nocbreak", curses_nocbreak, 0);
1506
+ rb_define_alias(mCurses, "crmode", "cbreak");
1507
+ rb_define_alias(mCurses, "nocrmode", "nocbreak");
1508
+ rb_define_module_function(mCurses, "nl", curses_nl, 0);
1509
+ rb_define_module_function(mCurses, "nonl", curses_nonl, 0);
1510
+ rb_define_module_function(mCurses, "beep", curses_beep, 0);
1511
+ rb_define_module_function(mCurses, "flash", curses_flash, 0);
1512
+ rb_define_module_function(mCurses, "ungetch", curses_ungetch, 1);
1513
+ rb_define_module_function(mCurses, "setpos", curses_setpos, 2);
1514
+ rb_define_module_function(mCurses, "standout", curses_standout, 0);
1515
+ rb_define_module_function(mCurses, "standend", curses_standend, 0);
1516
+ rb_define_module_function(mCurses, "inch", curses_inch, 0);
1517
+ rb_define_module_function(mCurses, "addch", curses_addch, 1);
1518
+ rb_define_module_function(mCurses, "insch", curses_insch, 1);
1519
+ rb_define_module_function(mCurses, "addstr", curses_addstr, 1);
1520
+ rb_define_module_function(mCurses, "getch", curses_getch, 0);
1521
+ rb_define_module_function(mCurses, "getstr", curses_getstr, 0);
1522
+ rb_define_module_function(mCurses, "delch", curses_delch, 0);
1523
+ rb_define_module_function(mCurses, "deleteln", curses_deleteln, 0);
1524
+ rb_define_module_function(mCurses, "insertln", curses_insertln, 0);
1525
+ rb_define_module_function(mCurses, "keyname", curses_keyname, 1);
1526
+ rb_define_module_function(mCurses, "lines", curses_lines, 0);
1527
+ rb_define_module_function(mCurses, "cols", curses_cols, 0);
1528
+ rb_define_module_function(mCurses, "curs_set", curses_curs_set, 1);
1529
+ rb_define_module_function(mCurses, "scrl", curses_scrl, 1);
1530
+ rb_define_module_function(mCurses, "setscrreg", curses_setscrreg, 2);
1531
+ rb_define_module_function(mCurses, "attroff", curses_attroff, 1);
1532
+ rb_define_module_function(mCurses, "attron", curses_attron, 1);
1533
+ rb_define_module_function(mCurses, "attrset", curses_attrset, 1);
1534
+ rb_define_module_function(mCurses, "bkgdset", curses_bkgdset, 1);
1535
+ rb_define_module_function(mCurses, "bkgd", curses_bkgd, 1);
1536
+ rb_define_module_function(mCurses, "resizeterm", curses_resizeterm, 2);
1537
+ rb_define_module_function(mCurses, "resize", curses_resizeterm, 2);
1538
+ #ifdef USE_COLOR
1539
+ rb_define_module_function(mCurses, "start_color", curses_start_color, 0);
1540
+ rb_define_module_function(mCurses, "init_pair", curses_init_pair, 3);
1541
+ rb_define_module_function(mCurses, "init_color", curses_init_color, 4);
1542
+ rb_define_module_function(mCurses, "has_colors?", curses_has_colors, 0);
1543
+ rb_define_module_function(mCurses, "can_change_color?",
1544
+ curses_can_change_color, 0);
1545
+ rb_define_module_function(mCurses, "color_content", curses_color_content, 1);
1546
+ rb_define_module_function(mCurses, "pair_content", curses_pair_content, 1);
1547
+ rb_define_module_function(mCurses, "color_pair", curses_color_pair, 1);
1548
+ rb_define_module_function(mCurses, "pair_number", curses_pair_number, 1);
1549
+ #endif /* USE_COLOR */
1550
+ #ifdef USE_MOUSE
1551
+ rb_define_module_function(mCurses, "getmouse", curses_getmouse, 0);
1552
+ rb_define_module_function(mCurses, "ungetmouse", curses_ungetmouse, 1);
1553
+ rb_define_module_function(mCurses, "mouseinterval", curses_mouseinterval, 1);
1554
+ rb_define_module_function(mCurses, "mousemask", curses_mousemask, 1);
1555
+ #endif /* USE_MOUSE */
1556
+
1557
+ rb_define_module_function(mCurses, "timeout=", curses_timeout, 1);
1558
+ rb_define_module_function(mCurses, "def_prog_mode", curses_def_prog_mode, 0);
1559
+ rb_define_module_function(mCurses, "reset_prog_mode", curses_reset_prog_mode, 0);
1560
+
1561
+ cWindow = rb_define_class_under(mCurses, "Window", rb_cData);
1562
+ rb_define_alloc_func(cWindow, window_s_allocate);
1563
+ rb_define_method(cWindow, "initialize", window_initialize, 4);
1564
+ rb_define_method(cWindow, "subwin", window_subwin, 4);
1565
+ rb_define_method(cWindow, "close", window_close, 0);
1566
+ rb_define_method(cWindow, "clear", window_clear, 0);
1567
+ rb_define_method(cWindow, "clrtoeol", window_clrtoeol, 0);
1568
+ rb_define_method(cWindow, "refresh", window_refresh, 0);
1569
+ rb_define_method(cWindow, "noutrefresh", window_noutrefresh, 0);
1570
+ rb_define_method(cWindow, "box", window_box, -1);
1571
+ rb_define_method(cWindow, "move", window_move, 2);
1572
+ rb_define_method(cWindow, "setpos", window_setpos, 2);
1573
+ #if defined(USE_COLOR) && defined(HAVE_WCOLOR_SET)
1574
+ rb_define_method(cWindow, "color_set", window_color_set, 1);
1575
+ #endif /* USE_COLOR && HAVE_WCOLOR_SET */
1576
+ rb_define_method(cWindow, "cury", window_cury, 0);
1577
+ rb_define_method(cWindow, "curx", window_curx, 0);
1578
+ rb_define_method(cWindow, "maxy", window_maxy, 0);
1579
+ rb_define_method(cWindow, "maxx", window_maxx, 0);
1580
+ rb_define_method(cWindow, "begy", window_begy, 0);
1581
+ rb_define_method(cWindow, "begx", window_begx, 0);
1582
+ rb_define_method(cWindow, "standout", window_standout, 0);
1583
+ rb_define_method(cWindow, "standend", window_standend, 0);
1584
+ rb_define_method(cWindow, "inch", window_inch, 0);
1585
+ rb_define_method(cWindow, "addch", window_addch, 1);
1586
+ rb_define_method(cWindow, "insch", window_insch, 1);
1587
+ rb_define_method(cWindow, "addstr", window_addstr, 1);
1588
+ rb_define_method(cWindow, "<<", window_addstr2, 1);
1589
+ rb_define_method(cWindow, "getch", window_getch, 0);
1590
+ rb_define_method(cWindow, "getstr", window_getstr, 0);
1591
+ rb_define_method(cWindow, "delch", window_delch, 0);
1592
+ rb_define_method(cWindow, "deleteln", window_deleteln, 0);
1593
+ rb_define_method(cWindow, "insertln", window_insertln, 0);
1594
+ rb_define_method(cWindow, "scroll", window_scroll, 0);
1595
+ rb_define_method(cWindow, "scrollok", window_scrollok, 1);
1596
+ rb_define_method(cWindow, "idlok", window_idlok, 1);
1597
+ rb_define_method(cWindow, "setscrreg", window_setscrreg, 2);
1598
+ rb_define_method(cWindow, "scrl", window_scrl, 1);
1599
+ rb_define_method(cWindow, "resize", window_resize, 2);
1600
+ rb_define_method(cWindow, "keypad", window_keypad, 1);
1601
+ rb_define_method(cWindow, "keypad=", window_keypad, 1);
1602
+
1603
+ rb_define_method(cWindow, "attroff", window_attroff, 1);
1604
+ rb_define_method(cWindow, "attron", window_attron, 1);
1605
+ rb_define_method(cWindow, "attrset", window_attrset, 1);
1606
+ rb_define_method(cWindow, "bkgdset", window_bkgdset, 1);
1607
+ rb_define_method(cWindow, "bkgd", window_bkgd, 1);
1608
+ rb_define_method(cWindow, "getbkgd", window_getbkgd, 0);
1609
+
1610
+ rb_define_method(cWindow, "nodelay=", window_nodelay, 1);
1611
+ rb_define_method(cWindow, "timeout=", window_timeout, 1);
1612
+
1613
+ #define rb_curses_define_const(c) rb_define_const(mCurses,#c,UINT2NUM(c))
1614
+
1615
+ #ifdef USE_COLOR
1616
+ rb_curses_define_const(A_ATTRIBUTES);
1617
+ #ifdef A_NORMAL
1618
+ rb_curses_define_const(A_NORMAL);
1619
+ #endif
1620
+ rb_curses_define_const(A_STANDOUT);
1621
+ rb_curses_define_const(A_UNDERLINE);
1622
+ rb_curses_define_const(A_REVERSE);
1623
+ rb_curses_define_const(A_BLINK);
1624
+ rb_curses_define_const(A_DIM);
1625
+ rb_curses_define_const(A_BOLD);
1626
+ rb_curses_define_const(A_PROTECT);
1627
+ #ifdef A_INVIS /* for NetBSD */
1628
+ rb_curses_define_const(A_INVIS);
1629
+ #endif
1630
+ rb_curses_define_const(A_ALTCHARSET);
1631
+ rb_curses_define_const(A_CHARTEXT);
1632
+ #ifdef A_HORIZONTAL
1633
+ rb_curses_define_const(A_HORIZONTAL);
1634
+ #endif
1635
+ #ifdef A_LEFT
1636
+ rb_curses_define_const(A_LEFT);
1637
+ #endif
1638
+ #ifdef A_LOW
1639
+ rb_curses_define_const(A_LOW);
1640
+ #endif
1641
+ #ifdef A_RIGHT
1642
+ rb_curses_define_const(A_RIGHT);
1643
+ #endif
1644
+ #ifdef A_TOP
1645
+ rb_curses_define_const(A_TOP);
1646
+ #endif
1647
+ #ifdef A_VERTICAL
1648
+ rb_curses_define_const(A_VERTICAL);
1649
+ #endif
1650
+ rb_curses_define_const(A_COLOR);
1651
+
1652
+ #ifdef COLORS
1653
+ rb_curses_define_const(COLORS);
1654
+ #endif
1655
+ rb_curses_define_const(COLOR_BLACK);
1656
+ rb_curses_define_const(COLOR_RED);
1657
+ rb_curses_define_const(COLOR_GREEN);
1658
+ rb_curses_define_const(COLOR_YELLOW);
1659
+ rb_curses_define_const(COLOR_BLUE);
1660
+ rb_curses_define_const(COLOR_MAGENTA);
1661
+ rb_curses_define_const(COLOR_CYAN);
1662
+ rb_curses_define_const(COLOR_WHITE);
1663
+ #endif /* USE_COLOR */
1664
+ #ifdef USE_MOUSE
1665
+ #ifdef BUTTON1_PRESSED
1666
+ rb_curses_define_const(BUTTON1_PRESSED);
1667
+ #endif
1668
+ #ifdef BUTTON1_RELEASED
1669
+ rb_curses_define_const(BUTTON1_RELEASED);
1670
+ #endif
1671
+ #ifdef BUTTON1_CLICKED
1672
+ rb_curses_define_const(BUTTON1_CLICKED);
1673
+ #endif
1674
+ #ifdef BUTTON1_DOUBLE_CLICKED
1675
+ rb_curses_define_const(BUTTON1_DOUBLE_CLICKED);
1676
+ #endif
1677
+ #ifdef BUTTON1_TRIPLE_CLICKED
1678
+ rb_curses_define_const(BUTTON1_TRIPLE_CLICKED);
1679
+ #endif
1680
+ #ifdef BUTTON2_PRESSED
1681
+ rb_curses_define_const(BUTTON2_PRESSED);
1682
+ #endif
1683
+ #ifdef BUTTON2_RELEASED
1684
+ rb_curses_define_const(BUTTON2_RELEASED);
1685
+ #endif
1686
+ #ifdef BUTTON2_CLICKED
1687
+ rb_curses_define_const(BUTTON2_CLICKED);
1688
+ #endif
1689
+ #ifdef BUTTON2_DOUBLE_CLICKED
1690
+ rb_curses_define_const(BUTTON2_DOUBLE_CLICKED);
1691
+ #endif
1692
+ #ifdef BUTTON2_TRIPLE_CLICKED
1693
+ rb_curses_define_const(BUTTON2_TRIPLE_CLICKED);
1694
+ #endif
1695
+ #ifdef BUTTON3_PRESSED
1696
+ rb_curses_define_const(BUTTON3_PRESSED);
1697
+ #endif
1698
+ #ifdef BUTTON3_RELEASED
1699
+ rb_curses_define_const(BUTTON3_RELEASED);
1700
+ #endif
1701
+ #ifdef BUTTON3_CLICKED
1702
+ rb_curses_define_const(BUTTON3_CLICKED);
1703
+ #endif
1704
+ #ifdef BUTTON3_DOUBLE_CLICKED
1705
+ rb_curses_define_const(BUTTON3_DOUBLE_CLICKED);
1706
+ #endif
1707
+ #ifdef BUTTON3_TRIPLE_CLICKED
1708
+ rb_curses_define_const(BUTTON3_TRIPLE_CLICKED);
1709
+ #endif
1710
+ #ifdef BUTTON4_PRESSED
1711
+ rb_curses_define_const(BUTTON4_PRESSED);
1712
+ #endif
1713
+ #ifdef BUTTON4_RELEASED
1714
+ rb_curses_define_const(BUTTON4_RELEASED);
1715
+ #endif
1716
+ #ifdef BUTTON4_CLICKED
1717
+ rb_curses_define_const(BUTTON4_CLICKED);
1718
+ #endif
1719
+ #ifdef BUTTON4_DOUBLE_CLICKED
1720
+ rb_curses_define_const(BUTTON4_DOUBLE_CLICKED);
1721
+ #endif
1722
+ #ifdef BUTTON4_TRIPLE_CLICKED
1723
+ rb_curses_define_const(BUTTON4_TRIPLE_CLICKED);
1724
+ #endif
1725
+ #ifdef BUTTON_SHIFT
1726
+ rb_curses_define_const(BUTTON_SHIFT);
1727
+ #endif
1728
+ #ifdef BUTTON_CTRL
1729
+ rb_curses_define_const(BUTTON_CTRL);
1730
+ #endif
1731
+ #ifdef BUTTON_ALT
1732
+ rb_curses_define_const(BUTTON_ALT);
1733
+ #endif
1734
+ #ifdef ALL_MOUSE_EVENTS
1735
+ rb_curses_define_const(ALL_MOUSE_EVENTS);
1736
+ #endif
1737
+ #ifdef REPORT_MOUSE_POSITION
1738
+ rb_curses_define_const(REPORT_MOUSE_POSITION);
1739
+ #endif
1740
+ #endif /* USE_MOUSE */
1741
+
1742
+ #if defined(KEY_MOUSE) && defined(USE_MOUSE)
1743
+ rb_curses_define_const(KEY_MOUSE);
1744
+ rb_define_const(mKey, "MOUSE", INT2NUM(KEY_MOUSE));
1745
+ #endif
1746
+ #ifdef KEY_MIN
1747
+ rb_curses_define_const(KEY_MIN);
1748
+ rb_define_const(mKey, "MIN", INT2NUM(KEY_MIN));
1749
+ #endif
1750
+ #ifdef KEY_BREAK
1751
+ rb_curses_define_const(KEY_BREAK);
1752
+ rb_define_const(mKey, "BREAK", INT2NUM(KEY_BREAK));
1753
+ #endif
1754
+ #ifdef KEY_DOWN
1755
+ rb_curses_define_const(KEY_DOWN);
1756
+ rb_define_const(mKey, "DOWN", INT2NUM(KEY_DOWN));
1757
+ #endif
1758
+ #ifdef KEY_UP
1759
+ rb_curses_define_const(KEY_UP);
1760
+ rb_define_const(mKey, "UP", INT2NUM(KEY_UP));
1761
+ #endif
1762
+ #ifdef KEY_LEFT
1763
+ rb_curses_define_const(KEY_LEFT);
1764
+ rb_define_const(mKey, "LEFT", INT2NUM(KEY_LEFT));
1765
+ #endif
1766
+ #ifdef KEY_RIGHT
1767
+ rb_curses_define_const(KEY_RIGHT);
1768
+ rb_define_const(mKey, "RIGHT", INT2NUM(KEY_RIGHT));
1769
+ #endif
1770
+ #ifdef KEY_HOME
1771
+ rb_curses_define_const(KEY_HOME);
1772
+ rb_define_const(mKey, "HOME", INT2NUM(KEY_HOME));
1773
+ #endif
1774
+ #ifdef KEY_BACKSPACE
1775
+ rb_curses_define_const(KEY_BACKSPACE);
1776
+ rb_define_const(mKey, "BACKSPACE", INT2NUM(KEY_BACKSPACE));
1777
+ #endif
1778
+ #ifdef KEY_F
1779
+ /* KEY_F(n) : 0 <= n <= 63 */
1780
+ {
1781
+ int i;
1782
+ char c[8];
1783
+ for( i=0; i<64; i++ ){
1784
+ sprintf(c, "KEY_F%d", i);
1785
+ rb_define_const(mCurses, c, INT2NUM(KEY_F(i)));
1786
+ sprintf(c, "F%d", i);
1787
+ rb_define_const(mKey, c, INT2NUM(KEY_F(i)));
1788
+ }
1789
+ }
1790
+ #endif
1791
+ #ifdef KEY_DL
1792
+ rb_curses_define_const(KEY_DL);
1793
+ rb_define_const(mKey, "DL", INT2NUM(KEY_DL));
1794
+ #endif
1795
+ #ifdef KEY_IL
1796
+ rb_curses_define_const(KEY_IL);
1797
+ rb_define_const(mKey, "IL", INT2NUM(KEY_IL));
1798
+ #endif
1799
+ #ifdef KEY_DC
1800
+ rb_curses_define_const(KEY_DC);
1801
+ rb_define_const(mKey, "DC", INT2NUM(KEY_DC));
1802
+ #endif
1803
+ #ifdef KEY_IC
1804
+ rb_curses_define_const(KEY_IC);
1805
+ rb_define_const(mKey, "IC", INT2NUM(KEY_IC));
1806
+ #endif
1807
+ #ifdef KEY_EIC
1808
+ rb_curses_define_const(KEY_EIC);
1809
+ rb_define_const(mKey, "EIC", INT2NUM(KEY_EIC));
1810
+ #endif
1811
+ #ifdef KEY_CLEAR
1812
+ rb_curses_define_const(KEY_CLEAR);
1813
+ rb_define_const(mKey, "CLEAR", INT2NUM(KEY_CLEAR));
1814
+ #endif
1815
+ #ifdef KEY_EOS
1816
+ rb_curses_define_const(KEY_EOS);
1817
+ rb_define_const(mKey, "EOS", INT2NUM(KEY_EOS));
1818
+ #endif
1819
+ #ifdef KEY_EOL
1820
+ rb_curses_define_const(KEY_EOL);
1821
+ rb_define_const(mKey, "EOL", INT2NUM(KEY_EOL));
1822
+ #endif
1823
+ #ifdef KEY_SF
1824
+ rb_curses_define_const(KEY_SF);
1825
+ rb_define_const(mKey, "SF", INT2NUM(KEY_SF));
1826
+ #endif
1827
+ #ifdef KEY_SR
1828
+ rb_curses_define_const(KEY_SR);
1829
+ rb_define_const(mKey, "SR", INT2NUM(KEY_SR));
1830
+ #endif
1831
+ #ifdef KEY_NPAGE
1832
+ rb_curses_define_const(KEY_NPAGE);
1833
+ rb_define_const(mKey, "NPAGE", INT2NUM(KEY_NPAGE));
1834
+ #endif
1835
+ #ifdef KEY_PPAGE
1836
+ rb_curses_define_const(KEY_PPAGE);
1837
+ rb_define_const(mKey, "PPAGE", INT2NUM(KEY_PPAGE));
1838
+ #endif
1839
+ #ifdef KEY_STAB
1840
+ rb_curses_define_const(KEY_STAB);
1841
+ rb_define_const(mKey, "STAB", INT2NUM(KEY_STAB));
1842
+ #endif
1843
+ #ifdef KEY_CTAB
1844
+ rb_curses_define_const(KEY_CTAB);
1845
+ rb_define_const(mKey, "CTAB", INT2NUM(KEY_CTAB));
1846
+ #endif
1847
+ #ifdef KEY_CATAB
1848
+ rb_curses_define_const(KEY_CATAB);
1849
+ rb_define_const(mKey, "CATAB", INT2NUM(KEY_CATAB));
1850
+ #endif
1851
+ #ifdef KEY_ENTER
1852
+ rb_curses_define_const(KEY_ENTER);
1853
+ rb_define_const(mKey, "ENTER", INT2NUM(KEY_ENTER));
1854
+ #endif
1855
+ #ifdef KEY_SRESET
1856
+ rb_curses_define_const(KEY_SRESET);
1857
+ rb_define_const(mKey, "SRESET", INT2NUM(KEY_SRESET));
1858
+ #endif
1859
+ #ifdef KEY_RESET
1860
+ rb_curses_define_const(KEY_RESET);
1861
+ rb_define_const(mKey, "RESET", INT2NUM(KEY_RESET));
1862
+ #endif
1863
+ #ifdef KEY_PRINT
1864
+ rb_curses_define_const(KEY_PRINT);
1865
+ rb_define_const(mKey, "PRINT", INT2NUM(KEY_PRINT));
1866
+ #endif
1867
+ #ifdef KEY_LL
1868
+ rb_curses_define_const(KEY_LL);
1869
+ rb_define_const(mKey, "LL", INT2NUM(KEY_LL));
1870
+ #endif
1871
+ #ifdef KEY_A1
1872
+ rb_curses_define_const(KEY_A1);
1873
+ rb_define_const(mKey, "A1", INT2NUM(KEY_A1));
1874
+ #endif
1875
+ #ifdef KEY_A3
1876
+ rb_curses_define_const(KEY_A3);
1877
+ rb_define_const(mKey, "A3", INT2NUM(KEY_A3));
1878
+ #endif
1879
+ #ifdef KEY_B2
1880
+ rb_curses_define_const(KEY_B2);
1881
+ rb_define_const(mKey, "B2", INT2NUM(KEY_B2));
1882
+ #endif
1883
+ #ifdef KEY_C1
1884
+ rb_curses_define_const(KEY_C1);
1885
+ rb_define_const(mKey, "C1", INT2NUM(KEY_C1));
1886
+ #endif
1887
+ #ifdef KEY_C3
1888
+ rb_curses_define_const(KEY_C3);
1889
+ rb_define_const(mKey, "C3", INT2NUM(KEY_C3));
1890
+ #endif
1891
+ #ifdef KEY_BTAB
1892
+ rb_curses_define_const(KEY_BTAB);
1893
+ rb_define_const(mKey, "BTAB", INT2NUM(KEY_BTAB));
1894
+ #endif
1895
+ #ifdef KEY_BEG
1896
+ rb_curses_define_const(KEY_BEG);
1897
+ rb_define_const(mKey, "BEG", INT2NUM(KEY_BEG));
1898
+ #endif
1899
+ #ifdef KEY_CANCEL
1900
+ rb_curses_define_const(KEY_CANCEL);
1901
+ rb_define_const(mKey, "CANCEL", INT2NUM(KEY_CANCEL));
1902
+ #endif
1903
+ #ifdef KEY_CLOSE
1904
+ rb_curses_define_const(KEY_CLOSE);
1905
+ rb_define_const(mKey, "CLOSE", INT2NUM(KEY_CLOSE));
1906
+ #endif
1907
+ #ifdef KEY_COMMAND
1908
+ rb_curses_define_const(KEY_COMMAND);
1909
+ rb_define_const(mKey, "COMMAND", INT2NUM(KEY_COMMAND));
1910
+ #endif
1911
+ #ifdef KEY_COPY
1912
+ rb_curses_define_const(KEY_COPY);
1913
+ rb_define_const(mKey, "COPY", INT2NUM(KEY_COPY));
1914
+ #endif
1915
+ #ifdef KEY_CREATE
1916
+ rb_curses_define_const(KEY_CREATE);
1917
+ rb_define_const(mKey, "CREATE", INT2NUM(KEY_CREATE));
1918
+ #endif
1919
+ #ifdef KEY_END
1920
+ rb_curses_define_const(KEY_END);
1921
+ rb_define_const(mKey, "END", INT2NUM(KEY_END));
1922
+ #endif
1923
+ #ifdef KEY_EXIT
1924
+ rb_curses_define_const(KEY_EXIT);
1925
+ rb_define_const(mKey, "EXIT", INT2NUM(KEY_EXIT));
1926
+ #endif
1927
+ #ifdef KEY_FIND
1928
+ rb_curses_define_const(KEY_FIND);
1929
+ rb_define_const(mKey, "FIND", INT2NUM(KEY_FIND));
1930
+ #endif
1931
+ #ifdef KEY_HELP
1932
+ rb_curses_define_const(KEY_HELP);
1933
+ rb_define_const(mKey, "HELP", INT2NUM(KEY_HELP));
1934
+ #endif
1935
+ #ifdef KEY_MARK
1936
+ rb_curses_define_const(KEY_MARK);
1937
+ rb_define_const(mKey, "MARK", INT2NUM(KEY_MARK));
1938
+ #endif
1939
+ #ifdef KEY_MESSAGE
1940
+ rb_curses_define_const(KEY_MESSAGE);
1941
+ rb_define_const(mKey, "MESSAGE", INT2NUM(KEY_MESSAGE));
1942
+ #endif
1943
+ #ifdef KEY_MOVE
1944
+ rb_curses_define_const(KEY_MOVE);
1945
+ rb_define_const(mKey, "MOVE", INT2NUM(KEY_MOVE));
1946
+ #endif
1947
+ #ifdef KEY_NEXT
1948
+ rb_curses_define_const(KEY_NEXT);
1949
+ rb_define_const(mKey, "NEXT", INT2NUM(KEY_NEXT));
1950
+ #endif
1951
+ #ifdef KEY_OPEN
1952
+ rb_curses_define_const(KEY_OPEN);
1953
+ rb_define_const(mKey, "OPEN", INT2NUM(KEY_OPEN));
1954
+ #endif
1955
+ #ifdef KEY_OPTIONS
1956
+ rb_curses_define_const(KEY_OPTIONS);
1957
+ rb_define_const(mKey, "OPTIONS", INT2NUM(KEY_OPTIONS));
1958
+ #endif
1959
+ #ifdef KEY_PREVIOUS
1960
+ rb_curses_define_const(KEY_PREVIOUS);
1961
+ rb_define_const(mKey, "PREVIOUS", INT2NUM(KEY_PREVIOUS));
1962
+ #endif
1963
+ #ifdef KEY_REDO
1964
+ rb_curses_define_const(KEY_REDO);
1965
+ rb_define_const(mKey, "REDO", INT2NUM(KEY_REDO));
1966
+ #endif
1967
+ #ifdef KEY_REFERENCE
1968
+ rb_curses_define_const(KEY_REFERENCE);
1969
+ rb_define_const(mKey, "REFERENCE", INT2NUM(KEY_REFERENCE));
1970
+ #endif
1971
+ #ifdef KEY_REFRESH
1972
+ rb_curses_define_const(KEY_REFRESH);
1973
+ rb_define_const(mKey, "REFRESH", INT2NUM(KEY_REFRESH));
1974
+ #endif
1975
+ #ifdef KEY_REPLACE
1976
+ rb_curses_define_const(KEY_REPLACE);
1977
+ rb_define_const(mKey, "REPLACE", INT2NUM(KEY_REPLACE));
1978
+ #endif
1979
+ #ifdef KEY_RESTART
1980
+ rb_curses_define_const(KEY_RESTART);
1981
+ rb_define_const(mKey, "RESTART", INT2NUM(KEY_RESTART));
1982
+ #endif
1983
+ #ifdef KEY_RESUME
1984
+ rb_curses_define_const(KEY_RESUME);
1985
+ rb_define_const(mKey, "RESUME", INT2NUM(KEY_RESUME));
1986
+ #endif
1987
+ #ifdef KEY_SAVE
1988
+ rb_curses_define_const(KEY_SAVE);
1989
+ rb_define_const(mKey, "SAVE", INT2NUM(KEY_SAVE));
1990
+ #endif
1991
+ #ifdef KEY_SBEG
1992
+ rb_curses_define_const(KEY_SBEG);
1993
+ rb_define_const(mKey, "SBEG", INT2NUM(KEY_SBEG));
1994
+ #endif
1995
+ #ifdef KEY_SCANCEL
1996
+ rb_curses_define_const(KEY_SCANCEL);
1997
+ rb_define_const(mKey, "SCANCEL", INT2NUM(KEY_SCANCEL));
1998
+ #endif
1999
+ #ifdef KEY_SCOMMAND
2000
+ rb_curses_define_const(KEY_SCOMMAND);
2001
+ rb_define_const(mKey, "SCOMMAND", INT2NUM(KEY_SCOMMAND));
2002
+ #endif
2003
+ #ifdef KEY_SCOPY
2004
+ rb_curses_define_const(KEY_SCOPY);
2005
+ rb_define_const(mKey, "SCOPY", INT2NUM(KEY_SCOPY));
2006
+ #endif
2007
+ #ifdef KEY_SCREATE
2008
+ rb_curses_define_const(KEY_SCREATE);
2009
+ rb_define_const(mKey, "SCREATE", INT2NUM(KEY_SCREATE));
2010
+ #endif
2011
+ #ifdef KEY_SDC
2012
+ rb_curses_define_const(KEY_SDC);
2013
+ rb_define_const(mKey, "SDC", INT2NUM(KEY_SDC));
2014
+ #endif
2015
+ #ifdef KEY_SDL
2016
+ rb_curses_define_const(KEY_SDL);
2017
+ rb_define_const(mKey, "SDL", INT2NUM(KEY_SDL));
2018
+ #endif
2019
+ #ifdef KEY_SELECT
2020
+ rb_curses_define_const(KEY_SELECT);
2021
+ rb_define_const(mKey, "SELECT", INT2NUM(KEY_SELECT));
2022
+ #endif
2023
+ #ifdef KEY_SEND
2024
+ rb_curses_define_const(KEY_SEND);
2025
+ rb_define_const(mKey, "SEND", INT2NUM(KEY_SEND));
2026
+ #endif
2027
+ #ifdef KEY_SEOL
2028
+ rb_curses_define_const(KEY_SEOL);
2029
+ rb_define_const(mKey, "SEOL", INT2NUM(KEY_SEOL));
2030
+ #endif
2031
+ #ifdef KEY_SEXIT
2032
+ rb_curses_define_const(KEY_SEXIT);
2033
+ rb_define_const(mKey, "SEXIT", INT2NUM(KEY_SEXIT));
2034
+ #endif
2035
+ #ifdef KEY_SFIND
2036
+ rb_curses_define_const(KEY_SFIND);
2037
+ rb_define_const(mKey, "SFIND", INT2NUM(KEY_SFIND));
2038
+ #endif
2039
+ #ifdef KEY_SHELP
2040
+ rb_curses_define_const(KEY_SHELP);
2041
+ rb_define_const(mKey, "SHELP", INT2NUM(KEY_SHELP));
2042
+ #endif
2043
+ #ifdef KEY_SHOME
2044
+ rb_curses_define_const(KEY_SHOME);
2045
+ rb_define_const(mKey, "SHOME", INT2NUM(KEY_SHOME));
2046
+ #endif
2047
+ #ifdef KEY_SIC
2048
+ rb_curses_define_const(KEY_SIC);
2049
+ rb_define_const(mKey, "SIC", INT2NUM(KEY_SIC));
2050
+ #endif
2051
+ #ifdef KEY_SLEFT
2052
+ rb_curses_define_const(KEY_SLEFT);
2053
+ rb_define_const(mKey, "SLEFT", INT2NUM(KEY_SLEFT));
2054
+ #endif
2055
+ #ifdef KEY_SMESSAGE
2056
+ rb_curses_define_const(KEY_SMESSAGE);
2057
+ rb_define_const(mKey, "SMESSAGE", INT2NUM(KEY_SMESSAGE));
2058
+ #endif
2059
+ #ifdef KEY_SMOVE
2060
+ rb_curses_define_const(KEY_SMOVE);
2061
+ rb_define_const(mKey, "SMOVE", INT2NUM(KEY_SMOVE));
2062
+ #endif
2063
+ #ifdef KEY_SNEXT
2064
+ rb_curses_define_const(KEY_SNEXT);
2065
+ rb_define_const(mKey, "SNEXT", INT2NUM(KEY_SNEXT));
2066
+ #endif
2067
+ #ifdef KEY_SOPTIONS
2068
+ rb_curses_define_const(KEY_SOPTIONS);
2069
+ rb_define_const(mKey, "SOPTIONS", INT2NUM(KEY_SOPTIONS));
2070
+ #endif
2071
+ #ifdef KEY_SPREVIOUS
2072
+ rb_curses_define_const(KEY_SPREVIOUS);
2073
+ rb_define_const(mKey, "SPREVIOUS", INT2NUM(KEY_SPREVIOUS));
2074
+ #endif
2075
+ #ifdef KEY_SPRINT
2076
+ rb_curses_define_const(KEY_SPRINT);
2077
+ rb_define_const(mKey, "SPRINT", INT2NUM(KEY_SPRINT));
2078
+ #endif
2079
+ #ifdef KEY_SREDO
2080
+ rb_curses_define_const(KEY_SREDO);
2081
+ rb_define_const(mKey, "SREDO", INT2NUM(KEY_SREDO));
2082
+ #endif
2083
+ #ifdef KEY_SREPLACE
2084
+ rb_curses_define_const(KEY_SREPLACE);
2085
+ rb_define_const(mKey, "SREPLACE", INT2NUM(KEY_SREPLACE));
2086
+ #endif
2087
+ #ifdef KEY_SRIGHT
2088
+ rb_curses_define_const(KEY_SRIGHT);
2089
+ rb_define_const(mKey, "SRIGHT", INT2NUM(KEY_SRIGHT));
2090
+ #endif
2091
+ #ifdef KEY_SRSUME
2092
+ rb_curses_define_const(KEY_SRSUME);
2093
+ rb_define_const(mKey, "SRSUME", INT2NUM(KEY_SRSUME));
2094
+ #endif
2095
+ #ifdef KEY_SSAVE
2096
+ rb_curses_define_const(KEY_SSAVE);
2097
+ rb_define_const(mKey, "SSAVE", INT2NUM(KEY_SSAVE));
2098
+ #endif
2099
+ #ifdef KEY_SSUSPEND
2100
+ rb_curses_define_const(KEY_SSUSPEND);
2101
+ rb_define_const(mKey, "SSUSPEND", INT2NUM(KEY_SSUSPEND));
2102
+ #endif
2103
+ #ifdef KEY_SUNDO
2104
+ rb_curses_define_const(KEY_SUNDO);
2105
+ rb_define_const(mKey, "SUNDO", INT2NUM(KEY_SUNDO));
2106
+ #endif
2107
+ #ifdef KEY_SUSPEND
2108
+ rb_curses_define_const(KEY_SUSPEND);
2109
+ rb_define_const(mKey, "SUSPEND", INT2NUM(KEY_SUSPEND));
2110
+ #endif
2111
+ #ifdef KEY_UNDO
2112
+ rb_curses_define_const(KEY_UNDO);
2113
+ rb_define_const(mKey, "UNDO", INT2NUM(KEY_UNDO));
2114
+ #endif
2115
+ #ifdef KEY_RESIZE
2116
+ rb_curses_define_const(KEY_RESIZE);
2117
+ rb_define_const(mKey, "RESIZE", INT2NUM(KEY_RESIZE));
2118
+ #endif
2119
+ #ifdef KEY_MAX
2120
+ rb_curses_define_const(KEY_MAX);
2121
+ rb_define_const(mKey, "MAX", INT2NUM(KEY_MAX));
2122
+ #endif
2123
+ {
2124
+ int c;
2125
+ char name[] = "KEY_CTRL_x";
2126
+ for( c = 'A'; c <= 'Z'; c++ ){
2127
+ sprintf(name, "KEY_CTRL_%c", c);
2128
+ rb_define_const(mCurses, name, INT2FIX(c - 'A' + 1));
2129
+ }
2130
+ }
2131
+ #undef rb_curses_define_const
2132
+
2133
+ rb_set_end_proc(curses_finalize, 0);
2134
+ }