-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathSystemCalls.clcl
820 lines (713 loc) · 25.2 KB
/
SystemCalls.clcl
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
class getopt_long_option
{
include MObjectBase;
name:String;
has_arg:int;
flag:pointer@int;
val_:int;
def initialize() {
}
def initialize(name:String, has_arg:int, flag:pointer@int, val_:char) {
self.name = name;
self.has_arg = has_arg;
self.flag = flag;
self.val_ = val_.to_int;
}
def clone(): getopt_long_option {
result := getopt_long_option();
if(self.name.identifyWith(null).negative()) {
result.name = self.name.clone();
}
result.has_arg = self.has_arg;
result.flag = self.flag;
result.val_ = self.val_;
return result;
}
}
class fd_set
{
include MObjectBase;
def initialize() {}
def allocSize(): static native ulong;
def clone():fd_set {
result := fd_set();
memcpy(result.headOfMemory(), self.headOfMemory(), allocSize());
return result;
}
}
class timeval
{
include MObjectBase;
tv_sec: time_t;
tv_usec: long;
def initialize() {}
def clone(): timeval {
result := timeval();
result.tv_sec = self.tv_sec;
result.tv_usec = self.tv_usec;
return result;
}
}
inherit System
{
def alarm(seconads: uint): static native uint;
def dup(old_fd:int): static native throws Exception;
# def dup3(old_fd:int, new_fd:int, flags:int): static native throws Exception;
def execvpe(path:String, argv:List<String>, envp:List<String>):static native throws Exception;
def initialize_system_calls_system():static native;
def initialize(): static {
inherit();
initialize_system_calls_system();
}
def getopt(optstring:String, opterr:bool=true): native static Tuple3<Integer, String?, Integer>;
# result is Integer --> (result value of getopt) String --> (optarg) Integer --> (optind)
def getopt_long(optstring:String, longopts:getopt_long_option[], opterr:bool=true): native static Tuple4<Integer, String?, Integer, Integer>;
# result is Integer --> (result value of getopt_long) String --> (optarg) Integer --> (optind) Integer --> longindex
def getopt_long_only(optstring:String, longopts:getopt_long_option[], opterr:bool=true): native static Tuple4<Integer, String?, Integer, Integer>;
# result is Integer --> (result value of getopt_long) String --> (optarg) Integer --> (optind) Integer --> longindex
O_CLOEXEC: static int;
no_argument:static int;
required_argument:static int;
optional_argument:static int;
typedef useconds_t int;
_IONBF: static int;
_IOLBF: static int;
_IOFBF: static int;
SIG_IGN:static pointer@sighandler_t;
SIG_DFL:static pointer@sighandler_t;
SIGHUP:static int;
SIGINT:static int;
SIGQUIT:static int;
SIGILL:static int;
SIGTRAP:static int;
SIGABRT:static int;
SIGBUS:static int;
SIGFPE:static int;
SIGKILL:static int;
SIGUSR1:static int;
SIGSEGV:static int;
SIGUSR2:static int;
SIGPIPE:static int;
SIGALRM:static int;
SIGTERM:static int;
SIGSTKFLT:static int;
SIGCHLD:static int;
SIGCONT:static int;
SIGSTOP:static int;
SIGTSTP:static int;
SIGTTIN:static int;
SIGTTOU:static int;
SIGURG:static int;
SIGXCPU:static int;
SIGXFSZ:static int;
SIGVTALRM:static int;
SIGPROF:static int;
SIGWINCH:static int;
SIGIO:static int;
SIGPWR:static int;
SIGSYS:static int;
def getppid():static native pid_t;
def setsid():static native pid_t throws Exception;
def getsid(pid:pid_t):static native pid_t throws Exception;
def setpgrp():static native pid_t throws Exception;
def getbsize(headerlenp:pointer@int, blocksizep:pointer@long): static native String;
def getuid(): static native uid_t;
def geteuid(): static native uid_t;
def getgid(): static native gid_t;
def getugid(): static native gid_t;
def isatty(fd:int): static native bool;
def umask(mask:mode_t): static native mode_t;
def usleep(usec:useconds_t): static native throws Exception;
def nanosleep(req:timespec, rem:timespec?): static native throws Exception;
def putenv(string:String): static native throws Exception;
def secure_getenv(name:String): static native String?;
def setvbuf(stream:pointer@FILE, buf:pointer?@char, mode:int, size:size_t): static native throws Exception;
def strncat(dest:pointer@char, src:pointer@char, size:size_t): static native pointer@char;
def strchr(str:pointer@char, c:byte): static native pointer?@char;
def signal(signum:int, handler:pointer@sighandler_t): static native pointer@sighandler_t throws Exception;
def signal(signum:int, handler:lambda(int)): static native lambda(int) throws Exception;
def FD_ZERO(fdset:fd_set): static native;
def FD_CLR(fd:int, fdset:fd_set): static native;
def FD_SET(fd:int, fdset:fd_set): static native;
def FD_ISSET(fd:int, fdset:fd_set): static native bool;
FD_SETSIZE:static int;
def select(nfds:int, readfds:fd_set?, writefds:fd_set?, errorfds:fd_set?, timeout:timeval?): static native int throws Exception;
SIOCADDRT:static int;
SIOCDELRT:static int;
SIOCRTMSG:static int;
SIOCGIFNAME: static int;
SIOCSIFLINK: static int;
SIOCGIFCONF: static int;
SIOCGIFFLAGS: static int;
SIOCSIFFLAGS: static int;
SIOCGIFADDR: static int;
SIOCSIFADDR: static int;
SIOCGIFDSTADDR: static int;
SIOCSIFDSTADDR: static int;
SIOCGIFBRDADDR: static int;
SIOCSIFBRDADDR: static int;
SIOCGIFNETMASK: static int;
SIOCSIFNETMASK: static int;
SIOCGIFMETRIC: static int;
SIOCSIFMETRIC: static int;
SIOCGIFMEM: static int;
SIOCSIFMEM: static int;
SIOCGIFMTU: static int;
SIOCSIFMTU: static int;
SIOCSIFNAME: static int;
SIOCSIFHWADDR: static int;
SIOCGIFENCAP: static int;
SIOCSIFENCAP: static int;
SIOCGIFHWADDR: static int;
SIOCGIFSLAVE: static int;
SIOCSIFSLAVE: static int;
SIOCADDMULTI: static int;
SIOCDELMULTI: static int;
SIOCGIFINDEX: static int;
SIOGIFINDEX: static int;
SIOCSIFPFLAGS: static int;
SIOCGIFPFLAGS: static int;
SIOCDIFADDR: static int;
SIOCSIFHWBROADCAST: static int;
SIOCGIFCOUNT: static int;
SIOCGIFBR: static int;
SIOCSIFBR: static int;
SIOCGIFTXQLEN: static int;
SIOCSIFTXQLEN: static int;
SIOCDARP:static int;
SIOCGARP:static int;
SIOCSARP:static int;
SIOCDRARP: static int;
SIOCGRARP: static int;
SIOCSRARP: static int;
SIOCGIFMAP: static int;
SIOCSIFMAP: static int;
SIOCADDDLCI: static int;
SIOCDELDLCI: static int;
SIOCDEVPRIVATE: static int;
SIOCPROTOPRIVATE: static int;
TIOCM_LE: static int;
TIOCM_DTR: static int;
TIOCM_RTS: static int;
TIOCM_ST: static int;
TIOCM_SR: static int;
TIOCM_CTS: static int;
TIOCM_CAR: static int;
TIOCM_RNG: static int;
TIOCM_DSR: static int;
TIOCM_CD: static int;
TIOCM_RI: static int;
N_TTY: static int;
N_SLIP: static int;
N_MOUSE: static int;
N_PPP: static int;
N_STRIP: static int;
N_AX25: static int;
N_X25: static int;
N_6PACK: static int;
N_MASC: static int;
N_R3964: static int;
N_PROFIBUS_FDL: static int;
N_IRDA: static int;
N_SMSBLOCK: static int;
N_HDLC: static int;
N_SYNC_PPP: static int;
N_HCI: static int;
TCGETS: static int;
TCSETS: static int;
TCSETSW: static int;
TCSETSF: static int;
TCGETA: static int;
TCSETA: static int;
TCSETAW: static int;
TCSETAF: static int;
TCSBRK: static int;
TCXONC: static int;
TCFLSH: static int;
TIOCEXCL: static int;
TIOCNXCL: static int;
TIOCSCTTY: static int;
TIOCGPGRP: static int;
TIOCSPGRP: static int;
TIOCOUTQ: static int;
TIOCSTI: static int;
TIOCGWINSZ: static int;
TIOCSWINSZ: static int;
TIOCMGET: static int;
TIOCMBIS: static int;
TIOCMBIC: static int;
TIOCMSET: static int;
TIOCGSOFTCAR: static int;
TIOCSSOFTCAR: static int;
FIONREAD: static int;
TIOCINQ: static int;
TIOCLINUX: static int;
TIOCCONS: static int;
TIOCGSERIAL: static int;
TIOCSSERIAL: static int;
TIOCPKT: static int;
FIONBIO: static int;
TIOCNOTTY: static int;
TIOCSETD: static int;
TIOCGETD: static int;
TCSBRKP: static int;
TIOCSBRK: static int;
TIOCCBRK: static int;
TIOCGSID: static int;
TIOCGRS485: static int;
TIOCSRS485: static int;
TIOCGPTN: static int;
TIOCSPTLCK: static int;
TIOCGDEV: static int;
TCGETX: static int;
TCSETX: static int;
TCSETXF: static int;
TCSETXW: static int;
TIOCSIG: static int;
TIOCVHANGUP: static int;
TIOCGPKT: static int;
TIOCGPTLCK: static int;
TIOCGEXCL: static int;
FIONCLEX: static int;
FIOCLEX: static int;
FIOASYNC: static int;
TIOCSERCONFIG: static int;
TIOCSERGWILD: static int;
TIOCSERSWILD: static int;
TIOCGLCKTRMIOS: static int;
TIOCSLCKTRMIOS: static int;
TIOCSERGSTRUCT: static int;
TIOCSERGETLSR : static int;
TIOCSERGETMULTI: static int;
TIOCSERSETMULTI: static int;
TIOCMIWAIT: static int;
TIOCGICOUNT: static int;
FIOQSIZE: static int;
TIOCPKT_DATA: static int;
TIOCPKT_FLUSHREAD: static int;
TIOCPKT_FLUSHWRITE: static int;
TIOCPKT_STOP: static int;
TIOCPKT_START: static int;
TIOCPKT_NOSTOP: static int;
TIOCPKT_DOSTOP: static int;
TIOCPKT_IOCTL: static int;
TIOCSER_TEMT:static int;
### curses ###
ACS_BLOCK:static int;
ACS_BOARD:static int;
ACS_BTEE:static int;
ACS_BULLET:static int;
ACS_CKBOARD:static int;
ACS_DARROW:static int;
ACS_DEGREE:static int;
ACS_DIAMOND:static int;
ACS_GEQUAL:static int;
ACS_HLINE:static int;
ACS_LANTERN:static int;
ACS_LARROW:static int;
ACS_LEQUAL:static int;
ACS_LLCORNER:static int;
ACS_LRCORNER:static int;
ACS_LTEE:static int;
ACS_NEQUAL:static int;
ACS_PI:static int;
ACS_PLMINUS:static int;
ACS_PLUS:static int;
ACS_RARROW:static int;
ACS_RTEE:static int;
ACS_S1:static int;
ACS_S3:static int;
ACS_S7:static int;
ACS_S9:static int;
ACS_STERLING:static int;
ACS_TTEE:static int;
ACS_UARROW:static int;
ACS_ULCORNER:static int;
ACS_URCORNER:static int;
ACS_VLINE:static int;
A_BLINK: static int;
A_BOLD:static int;
A_DIM:static int;
A_REVERSE:static int;
A_STANDOUT:static int;
A_UNDERLINE:static int;
A_ATTRIBUTES:static int;
A_ALTCHARSET:static int;
A_HORIZONTAL:static int;
A_LFET:static int;
A_LOW:static int;
A_TOP:static int;
A_VERTICAL:static int;
A_ITALIC:static int;
COLOR_BLACK:static int;
COLOR_RED:static int;
COLOR_GREEN:static int;
COLOR_YELLOW:static int;
COLOR_BLUE:static int;
COLOR_MAGENTA:static int;
COLOR_CYAN:static int;
COLOR_WHITE:static int;
typedef attr_t uint;
typedef chtype uint;
def addch(c:char): native throws Exception;
def addstr(str:String):native throws Exception;
def start_color():native throws Exception;
def init_pair(n:short, fg:short, bg:short): native throws Exception;
def COLOR_PAIR(n:int):native int;
def beep(): native throws Exception;
def def_shell_mode(): native throws Exception;
def def_prog_mode(): native throws Exception;
def wborder(win:pointer@WINDOW, ls:char, rs:char, ts:char, bs:char, tl:char, tr:char, bl:char, br:char): native throws Exception;
def border(ls:char, rs:char, ts:char, bs:char, tl:char, tr:char, bl:char, br:char): native throws Exception;
def idlok(win:pointer@WINDOW, flag:bool): native static int throws Exception;
def idcok(win:pointer@WINDOW, flag:bool): native static;
def clearok(win:pointer@WINDOW, flag:bool): native;
def immedok(win:pointer@WINDOW, flag:bool): native;
def leaveok(win:pointer@WINDOW, flag:bool): native;
def is_cleared(win:pointer@WINDOW):native bool;
def is_idcok(win:pointer@WINDOW): native bool;
def is_islok(win:pointer@WINDOW): native bool;
def is_immedok(win:pointer@WINDOW): native bool;
def is_keypad(win:pointer@WINDOW): native bool;
def is_leaveok(win:pointer@WINDOW): native bool;
def is_nodelay(win:pointer@WINDOW): native bool;
def is_notimeout(win:pointer@WINDOW): native bool;
# def is_pad(win:pointer@WINDOW): native bool;
def is_scrolok(win:pointer@WINDOW): native bool;
# def is_subwin(win:pointer@WINDOW): native bool;
def is_syncok(win:pointer@WINDOW): native bool;
def wgetparent(win:pointer@WINDOW): native pointer@WINDOW;
# def wgetdelay(win:pointer@WINDOW): native int;
def wgetscrreg(win:pointer@WINDOW, top:pointer@int, bottom:pointer@int): native;
def clrtobot(): native;
def wclrtobot(win:pointer@WINDOW): native;
def clrtoeol(): native;
def wclrtoeol(win:pointer@WINDOW): native;
def werase(win:pointer@WINDOW): native;
def resetty(): native;
def savetty(): native;
def reset_prog_mode(): native;
def reset_shell_mode():native;
def getsyx(y:int, x:int):native;
def setsyx(y:int, x:int):native;
def curs_set(visibility:bool):native int;
def napms(ms:int): native;
def flash(): native;
def can_change_color():native bool;
def has_colors(): native bool;
def init_color(pair:short, r:short, g:short, b:short): native;
def color_content(color:short, r:pointer@short, g:pointer@short, b:pointer@short):native;
def pair_content(pair:short, f:pointer@short, b:pointer@short): native;
#def reset_color_pairs(): native;
def COLOR_PAIRS(n:int):native int;
def PAIR_NUMBER(attr:int):native int;
def attr_get(attrs:pointer@attr_t, pair:pointer@short, opts:pointer): native;
def wattr_get(win:pointer@WINDOW, attrs:pointer@attr_t, pair:pointer@short, opts:pointer): native;
def attr_set(attrs:attr_t, pair:short, opts:pointer):native;
def wattr_set(win:pointer@WINDOW, attrs:attr_t, pair:short, opts:pointer):native;
def attr_off(attrs:attr_t, opts:pointer):native;
def wattr_off(win:pointer@WINDOW, attrs:attr_t, opts:pointer):native;
def attr_on(attrs:attr_t, opts:pointer):native;
def wattr_on(win:pointer@WINDOW, attrs:attr_t, opts:pointer):native;
def wattroff(win:pointer@WINDOW, attrs:int):native;
def wattron(win:pointer@WINDOW, attrs:int):native;
def attrset(attrs:int):native;
def wattrset(win:pointer@WINDOW,attrs:int):native;
def chgat(n:int, attr:attr_t, pair:short, opts:pointer):native;
def wchgat(win:pointer@WINDOW, n:int, attr:attr_t, pair:short, opts:pointer):native;
def mvchgat(y:int, x:int, n:int, attr:attr_t, pair:short, opts:pointer):native;
def mvwchgat(win:pointer@WINDOW, y:int, x:int, n:int, attr:attr_t, pair:short, opts:pointer):native;
def color_set(pair:short, opts:pointer):native;
def wcolor_set(win:pointer@WINDOW, pair:short, opts:pointer):native;
def standend(): native;
def wstandend(win:pointer@WINDOW):native;
def standout(): native;
def wstandout(win:pointer@WINDOW):native;
def bkgdset(ch:chtype):native;
def wbkgdset(win:pointer@WINDOW, ch:chtype):native;
def bkgd(c:chtype):native;
def wbkgd(win:pointer@WINDOW, ch:chtype):native;
def getbkgd(win:pointer@WINDOW): native chtype;
def wgetch(win:pointer@WINDOW): native;
def mvgetch(y:int, x:int):native;
def mvwgetch(win:pointer@WINDOW, y:int, x:int): native;
def ungetch(ch:int):native;
def has_key(ch:int):native bool;
def delay_output(ms:int):native;
def keyname(c:int):native String;
def key_name(w:char):native String;
def unctrl(c:chtype):native String;
def filter():native;
def nofilter():native;
def delch():native;
def wdelch(win:pointer@WINDOW):native;
def mvdelch(y:int, x:int):native;
def mvwdelch(win:pointer@WINDOW, y:int, x:int):native;
def meta(win:pointer@WINDOW, bf:bool): native;
KEY_DOWN: static int;
KEY_UP: static int;
KEY_LEFT: static int;
KEY_RIGHT: static int;
KEY_HOME: static int;
KEY_BACKSPACE: static int;
KEY_DL: static int;
KEY_IL: static int;
KEY_DC: static int;
KEY_IC: static int;
KEY_EIC: static int;
KEY_CLEAR: static int;
KEY_EOS: static int;
KEY_EOL: static int;
KEY_SF: static int;
KEY_SR: static int;
KEY_NPAGE: static int;
KEY_PPAGE: static int;
KEY_STAB: static int;
KEY_CTAB: static int;
KEY_CATAB: static int;
KEY_ENTER: static int;
KEY_PRINT: static int;
KEY_LL: static int;
KEY_A1: static int;
KEY_A3: static int;
KEY_B2: static int;
KEY_C1: static int;
KEY_C3: static int;
KEY_BTAB: static int;
KEY_BEG: static int;
KEY_CANCEL: static int;
KEY_CLOSE: static int;
KEY_COMMAND: static int;
KEY_COPY: static int;
KEY_CREATE: static int;
KEY_END:static int;
KEY_EXIT: static int;
KEY_FIND: static int;
KEY_HELP: static int;
KEY_MARK: static int;
KEY_MESSAGE: static int;
KEY_MOVE: static int;
KEY_NEXT: static int;
KEY_OPEN: static int;
KEY_OPTIONS: static int;
KEY_PREVIOUS: static int;
KEY_REDO: static int;
KEY_REFERENCE: static int;
KEY_REFRESH: static int;
KEY_REPLACE: static int;
KEY_RESTART: static int;
KEY_RESUME: static int;
KEY_SAVE: static int;
KEY_SBEG: static int;
KEY_SCANCEL: static int;
KEY_SCOMMAND: static int;
KEY_SCOPY: static int;
KEY_SCREATE: static int;
KEY_SDC: static int;
KEY_SDL: static int;
KEY_SELECT: static int;
KEY_SEND: static int;
KEY_SEOL: static int;
KEY_SEXIT: static int;
KEY_SFIND: static int;
KEY_SHELP: static int;
KEY_SHOME: static int;
KEY_SIC: static int;
KEY_SLEFT: static int;
KEY_SMESSAGE: static int;
KEY_SMOVE: static int;
KEY_SNEXT: static int;
KEY_SOPTIONS: static int;
KEY_SPREVIOUS: static int;
KEY_SPRINT: static int;
KEY_SREDO: static int;
KEY_SREPLACE: static int;
KEY_SRIGHT: static int;
KEY_SRSUME: static int;
KEY_SSAVE: static int;
KEY_SSUSPEND: static int;
KEY_SUNDO: static int;
KEY_SUSPEND: static int;
KEY_UNDO: static int;
KEY_MOUSE: static int;
KEY_RESIZE: static int;
KEY_EVENT: static int;
KEY_MAX: static int;
stdscr: static pointer@WINDOW;
def ioctl(fd:int, request:int, arg:pointer):static native int throws Exception;
def initscr(): native static pointer@WINDOW throws Exception;
def endwin(): native static throws Exception;
def move(y:int, x:int): native static throws Exception;
def printw(str:String): native static throws Exception;
def printw(format:String, params:Array<Object>): static throws Exception {
str := sprintf(format, params);
printw(str);
}
def printw(format:String, params:SortableList<ISortable>): static throws Exception {
str := Global.sprintf(format, params);
printw(str);
}
def mvprintw(y:int, x:int, str:String): static throws Exception {
maxx := getmaxx();
maxy := getmaxy();
if(y > maxy || x > maxx || x < 0 || y < 0) {
throw Exception("x or y is out of Range");
}
move(y, x);
printw(str);
}
def mvprintw(y:int, x:int, format:String, params:Array<Object>): static throws Exception {
maxx := getmaxx();
maxy := getmaxy();
if(y > maxy || x > maxx || x < 0 || y < 0) {
throw Exception("x or y is out of Range");
}
move(y, x);
printw(format, params);
}
def mvprintw(y:int, x:int, format:String, params:SortableList<ISortable>): static throws Exception {
maxx := getmaxx();
maxy := getmaxy();
if(y > maxy || x > maxx || x < 0 || y < 0) {
throw Exception("x or y is out of Range");
}
move(y, x);
printw(format, params);
}
def refresh(): native static throws Exception;
def box(win_ptr:pointer@WINDOW, vetical_char:char, horizonal_char:char): native static throws Exception;
def isendwin(): native static bool;
def clear(): native static int throws Exception;
def erase(): native static int throws Exception;
def attron(attribute:int): static native throws Exception;
def attroff(attribute:int): static native throws Exception;
def attrset(attribute:int): static native throws Exception;
def echo(): static native throws Exception;
def noecho(): static native throws Exception;
def cbreak(): static native throws Exception;
def nocbreak(): static native throws Exception;
def raw(): static native throws Exception;
def noraw(): static native throws Exception;
def getch(): static native int throws Exception;
def nodelay(window:pointer@WINDOW, true_or_false:bool): static native throws Exception;
def setEscapeDelay(msec:int): static native;
def getEscapeDelay(): static native int;
def newwin(num_of_lines:int, num_of_cols:int, start_y:int, start_x:int): native static pointer@WINDOW throws Exception;
def delwin(window_to_delete:pointer@WINDOW): static native throws Exception;
def mvwin(window_to_move:pointer@WINDOW, new_y:int, new_x:int): static native throws Exception;
def wrefresh(window_to_ptr:pointer@WINDOW): static native throws Exception;
def wclear(window_to_ptr:pointer@WINDOW): static native throws Exception;
def touchwin(window_to_ptr:pointer@WINDOW): static native throws Exception;
def keypad(window:pointer@WINDOW, keypad_on:bool): static native throws Exception;
def wmove(window:pointer@WINDWO, y:int, x:int): native static throws Exception;
def wprintw(window:pointer@WINDOW, str:String): native static throws Exception;
def wprintw(window:pointer@WINDOW, format:String, params:Array<Object>): static throws Exception {
str := sprintf(format, params);
wprintw(window, str);
}
}
inherit String
{
def printw(format:String): throws Exception {
System.printw(format, array { self });
}
def mvprintw(y:int, x:int, format:String): throws Exception {
System.mvprintw(y, x, format, array { self });
}
}
inherit Command
{
def selector(): String {
result:String = "";
if(self.data != null && !self.data.equals("")) {
end_of_select := false;
canceled := false;
initscr();
keypad(stdscr, true);
noecho();
raw();
maxx := getmaxx();
maxy := getmaxy();
lines := self.data.split(/\n/);
scrolltop := 0;
cursor := 0;
space_string1 := " ".multiply(maxx);
space_string2 := " ".multiply(maxx-1);
while(!end_of_select) {
maxy2 := lines.length() - scrolltop;
### view ###
for(i:=0; i<maxy; i++) {
if(i == maxy -1) {
mvprintw(i,0, space_string2);
}
else {
mvprintw(i, 0, space_string1);
}
}
for(y:=0; y<maxy && y < maxy2; y++) {
it := lines.items(scrolltop+y);
line := it.subString(0, maxx-1);
if(cursor == y) {
attron(A_REVERSE);
mvprintw(y, 0, "%s", array { line });
attroff(A_REVERSE);
}
else {
mvprintw(y, 0, "%s", array { line });
}
}
refresh();
### input ###
key := getch();
when(key) {
case (KEY_UP, 'k'.to_int, ('P'-'A').to_int+1) {
cursor--;
}
case (KEY_DOWN, 'j'.to_int, ('N'-'A').to_int+1) {
cursor++;
}
case (('D'-'A').to_int+1) {
cursor+=10;
}
case (('U'-'A').to_int+1) {
cursor-=10;
}
case (('C'-'A').to_int+1, 'q'.to_int, ('['-'A').to_int+1) {
canceled = true;
end_of_select = true;
}
case (KEY_ENTER, ('J'-'A').to_int+1) {
end_of_select = true;
}
}
### modification ###
if(cursor < 0) {
scroll_size := -cursor +1;
cursor = 0;
scrolltop-=scroll_size;
if(scrolltop < 0) {
scrolltop = 0;
cursor = 0;
}
}
if(maxy2 < maxy) {
if(cursor >= maxy2) {
cursor = maxy2 - 1;
}
}
else {
if(cursor >= maxy) {
scroll_size := cursor - maxy + 1;
scrolltop += scroll_size;
cursor -= scroll_size;
}
}
}
if(!canceled) {
result = lines.items(scrolltop+cursor);
}
endwin();
}
return result;
}
}