This repository has been archived by the owner on Jul 3, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
libpasncurses.pas
3992 lines (3504 loc) · 206 KB
/
libpasncurses.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
(******************************************************************************)
(* libPasNCurses *)
(* object pascal wrapper around ncurses library *)
(* https://invisible-island.net/ncurses/ncurses.html *)
(* *)
(* Copyright (c) 2020 Ivan Semenkov *)
(* https://github.com/isemenkov/libpasncurses ivan@semenkov.pro *)
(* Ukraine *)
(******************************************************************************)
(* *)
(* This source is free software; you can redistribute it and/or modify it *)
(* under the terms of the GNU General Public License as published by the Free *)
(* Software Foundation; either version 3 of the License. *)
(* *)
(* This code is distributed in the hope that it will be useful, but WITHOUT *)
(* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or *)
(* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for *)
(* more details. *)
(* *)
(* A copy of the GNU General Public License is available on the World Wide *)
(* Web at <http://www.gnu.org/copyleft/gpl.html>. You can also obtain it by *)
(* writing to the Free Software Foundation, Inc., 51 Franklin Street - Fifth *)
(* Floor, Boston, MA 02110-1335, USA. *)
(* *)
(******************************************************************************)
unit libpasncurses;
{$IFDEF FPC}
{$mode objfpc}{$H+}
{$ENDIF}
interface
uses
Classes, SysUtils;
{$IFDEF FPC}
{$PACKRECORDS C}
{$ENDIF}
{$IFDEF FPC}
{$IFDEF WINDOWS}
const libNCurses = 'libncursesw6.dll';
{$ENDIF}
{$IFDEF LINUX}
const libNCurses = 'libncurses.so';
{$ENDIF}
{$ELSE}
{$IFDEF MSWINDOWS OR defined(MSWINDOWS)}
const libNCurses = 'libncursesw6.dll';
{$ENDIF}
{$IFDEF LINUX}
const libNCurses = 'libncurses.so';
{$ENDIF}
{$ENDIF}
const
{ colors }
COLOR_BLACK = 0;
COLOR_RED = 1;
COLOR_GREEN = 2;
COLOR_YELLOW = 3;
COLOR_BLUE = 4;
COLOR_MAGENTA = 5;
COLOR_CYAN = 6;
COLOR_WHITE = 7;
ERR = -1;
OK = 0;
{ values for the _flags member }
_SUBWIN { is this a sub-window? } = $01;
_ENDLINE { is the window flush right? } = $02;
_FULLWIN { is the window full-screen? } = $04;
_SCROLLWIN { bottom edge is at screen bottom? } = $08;
_ISPAD { is this window a pad? } = $10;
_HASMOVED { has cursor moved since last refresh? } = $20;
_WRAPPED { cursor was just wrappped } = $40;
{ this value is used in the firstchar and lastchar fields to mark
unchanged lines }
_NOCHANGE = -1;
{ this value is used in the oldindex field to mark lines created by insertions
and scrolls. }
_NEWINDEX = -1;
CCHARW_MAX = 5;
A_NORMAL = 0;
A_ATTRIBUTES = Not (0 shl (0 + 8));
A_CHARTEXT = (1 shl (0 + 8)) - 1;
A_COLOR = ((1 shl 8) - 1) shl (0 + 8);
A_STANDOUT = 1 shl (8 + 8);
A_UNDERLINE = 1 shl (9 + 8);
A_REVERSE = 1 shl (10 + 8);
A_BLINK = 1 shl (11 + 8);
A_DIM = 1 shl (12 + 8);
A_BOLD = 1 shl (13 + 8);
A_ALTCHARSET = 1 shl (14 + 8);
A_INVIS = 1 shl (15 + 8);
A_PROTECT = 1 shl (16 + 8);
A_HORIZONTAL = 1 shl (17 + 8);
A_LEFT = 1 shl (18 + 8);
A_LOW = 1 shl (19 + 8);
A_RIGHT = 1 shl (20 + 8);
A_TOP = 1 shl (21 + 8);
A_VERTICAL = 1 shl (22 + 8);
A_ITALIC = 1 shl (23 + 8);
WA_ATTRIBUTES = A_ATTRIBUTES;
WA_NORMAL = A_NORMAL;
WA_STANDOUT = A_STANDOUT;
WA_UNDERLINE = A_UNDERLINE;
WA_REVERSE = A_REVERSE;
WA_BLINK = A_BLINK;
WA_DIM = A_DIM;
WA_BOLD = A_BOLD;
WA_ALTCHARSET = A_ALTCHARSET;
WA_INVIS = A_INVIS;
WA_PROTECT = A_PROTECT;
WA_HORIZONTAL = A_HORIZONTAL;
WA_LEFT = A_LEFT;
WA_LOW = A_LOW;
WA_RIGHT = A_RIGHT;
WA_TOP = A_TOP;
WA_VERTICAL = A_VERTICAL;
WA_ITALIC = A_ITALIC;
{ Pseudo-character tokens outside ASCII range. The curses wgetch() function
will return any given one of these only if the corresponding k- capability
is defined in your terminal's terminfo entry.
Some keys (KEY_A1, etc) are arranged like this:
a1 up a3
left b2 right
c1 down c3
A few key codes do not depend upon the terminfo entry. }
KEY_CODE_YES { A wchar_t contains a key code } = &0400;
KEY_MIN { Minimum curses key } = &0401;
KEY_BREAK { Break key (unreliable) } = &0401;
KEY_SRESET { Soft (partial) reset (unreliable) } = &0530;
KEY_RESET { Reset or hard reset (unreliable) } = &0531;
{ These definitions were generated by ./MKkey_defs.sh ./Caps ./Caps-ncurses }
KEY_DOWN { down-arrow key } = &0402;
KEY_UP { up-arrow key } = &0403;
KEY_LEFT { left-arrow key } = &0404;
KEY_RIGHT { right-arrow key } = &0405;
KEY_HOME { home key } = &0406;
KEY_BACKSPACE { backspace key } = &0407;
KEY_F0 { Function keys. Space for 64 } = &0410;
KEY_F1 = &0411;
KEY_F2 = &0412;
KEY_F3 = &0413;
KEY_F4 = &0414;
KEY_F5 = &0415;
KEY_F6 = &0416;
KEY_F7 = &0417;
KEY_F8 = &0420;
KEY_F9 = &0421;
KEY_F10 = &0422;
KEY_F11 = &0423;
KEY_F12 = &0424;
KEY_DL { delete-line key } = &0510;
KEY_IL { insert-line key } = &0511;
KEY_DC { delete-character key } = &0512;
KEY_IC { insert-character key } = &0513;
KEY_EIC { sent by rmir or smir in insert mode } = &0514;
KEY_CLEAR { clear-screen or erase key } = &0515;
KEY_EOS { clear-to-end-of-screen key } = &0516;
KEY_EOL { clear-to-end-of-line key } = &0517;
KEY_SF { scroll-forward key } = &0520;
KEY_SR { scroll-backward key } = &0521;
KEY_NPAGE { next-page key } = &0522;
KEY_PPAGE { previous-page key } = &0523;
KEY_STAB { set-tab key } = &0524;
KEY_CTAB { clear-tab key } = &0525;
KEY_CATAB { clear-all-tabs key } = &0526;
KEY_ENTER { enter/send key } = &0527;
KEY_PRINT { print key } = &0532;
KEY_LL { lower-left key (home down) } = &0533;
KEY_A1 { upper left of keypad } = &0534;
KEY_A3 { upper right of keypad } = &0535;
KEY_B2 { center of keypad } = &0536;
KEY_C1 { lower left of keypad } = &0537;
KEY_C3 { lower right of keypad } = &0540;
KEY_BTAB { back-tab key } = &0541;
KEY_BEG { begin key } = &0542;
KEY_CANCEL { cancel key } = &0543;
KEY_CLOSE { close key } = &0544;
KEY_COMMAND { command key } = &0545;
KEY_COPY { copy key } = &0546;
KEY_CREATE { create key } = &0547;
KEY_END { end key } = &0550;
KEY_EXIT { exit key } = &0551;
KEY_FIND { find key } = &0552;
KEY_HELP { help key } = &0553;
KEY_MARK { mark key } = &0554;
KEY_MESSAGE { message key } = &0555;
KEY_MOVE { move key } = &0556;
KEY_NEXT { next key } = &0557;
KEY_OPEN { open key } = &0560;
KEY_OPTIONS { options key } = &0561;
KEY_PREVIOUS { previous key } = &0562;
KEY_REDO { redo key } = &0563;
KEY_REFERENCE { reference key } = &0564;
KEY_REFRESH { refresh key } = &0565;
KEY_REPLACE { replace key } = &0566;
KEY_RESTART { restart key } = &0567;
KEY_RESUME { resume key } = &0570;
KEY_SAVE { save key } = &0571;
KEY_SBEG { shifted begin key } = &0572;
KEY_SCANCEL { shifted cancel key } = &0573;
KEY_SCOMMAND { shifted command key } = &0574;
KEY_SCOPY { shifted copy key } = &0575;
KEY_SCREATE { shifted create key } = &0576;
KEY_SDC { shifted delete-character key } = &0577;
KEY_SDL { shifted delete-line key } = &0600;
KEY_SELECT { select key } = &0601;
KEY_SEND { shifted end key } = &0602;
KEY_SEOL { shifted clear-to-end-of-line key } = &0603;
KEY_SEXIT { shifted exit key } = &0604;
KEY_SFIND { shifted find key } = &0605;
KEY_SHELP { shifted help key } = &0606;
KEY_SHOME { shifted home key } = &0607;
KEY_SIC { shifted insert-character key } = &0610;
KEY_SLEFT { shifted left-arrow key } = &0611;
KEY_SMESSAGE { shifted message key } = &0612;
KEY_SMOVE { shifted move key } = &0613;
KEY_SNEXT { shifted next key } = &0614;
KEY_SOPTIONS { shifted options key } = &0615;
KEY_SPREVIOUS { shifted previous key } = &0616;
KEY_SPRINT { shifted print key } = &0617;
KEY_SREDO { shifted redo key } = &0620;
KEY_SREPLACE { shifted replace key } = &0621;
KEY_SRIGHT { shifted right-arrow key } = &0622;
KEY_SRSUME { shifted resume key } = &0623;
KEY_SSAVE { shifted save key } = &0624;
KEY_SSUSPEND { shifted suspend key } = &0625;
KEY_SUNDO { shifted undo key } = &0626;
KEY_SUSPEND { suspend key } = &0627;
KEY_UNDO { undo key } = &0630;
KEY_MOUSE { Mouse event has occurred } = &0631;
KEY_RESIZE { Terminal resize event } = &0632;
KEY_EVENT { We were interrupted by an event } = &0633;
KEY_MAX { Maximum key value is 0633 } = &0777;
NCURSES_BUTTON_RELEASED = 001;
NCURSES_BUTTON_PRESSED = 002;
NCURSES_BUTTON_CLICKED = 004;
NCURSES_DOUBLE_CLICKED = 010;
NCURSES_TRIPLE_CLICKED = 020;
NCURSES_RESERVED_EVENT = 040;
{ trace masks }
TRACE_DISABLE { turn off tracing } = $0000;
TRACE_TIMES { trace user and system times of updates } = $0001;
TRACE_TPUTS { trace tputs calls } = $0002;
TRACE_UPDATE { trace update actions, old & new screens } = $0004;
TRACE_MOVE { trace cursor moves and scrolls } = $0008;
TRACE_CHARPUT { trace all character outputs } = $0010;
TRACE_ORDINARY { trace all update actions } = $001F;
TRACE_CALLS { trace all curses calls } = $0020;
TRACE_VIRTPUT { trace virtual character puts } = $0040;
TRACE_IEVENT { trace low-level input processing } = $0080;
TRACE_BITS { trace state of TTY control bits } = $0100;
TRACE_ICALLS { trace internal/nested calls } = $0200;
TRACE_CCALLS { trace per-character calls } = $0400;
TRACE_DATABASE { trace read/write of terminfo/termcap data } = $0800;
TRACE_ATTRS { trace attribute updates } = $1000;
E_OK = 0;
E_SYSTEM_ERROR = -1;
E_BAD_ARGUMENT = -2;
E_POSTED = -3;
E_CONNECTED = -4;
E_BAD_STATE = -5;
E_NO_ROOM = -6;
E_NOT_POSTED = -7;
E_UNKNOWN_COMMAND = -8;
E_NO_MATCH = -9;
E_NOT_SELECTABLE = -10;
E_NOT_CONNECTED = -11;
E_REQUEST_DENIED = -12;
E_INVALID_FIELD = -13;
E_CURRENT = -14;
{ Menu options: }
O_ONEVALUE = $01;
O_SHOWDESC = $02;
O_ROWMAJOR = $04;
O_IGNORECASE = $08;
O_SHOWMATCH = $10;
O_NONCYCLIC = $20;
O_MOUSE_MENU = $40;
{ Item options: }
O_SELECTABLE = $01;
{ Define keys }
REQ_LEFT_ITEM = KEY_MAX + 1;
REQ_RIGHT_ITEM = KEY_MAX + 2;
REQ_UP_ITEM = KEY_MAX + 3;
REQ_DOWN_ITEM = KEY_MAX + 4;
REQ_SCR_ULINE = KEY_MAX + 5;
REQ_SCR_DLINE = KEY_MAX + 6;
REQ_SCR_DPAGE = KEY_MAX + 7;
REQ_SCR_UPAGE = KEY_MAX + 8;
REQ_FIRST_ITEM = KEY_MAX + 9;
REQ_LAST_ITEM = KEY_MAX + 10;
REQ_NEXT_ITEM = KEY_MAX + 11;
REQ_PREV_ITEM = KEY_MAX + 12;
REQ_TOGGLE_ITEM = KEY_MAX + 13;
REQ_CLEAR_PATTERN = KEY_MAX + 14;
REQ_BACK_PATTERN = KEY_MAX + 15;
REQ_NEXT_MATCH = KEY_MAX + 16;
REQ_PREV_MATCH = KEY_MAX + 17;
MIN_MENU_COMMAND = KEY_MAX + 1;
MAX_MENU_COMMAND = KEY_MAX + 17;
{ Some AT&T code expects MAX_COMMAND to be out-of-band not just for menu
commands but for forms ones as well. }
MAX_COMMAND = KEY_MAX + 128;
{ field justification }
NO_JUSTIFICATION = 0;
JUSTIFY_LEFT = 1;
JUSTIFY_CENTER = 2;
JUSTIFY_RIGHT = 3;
{ field options }
O_VISIBLE = $0001;
O_ACTIVE = $0002;
O_PUBLIC = $0004;
O_EDIT = $0008;
O_WRAP = $0010;
O_BLANK = $0020;
O_AUTOSKIP = $0040;
O_NULLOK = $0080;
O_PASSOK = $0100;
O_STATIC = $0200;
O_DYNAMIC_JUSTIFY { ncurses extension } = $0400;
O_NO_LEFT_STRIP { ncurses extension } = $0800;
O_EDGE_INSERT_STAY{ ncurses extension } = $1000;
O_INPUT_LIMIT { ncurses extension } = $2000;
{ form options }
O_NL_OVERLOAD = $0001;
O_BS_OVERLOAD = $0002;
{ form driver commands }
REQ_NEXT_PAGE { move to next page } = KEY_MAX + 1;
REQ_PREV_PAGE { move to previous page } = KEY_MAX + 2;
REQ_FIRST_PAGE { move to first page } = KEY_MAX + 3;
REQ_LAST_PAGE { move to last page } = KEY_MAX + 4;
REQ_NEXT_FIELD { move to next field } = KEY_MAX + 5;
REQ_PREV_FIELD { move to previous field } = KEY_MAX + 6;
REQ_FIRST_FIELD { move to first field } = KEY_MAX + 7;
REQ_LAST_FIELD { move to last field } = KEY_MAX + 8;
REQ_SNEXT_FIELD { move to sorted next field } = KEY_MAX + 9;
REQ_SPREV_FIELD { move to sorted prev field } = KEY_MAX + 10;
REQ_SFIRST_FIELD { move to sorted first field } = KEY_MAX + 11;
REQ_SLAST_FIELD { move to sorted last field } = KEY_MAX + 12;
REQ_LEFT_FIELD { move to left to field } = KEY_MAX + 13;
REQ_RIGHT_FIELD { move to right to field } = KEY_MAX + 14;
REQ_UP_FIELD { move to up to field } = KEY_MAX + 15;
REQ_DOWN_FIELD { move to down to field } = KEY_MAX + 16;
REQ_NEXT_CHAR { move to next char in field } = KEY_MAX + 17;
REQ_PREV_CHAR { move to prev char in field } = KEY_MAX + 18;
REQ_NEXT_LINE { move to next line in field } = KEY_MAX + 19;
REQ_PREV_LINE { move to prev line in field } = KEY_MAX + 20;
REQ_NEXT_WORD { move to next word in field } = KEY_MAX + 21;
REQ_PREV_WORD { move to prev word in field } = KEY_MAX + 22;
REQ_BEG_FIELD { move to first char in field } = KEY_MAX + 23;
REQ_END_FIELD { move after last char in fld } = KEY_MAX + 24;
REQ_BEG_LINE { move to beginning of line } = KEY_MAX + 25;
REQ_END_LINE { move after last char in line } = KEY_MAX + 26;
REQ_LEFT_CHAR { move left in field } = KEY_MAX + 27;
REQ_RIGHT_CHAR { move right in field } = KEY_MAX + 28;
REQ_UP_CHAR { move up in field } = KEY_MAX + 29;
REQ_DOWN_CHAR { move down in field } = KEY_MAX + 30;
REQ_NEW_LINE { insert/overlay new line } = KEY_MAX + 31;
REQ_INS_CHAR { insert blank char at cursor } = KEY_MAX + 32;
REQ_INS_LINE { insert blank line at cursor } = KEY_MAX + 33;
REQ_DEL_CHAR { delete char at cursor } = KEY_MAX + 34;
REQ_DEL_PREV { delete char before cursor } = KEY_MAX + 35;
REQ_DEL_LINE { delete line at cursor } = KEY_MAX + 36;
REQ_DEL_WORD { delete word at cursor } = KEY_MAX + 37;
REQ_CLR_EOL { clear to end of line } = KEY_MAX + 38;
REQ_CLR_EOF { clear to end of field } = KEY_MAX + 39;
REQ_CLR_FIELD { clear entire field } = KEY_MAX + 40;
REQ_OVL_MODE { begin overlay mode } = KEY_MAX + 41;
REQ_INS_MODE { begin insert mode } = KEY_MAX + 42;
REQ_SCR_FLINE { scroll field forward a line } = KEY_MAX + 43;
REQ_SCR_BLINE { scroll field backward a line } = KEY_MAX + 44;
REQ_SCR_FPAGE { scroll field forward a page } = KEY_MAX + 45;
REQ_SCR_BPAGE { scroll field backward a page } = KEY_MAX + 46;
REQ_SCR_FHPAGE { scroll field forward half page } = KEY_MAX + 47;
REQ_SCR_BHPAGE { scroll field backward half page } = KEY_MAX + 48;
REQ_SCR_FCHAR { horizontal scroll char } = KEY_MAX + 49;
REQ_SCR_BCHAR { horizontal scroll char } = KEY_MAX + 50;
REQ_SCR_HFLINE { horizontal scroll line } = KEY_MAX + 51;
REQ_SCR_HBLINE { horizontal scroll line } = KEY_MAX + 52;
REQ_SCR_HFHALF { horizontal scroll half line } = KEY_MAX + 53;
REQ_SCR_HBHALF { horizontal scroll half line } = KEY_MAX + 54;
REQ_VALIDATION { validate field } = KEY_MAX + 55;
REQ_NEXT_CHOICE { display next field choice } = KEY_MAX + 56;
REQ_PREV_CHOICE { display prev field choice } = KEY_MAX + 57;
MIN_FORM_COMMAND { used by form_driver } = KEY_MAX + 1;
MAX_FORM_COMMAND { used by form_driver } = KEY_MAX + 57;
type
NCURSES_ATTR_T = type Integer;
{ The standard type used for color values, and for color-pairs. The latter
allows the curses library to enumerate the combinations of foreground and
background colors used by an application, and is normally the product of the
total foreground and background colors.
X/Open uses "short" for both of these types, ultimately because they are
numbers from the SVr4 terminal database, which uses 16-bit signed values. }
PNCURSES_COLOR_T = ^NCURSES_COLOR_T;
NCURSES_COLOR_T = type ShortInt;
PNCURSES_PAIRS_T = ^NCURSES_PAIRS_T;
NCURSES_PAIRS_T = type ShortInt;
{ The internal type used for window dimensions. }
NCURSES_SIZE_T = type ShortInt;
{ Control type used for tparm's arguments. While X/Open equates long and
char* values, this is not always workable for 64-bit platforms. }
NCURSES_TPARM_ARG = type PInteger;
pchtype = ^chtype;
chtype = type Cardinal;
pmmask_t = ^mmask_t;
mmask_t = type Cardinal;
{ ...must be at least as wide as chtype }
pattr_t = ^attr_t;
attr_t = chtype;
NCURSES_BOOL = type Boolean;
SCREEN = type Pointer;
PSCREEN = ^SCREEN;
pldat = ^ldat;
ldat = type Pointer;
PWINDOW = ^WINDOW;
pdat = record
_pad_x : NCURSES_SIZE_T;
_pad_y : NCURSES_SIZE_T;
_pad_top : NCURSES_SIZE_T;
_pad_left : NCURSES_SIZE_T;
_pad_bottom : NCURSES_SIZE_T;
_pad_right : NCURSES_SIZE_T;
end;
{ cchar_t stores an array of CCHARW_MAX wide characters. The first is
normally a spacing character. The others are non-spacing. If those
(spacing and nonspacing) do not fill the array, a null L'\0' follows.
Otherwise, a null is assumed to follow when extracting via getcchar(). }
cchar_t = record
attr : attr_t;
chars : array [0..CCHARW_MAX] of WideChar;
ext_color : Integer;
end;
_win_st = record
_cury, _curx : NCURSES_SIZE_T; { current cursor position }
{ window location and size }
_maxy, _maxx : NCURSES_SIZE_T; { maximums of x and y, NOT window size }
_begy, _begx : NCURSES_SIZE_T; { screen coords of upper-left-hand corner }
_flags : ShortInt; { window state flags }
{ attribute tracking }
_attrs : attr_t; { current attribute for non-space character }
_bkgd : chtype; { current background char/attribute pair }
{ option values set by user }
_notimeout : Boolean; { no time out on function-key entry? }
_clear : Boolean; { consider all data in the window invalid? }
_leaveok : Boolean; { OK to not reset cursor on exit? }
_scroll : Boolean; { OK to scroll this window? }
_idlok : Boolean; { OK to use insert/delete line? }
_idcok : Boolean; { OK to use insert/delete char? }
_immed : Boolean; { window in immed mode? (not yet used) }
_sync : Boolean; { window in sync mode? }
_use_keypad : Boolean; { process function keys into KEY_ symbols? }
_delay : Integer; { 0 = nodelay, <0 = blocking, >0 = delay }
_line : pldat; { the actual line data }
{ global screen state }
_regtop : NCURSES_SIZE_T; { top line of scrolling region }
_regbottom : NCURSES_SIZE_T; { bottom line of scrolling region }
{ these are used only if this is a sub-window }
_parx : Integer; { x coordinate of this window in parent }
_pary : Integer; { y coordinate of this window in parent }
_parent : PWINDOW; { pointer to parent if a sub-window }
{ these are used only if this is a pad }
_pad : pdat;
_yoffset : NCURSES_SIZE_T; { real begy is _begy + _yoffset }
_bkgrnd : cchar_t; { current background char/attribute pair }
_color : Integer; { current color-pair for non-space character}
end;
WINDOW = _win_st;
PMEVENT = ^MEVENT;
MEVENT = record
id : Shortint; { ID to distinguish multiple devices }
x, y, z : Integer; { event coordinates (character-cell) }
bstate : mmask_t; { button state bits }
end;
{ Curses uses a helper function. Define our type for this to simplify
extending it for the sp-funcs feature. }
NCURSES_OUTC = function (putc : Integer) : Integer of object;
NCURSES_SP_OUTC = function (src : PSCREEN; val : Integer) : Integer of
object;
NCURSES_WINDOW_CB = function (win : PWINDOW; ptr : Pointer) : Integer of
object;
NCURSES_SCREEN_CB = function (scr : PSCREEN; ptr : Pointer) : Integer of
object;
ripoffline_init_callback = function (win : PWINDOW; val : Integer) : Integer
of object;
PPANEL = ^PANEL;
PANEL = record
win : PWINDOW;
below : PPANEL;
above : PPANEL;
user : Pointer;
end;
Menu_Options = type Integer;
Item_Options = type Integer;
PTEXT = ^TEXT;
TEXT = record
str : PChar;
length : Word;
end;
PMENU = ^MENU;
PPITEM = ^PITEM;
PITEM = ^ITEM;
ITEM = record
name : TEXT; { name of menu item }
description : TEXT; { description of item, optional in display }
imenu : PMENU; { Pointer to parent menu }
userptr : Pointer; { Pointer to user defined per item data }
opt : Item_Options; { Item options }
index : Smallint; { Item number if connected to a menu }
y : Smallint; { y and x location of item in menu }
x : Smallint;
value : Boolean; { Selection value }
left : PITEM; { neighbor items }
right : PITEM;
up : PITEM;
down : PITEM;
end;
Menu_Hook = procedure (mnu : PMENU) of object;
MENU = record
height : Smallint; { Nr. of chars high }
width : Smallint; { Nr. of chars wide }
rows : Smallint; { Nr. of items high }
cols : Smallint; { Nr. of items wide }
frows : Smallint; { Nr. of formatted items high }
fcols : Smallint; { Nr. of formatted items wide }
arows : Smallint; { Nr. of items high (actual) }
namelen : Smallint; { Max. name length }
desclen : Smallint; { Max. description length }
marklen : Smallint; { Length of mark, if any }
itemlen : Smallint; { Length of one item }
spc_desc : Smallint;{ Spacing for descriptor }
spc_cols : Smallint;{ Spacing for columns }
spc_rows : Smallint;{ Spacing for rows }
pattern : PChar; { Buffer to store match chars }
pindex : Smallint; { Index into pattern buffer }
win : PWINDOW; { Window containing menu }
sub : PWINDOW; { Subwindow for menu display }
userwin : PWINDOW; { User's window }
usersub : PWINDOW; { User's subwindow }
items : PPITEM; { array of items }
nitems : Smallint; { Nr. of items in menu }
curitem : PITEM; { Current item }
toprow : Smallint; { Top row of menu }
fore : chtype; { Selection attribute }
back : chtype; { Nonselection attribute }
grey : chtype; { Inactive attribute }
pad : Byte; { Pad character }
menuinit : Menu_Hook; { User hooks }
menuterm : Menu_Hook;
iteminit : Menu_Hook;
itemterm : Menu_Hook;
userptr : Pointer; { Pointer to menus user data }
mark : PChar; { Pointer to marker string }
opt : Menu_Options; { Menu options }
status : Word; { Internal state of menu }
end;
PFIELD_CELL = ^FIELD_CELL;
FIELD_CELL = type Pointer;
Form_Options = type Integer;
Field_Options = type Integer;
ppagenode = ^pagenode;
pagenode = record
pmin : Smallint;
pmax : Smallint;
smin : Smallint;
smax : Smallint;
end;
_PPAGE = ^_PAGE;
_PAGE = pagenode;
pformnode = ^formnode;
ptypenode = ^typenode;
pfieldnode = ^fieldnode;
fieldnode = record
status : Word; { flags }
rows : Smallint; { size in rows }
cols : Smallint; { size in cols }
frow : Smallint; { first row }
fcol : Smallint; { first col }
drows : Integer; { dynamic rows }
dcols : Integer; { dynamic cols }
maxgrow : Integer; { maximum field growth }
nrow : Integer; { off-screen rows }
nbuf : Smallint; { additional buffers }
just : Smallint; { justification }
page : Smallint; { page on form }
index : Smallint; { into form -> field }
pad : Integer; { pad character }
fore : chtype; { foreground attribute }
back : chtype; { background attribute }
opts : Field_Options; { options }
snext : pfieldnode; { sorted order pointer }
sprev : pfieldnode; { sorted order pointer }
link : pfieldnode; { linked field chain }
form : pformnode; { containing form }
field_type : ptypenode; { field type }
arg : Pointer; { argument for type }
buf : PFIELD_CELL; { field buffers }
usrptr : Pointer; { user pointer }
end;
PFIELD = ^FIELD;
PPFIELD = ^PFIELD;
FIELD = fieldnode;
forminit_callback = procedure (node : pformnode) of object;
formterm_callback = procedure (node : pformnode) of object;
fieldinit_callback = procedure (node : pformnode) of object;
fieldterm_callback = procedure (node : pformnode) of object;
formnode = record
status : Word; { flags }
rows : Smallint; { size in rows }
cols : Smallint; { size in cols }
currow : Integer; { current row in field window }
curcol : Integer; { current col in field window }
toprow : Integer; { in scrollable field window }
begincol : Integer; { in horiz. scrollable field }
maxfield : Smallint;{ number of fields }
maxpage : Smallint; { number of pages }
curpage : Smallint; { index into page }
opts : Form_Options;{ options }
win : PWINDOW; { window }
sub : PWINDOW; { subwindow }
w : PWINDOW; { window for current field }
field : PPFIELD; { field [maxfield] }
current : PFIELD; { current field }
page : _PPAGE; { page [maxpage] }
usrptr : Pointer; { user pointer }
forminit : forminit_callback;
formterm : formterm_callback;
fieldinit : fieldinit_callback;
fieldterm : fieldterm_callback;
end;
PFORM = ^FORM;
FORM = formnode;
makearg_callback = function (args : array of const) : Pointer of object;
copyarg_callback = function (const ptr : Pointer) : Pointer of object;
freearg_callback = procedure (args : Pointer) of object;
fcheck_callback = function (fld : PFIELD; const ptr : Pointer) : Boolean
of object;
ccheck_callback = function (val : Integer; const ptr : Pointer) : Boolean
of object;
next_callback = function (fld : PFIELD; const ptr : Pointer) : Boolean
of object;
prev_callback = function (fld : PFIELD; const ptr : Pointer) : Boolean
of object;
typenode = record
status : Word; { flags }
ref : Longint; { reference count }
left : ptypenode; { ptr to operand for | }
right: ptypenode; { ptr to operand for | }
makearg : makearg_callback; { make fieldtype arg }
copyarg : copyarg_callback; { copy fieldtype arg }
freearg : freearg_callback; { free fieldtype arg }
fcheck : fcheck_callback; { field validation }
ccheck : ccheck_callback; { character validation }
next : next_callback; { enumerate next value }
prev : prev_callback; { enumerate prev value }
end;
PFIELDTYPE = ^FIELDTYPE;
FIELDTYPE = typenode;
Form_Hook = procedure (frm : PFORM) of object;
field_check_callback = function (fld : PFIELD; const ptr : Pointer) : Boolean
of object;
char_check_callback = function (val : Integer; const ptr : Pointer) : Boolean
of object;
{
var
TYPE_ALPHA : PFIELDTYPE; external;
TYPE_ALNUM : PFIELDTYPE; external;
TYPE_ENUM : PFIELDTYPE; external;
TYPE_INTEGER : PFIELDTYPE; external;
TYPE_NUMERIC : PFIELDTYPE; external;
TYPE_REGEXP : PFIELDTYPE; external;
TYPE_IPV4 : PFIELDTYPE; external;
}
{ Function prototypes. This is the complete X/Open Curses list of required
functions. Those marked `generated' will have sources generated from the
macro definitions later in this file, in order to satisfy XPG4.2
requirements. }
{ The addch, waddch, mvaddch and mvwaddch routines put the character ch into
the given window at its current window position, which is then advanced.
They are analogous to putchar in stdio. If the advance is at the right
margin, the cursor automatically wraps to the beginning of the next line. At
the bottom of the current scrolling region, if scrollok is enabled, the
scrolling region is scrolled up one line.
If ch is a tab, newline, or backspace, the cursor is moved appropriately
within the window. Backspace moves the cursor one character left; at the
left edge of a window it does nothing. Newline does a clrtoeol, then moves
the cursor to the window left margin on the next line, scrolling the window
if on the last line. Tabs are considered to be at every eighth column. The
tab interval may be altered by setting the TABSIZE variable.
If ch is any control character other than tab, newline, or backspace, it is
drawn in ^X notation. Calling winch after adding a control character does
not return the character itself, but instead returns the ^-representation of
the control character.
Video attributes can be combined with a character argument passed to addch
or related functions by logical-ORing them into the character. (Thus, text,
including attributes, can be copied from one place to another using inch and
addch.) See the curs_attr(3X) page for values of predefined video attribute
constants that can be usefully OR'ed into characters.
The echochar and wechochar routines are equivalent to a call to addch
followed by a call to refresh, or a call to waddch followed by a call to
wrefresh. The knowledge that only a single character is being output is used
and, for non-control characters, a considerable performance gain may be seen
by using these routines instead of their equivalents. }
function addch (const ch : chtype) : Integer; cdecl; external libNCurses;
function waddch (win : PWINDOW; const ch : chtype) : Integer; cdecl;
external libNCurses;
function mvaddch (y : Integer; x : Integer; const ch : chtype) : Integer;
cdecl; external libNCurses;
function mvwaddch (win : PWINDOW; y : Integer; x : Integer; const ch: chtype):
Integer; cdecl; external libNCurses;
function echochar (const ch : chtype) : Integer; cdecl; external libNCurses;
function wechochar (win : PWINDOW; const ch : chtype) : Integer; cdecl;
external libNCurses;
{ These routines copy chstr into the window image structure at and after the
current cursor position. The four routines with n as the last argument copy
at most n elements, but no more than will fit on the line. If n=-1 then the
whole string is copied, to the maximum number of characters that will fit on
the line.
The window cursor is not advanced, and these routines work faster than
waddnstr. On the other hand, they do not perform any kind of checking (such
as for the newline, backspace, or carriage return characters), they do not
advance the current cursor position, they do not expand other control
characters to ^-escapes, and they truncate the string if it crosses the
right margin, rather than wrapping it around to the new line. }
function addchstr (const chstr : pchtype) : Integer; cdecl;
external libNCurses;
function addchnstr (const chstr : pchtype; n : Integer) : Integer; cdecl;
external libNCurses;
function waddchstr (win : PWINDOW; const chstr : pchtype) : Integer; cdecl;
external libNCurses;
function waddchnstr (win : PWINDOW; const chstr : pchtype; n : Integer) :
Integer; cdecl; external libNCurses;
function mvaddchstr (y : Integer; x : Integer; const chstr : pchtype) :
Integer; cdecl; external libNCurses;
function mvaddchnstr (y : Integer; x : Integer; const chstr : pchtype; n :
Integer) : Integer; cdecl; external libNCurses;
function mvwaddchstr (win : PWINDOW; y : Integer; x : Integer; const chstr :
pchtype) : Integer; cdecl; external libNCurses;
function mvwaddchnstr (win : PWINDOW; y : Integer; x : Integer; const chstr :
pchtype; n : Integer) : Integer; cdecl; external libNCurses;
{ These routines write the characters of the (null-terminated) character
string str on the given window. It is similar to calling waddch once for
each character in the string. The four routines with n as the last argument
write at most n characters. If n is -1, then the entire string will be
added, up to the maximum number of characters that will fit on the line, or
until a terminating null is reached. }
function addstr (const str : PChar) : Integer; cdecl; external libNCurses;
function addnstr (const str : PChar; n : Integer) : Integer; cdecl;
external libNCurses;
function waddstr (win : PWINDOW; const str : PChar) : Integer; cdecl;
external libNCurses;
function waddnstr (win : PWINDOW; const str : PChar; n : Integer) : Integer;
cdecl; external libNCurses;
function mvaddstr (y : Integer; x : Integer; const str : PChar) : Integer;
cdecl; external libNCurses;
function mvaddnstr (y : Integer; x : Integer; const str : PChar; n : Integer):
Integer; cdecl; external libNCurses;
function mvwaddstr (win : PWINDOW; y : Integer; x : Integer; const str :
PChar) : Integer; cdecl; external libNCurses;
function mvwaddnstr (win : PWINDOW; y : Integer; x : Integer; const str :
PChar; n : Integer) : Integer; cdecl; external libNCurses;
{ These routines manipulate the current attributes of the named window. The
current attributes of a window apply to all characters that are written into
the window with waddch, waddstr and wprintw. Attributes are a property of
the character, and move with the character through any scrolling and
insert/delete line/character operations. To the extent possible, they are
displayed as appropriate modifications to the graphic rendition of
characters put on the screen.
The routine attrset sets the current attributes of the given window to
attrs. The routine attroff turns off the named attributes without turning
any other attributes on or off. The routine attron turns on the named
attributes without affecting any others. The routine standout is the same as
attron(A_STANDOUT). The routine standend is the same as attrset(A_NORMAL) or
attrset, that is, it turns off all attributes.
The attrset and related routines do not affect the attributes used when
erasing portions of the window. See curs_bkgd for functions which modify
the attributes used for erasing and clearing.
The routine color_set sets the current color of the given window to the
foreground/background combination described by the color_pair_number. The
parameter opts is reserved for future use, applications must supply a null
pointer.
The routine wattr_get returns the current attribute and color pair for the
given window; attr_get returns the current attribute and color pair for
stdscr. The remaining attr_* functions operate exactly like the
corresponding attr* functions, except that they take arguments of type
attr_t rather than int.
The routine chgat changes the attributes of a given number of characters
starting at the current cursor location of stdscr. It does not update the
cursor and does not perform wrapping. A character count of -1 or greater
than the remaining window width means to change attributes all the way to
the end of the current line. The wchgat function generalizes this to any
window; the mvwchgat function does a cursor move before acting. In these
functions, the color argument is a color-pair index (as in the first
argument of init_pair, see curs_color(3X)). The opts argument is not
presently used, but is reserved for the future (leave it NULL). }
function attroff (attrs : NCURSES_ATTR_T) : Integer; cdecl;
external libNCurses;
function wattroff (win : PWINDOW; attrs : NCURSES_ATTR_T) : Integer; cdecl;
external libNCurses;
function attron (attrs : NCURSES_ATTR_T) : Integer; cdecl;
external libNCurses;
function wattron (win : PWINDOW; attrs : NCURSES_ATTR_T) : Integer; cdecl;
external libNCurses;
function attrset (attrs : NCURSES_ATTR_T) : Integer; cdecl;
external libNCurses;
function wattrset (win : PWINDOW; attrs : NCURSES_ATTR_T) : Integer; cdecl;
external libNCurses;
function color_set (color_pair_number : NCURSES_PAIRS_T; opts : Pointer) :
Integer; cdecl; external libNCurses;
function wcolor_set (win : PWINDOW; color_pair_number : NCURSES_PAIRS_T;
opts : Pointer) : Integer; cdecl; external libNCurses;
function standend : Integer; cdecl; external libNCurses;
function wstandend (win : PWINDOW) : Integer; cdecl; external libNCurses;
function standout : Integer; cdecl; external libNCurses;
function wstandout (win : PWINDOW) : Integer; cdecl; external libNCurses;
function attr_get (attrs : pattr_t; pair : NCURSES_PAIRS_T; opts : Pointer) :
Integer; cdecl; external libNCurses;
function wattr_get (win : PWINDOW; attrs : pattr_t; pair : PNCURSES_PAIRS_T;
opts : Pointer) : Integer; cdecl; external libNCurses;
function attr_off (attrs : attr_t; opts : Pointer) : Integer; cdecl;
external libNCurses;
function wattr_off (win : PWINDOW; attrs : attr_t; opts : Pointer) : Integer;
cdecl; external libNCurses;
function attr_on (attrs : attr_t; opts : Pointer) : Integer; cdecl;
external libNCurses;
function wattr_on (win : PWINDOW; attrs : attr_t; opts : Pointer) : Integer;
cdecl; external libNCurses;
function attr_set (attrs : attr_t; pair : NCURSES_PAIRS_T; opts : Pointer) :
Integer; cdecl; external libNCurses;
function wattr_set (win : PWINDOW; attrs : attr_t; pair : NCURSES_PAIRS_T;
opts : Pointer) : Integer; cdecl; external libNCurses;
function chgat (n : Integer; attr : attr_t; color : NCURSES_PAIRS_T;
const opts : Pointer) : Integer; cdecl; external libNCurses;
function wchgat (win : PWINDOW; n : Integer; attr : attr_t; color :
NCURSES_PAIRS_T; const opts : Pointer) : Integer; cdecl;
external libNCurses;
function mvchgat (y : Integer; x : Integer; n : Integer; attr : attr_t;
color : NCURSES_PAIRS_T; const opts : Pointer) : Integer; cdecl;
external libNCurses;
function mvwchgat (win : PWINDOW; y : Integer; x : Integer; n : Integer;
attr : attr_t; color : NCURSES_PAIRS_T; const opts : Pointer) : Integer;
cdecl; external libNCurses;
function PAIR_NUMBER (attr : Integer) : Integer; cdecl; external libNCurses;
{ The baudrate routine returns the output speed of the terminal. The number
returned is in bits per second, for example 9600, and is an integer.
The erasechar routine returns the user's current erase character.
The erasewchar routine stores the current erase character in the location
referenced by ch. If no erase character has been defined, the routine fails
and the location referenced by ch is not changed.
The has_ic routine is true if the terminal has insert- and delete- character
capabilities.
The has_il routine is true if the terminal has insert- and delete-line
capabilities, or can simulate them using scrolling regions. This might be
used to determine if it would be appropriate to turn on physical scrolling
using scrollok.
The killchar routine returns the user's current line kill character.
The killwchar routine stores the current line-kill character in the location
referenced by ch. If no line-kill character has been defined, the routine
fails and the location referenced by ch is not changed.
The longname routine returns a pointer to a static area containing a verbose
description of the current terminal. The maximum length of a verbose
description is 128 characters. It is defined only after the call to initscr
or newterm. The area is overwritten by each call to newterm and is not
restored by set_term, so the value should be saved between calls to newterm
if longname is going to be used with multiple terminals.
If a given terminal does not support a video attribute that an application
program is trying to use, curses may substitute a different video attribute
for it. The termattrs and term_attrs functions return a logical OR of all
video attributes supported by the terminal using A_ and WA_ constants
respectively. This information is useful when a curses program needs
complete control over the appearance of the screen.
The termname routine returns the terminal name used by setupterm. }
function baudrate : Integer; cdecl; external libNCurses;
function baudrate_sp (src : PSCREEN) : Integer; cdecl; external libNCurses;
function erasechar : Char; cdecl; external libNCurses;
function erasechar_sp (src : PSCREEN) : Char; cdecl; external libNCurses;
function erasewchar (ch : PWideChar) : Integer; cdecl; external libNCurses;
function has_ic : Boolean; cdecl; external libNCurses;
function has_ic_sp (src : PSCREEN) : Boolean; cdecl; external libNCurses;
function has_il : Boolean; cdecl; external libNCurses;
function has_il_sp (src : PSCREEN) : Boolean; cdecl; external libNCurses;
function killchar : Char; cdecl; external libNCurses;
function killchar_sp (src : PSCREEN) : Char; cdecl; external libNCurses;
function killwchar (ch : PWideChar) : Integer; cdecl; external libNCurses;
function longname : PChar; cdecl; external libNCurses;
function longname_sp (src : PSCREEN) : PChar; cdecl; external libNCurses;
function term_attrs : attr_t; cdecl; external libNCurses;
function termattrs : chtype; cdecl; external libNCurses;
function termattrs_sp (src : PSCREEN) : chtype; cdecl; external libNCurses;