CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

Path: gap4r8 / pkg / Browse / src / ncurses.c
Views: 418346
1
/***************************************************************************
2
**
3
*A ncurses.c BROWSE package Frank Lübeck
4
**
5
** Provide functions from ncurses C-library to GAP.
6
** We choose a subset of functions, usually the 'w'-variants.
7
** Panels can also be used.
8
**
9
*/
10
11
#define VERSION "1.8.7"
12
13
const char * Revision_ncurses_c =
14
"VERSION";
15
16
/* read GAP source header files with a combined header file */
17
18
#include "src/compiled.h" /* GAP headers */
19
#include <stdio.h>
20
#include <unistd.h>
21
#include <stdlib.h> /* for getenv and co */
22
#ifdef WIDECHARS
23
#define _XOPEN_SOURCE_EXTENDED
24
#include <locale.h>
25
#include <ncursesw/curses.h>
26
#include <ncursesw/panel.h>
27
#else
28
#include <ncurses.h>
29
#include <panel.h>
30
#endif
31
32
/* remember attributes at init time XXX
33
static attr_t startattr;
34
static short startcp;
35
*/
36
37
/* We store the living WINDOW and PANEL pointers in two strings. The
38
pointer to window i (zero based counting) is stored in
39
((WINDOW**)CHARS_STRING(winlist))[i]. If this window is wrapped in
40
a panel then the pointer to this panel is stored in the same position of
41
panellist.
42
43
For debugging purposes the strings winlist and panellist are available in
44
GAP as record components of the same name in 'NCurses'.
45
*/
46
static Obj winlist;
47
static Obj panellist;
48
49
/* the functions */
50
51
52
/* get the win or panel from number (return NULL if no valid input) */
53
WINDOW* winnum(Obj num) {
54
Int n;
55
if (!IS_INTOBJ(num))
56
return (WINDOW*)0;
57
n = INT_INTOBJ(num);
58
if (n < 0 || n * sizeof(Obj) >= GET_LEN_STRING(winlist))
59
return (WINDOW*)0;
60
return ((WINDOW**)CHARS_STRING(winlist))[n];
61
}
62
PANEL* pannum(Obj num) {
63
Int n;
64
if (!IS_INTOBJ(num))
65
return (PANEL*)0;
66
n = INT_INTOBJ(num);
67
/* no panel for stdscr */
68
if (n < 1 || n * sizeof(Obj) >= GET_LEN_STRING(panellist))
69
return (PANEL*)0;
70
return ((PANEL**)CHARS_STRING(panellist))[n];
71
}
72
73
Obj IsStdinATty(Obj self) {
74
if (isatty(0))
75
return True;
76
else
77
return False;
78
}
79
80
Obj IsStdoutATty(Obj self) {
81
if (isatty(1))
82
return True;
83
else
84
return False;
85
}
86
87
/* interface to configure some basic behaviour of the ncurses screen */
88
Obj Cbreak(Obj self) {
89
if (cbreak() != ERR)
90
return True;
91
else
92
return False;
93
}
94
95
Obj Nocbreak(Obj self) {
96
if (nocbreak() != ERR)
97
return True;
98
else
99
return False;
100
}
101
102
Obj Echo(Obj self) {
103
if (echo() != ERR)
104
return True;
105
else
106
return False;
107
}
108
109
Obj Noecho(Obj self) {
110
if (noecho() != ERR)
111
return True;
112
else
113
return False;
114
}
115
116
Obj Nl(Obj self) {
117
if (nl() != ERR)
118
return True;
119
else
120
return False;
121
}
122
123
Obj Nonl(Obj self) {
124
if (nonl() != ERR)
125
return True;
126
else
127
return False;
128
}
129
130
Obj Raw(Obj self) {
131
if (raw() != ERR)
132
return True;
133
else
134
return False;
135
}
136
137
Obj Noraw(Obj self) {
138
if (noraw() != ERR)
139
return True;
140
else
141
return False;
142
}
143
144
Obj Intrflush(Obj self, Obj num, Obj bf) {
145
WINDOW *win;
146
win = winnum(num);
147
if (!win)
148
return False;
149
if (bf == True)
150
if (intrflush(win, TRUE) != ERR)
151
return True;
152
else
153
return False;
154
else
155
if (intrflush(win, FALSE) != ERR)
156
return True;
157
else
158
return False;
159
}
160
161
Obj Keypad(Obj self, Obj num, Obj bf) {
162
WINDOW *win;
163
win = winnum(num);
164
if (!win)
165
return False;
166
if (bf == True)
167
if (keypad(win, TRUE) != ERR)
168
return True;
169
else
170
return False;
171
else
172
if (keypad(win, FALSE) != ERR)
173
return True;
174
else
175
return False;
176
}
177
178
Obj Idlok(Obj self, Obj num, Obj bf) {
179
WINDOW *win;
180
win = winnum(num);
181
if (!win)
182
return False;
183
if (bf == True)
184
if (idlok(win, TRUE) != ERR)
185
return True;
186
else
187
return False;
188
else
189
if (idlok(win, FALSE) != ERR)
190
return True;
191
else
192
return False;
193
}
194
195
Obj Leaveok(Obj self, Obj num, Obj bf) {
196
WINDOW *win;
197
win = winnum(num);
198
if (!win)
199
return False;
200
if (bf == True)
201
if (leaveok(win, TRUE) != ERR)
202
return True;
203
else
204
return False;
205
else
206
if (leaveok(win, FALSE) != ERR)
207
return True;
208
else
209
return False;
210
}
211
212
Obj Scrollok(Obj self, Obj num, Obj bf) {
213
WINDOW *win;
214
win = winnum(num);
215
if (!win)
216
return False;
217
if (bf == True)
218
if (scrollok(win, TRUE) != ERR)
219
return True;
220
else
221
return False;
222
else
223
if (scrollok(win, FALSE) != ERR)
224
return True;
225
else
226
return False;
227
}
228
229
Obj Clearok(Obj self, Obj num, Obj bf) {
230
WINDOW *win;
231
win = winnum(num);
232
if (!win)
233
return False;
234
if (bf == True)
235
if (clearok(win, TRUE) != ERR)
236
return True;
237
else
238
return False;
239
else
240
if (clearok(win, FALSE) != ERR)
241
return True;
242
else
243
return False;
244
}
245
246
Obj Immedok(Obj self, Obj num, Obj bf) {
247
WINDOW *win;
248
win = winnum(num);
249
if (!win)
250
return False;
251
if (bf == True)
252
immedok(win, TRUE);
253
else
254
immedok(win, FALSE);
255
return True;
256
}
257
258
Obj WTimeout(Obj self, Obj num, Obj time) {
259
WINDOW *win;
260
Int t;
261
win = winnum(num);
262
if (!win)
263
return False;
264
if (!IS_INTOBJ(time))
265
t = 0;
266
else
267
t = INT_INTOBJ(time);
268
wtimeout(win, (int)t);
269
return True;
270
}
271
272
Obj Napms(Obj self, Obj time) {
273
Int t;
274
if (!IS_INTOBJ(time))
275
t = 0;
276
else
277
t = INT_INTOBJ(time);
278
napms(t);
279
return True;
280
}
281
282
Obj Curs_set(Obj self, Obj vis) {
283
int res;
284
if (!IS_INTOBJ(vis))
285
return False;
286
res = curs_set(INT_INTOBJ(vis));
287
if (res == ERR)
288
return False;
289
return INTOBJ_INT(res);
290
}
291
292
Obj Savetty(Obj self) {
293
savetty();
294
return True;
295
}
296
297
Obj Resetty(Obj self) {
298
resetty();
299
return True;
300
}
301
302
static int default_curs_vis = ERR;
303
Obj ResetCursor(Obj self) {
304
if (default_curs_vis != ERR)
305
curs_set(default_curs_vis);
306
return True;
307
}
308
309
/* set default attributes, stored during init of ncurses XXX
310
Obj Attrsetdefault(Obj self) {
311
attr_set(startattr, startcp, 0);
312
return (Obj)0;
313
}*/
314
315
/* delete all windows, except stdscr, and panels; clear stdscr */
316
Obj ClearAll(Obj self) {
317
318
SET_LEN_STRING(winlist, sizeof(Obj));
319
SET_LEN_STRING(panellist, sizeof(Obj));
320
clear();
321
return (Obj)0;
322
}
323
324
/* basic functions: wrefresh, endwin, doupdate */
325
Obj WRefresh( Obj self, Obj num ) {
326
WINDOW* win;
327
win = winnum(num);
328
if (win) {
329
if (wrefresh(win) != ERR)
330
return True;
331
else
332
return False;
333
}
334
else
335
return False;
336
}
337
338
Obj Doupdate( Obj self ) {
339
if (doupdate() != ERR)
340
return True;
341
else
342
return False;
343
}
344
345
Obj Endwin( Obj self ) {
346
if (endwin() != ERR)
347
return True;
348
else
349
return False;
350
}
351
352
Obj Isendwin( Obj self ) {
353
if (isendwin())
354
return True;
355
else
356
return False;
357
}
358
359
360
/* create, delete, move windows */
361
Obj Newwin( Obj self, Obj nlines, Obj ncols, Obj begin_y, Obj begin_x) {
362
Int nl, nc, by, bx;
363
int num;
364
WINDOW *win;
365
366
if (IS_INTOBJ(nlines))
367
nl = INT_INTOBJ(nlines);
368
else
369
nl = 0;
370
if (IS_INTOBJ(ncols))
371
nc = INT_INTOBJ(ncols);
372
else
373
nc = 0;
374
if (IS_INTOBJ(begin_y))
375
by = INT_INTOBJ(begin_y);
376
else
377
by = 0;
378
if (IS_INTOBJ(begin_x))
379
bx = INT_INTOBJ(begin_x);
380
else
381
bx = 0;
382
win = newwin(nl, nc, by, bx);
383
if (win) {
384
num = GET_LEN_STRING(winlist)/sizeof(Obj);
385
GROW_STRING(winlist, (num+1)*sizeof(Obj));
386
((WINDOW**)(CHARS_STRING(winlist)))[num] = win;
387
SET_LEN_STRING(winlist, (num+1)*sizeof(Obj));
388
CHANGED_BAG(winlist);
389
return INTOBJ_INT(num);
390
}
391
else
392
return False;
393
}
394
395
Obj Delwin( Obj self, Obj num ) {
396
WINDOW* win;
397
Int i, n;
398
win = winnum(num);
399
if (win) {
400
if (delwin(win) != ERR) {
401
n = INT_INTOBJ(num);
402
((WINDOW**)(CHARS_STRING(winlist)))[n] = 0;
403
if ((n+1)*sizeof(Obj) == GET_LEN_STRING(winlist)) {
404
for (i = GET_LEN_STRING(winlist)/sizeof(Obj);
405
i > 0 && ((WINDOW**)(CHARS_STRING(winlist)))[i-1] == 0;
406
i--);
407
SET_LEN_STRING(winlist, i * sizeof(Obj));
408
}
409
CHANGED_BAG(winlist);
410
return True;
411
}
412
else
413
return False;
414
}
415
else
416
return False;
417
}
418
419
Obj Mvwin(Obj self, Obj num, Obj y, Obj x) {
420
Int iy, ix;
421
WINDOW *win;
422
win = winnum(num);
423
if (!win)
424
return False;
425
if (IS_INTOBJ(y))
426
iy = INT_INTOBJ(y);
427
else
428
iy = 0;
429
if (IS_INTOBJ(x))
430
ix = INT_INTOBJ(x);
431
else
432
ix = 0;
433
if (mvwin(win, iy, ix) != ERR)
434
return True;
435
else
436
return False;
437
}
438
439
/* moving curser, writing characters and strings to terminal */
440
Obj WMove(Obj self, Obj num, Obj y, Obj x) {
441
WINDOW *win;
442
Int iy, ix;
443
win = winnum(num);
444
if (!win)
445
return False;
446
if (IS_INTOBJ(y))
447
iy = INT_INTOBJ(y);
448
else
449
iy = 0;
450
if (IS_INTOBJ(x))
451
ix = INT_INTOBJ(x);
452
else
453
ix = 0;
454
if (wmove(win, iy, ix) != ERR)
455
return True;
456
else
457
return False;
458
}
459
460
/* whole window, or to EOL or to bottom of window */
461
Obj WClear( Obj self, Obj num ) {
462
WINDOW* win;
463
win = winnum(num);
464
if (win) {
465
if (wclear(win) != ERR)
466
return True;
467
else
468
return False;
469
}
470
else
471
return False;
472
}
473
474
Obj WErase( Obj self, Obj num ) {
475
WINDOW* win;
476
win = winnum(num);
477
if (win) {
478
if (werase(win) != ERR)
479
return True;
480
else
481
return False;
482
}
483
else
484
return False;
485
}
486
487
Obj WClrtoeol( Obj self, Obj num ) {
488
WINDOW* win;
489
win = winnum(num);
490
if (win) {
491
if (wclrtoeol(win) != ERR)
492
return True;
493
else
494
return False;
495
}
496
else
497
return False;
498
}
499
500
Obj WClrtobot( Obj self, Obj num ) {
501
WINDOW* win;
502
win = winnum(num);
503
if (win) {
504
if (wclrtobot(win) != ERR)
505
return True;
506
else
507
return False;
508
}
509
else
510
return False;
511
}
512
513
Obj WAddnstr(Obj self, Obj num, Obj str, Obj n) {
514
WINDOW *win;
515
Int len;
516
win = winnum(num);
517
if (!win)
518
return False;
519
if (!IS_STRING_REP(str))
520
return False;
521
if (!IS_INTOBJ(n))
522
len = GET_LEN_STRING(str);
523
else
524
len = INT_INTOBJ(n);
525
if (waddnstr(win, CSTR_STRING(str), len) != ERR)
526
return True;
527
else
528
return False;
529
}
530
531
/* ch can be a GAP character or an INTOBJ (possibly containing
532
attribute info) */
533
Obj WAddch(Obj self, Obj num, Obj ch) {
534
WINDOW *win;
535
Int ich;
536
win = winnum(num);
537
if (!win)
538
return False;
539
if (TNUM_OBJ(ch) == T_CHAR)
540
ich = *(UChar*)ADDR_OBJ(ch);
541
else if (IS_INTOBJ(ch))
542
ich = INT_INTOBJ(ch);
543
else
544
return False;
545
if (waddch(win, ich) != ERR)
546
return True;
547
else
548
return False;
549
}
550
551
#ifdef WIDECHARS
552
Obj WAddwch(Obj self, Obj num, Obj ch) {
553
WINDOW *win;
554
wchar_t ich[CCHARW_MAX];
555
cchar_t cc;
556
Obj c;
557
Int i;
558
559
win = winnum(num);
560
if (!win)
561
return False;
562
if (TNUM_OBJ(ch) == T_CHAR){
563
ich[0] = *(UChar*)ADDR_OBJ(ch);
564
ich[1] = L'\0';
565
}
566
else if (IS_INTOBJ(ch)){
567
ich[0] = INT_INTOBJ(ch);
568
ich[1] = L'\0';
569
}
570
else if (IS_LIST(ch)){
571
for (i=1, c=ELM0_LIST(ch,1); i < CCHARW_MAX && IS_INTOBJ(c);
572
i++, c=ELM0_LIST(ch,i)) {
573
ich[i-1] = INT_INTOBJ(c);
574
}
575
ich[i-1] = L'\0';
576
}
577
else
578
return False;
579
580
if (setcchar(&cc, ich, 0, 0, NULL) == ERR)
581
return False;
582
583
584
if (wecho_wchar(win, &cc) != ERR)
585
return True;
586
else
587
return False;
588
}
589
#endif
590
591
Obj WBorder(Obj self, Obj num, Obj chars) {
592
WINDOW *win;
593
Obj ls, rs, ts, bs, tl, tr, bl, br;
594
Int ils, irs, its, ibs, itl, itr, ibl, ibr;
595
if (IS_PLIST(chars) && LEN_PLIST(chars) > 7) {
596
ls = ELM_PLIST(chars, 1);
597
rs = ELM_PLIST(chars, 2);
598
ts = ELM_PLIST(chars, 3);
599
bs = ELM_PLIST(chars, 4);
600
tl = ELM_PLIST(chars, 5);
601
tr = ELM_PLIST(chars, 6);
602
bl = ELM_PLIST(chars, 7);
603
br = ELM_PLIST(chars, 8);
604
}
605
else {
606
ls = Fail; rs = Fail; ts = Fail; bs = Fail;
607
tl = Fail; tr = Fail; bl = Fail; br = Fail;
608
}
609
win = winnum(num);
610
if (!win)
611
return False;
612
if (TNUM_OBJ(ls) == T_CHAR)
613
ils = *(UChar*)ADDR_OBJ(ls);
614
else if (IS_INTOBJ(ls))
615
ils = INT_INTOBJ(ls);
616
else
617
ils = 0;
618
if (TNUM_OBJ(rs) == T_CHAR)
619
irs = *(UChar*)ADDR_OBJ(rs);
620
else if (IS_INTOBJ(rs))
621
irs = INT_INTOBJ(rs);
622
else
623
irs = 0;
624
if (TNUM_OBJ(ts) == T_CHAR)
625
its = *(UChar*)ADDR_OBJ(ts);
626
else if (IS_INTOBJ(ts))
627
its = INT_INTOBJ(ts);
628
else
629
its = 0;
630
if (TNUM_OBJ(bs) == T_CHAR)
631
ibs = *(UChar*)ADDR_OBJ(bs);
632
else if (IS_INTOBJ(bs))
633
ibs = INT_INTOBJ(bs);
634
else
635
ibs = 0;
636
if (TNUM_OBJ(tl) == T_CHAR)
637
itl = *(UChar*)ADDR_OBJ(tl);
638
else if (IS_INTOBJ(tl))
639
itl = INT_INTOBJ(tl);
640
else
641
itl = 0;
642
if (TNUM_OBJ(tr) == T_CHAR)
643
itr = *(UChar*)ADDR_OBJ(tr);
644
else if (IS_INTOBJ(tr))
645
itr = INT_INTOBJ(tr);
646
else
647
itr = 0;
648
if (TNUM_OBJ(bl) == T_CHAR)
649
ibl = *(UChar*)ADDR_OBJ(bl);
650
else if (IS_INTOBJ(bl))
651
ibl = INT_INTOBJ(bl);
652
else
653
ibl = 0;
654
if (TNUM_OBJ(br) == T_CHAR)
655
ibr = *(UChar*)ADDR_OBJ(br);
656
else if (IS_INTOBJ(br))
657
ibr = INT_INTOBJ(br);
658
else
659
ibr = 0;
660
if (wborder(win, (chtype)ils, (chtype)irs, (chtype)its, (chtype)ibs,
661
(chtype)itl, (chtype)itr, (chtype)ibl, (chtype)ibr) != ERR)
662
return True;
663
else
664
return False;
665
}
666
667
Obj WVline(Obj self, Obj num, Obj ch, Obj n) {
668
Int x, y, ich;
669
WINDOW *win;
670
win = winnum(num);
671
if (!win)
672
return False;
673
if (TNUM_OBJ(ch) == T_CHAR)
674
ich = *(UChar*)ADDR_OBJ(ch);
675
else if (IS_INTOBJ(ch))
676
ich = INT_INTOBJ(ch);
677
else
678
ich = 0;
679
if (!IS_INTOBJ(n))
680
getmaxyx(win, y, x);
681
else
682
y = INT_INTOBJ(n);
683
x = wvline(win, ich, y);
684
if (x != ERR)
685
return INTOBJ_INT(x);
686
else
687
return False;
688
}
689
690
Obj WHline(Obj self, Obj num, Obj ch, Obj n) {
691
Int x, y, ich;
692
WINDOW *win;
693
win = winnum(num);
694
if (!win)
695
return False;
696
if (TNUM_OBJ(ch) == T_CHAR)
697
ich = *(UChar*)ADDR_OBJ(ch);
698
else if (IS_INTOBJ(ch))
699
ich = INT_INTOBJ(ch);
700
else
701
ich = 0;
702
if (!IS_INTOBJ(n))
703
getmaxyx(win, y, x);
704
else
705
x = INT_INTOBJ(n);
706
y = whline(win, ich, x);
707
if (y != ERR)
708
return INTOBJ_INT(y);
709
else
710
return False;
711
}
712
713
/* returns integer which can be fed back in waddch */
714
Obj WInch(Obj self, Obj num) {
715
WINDOW *win;
716
win = winnum(num);
717
if (!win)
718
return False;
719
return INTOBJ_INT((Int) winch(win));
720
}
721
722
/* get size of window and cursor position */
723
Obj Getyx(Obj self, Obj num) {
724
WINDOW *win;
725
int x, y;
726
Obj res;
727
win = winnum(num);
728
if (!win)
729
return False;
730
res = NEW_PLIST(T_PLIST, 2);
731
SET_LEN_PLIST(res, 2);
732
getyx(win, y, x);
733
SET_ELM_PLIST(res, 1, INTOBJ_INT(y));
734
SET_ELM_PLIST(res, 2, INTOBJ_INT(x));
735
return res;
736
}
737
738
Obj Getbegyx(Obj self, Obj num) {
739
WINDOW *win;
740
int x, y;
741
Obj res;
742
win = winnum(num);
743
if (!win)
744
return False;
745
res = NEW_PLIST(T_PLIST, 2);
746
SET_LEN_PLIST(res, 2);
747
getbegyx(win, y, x);
748
SET_ELM_PLIST(res, 1, INTOBJ_INT(y));
749
SET_ELM_PLIST(res, 2, INTOBJ_INT(x));
750
return res;
751
}
752
753
Obj Getmaxyx(Obj self, Obj num) {
754
WINDOW *win;
755
int x, y;
756
Obj res;
757
win = winnum(num);
758
if (!win)
759
return False;
760
res = NEW_PLIST(T_PLIST, 2);
761
SET_LEN_PLIST(res, 2);
762
getmaxyx(win, y, x);
763
SET_ELM_PLIST(res, 1, INTOBJ_INT(y));
764
SET_ELM_PLIST(res, 2, INTOBJ_INT(x));
765
return res;
766
}
767
768
769
/* the win argument is used for possible echoing */
770
Obj WGetch(Obj self, Obj num) {
771
int c;
772
WINDOW *win;
773
win = winnum(num);
774
if (!win)
775
win = stdscr;
776
c = getch();
777
if (c != ERR)
778
return INTOBJ_INT(c == 127 ? KEY_BACKSPACE : c);
779
else
780
return False;
781
}
782
783
Obj Ungetch(Obj self, Obj ch) {
784
int ich;
785
if (!IS_INTOBJ(ch))
786
return False;
787
ich = (int) INT_INTOBJ(ch);
788
if (ungetch(ich) != ERR)
789
return True;
790
else
791
return False;
792
}
793
794
Obj Has_key(Obj self, Obj ch) {
795
int ich;
796
if (!IS_INTOBJ(ch))
797
return False;
798
ich = (int) INT_INTOBJ(ch);
799
if (has_key(ich) == TRUE)
800
return True;
801
else
802
return False;
803
}
804
805
806
807
/* Keys, we give symbols of standard special keys to GAP */
808
809
/* test with 'has_key' and add some more (?),
810
see http://hessling-editor.sourceforge.net/doc/misc/app2.html */
811
Obj InitKeys() {
812
Obj tmp;
813
814
tmp = NEW_PREC(0);
815
AssPRec(tmp, RNamName("DOWN"), INTOBJ_INT((Int)KEY_DOWN));
816
AssPRec(tmp, RNamName("UP"), INTOBJ_INT((Int)KEY_UP));
817
AssPRec(tmp, RNamName("LEFT"), INTOBJ_INT((Int)KEY_LEFT));
818
AssPRec(tmp, RNamName("RIGHT"), INTOBJ_INT((Int)KEY_RIGHT));
819
AssPRec(tmp, RNamName("HOME"), INTOBJ_INT((Int)KEY_HOME));
820
AssPRec(tmp, RNamName("END"), INTOBJ_INT((Int)KEY_END));
821
AssPRec(tmp, RNamName("PPAGE"), INTOBJ_INT((Int)KEY_PPAGE));
822
AssPRec(tmp, RNamName("NPAGE"), INTOBJ_INT((Int)KEY_NPAGE));
823
AssPRec(tmp, RNamName("BACKSPACE"), INTOBJ_INT((Int)KEY_BACKSPACE));
824
AssPRec(tmp, RNamName("DC"), INTOBJ_INT((Int)KEY_DC));
825
AssPRec(tmp, RNamName("ENTER"), INTOBJ_INT((Int)KEY_ENTER));
826
AssPRec(tmp, RNamName("IC"), INTOBJ_INT((Int)KEY_IC));
827
AssPRec(tmp, RNamName("REPLACE"), INTOBJ_INT((Int)KEY_REPLACE));
828
AssPRec(tmp, RNamName("STAB"), INTOBJ_INT((Int)KEY_STAB));
829
AssPRec(tmp, RNamName("F1"), INTOBJ_INT((Int)KEY_F(1)));
830
AssPRec(tmp, RNamName("F2"), INTOBJ_INT((Int)KEY_F(2)));
831
AssPRec(tmp, RNamName("F3"), INTOBJ_INT((Int)KEY_F(3)));
832
AssPRec(tmp, RNamName("F4"), INTOBJ_INT((Int)KEY_F(4)));
833
AssPRec(tmp, RNamName("F5"), INTOBJ_INT((Int)KEY_F(5)));
834
AssPRec(tmp, RNamName("F6"), INTOBJ_INT((Int)KEY_F(6)));
835
AssPRec(tmp, RNamName("F7"), INTOBJ_INT((Int)KEY_F(7)));
836
AssPRec(tmp, RNamName("F8"), INTOBJ_INT((Int)KEY_F(8)));
837
AssPRec(tmp, RNamName("F9"), INTOBJ_INT((Int)KEY_F(9)));
838
AssPRec(tmp, RNamName("F10"), INTOBJ_INT((Int)KEY_F(10)));
839
AssPRec(tmp, RNamName("F11"), INTOBJ_INT((Int)KEY_F(11)));
840
AssPRec(tmp, RNamName("F12"), INTOBJ_INT((Int)KEY_F(12)));
841
AssPRec(tmp, RNamName("F13"), INTOBJ_INT((Int)KEY_F(13)));
842
AssPRec(tmp, RNamName("F14"), INTOBJ_INT((Int)KEY_F(14)));
843
AssPRec(tmp, RNamName("F15"), INTOBJ_INT((Int)KEY_F(15)));
844
AssPRec(tmp, RNamName("F16"), INTOBJ_INT((Int)KEY_F(16)));
845
AssPRec(tmp, RNamName("F17"), INTOBJ_INT((Int)KEY_F(17)));
846
AssPRec(tmp, RNamName("F18"), INTOBJ_INT((Int)KEY_F(18)));
847
AssPRec(tmp, RNamName("F19"), INTOBJ_INT((Int)KEY_F(19)));
848
AssPRec(tmp, RNamName("F20"), INTOBJ_INT((Int)KEY_F(20)));
849
AssPRec(tmp, RNamName("F21"), INTOBJ_INT((Int)KEY_F(21)));
850
AssPRec(tmp, RNamName("F22"), INTOBJ_INT((Int)KEY_F(22)));
851
AssPRec(tmp, RNamName("F23"), INTOBJ_INT((Int)KEY_F(23)));
852
AssPRec(tmp, RNamName("F24"), INTOBJ_INT((Int)KEY_F(24)));
853
AssPRec(tmp, RNamName("A1"), INTOBJ_INT((Int)KEY_A1));
854
AssPRec(tmp, RNamName("A3"), INTOBJ_INT((Int)KEY_A3));
855
AssPRec(tmp, RNamName("B2"), INTOBJ_INT((Int)KEY_B2));
856
AssPRec(tmp, RNamName("C1"), INTOBJ_INT((Int)KEY_C1));
857
AssPRec(tmp, RNamName("C3"), INTOBJ_INT((Int)KEY_C3));
858
AssPRec(tmp, RNamName("MOUSE"), INTOBJ_INT((Int)KEY_MOUSE));
859
860
return tmp;
861
}
862
863
/* Line drawing characters on GAP level */
864
Obj InitLineDraw() {
865
Obj res;
866
res = NEW_PREC(0);
867
AssPRec(res, RNamName("BLOCK"), INTOBJ_INT((Int)ACS_BLOCK));
868
AssPRec(res, RNamName("BOARD"), INTOBJ_INT((Int)ACS_BOARD));
869
AssPRec(res, RNamName("BTEE"), INTOBJ_INT((Int)ACS_BTEE));
870
AssPRec(res, RNamName("BULLET"), INTOBJ_INT((Int)ACS_BULLET));
871
AssPRec(res, RNamName("CKBOARD"), INTOBJ_INT((Int)ACS_CKBOARD));
872
AssPRec(res, RNamName("DARROW"), INTOBJ_INT((Int)ACS_DARROW));
873
AssPRec(res, RNamName("DEGREE"), INTOBJ_INT((Int)ACS_DEGREE));
874
AssPRec(res, RNamName("DIAMOND"), INTOBJ_INT((Int)ACS_DIAMOND));
875
AssPRec(res, RNamName("GEQUAL"), INTOBJ_INT((Int)ACS_GEQUAL));
876
AssPRec(res, RNamName("HLINE"), INTOBJ_INT((Int)ACS_HLINE));
877
AssPRec(res, RNamName("LANTERN"), INTOBJ_INT((Int)ACS_LANTERN));
878
AssPRec(res, RNamName("LARROW"), INTOBJ_INT((Int)ACS_LARROW));
879
AssPRec(res, RNamName("LEQUAL"), INTOBJ_INT((Int)ACS_LEQUAL));
880
AssPRec(res, RNamName("LLCORNER"), INTOBJ_INT((Int)ACS_LLCORNER));
881
AssPRec(res, RNamName("LRCORNER"), INTOBJ_INT((Int)ACS_LRCORNER));
882
AssPRec(res, RNamName("LTEE"), INTOBJ_INT((Int)ACS_LTEE));
883
AssPRec(res, RNamName("NEQUAL"), INTOBJ_INT((Int)ACS_NEQUAL));
884
AssPRec(res, RNamName("PI"), INTOBJ_INT((Int)ACS_PI));
885
AssPRec(res, RNamName("PLMINUS"), INTOBJ_INT((Int)ACS_PLMINUS));
886
AssPRec(res, RNamName("PLUS"), INTOBJ_INT((Int)ACS_PLUS));
887
AssPRec(res, RNamName("RARROW"), INTOBJ_INT((Int)ACS_RARROW));
888
AssPRec(res, RNamName("RTEE"), INTOBJ_INT((Int)ACS_RTEE));
889
AssPRec(res, RNamName("S1"), INTOBJ_INT((Int)ACS_S1));
890
AssPRec(res, RNamName("S3"), INTOBJ_INT((Int)ACS_S3));
891
AssPRec(res, RNamName("S7"), INTOBJ_INT((Int)ACS_S7));
892
AssPRec(res, RNamName("S9"), INTOBJ_INT((Int)ACS_S9));
893
AssPRec(res, RNamName("STERLING"), INTOBJ_INT((Int)ACS_STERLING));
894
AssPRec(res, RNamName("TTEE"), INTOBJ_INT((Int)ACS_TTEE));
895
AssPRec(res, RNamName("UARROW"), INTOBJ_INT((Int)ACS_UARROW));
896
AssPRec(res, RNamName("ULCORNER"), INTOBJ_INT((Int)ACS_ULCORNER));
897
AssPRec(res, RNamName("URCORNER"), INTOBJ_INT((Int)ACS_URCORNER));
898
AssPRec(res, RNamName("VLINE"), INTOBJ_INT((Int)ACS_VLINE));
899
900
return res;
901
}
902
903
/* Attributes, we handle colors and standard attributes */
904
905
Obj InitAttrs() {
906
Obj tmp, cp;
907
UInt4 i, n;
908
909
tmp = NEW_PREC(0);
910
if (has_colors()) {
911
start_color();
912
use_default_colors();
913
AssPRec(tmp, RNamName("has_colors"), True);
914
/* initialize color pairs 1..64 */
915
cp = NEW_PLIST(T_PLIST, 64);
916
for (i = 1; i <= 64 && i < COLOR_PAIRS; i++) {
917
if (i < 64)
918
if (i%8 == i/8) {
919
init_pair(i, i%8, -1);
920
} else {
921
init_pair(i, i % 8, i/8);
922
}
923
else
924
init_pair(i, 0, -1);
925
n = COLOR_PAIR(i);
926
SET_ELM_PLIST(cp, i, INTOBJ_INT(n));
927
SET_LEN_PLIST(cp, (UInt)i);
928
}
929
AssPRec(tmp, RNamName("ColorPairs"), cp);
930
/* fgcolor with default background */
931
if (72 < COLOR_PAIRS) {
932
cp = NEW_PLIST(T_PLIST, 8);
933
SET_LEN_PLIST(cp, 8);
934
for (i = 0; i <= 7; i++) {
935
init_pair(65+i, i, -1);
936
n = COLOR_PAIR(65+i);
937
SET_ELM_PLIST(cp, i+1, INTOBJ_INT(n));
938
}
939
AssPRec(tmp, RNamName("ColorPairsFg"), cp);
940
}
941
/* bgcolor with default foreground */
942
if (80 < COLOR_PAIRS) {
943
cp = NEW_PLIST(T_PLIST, 8);
944
SET_LEN_PLIST(cp, 8);
945
for (i = 0; i <= 7; i++) {
946
init_pair(73+i, -1, i);
947
n = COLOR_PAIR(73+i);
948
SET_ELM_PLIST(cp, i+1, INTOBJ_INT(n));
949
}
950
AssPRec(tmp, RNamName("ColorPairsBg"), cp);
951
}
952
}
953
else {
954
AssPRec(tmp, RNamName("has_colors"), False);
955
}
956
/* the other attributes */
957
AssPRec(tmp, RNamName("NORMAL"), INTOBJ_INT(A_NORMAL));
958
AssPRec(tmp, RNamName("STANDOUT"), INTOBJ_INT(A_STANDOUT));
959
AssPRec(tmp, RNamName("UNDERLINE"), INTOBJ_INT(A_UNDERLINE));
960
AssPRec(tmp, RNamName("REVERSE"), INTOBJ_INT(A_REVERSE));
961
AssPRec(tmp, RNamName("BLINK"), INTOBJ_INT(A_BLINK));
962
AssPRec(tmp, RNamName("DIM"), INTOBJ_INT(A_DIM));
963
AssPRec(tmp, RNamName("BOLD"), INTOBJ_INT(A_BOLD));
964
965
return tmp;
966
}
967
968
Obj WAttrset(Obj self, Obj num, Obj attrs) {
969
Int i;
970
WINDOW *win;
971
win = winnum(num);
972
if (!win)
973
return False;
974
if (IS_INTOBJ(attrs))
975
i = INT_INTOBJ(attrs);
976
else
977
i = 0;
978
if (wattrset(win, i) != ERR)
979
return True;
980
else
981
return False;
982
}
983
984
Obj WAttron(Obj self, Obj num, Obj attrs) {
985
Int i;
986
WINDOW *win;
987
win = winnum(num);
988
if (!win)
989
return False;
990
if (IS_INTOBJ(attrs))
991
i = INT_INTOBJ(attrs);
992
else
993
i = 0;
994
if (wattron(win, i) != ERR)
995
return True;
996
else
997
return False;
998
}
999
1000
Obj WAttroff(Obj self, Obj num, Obj attrs) {
1001
Int i;
1002
WINDOW *win;
1003
win = winnum(num);
1004
if (!win)
1005
return False;
1006
if (IS_INTOBJ(attrs))
1007
i = INT_INTOBJ(attrs);
1008
else
1009
i = 0;
1010
if (wattroff(win, i) != ERR)
1011
return True;
1012
else
1013
return False;
1014
}
1015
1016
/* wattr_get is a macro and allows NULL pointers as arguments, this is
1017
checked in the code.
1018
If we call it with arguments which are obviously never NULL, then
1019
gcc >= 4.6 with -Wall or -Waddress issues a warning that a pointer
1020
is checked for not being NULL although it is never NULL.
1021
We wrap that macro in a function to avoid the warning. */
1022
int wattr_get_fun(WINDOW *win, attr_t * pa, short *ps, void *opts) {
1023
int ret;
1024
ret = wattr_get(win, pa, ps, opts);
1025
return ret;
1026
}
1027
Obj WAttrCPGet(Obj self, Obj num) {
1028
WINDOW *win;
1029
attr_t a;
1030
short cp;
1031
Obj res;
1032
win = winnum(num);
1033
if (!win)
1034
return False;
1035
wattr_get_fun(win, &a, &cp, NULL);
1036
res = NEW_PLIST(T_PLIST, 2);
1037
SET_LEN_PLIST(res, 2);
1038
SET_ELM_PLIST(res, 1, INTOBJ_INT((int)a));
1039
SET_ELM_PLIST(res, 2, INTOBJ_INT((int)cp));
1040
return res;
1041
};
1042
1043
1044
Obj WBkgdset(Obj self, Obj num, Obj attrs) {
1045
Int i;
1046
WINDOW *win;
1047
win = winnum(num);
1048
if (!win)
1049
return False;
1050
if (IS_INTOBJ(attrs))
1051
i = INT_INTOBJ(attrs);
1052
else
1053
i = 0;
1054
wbkgdset(win, i);
1055
return True;
1056
}
1057
1058
Obj WBkgd(Obj self, Obj num, Obj attrs) {
1059
Int i;
1060
WINDOW *win;
1061
win = winnum(num);
1062
if (!win)
1063
return False;
1064
if (IS_INTOBJ(attrs))
1065
i = INT_INTOBJ(attrs);
1066
else
1067
i = 0;
1068
wbkgd(win, i);
1069
return True;
1070
}
1071
1072
1073
/* Panels: create, delete, update, move, stack movements, hide, show */
1074
Obj New_panel(Obj self, Obj num) {
1075
WINDOW *win;
1076
PANEL *pan;
1077
int n;
1078
win = winnum(num);
1079
if (!win)
1080
return False;
1081
n = INT_INTOBJ(num);
1082
if (n == 0)
1083
/* no panel for stdscr */
1084
return False;
1085
pan = new_panel(win);
1086
if (!pan)
1087
return False;
1088
GROW_STRING(panellist, (n+1)*sizeof(Obj));
1089
((PANEL**)(CHARS_STRING(panellist)))[n] = pan;
1090
if ((n+1)*sizeof(Obj) > GET_LEN_STRING(panellist))
1091
SET_LEN_STRING(panellist, (n+1)*sizeof(Obj));
1092
CHANGED_BAG(panellist);
1093
return num;
1094
}
1095
1096
Obj Del_panel(Obj self, Obj pnum) {
1097
PANEL *pan;
1098
Int i, n;
1099
pan = pannum(pnum);
1100
if (!pan)
1101
return False;
1102
if (del_panel(pan) != ERR) {
1103
n = INT_INTOBJ(pnum);
1104
((PANEL**)(CHARS_STRING(panellist)))[n] = 0;
1105
if ((n+1)*sizeof(Obj) == GET_LEN_STRING(panellist)) {
1106
for (i = GET_LEN_STRING(panellist)/sizeof(Obj);
1107
i > 0 && ((PANEL**)(CHARS_STRING(panellist)))[i-1] == 0;
1108
i--);
1109
SET_LEN_STRING(panellist, i * sizeof(Obj));
1110
}
1111
CHANGED_BAG(panellist);
1112
return True;
1113
}
1114
else
1115
return False;
1116
}
1117
1118
Obj Update_panels(Obj self) {
1119
update_panels();
1120
return True;
1121
}
1122
1123
Obj Hide_panel(Obj self, Obj pnum) {
1124
PANEL *pan;
1125
pan = pannum(pnum);
1126
if (!pan)
1127
return False;
1128
if (hide_panel(pan) != ERR) {
1129
return True;
1130
}
1131
else
1132
return False;
1133
}
1134
1135
Obj Show_panel(Obj self, Obj pnum) {
1136
PANEL *pan;
1137
pan = pannum(pnum);
1138
if (!pan)
1139
return False;
1140
if (show_panel(pan) != ERR) {
1141
return True;
1142
}
1143
else
1144
return False;
1145
}
1146
1147
Obj Bottom_panel(Obj self, Obj pnum) {
1148
PANEL *pan;
1149
pan = pannum(pnum);
1150
if (!pan)
1151
return False;
1152
if (bottom_panel(pan) != ERR) {
1153
return True;
1154
}
1155
else
1156
return False;
1157
}
1158
1159
Obj Top_panel(Obj self, Obj pnum) {
1160
PANEL *pan;
1161
pan = pannum(pnum);
1162
if (!pan)
1163
return False;
1164
if (top_panel(pan) != ERR) {
1165
return True;
1166
}
1167
else
1168
return False;
1169
}
1170
1171
Obj Panel_above(Obj self, Obj pnum) {
1172
PANEL *pan;
1173
int i;
1174
pan = pannum(pnum);
1175
pan = panel_above(pan);
1176
if (!pan)
1177
return False;
1178
for(i = 1; ((PANEL**)(CHARS_STRING(panellist)))[i] != pan; i++);
1179
return INTOBJ_INT((Int)i);
1180
}
1181
1182
Obj Panel_below(Obj self, Obj pnum) {
1183
PANEL *pan;
1184
int i;
1185
pan = pannum(pnum);
1186
pan = panel_below(pan);
1187
if (!pan)
1188
return False;
1189
for(i = 1; ((PANEL**)(CHARS_STRING(panellist)))[i] != pan; i++);
1190
return INTOBJ_INT((Int)i);
1191
}
1192
1193
Obj Move_panel(Obj self, Obj pnum, Obj y, Obj x) {
1194
Int iy, ix;
1195
PANEL *pan;
1196
pan = pannum(pnum);
1197
if (!pan)
1198
return False;
1199
if (IS_INTOBJ(y))
1200
iy = INT_INTOBJ(y);
1201
else
1202
iy = 0;
1203
if (IS_INTOBJ(x))
1204
ix = INT_INTOBJ(x);
1205
else
1206
ix = 0;
1207
if (move_panel(pan, iy, ix) != ERR)
1208
return True;
1209
else
1210
return False;
1211
}
1212
1213
/* mouse interface if available */
1214
#ifdef NCURSES_MOUSE_VERSION
1215
static mmask_t mmaskbits[] = {
1216
BUTTON1_PRESSED, BUTTON1_RELEASED, BUTTON1_CLICKED, BUTTON1_DOUBLE_CLICKED,
1217
BUTTON1_TRIPLE_CLICKED,
1218
BUTTON2_PRESSED, BUTTON2_RELEASED, BUTTON2_CLICKED, BUTTON2_DOUBLE_CLICKED,
1219
BUTTON2_TRIPLE_CLICKED,
1220
BUTTON3_PRESSED, BUTTON3_RELEASED, BUTTON3_CLICKED, BUTTON3_DOUBLE_CLICKED,
1221
BUTTON3_TRIPLE_CLICKED,
1222
BUTTON4_PRESSED, BUTTON4_RELEASED, BUTTON4_CLICKED, BUTTON4_DOUBLE_CLICKED,
1223
BUTTON4_TRIPLE_CLICKED,
1224
BUTTON_SHIFT, BUTTON_CTRL, BUTTON_ALT, REPORT_MOUSE_POSITION
1225
#if NCURSES_MOUSE_VERSION == 2
1226
, BUTTON5_PRESSED, BUTTON5_RELEASED, BUTTON5_CLICKED, BUTTON5_DOUBLE_CLICKED,
1227
BUTTON5_TRIPLE_CLICKED,
1228
#endif
1229
};
1230
#if NCURSES_MOUSE_VERSION == 2
1231
# define LENmmaskbits 29
1232
#else
1233
# define LENmmaskbits 24
1234
#endif
1235
1236
1237
/* translate mmask_t to list of integers and vice versa */
1238
Obj IntlistMmask_t(mmask_t mask) {
1239
Obj res;
1240
Int l, i;
1241
res = NEW_PLIST(T_PLIST, 1);
1242
SET_LEN_PLIST(res, 0);
1243
for (l=1, i=0; i<LENmmaskbits; i++) {
1244
if (mask & mmaskbits[i]) {AssPlist(res, l, INTOBJ_INT(i)); l++;}
1245
}
1246
return res;
1247
}
1248
mmask_t mmaskIntlist(Obj list) {
1249
mmask_t res = (mmask_t)0;
1250
Int l, i, n;
1251
while (! IS_PLIST(list)) {
1252
list = ErrorReturnObj("<list> must be a plain list of integers, not a %s)",
1253
(Int)TNAM_OBJ(list), 0L,
1254
"you can replace <list> via 'return <list>;'" );
1255
}
1256
l = LEN_PLIST(list);
1257
for (i = 0; i<l; i++) {
1258
n = INT_INTOBJ(ELM_PLIST(list, i+1));
1259
if (n >= 0 && n < LENmmaskbits) {res += mmaskbits[n];}
1260
}
1261
return res;
1262
}
1263
1264
Obj Mousemask(Obj self, Obj list) {
1265
mmask_t new, old;
1266
Obj res;
1267
while (! IS_PLIST(list)) {
1268
list = ErrorReturnObj("<list> must be a plain list of integers, not a %s)",
1269
(Int)TNAM_OBJ(list), 0L,
1270
"you can replace <list> via 'return <list>;'" );
1271
}
1272
new = mmaskIntlist(list);
1273
new = mousemask(new, &old);
1274
res = NEW_PREC(0);
1275
AssPRec(res, RNamName("new"), IntlistMmask_t(new));
1276
AssPRec(res, RNamName("old"), IntlistMmask_t(old));
1277
return res;
1278
}
1279
1280
static MEVENT mev;
1281
1282
Obj GetMouse(Obj self) {
1283
int y, x;
1284
Obj res, mask;
1285
if (getmouse(&mev) == ERR) return Fail;
1286
mask = IntlistMmask_t(mev.bstate);
1287
y = mev.y;
1288
x = mev.x;
1289
/* find panels/windows from above under mouse event */
1290
res = NEW_PLIST(T_PLIST, 3);
1291
SET_LEN_PLIST(res, 3);
1292
SET_ELM_PLIST(res, 1, INTOBJ_INT(y));
1293
SET_ELM_PLIST(res, 2, INTOBJ_INT(x));
1294
SET_ELM_PLIST(res, 3, mask);
1295
return res;
1296
}
1297
1298
Obj Wenclose(Obj self, Obj wnum, Obj iy, Obj ix) {
1299
WINDOW *win;
1300
int y, x;
1301
win = winnum(wnum);
1302
if (win == NULL) return False;
1303
if (! IS_INTOBJ(iy)) return False;
1304
else y = INT_INTOBJ(iy);
1305
if (! IS_INTOBJ(ix)) return False;
1306
else x = INT_INTOBJ(ix);
1307
if (wenclose(win, y, x) == TRUE) return True;
1308
else return False;
1309
}
1310
1311
Obj Mouseinterval( Obj len) {
1312
if (! IS_INTOBJ(len)) return INTOBJ_INT(mouseinterval(200));
1313
return INTOBJ_INT(mouseinterval(INT_INTOBJ(len)));
1314
}
1315
1316
1317
#endif
1318
1319
1320
/*F * * * * * * * * * * * initialize package * * * * * * * * * * * * * * * */
1321
1322
1323
1324
/****************************************************************************
1325
**
1326
1327
*V GVarFilts . . . . . . . . . . . . . . . . . . . list of filters to export
1328
*/
1329
/*static StructGVarFilt GVarFilts [] = {
1330
1331
{ "IS_BOOL", "obj", &IsBoolFilt,
1332
IsBoolHandler, "src/bool.c:IS_BOOL" },
1333
1334
{ 0 }
1335
1336
}; ?????*/
1337
1338
/****************************************************************************
1339
**
1340
1341
*V GVarFuncs . . . . . . . . . . . . . . . . . . list of functions to export
1342
*/
1343
static StructGVarFunc GVarFuncs [] = {
1344
1345
/* XXX { "attrsetdefault", 0, "", Attrsetdefault, "ncurses.c:Attrsetdefault" }, */
1346
{ "ClearAll", 0, "", ClearAll, "ncurses.c:ClearAll" },
1347
{ "cbreak", 0, "", Cbreak, "ncurses.c:Cbreak" },
1348
{ "nocbreak", 0, "", Nocbreak, "ncurses.c:Nocbreak" },
1349
{ "echo", 0, "", Echo, "ncurses.c:Echo" },
1350
{ "noecho", 0, "", Noecho, "ncurses.c:Noecho" },
1351
{ "intrflush", 2, "win, bool", Intrflush, "ncurses.c:Intrflush" },
1352
{ "keypad", 2, "win, bool", Keypad, "ncurses.c:Keypad" },
1353
{ "idlok", 2, "win, bool", Idlok, "ncurses.c:Idlok" },
1354
{ "leaveok", 2, "win, bool", Leaveok, "ncurses.c:Leaveok" },
1355
{ "scrollok", 2, "win, bool", Scrollok, "ncurses.c:Scrollok" },
1356
{ "clearok", 2, "win, bool", Clearok, "ncurses.c:Clearok" },
1357
{ "immedok", 2, "win, bool", Immedok, "ncurses.c:Immedok" },
1358
{ "raw", 0, "", Raw, "ncurses.c:Raw" },
1359
{ "noraw", 0, "", Noraw, "ncurses.c:Noraw" },
1360
{ "nl", 0, "", Nl, "ncurses.c:Nl" },
1361
{ "nonl", 0, "", Nonl, "ncurses.c:Nonl" },
1362
{ "curs_set", 1, "vis", Curs_set, "ncurses.c:Curs_set" },
1363
{ "ResetCursor", 0, "", ResetCursor, "ncurses.c:ResetCursor" },
1364
{ "wtimeout", 2, "win, time", WTimeout, "ncurses.c:WTimeout" },
1365
{ "IsStdinATty", 0, "", IsStdinATty, "ncurses.c:IsStdinATty" },
1366
{ "IsStdoutATty", 0, "", IsStdoutATty, "ncurses.c:IsStdoutATty" },
1367
{ "savetty", 0, "", Savetty, "ncurses.c:Savetty" },
1368
{ "resetty", 0, "", Resetty, "ncurses.c:Resetty" },
1369
{ "napms", 1, "time", Napms, "ncurses.c:Napms" },
1370
{ "doupdate", 0, "", Doupdate, "ncurses.c:Doupdate" },
1371
{ "wrefresh", 1, "win", WRefresh, "ncurses.c:WRefresh" },
1372
{ "wclear", 1, "win", WClear, "ncurses.c:WClear" },
1373
{ "werase", 1, "win", WErase, "ncurses.c:WErase" },
1374
{ "wclrtoeol", 1, "win", WClrtoeol, "ncurses.c:WClrtoeol" },
1375
{ "wclrtobot", 1, "win", WClrtobot, "ncurses.c:WClrtobot" },
1376
{ "endwin", 0, "", Endwin, "ncurses.c:Endwin" },
1377
{ "isendwin", 0, "", Isendwin, "ncurses.c:Isendwin" },
1378
{ "newwin", 4, "nlines, ncols, begin_y, begin_x",
1379
Newwin, "ncurses.c:Newwin" },
1380
{ "delwin", 1, "win", Delwin, "ncurses.c:Delwin" },
1381
{ "mvwin", 3, "win, y, x", Mvwin, "ncurses.c:Mvwin" },
1382
{ "wmove", 3, "win, y, x", WMove, "ncurses.c:WMove" },
1383
{ "waddnstr", 3, "win, str, len", WAddnstr, "ncurses.c:WAddnstr" },
1384
{ "waddch", 2, "win, ch", WAddch, "ncurses.c:WAddch" },
1385
#ifdef WIDECHARS
1386
{ "wecho_wchar", 2, "win, ch", WAddwch, "ncurses.c:WAddwch" },
1387
#endif
1388
{ "wborder", 2, "win, chars", WBorder, "ncurses.c:WBorder" },
1389
{ "wvline", 3, "win, ch, n", WVline, "ncurses.c:WVline" },
1390
{ "whline", 3, "win, ch, n", WHline, "ncurses.c:WHline" },
1391
{ "winch", 1, "win", WInch, "ncurses.c:WInch" },
1392
{ "wgetch", 1, "win", WGetch, "ncurses.c:WGetch" },
1393
{ "ungetch", 1, "ch", Ungetch, "ncurses.c:Ungetch" },
1394
{ "has_key", 1, "ch", Has_key, "ncurses.c:Has_key" },
1395
{ "getyx", 1, "win", Getyx, "ncurses.c:Getyx" },
1396
{ "getbegyx", 1, "win", Getbegyx, "ncurses.c:Getbegyx" },
1397
{ "getmaxyx", 1, "win", Getmaxyx, "ncurses.c:Getmaxyx" },
1398
{ "wattr_get", 1, "win", WAttrCPGet, "ncurses.c:WAttrCPGet" },
1399
{ "wattrset", 2, "win, attr", WAttrset, "ncurses.c:WAttrset" },
1400
{ "wattron", 2, "win, attr", WAttron, "ncurses.c:WAttron" },
1401
{ "wattroff", 2, "win, attr", WAttroff, "ncurses.c:WAttroff" },
1402
{ "wbkgdset", 2, "win, attr", WBkgdset, "ncurses.c:WBkgdset" },
1403
{ "wbkgd", 2, "win, attr", WBkgd, "ncurses.c:WBkgd" },
1404
{ "new_panel", 1, "win", New_panel, "ncurses.c:New_panel" },
1405
{ "update_panels", 0, "", Update_panels, "ncurses.c:Update_panels" },
1406
{ "bottom_panel", 1, "pan", Bottom_panel, "ncurses.c:Bottom_panel" },
1407
{ "top_panel", 1, "pan", Top_panel, "ncurses.c:Top_panel" },
1408
{ "show_panel", 1, "pan", Show_panel, "ncurses.c:Show_panel" },
1409
{ "hide_panel", 1, "pan", Hide_panel, "ncurses.c:Hide_panel" },
1410
{ "panel_above", 1, "pan", Panel_above, "ncurses.c:Panel_above" },
1411
{ "panel_below", 1, "pan", Panel_below, "ncurses.c:Panel_below" },
1412
{ "move_panel", 3, "pan, y, x", Move_panel, "ncurses.c:Move_panel" },
1413
{ "del_panel", 1, "pan", Del_panel, "ncurses.c:Del_panel" },
1414
#ifdef NCURSES_MOUSE_VERSION
1415
{ "mousemask", 1, "list", Mousemask, "ncurses.c:Mousemask" },
1416
{ "mouseinterval", 1, "len", Mouseinterval, "ncurses.c:Mouseinterval" },
1417
{ "getmouse", 0, "", GetMouse, "ncurses.c:GetMouse" },
1418
{ "wenclose", 3, "win, y, x", Wenclose, "ncurses.c:Wenclose" },
1419
#endif
1420
1421
{ 0 }
1422
1423
};
1424
1425
1426
1427
/**************************************************************************
1428
1429
*F InitKernel( <module> ) . . . . . . . . initialise kernel data structures
1430
*/
1431
static Int InitKernel (
1432
StructInitInfo * module )
1433
{
1434
1435
/* return success */
1436
InitGlobalBag( &winlist, "src/ncurses.c:winlist" );
1437
InitGlobalBag( &panellist, "src/ncurses.c:panellist" );
1438
1439
/* init filters and functions */
1440
InitHdlrFuncsFromTable( GVarFuncs );
1441
1442
return 0;
1443
}
1444
1445
/****************************************************************************
1446
**
1447
*F PostRestore( <module> ) . . . . . . . . . . . . . after restore workspace
1448
*/
1449
static Int PostRestore (
1450
StructInitInfo * module )
1451
{
1452
Int i, gvar;
1453
Obj tmp, vers;
1454
char* cvers = VERSION;
1455
1456
/* setup and initialize the ncurses package */
1457
winlist = NEW_STRING(sizeof(Obj));
1458
SET_LEN_STRING(winlist, sizeof(Obj));
1459
panellist = NEW_STRING(sizeof(Obj));
1460
SET_LEN_STRING(panellist, sizeof(Obj));
1461
1462
#ifdef WIDECHARS
1463
/* set locale from environment */
1464
setlocale(LC_ALL,"");
1465
#endif
1466
1467
/* make sure that TERM is set to avoid exit by initscr */
1468
if (getenv("TERM") == NULL)
1469
putenv("TERM=vt102");
1470
1471
/* init filters and functions
1472
we assign the functions to components of a record "NCurses" */
1473
/* (re)build kernel part of NCurses */
1474
gvar = GVarName("NCurses");
1475
tmp = VAL_GVAR(gvar);
1476
if (!tmp) {
1477
tmp = NEW_PREC(0);
1478
}
1479
1480
if (! isatty(1))
1481
putenv("TERM=dumb");
1482
/* initialize ncurses */
1483
((WINDOW**)CHARS_STRING(winlist))[0] = initscr();
1484
((PANEL**)CHARS_STRING(panellist))[0] = 0;
1485
endwin();
1486
1487
for ( i = 0; GVarFuncs[i].name != 0; i++ ) {
1488
AssPRec(tmp, RNamName((Char*)GVarFuncs[i].name),
1489
NewFunctionC( GVarFuncs[i].name, GVarFuncs[i].nargs,
1490
GVarFuncs[i].args, GVarFuncs[i].handler ) );
1491
}
1492
AssPRec(tmp, RNamName("keys"), InitKeys() );
1493
AssPRec(tmp, RNamName("attrs"), InitAttrs() );
1494
AssPRec(tmp, RNamName("lineDraw"), InitLineDraw() );
1495
AssPRec(tmp, RNamName("winlist"), winlist);
1496
AssPRec(tmp, RNamName("panellist"), panellist);
1497
vers = NEW_STRING(strlen(cvers));
1498
memcpy(CHARS_STRING(vers), cvers, strlen(cvers));
1499
AssPRec(tmp, RNamName("KernelModuleVersion"), vers);
1500
1501
/* (re)assign */
1502
MakeReadWriteGVar( gvar);
1503
AssGVar( gvar, tmp );
1504
MakeReadOnlyGVar(gvar);
1505
1506
/* find and save cursor visibility */
1507
for(i = 0; default_curs_vis == ERR && i < 3; i++) {
1508
default_curs_vis = curs_set(i);
1509
}
1510
if (default_curs_vis != ERR)
1511
curs_set(default_curs_vis);
1512
1513
/* return success */
1514
return 0;
1515
}
1516
1517
/****************************************************************************
1518
**
1519
*F InitLibrary( <module> ) . . . . . . . initialise library data structures
1520
*/
1521
static Int InitLibrary (
1522
StructInitInfo * module )
1523
{
1524
PostRestore( module );
1525
1526
/* return success */
1527
return 0;
1528
}
1529
1530
1531
/****************************************************************************
1532
**
1533
*F InitInfopl() . . . . . . . . . . . . . . . . . table of init functions
1534
*/
1535
/* <name> returns the description of this module */
1536
static StructInitInfo module = {
1537
#ifdef NCURSESSTATIC
1538
/* type = */ MODULE_STATIC,
1539
#else
1540
/* type = */ MODULE_DYNAMIC,
1541
#endif
1542
/* name = */ "ncurses",
1543
/* revision_c = */ 0,
1544
/* revision_h = */ 0,
1545
/* version = */ 0,
1546
/* crc = */ 0,
1547
/* initKernel = */ InitKernel,
1548
/* initLibrary = */ InitLibrary,
1549
/* checkInit = */ 0,
1550
/* preSave = */ 0,
1551
/* postSave = */ 0,
1552
/* postRestore = */ PostRestore
1553
};
1554
1555
#ifndef NCURSESSTATIC
1556
StructInitInfo * Init__Dynamic ( void )
1557
{
1558
return &module;
1559
}
1560
#endif
1561
1562
StructInitInfo * Init__ncurses ( void )
1563
{
1564
return &module;
1565
}
1566
1567
1568