-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprocCurs.nim
3643 lines (2955 loc) · 102 KB
/
procCurs.nim
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
#-------------------------------------------------------
## TERMCURS
## curse TERMINAL inspired 5250/3270 done only width nim
#-------------------------------------------------------
import termkey
from strformat import alignString, fmt
from strutils import `%`,isDigit,parseInt,parseEnum,parseBool,parseFloat
import std/[re] , math
import unicode
#proc beug(nline : int ; text :string ) =
# gotoXY(40, 1); echo "ligne>", nline, " :" , text ; let lcurs = getFunc()
const
EMPTY*:bool = true
FILL*:bool = false
type
REFTYP* {.pure.} = enum # type de Field
TEXT_FREE,
ALPHA,
ALPHA_UPPER,
ALPHA_NUMERIC,
ALPHA_NUMERIC_UPPER,
TEXT_FULL,
PASSWORD,
DIGIT,
DIGIT_SIGNED,
DECIMAL,
DECIMAL_SIGNED,
DATE_ISO,
DATE_FR,
DATE_US,
TELEPHONE,
MAIL_ISO,
YES_NO,
SWITCH,
FPROC,
FCALL
# FPROC appel d'une fonction interne "proc" --> Simulation KEYBOARD PROC
# FCALL appel d'une externe "programe" --> Simulation KEYBOARD CALL
CADRE* {.pure.} = enum
line0,
line1,
line2
MNUVH* {.pure.} = enum
vertical = 0 ,
horizontal
TKey_Grid* {.pure.} = enum
PGUp,
PGDown,
PGHome,
PGEnd
MNUATRB* = ref object
style* : set[Style]
backgr*: BackgroundColor
backbr*: bool
foregr*: ForegroundColor
forebr*: bool
styleCell* : set[Style]
BOXATRB* = ref object
style* : set[Style]
backgr*: BackgroundColor
backbr*: bool
foregr*: ForegroundColor
forebr*: bool
title_style* : set[Style]
title_backgr*: BackgroundColor
title_backbr*: bool
title_foregr*: ForegroundColor
title_forebr*: bool
ZONATRB* = ref object
style* : set[Style]
backgr*: BackgroundColor
backbr*: bool
foregr*: ForegroundColor
forebr*: bool
GRIDATRB* = ref object
style* : set[Style]
backgr*: BackgroundColor
backbr*: bool
foregr*: ForegroundColor
forebr*: bool
title_style* : set[Style]
title_backgr*: BackgroundColor
title_backbr*: bool
title_foregr*: ForegroundColor
title_forebr*: bool
CELLATRB* = ref object
cell_style* : set[Style]
cell_backgr*: BackgroundColor
cell_backbr*: bool
cell_foregr*: ForegroundColor
cell_forebr*: bool
BTNSPACE* = ref object
space* : Natural
FIELD* = object
name*: string
posx: Natural
posy: Natural
style : set[Style]
backgr: BackgroundColor
backbr: bool
foregr: ForegroundColor
forebr: bool
pstyle : set[Style]
pbackgr: BackgroundColor
pbackbr: bool
pforegr: ForegroundColor
pforebr: bool
reftyp: REFTYP # / ALPHA...SWITCH
width: Natural
scal: Natural
nbrcar: Natural # / nbrcar DECIMAL = (precision+scale + 1'.' ) + 1 this signed || other nbrcar = ALPA..DIGIT..
empty : bool # / EMPTY or FULL
protect: bool # / only display
pading: bool # / pading blank
edtcar: string # / edtcar for monnaie € $ ¥ ₪ £ or %
regex: string # / contrôle regex
errmsg: string # / message this field
help: string # / help this field
text*: string
switch* : bool # / CTRUE CFALSE
process:string # / name proc
err: bool # / force error
actif: bool # / zone active True
HIDEN* = object # / field block out
name: string
reftyp: REFTYP # / ALPHA...SWITCH
text*: string
switch* : bool
LABEL* = object
name*: string
posx: Natural
posy: Natural
style : set[Style]
backgr: BackgroundColor
backbr: bool
foregr: ForegroundColor
forebr: bool
text*: string
title: bool
actif: bool
BOX* = object
name : string
posx : Natural
posy : Natural
lines: Natural
cols : Natural
cadre: CADRE
style : set[Style]
backgr: BackgroundColor
backbr: bool
foregr: ForegroundColor
forebr: bool
title*: string
titlebackgr: BackgroundColor
titlebackbr: bool
titleforegr: ForegroundColor
titleforebr: bool
titlestyle: set[Style]
actif: bool
BUTTON* = object
key* : TKey
text*: string
ctrl*: bool
actif: bool
MENU* = ref object
name : string
posx : Natural
posy : Natural
lines: Natural
cols : Natural
cadre: CADRE
mnuvh : MNUVH
style : set[Style]
styleCell:set[Style]
backgr: BackgroundColor
backbr: bool
foregr: ForegroundColor
forebr: bool
item: seq[string]
selMenu : Natural
actif: bool
TerminalChar* = object
ch: Rune # char
bg: BackgroundColor # color
bgb: bool # brigth
fg: ForegroundColor # color
fgb: bool # brigth
style: set[Style] # style
on:bool # on = true -> cell active
PANEL* = ref object
name*: string
posx*: Natural
posy*: Natural
lines*: Natural
cols*: Natural
backgr*: BackgroundColor
backbr*: bool
foregr*: ForegroundColor
forebr*: bool
style*: set[Style]
cadre*: CADRE
boxpnl*: BOX
box*: seq[BOX]
label*: seq[LABEL]
field*: seq[FIELD]
hiden*: seq[HIDEN]
button*: seq[BUTTON]
index*: Natural
funcKey*: seq[TKey]
mouse*: bool
buf:seq[TerminalChar]
actif: bool
# GRID
GridStyle* = object
colSeparator*: string
CELL* = object
text* : string
long* : Natural
reftyp*: REFTYP
posy : Natural
edtcar: string
cellatr : CELLATRB
GRIDSFL* = ref object
name : string
posx: Natural
posy: Natural
lines: Natural
cols : Natural
pagerows: Natural
rows: seq[seq[string]]
nrow: seq[int]
headers: seq[CELL]
separator: GridStyle
gridatr : GRIDATRB
actif: bool
lignes: int
pages: int
cursligne:int
curspage:int
buf:seq[TerminalChar]
# var interne
let sepStyle* = GridStyle( colSeparator:"│")
let noStyle* = GridStyle( colSeparator:" ")
var pnlatr* = new(ZONATRB)
pnlatr.style = {styleDim}
pnlatr.backgr = BackgroundColor.bgBlack
pnlatr.backbr = false
pnlatr.foregr = ForegroundColor.fgWhite
pnlatr.forebr = false
var scratr* = new(ZONATRB)
scratr.style = {styleDim}
scratr.backgr = BackgroundColor.bgBlack
scratr.backbr = false
scratr.foregr = ForegroundColor.fgWhite
scratr.forebr = false
var mnuatr* = new(MNUATRB)
mnuatr.style = {styleDim}
mnuatr.backgr = BackgroundColor.bgWhite
mnuatr.backbr = true
mnuatr.foregr = ForegroundColor.fgBlue
mnuatr.forebr = true
mnuatr.styleCell = {styleReverse,styleItalic}
var mnuatrCadre* = new(MNUATRB)
mnuatrCadre.style = {styleDim}
mnuatrCadre.backgr = BackgroundColor.bgBlack
mnuatrCadre.backbr = false
mnuatrCadre.foregr = ForegroundColor.fgWhite
mnuatrCadre.forebr = true
mnuatrCadre.styleCell = {styleReverse,styleItalic}
var boxatr* = new(BOXATRB)
boxatr.style = {styleDim}
boxatr.backgr = BackgroundColor.bgBlack
boxatr.backbr = false
boxatr.foregr = ForegroundColor.fgRed
boxatr.forebr = true
boxatr.title_style = {styleDim}
boxatr.title_backgr = BackgroundColor.bgWhite
boxatr.title_backbr = false
boxatr.title_foregr = ForegroundColor.fgBlack
boxatr.title_forebr = false
var lblatr* = new(ZONATRB)
lblatr.style = {styleDim,styleItalic}
lblatr.backgr = BackgroundColor.bgBlack
lblatr.backbr = false
lblatr.foregr = ForegroundColor.fgGreen
lblatr.forebr = true
var ttlatr* = new(ZONATRB)
ttlatr.style = {styleBright}
ttlatr.backgr = BackgroundColor.bgBlack
ttlatr.backbr = false
ttlatr.foregr = ForegroundColor.fgCyan
ttlatr.forebr = true
var fldatr* = new(ZONATRB)
fldatr.style = {styleDim}
fldatr.backgr = BackgroundColor.bgWhite
fldatr.backbr = false
fldatr.foregr = ForegroundColor.fgBlue
fldatr.forebr = true
var prtatr* = new(ZONATRB)
prtatr.style = {styleDim,styleItalic}
prtatr.backgr = BackgroundColor.bgBlack
prtatr.backbr = false
prtatr.foregr = ForegroundColor.fgYellow
prtatr.forebr = true
var swtatr* = new(ZONATRB)
swtatr.style = {styleBright}
swtatr.backgr = BackgroundColor.bgblack
swtatr.backbr = false
swtatr.foregr = ForegroundColor.fgWhite
swtatr.forebr = false
var msgatr* = new(ZONATRB)
msgatr.style = {styleDim}
msgatr.backgr = BackgroundColor.bgBlack
msgatr.backbr = false
msgatr.foregr = ForegroundColor.fgRed
msgatr.forebr = true
var hlpatr* = new(ZONATRB)
hlpatr.style = {styleDim,styleItalic}
hlpatr.backgr = BackgroundColor.bgBlack
hlpatr.backbr = false
hlpatr.foregr = ForegroundColor.fgYellow
hlpatr.forebr = true
var btnatr* = new(BOXATRB)
btnatr.style = {styleDim}
btnatr.backgr = BackgroundColor.bgBlack
btnatr.backbr = false
btnatr.foregr = ForegroundColor.fgRed
btnatr.forebr = false
btnatr.title_style = {styleDim,styleItalic,styleUnderscore}
btnatr.title_backgr = BackgroundColor.bgBlack
btnatr.title_backbr = false
btnatr.title_foregr = ForegroundColor.fgCyan
boxatr.title_forebr = false
var btnspc* = new(BTNSPACE)
btnspc.space = 3
var gridatr* = new(GRIDATRB)
gridatr.style = {styleDim}
gridatr.backgr = BackgroundColor.bgblack
gridatr.backbr = false
gridatr.foregr = ForegroundColor.fgWhite
gridatr.forebr = false
gridatr.title_style = {styleDim,styleUnderscore}
gridatr.title_backgr = BackgroundColor.bgblack
gridatr.title_backbr = false
gridatr.title_foregr = ForegroundColor.fgGreen
gridatr.title_forebr = false
var cellatr* = new(CELLATRB)
cellatr.cell_style = {styleDim,styleItalic}
cellatr.cell_backgr = BackgroundColor.bgblack
cellatr.cell_backbr = false
cellatr.cell_foregr = ForegroundColor.fgCyan
cellatr.cell_forebr = false
## define type cursor
proc defCursor*(e_curs: Natural = 0) =
const CSIcurs = 0x1b.chr & "[?25h"
const CSIcurs0 = 0x1b.chr & "[0 q" # 0 → not blinking block
case e_curs
of 0:
stdout.write(CSIcurs0)
stdout.write(CSIcurs)
of 1:
const CSIcurs1 = 0x1b.chr & "[1 q" # 1 → blinking block
stdout.write(CSIcurs1)
stdout.write(CSIcurs)
of 2:
const CSIcurs2 = 0x1b.chr & "[2 q" # 2 → steady block
stdout.write(CSIcurs2)
stdout.write(CSIcurs)
of 3:
const CSIcurs3 = 0x1b.chr & "[3 q" # 3 → blinking underlines
stdout.write(CSIcurs3)
stdout.write(CSIcurs)
of 4:
const CSIcurs4 = 0x1b.chr & "[4 q" # 4 → steady underlines
stdout.write(CSIcurs4)
stdout.write(CSIcurs)
of 5:
const CSIcurs5 = 0x1b.chr & "[5 q" # 5 → blinking bar
stdout.write(CSIcurs5)
stdout.write(CSIcurs)
of 6:
const CSIcurs6 = 0x1b.chr & "[6 q" # 6 → steady bar
stdout.write(CSIcurs6)
stdout.write(CSIcurs)
else:
stdout.write(CSIcurs0)
stdout.write(CSIcurs)
stdout.flushFile()
stdin.flushFile()
## Erase and color and style default
proc setTerminal*(termatr : ZONATRB = scratr) =
setStyle(scratr.style)
setBackgroundColor(scratr.backgr,scratr.backbr)
setForegroundColor(scratr.foregr,scratr.forebr)
eraseTerm()
offCursor()
## return BUTTON
proc defButton*(key: TKey; text:string; ctrl:bool = false ; actif:bool = true): BUTTON =
var bt:BUTTON
bt.key = key
bt.text = text
bt.ctrl = ctrl
bt.actif = actif
return bt
## Define BOX
proc defBox*( name:string ; posx:Natural; posy:Natural; lines :Natural; cols:Natural;
cadre :CADRE; title: string; box_atr: BOXATRB = boxatr ;actif: bool = true) : BOX =
var box : BOX
box.name = name
box.posx = posx
box.posy = posy
box.lines = lines
box.cols = cols
box.cadre = cadre
box.style = box_atr.style
box.backgr = box_atr.backgr
box.backbr = box_atr.backbr
box.foregr = box_atr.foregr
box.forebr = box_atr.forebr
box.title = title
box.titlestyle = box_atr.title_style
box.titlebackgr = box_atr.title_backgr
box.titlebackbr = box_atr.title_backbr
box.titleforegr = box_atr.title_foregr
box.titleforebr = box_atr.title_forebr
box.actif = actif
return box
## assigne BOX to matrice for display
proc printBox*(pnl: var PANEL; box:BOX) =
if CADRE.line0 == box.cadre : return
let ACS_Hlines = "─"
let ACS_Vlines = "│"
let ACS_UCLEFT = "┌"
let ACS_UCRIGHT = "┐"
let ACS_LCLEFT = "└"
let ACS_LCRIGHT = "┘"
let ACS_Hline2 = "═"
let ACS_Vline2 = "║"
let ACS_UCLEFT2 = "╔"
let ACS_UCRIGHT2 = "╗"
let ACS_LCLEFT2 = "╚"
let ACS_LCRIGHT2 = "╝"
var trait:string = ""
var edt :bool
var
x: Natural = box.posx
row: Natural = 1
y: Natural
col: Natural
npos: Natural
n: Natural
while row <= box.lines:
y = box.posy
col = 1
while col <= box.cols:
edt = false
if row == 1:
if col == 1:
if CADRE.line1 == box.cadre : trait = ACS_UCLEFT
else: trait = ACS_UCLEFT2
edt = true
if col == box.cols:
if CADRE.line1 == box.cadre : trait = ACS_UCRIGHT
else : trait = ACS_UCRIGHT2
edt = true
if col > Natural(1) and col < box.cols:
if CADRE.line1 == box.cadre : trait = ACS_Hlines
else : trait = ACS_Hline2
edt = true
elif row == box.lines:
if col == Natural(1) :
if CADRE.line1 == box.cadre : trait = ACS_LCLEFT
else : trait = ACS_LCLEFT2
edt = true
if col == box.cols:
if CADRE.line1 == box.cadre : trait = ACS_LCRIGHT
else : trait = ACS_LCRIGHT2
edt = true
if col > Natural(1) and col < box.cols:
if CADRE.line1 == box.cadre : trait = ACS_Hlines
else : trait = ACS_Hline2
edt = true
elif row > Natural(1) and row < box.lines:
if col == Natural(1) or col == box.cols:
if CADRE.line1 == box.cadre : trait = ACS_Vlines
else : trait = ACS_Vline2
edt = true
if edt:
npos = box.cols * x
n = npos + y
pnl.buf[n].ch = trait.runeAt(0)
pnl.buf[n].bg = box.backgr
pnl.buf[n].bgb = box.backbr
pnl.buf[n].fg = box.foregr
pnl.buf[n].fgb = box.forebr
pnl.buf[n].style = box.style
pnl.buf[n].on = true
inc(y)
inc(col)
inc(x)
inc(row)
if box.title > "" :
if len(box.title) > box.cols - 2: return
npos = box.cols * box.posx
n = npos + (((box.cols - len(box.title) ) div 2) + box.posy)
for ch in runes(box.title):
pnl.buf[n].ch = ch
pnl.buf[n].bg = box.titlebackgr
pnl.buf[n].bgb = box.titlebackbr
pnl.buf[n].fg = box.titleforegr
pnl.buf[n].fgb = box.titleforebr
pnl.buf[n].style = box.titlestyle
pnl.buf[n].on = true
inc(n)
## Define Menu
proc newMenu*( name:string ; posx:Natural; posy:Natural;
mnuvh: MNUVH ; item : seq[string] ;cadre :CADRE = CADRE.line0 ; mnu_atr : MNUATRB = mnuatr ; actif: bool = true) :MENU =
var menu = new(MENU)
menu.name = name
menu.posx = posx
menu.posy = posy
menu.cadre = cadre
menu.mnuvh = mnuvh
var i : Natural = 0
menu.cols = 0
while i < len(item):
if mnuvh == MNUVH.vertical :
if menu.cols < len(item[i]) : menu.cols = runeLen(item[i])
if mnuvh == MNUVH.horizontal : menu.cols += runeLen(item[i])
inc(i)
if mnuvh == MNUVH.vertical:
if menu.cadre == CADRE.line1 or menu.cadre == CADRE.line2 :
menu.lines = len(item) + 1
menu.cols += 1
else :
menu.lines = len(item) + 1
if mnuvh == MNUVH.horizontal:
if menu.cadre == CADRE.line1 or menu.cadre == CADRE.line2 :
menu.lines = 2
menu.cols += 1
menu.style = mnu_atr.style
menu.styleCell = mnu_atr.styleCell
menu.backgr = mnu_atr.backgr
menu.backbr = mnu_atr.backbr
menu.foregr = mnu_atr.foregr
menu.forebr = mnu_atr.forebr
menu.item = item
menu.actif = actif
return menu
## assigne MENU to matrice for display
proc printMenu*(pnl: PANEL; mnu:MENU) =
var row: Natural
var col: Natural
if CADRE.line1 == mnu.cadre or CADRE.line2 == mnu.cadre:
let ACS_Hlines = "─"
let ACS_Vlines = "│"
let ACS_UCLEFT = "┌"
let ACS_UCRIGHT = "┐"
let ACS_LCLEFT = "└"
let ACS_LCRIGHT = "┘"
let ACS_Hline2 = "═"
let ACS_Vline2 = "║"
let ACS_UCLEFT2 = "╔"
let ACS_UCRIGHT2 = "╗"
let ACS_LCLEFT2 = "╚"
let ACS_LCRIGHT2 = "╝"
var trait:string = ""
var edt :bool
row = 0
while row <= mnu.lines:
col = 0
while col <= mnu.cols:
edt = false
if row == 0:
if col == 0:
if CADRE.line1 == mnu.cadre : trait = ACS_UCLEFT
else: trait = ACS_UCLEFT2
edt = true
if col == mnu.cols:
if CADRE.line1 == mnu.cadre : trait = ACS_UCRIGHT
else : trait = ACS_UCRIGHT2
edt = true
if col > Natural(0) and col < mnu.cols:
if CADRE.line1 == mnu.cadre : trait = ACS_Hlines
else : trait = ACS_Hline2
edt = true
elif row == mnu.lines:
if col == Natural(0) :
if CADRE.line1 == mnu.cadre : trait = ACS_LCLEFT
else : trait = ACS_LCLEFT2
edt = true
if col == mnu.cols:
if CADRE.line1 == mnu.cadre : trait = ACS_LCRIGHT
else : trait = ACS_LCRIGHT2
edt = true
if col > Natural(0) and col < mnu.cols:
if CADRE.line1 == mnu.cadre : trait = ACS_Hlines
else : trait = ACS_Hline2
edt = true
elif row > Natural(0) and row < mnu.lines:
if col == Natural(0) or col == mnu.cols:
if CADRE.line1 == mnu.cadre : trait = ACS_Vlines
else : trait = ACS_Vline2
edt = true
if edt:
gotoXY(row + mnu.posx + pnl.posx - 1 , col + mnu.posy + pnl.posy - 1)
setBackgroundColor(mnu.backgr,mnu.backbr)
setForegroundColor(mnu.foregr,mnu.forebr)
writeStyled(trait,mnu.style)
else:
gotoXY(row + mnu.posx + pnl.posx - 1 , col + mnu.posy + pnl.posy - 1)
setBackgroundColor(mnu.backgr,mnu.backbr)
setForegroundColor(mnu.foregr,mnu.forebr)
writeStyled(" ",mnu.style)
stdout.flushFile()
inc(col)
inc(row)
else : # no cadre
if mnu.mnuvh == MNUVH.vertical:
row = 0
while row <= mnu.lines:
col = 0
while col <= mnu.cols:
gotoXY(row + mnu.posx + pnl.posx - 1,mnu.posy + pnl.posy - 1)
setBackgroundColor(mnu.backgr,mnu.backbr)
setForegroundColor(mnu.foregr,mnu.forebr)
writeStyled(" ",mnu.style)
stdout.flushFile()
inc(col)
inc(row)
if mnu.mnuvh == MNUVH.horizontal:
col = 0
while col < mnu.cols:
gotoXY(mnu.posx + pnl.posx - 1, col + mnu.posy + pnl.posy - 1)
setBackgroundColor(mnu.backgr,mnu.backbr)
setForegroundColor(mnu.foregr,mnu.forebr)
writeStyled(" ",mnu.style)
stdout.flushFile()
inc(col)
proc dspMenuItem*(pnl: PANEL; mnu:MENU) =
var pos : Natural = 0
var n , h : Natural
printMenu(pnl, mnu)
onMouse()
offCursor()
stdout.flushFile()
if pos > len(mnu.item) or pos < 0 : pos = 0
n = 0
h = 0
for cell in mnu.item :
if mnu.mnuvh == MNUVH.vertical :
if mnu.cadre == CADRE.line0 :
gotoXY(mnu.posx + pnl.posx + n - 1 , mnu.posy + pnl.posy - 1)
else :
gotoXY(mnu.posx + pnl.posx + n, mnu.posy + pnl.posy)
if mnu.mnuvh == MNUVH.horizontal :
if mnu.cadre == CADRE.line0 :
gotoXY(mnu.posx + pnl.posx - 1 , h + mnu.posy + pnl.posy - 1)
else :
gotoXY(mnu.posx + pnl.posx , h + mnu.posy + pnl.posy )
setBackgroundColor(mnu.backgr,mnu.backbr)
setForegroundColor(mnu.foregr,mnu.forebr)
if pos == n :
writeStyled(cell.strip(),mnu.styleCell)
else :
writeStyled(cell.strip(),mnu.style)
inc(n)
h += runeLen(cell)
stdout.flushFile()
## Define Label
proc defLabel*(name:string ; posx:Natural; posy:Natural; text: string;
lbl_atr : ZONATRB = lblatr ; actif: bool = true) :LABEL =
var lbl : LABEL
lbl.name = name
lbl.posx = posx
lbl.posy = posy
lbl.text = text
lbl.title = false
lbl.actif = actif
lbl.style = lbl_atr.style
lbl.backgr = lbl_atr.backgr
lbl.backbr = lbl_atr.backbr
lbl.foregr = lbl_atr.foregr
lbl.forebr = lbl_atr.forebr
return lbl
## Define Title
proc defTitle*(name:string ; posx:Natural; posy:Natural; text: string;
ttl_atr : ZONATRB = ttlatr ; actif: bool = true) :LABEL =
var lbl : LABEL
lbl.name = name
lbl.posx = posx
lbl.posy = posy
lbl.text = text
lbl.title = true
lbl.actif = actif
lbl.style = ttl_atr.style
lbl.backgr = ttl_atr.backgr
lbl.backbr = ttl_atr.backbr
lbl.foregr = ttl_atr.foregr
lbl.forebr = ttl_atr.forebr
return lbl
## assigne LABEL to matrice for display
proc printLabel*(pnl: var PANEL, lbl : LABEL ) =
var npos = pnl.cols * lbl.posx
var n = npos + lbl.posy
for ch in runes(lbl.text):
if lbl.actif == true :
pnl.buf[n].ch = ch
pnl.buf[n].bg = lbl.backgr
pnl.buf[n].bgb = lbl.backbr
pnl.buf[n].fg = lbl.foregr
pnl.buf[n].fgb = lbl.forebr
pnl.buf[n].style = lbl.style
pnl.buf[n].on = true
else :
pnl.buf[n].ch = " ".runeAt(0)
pnl.buf[n].bg = pnl.backgr
pnl.buf[n].bgb = pnl.backbr
pnl.buf[n].fg = pnl.foregr
pnl.buf[n].fgb = pnl.forebr
pnl.buf[n].style = pnl.style
pnl.buf[n].on = false
inc(n)
## Define Field String Standard
proc defString*(name:string ; posx:Natural; posy:Natural; reftyp: REFTYP;
width: Natural;text: string; empty: bool;
errmsg: string ; help: string;
regex: string = "";
fld_atr : ZONATRB = fldatr ;protect_atr : ZONATRB = prtatr ;
actif: bool = true) : FIELD =
var fld : FIELD
fld.name = name
fld.posx = posx
fld.posy = posy
fld.reftyp = reftyp # / ALPHA...SWITCH
fld.width = width
fld.scal = 0
fld.nbrcar = width
fld.text = text
fld.empty = empty
fld.protect = false # / only display
fld.pading = true # / pading blank
fld.edtcar = "" # / edtcar for monnaie € $ ¥ ₪ £ or %
fld.regex = regex # / contrôle regex
fld.errmsg = errmsg # / message this field
fld.help = help # / help this field
fld.switch = false # / CTRUE CFALSE
fld.err = false # / zone error False
fld.actif = actif # / zone active True
fld.process = "" # / name calls proc or pgm
fld.style = fld_atr.style
fld.backgr = fld_atr.backgr
fld.backbr = fld_atr.backbr
fld.foregr = fld_atr.foregr
fld.forebr = fld_atr.forebr
fld.pstyle = protect_atr.style
fld.pbackgr = protect_atr.backgr
fld.pbackbr = protect_atr.backbr
fld.pforegr = protect_atr.foregr
fld.pforebr = protect_atr.forebr
return fld
## Define Field Mail
proc defMail*(name:string ; posx:Natural; posy:Natural; reftyp: REFTYP;
width: Natural;text: string; empty: bool;
errmsg: string ; help: string;
fld_atr : ZONATRB = fldatr ;protect_atr : ZONATRB = prtatr ;
actif: bool = true) :FIELD =
var fld : FIELD
fld.name = name
fld.posx = posx
fld.posy = posy
fld.reftyp = reftyp # / ALPHA...SWITCH
fld.width = width
fld.scal = 0
fld.nbrcar = width
fld.text = text
fld.empty = empty
fld.protect = false # / only display
fld.pading = true # / pading blank
fld.edtcar = "" # / edtcar for monnaie € $ ¥ ₪ £ or %
fld.regex ="""(?:[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])"""
# / contrôle regex [ABNF] [RFC 2822]
fld.errmsg = errmsg # / message this field
fld.help = help # / help this field
fld.switch = false # / CTRUE CFALSE
fld.err = false # / zone error False
fld.actif = actif # / zone active True
fld.process = "" # / name calls proc or pgm
fld.style = fld_atr.style
fld.backgr = fld_atr.backgr
fld.backbr = fld_atr.backbr
fld.foregr = fld_atr.foregr
fld.forebr = fld_atr.forebr
fld.pstyle = protect_atr.style
fld.pbackgr = protect_atr.backgr