-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathReadMultiLine.Lib.dog
More file actions
636 lines (583 loc) · 25 KB
/
ReadMultiLine.Lib.dog
File metadata and controls
636 lines (583 loc) · 25 KB
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
// CodeDog Read Line Library
ProgramOrLibrary = "library"
featuresNeeded = [Terminal]
requirements = []
LibDescription ={
useStatus = dynamic
description ='Library for read multiline'
features =[ReadMultiLine]
}
deinitCode = "endwin()"
// Text to test:
// Hello
// مرحبا!
// もしもし!
// வணக்கம்
struct GLOBAL{
void: putCharX(their charX: chX, me uint: EntryAttrs) <- {
if(chX.colorCode>0) {attrOn(getColorPair(chX.colorCode))}
else if(EntryAttrs>0) {attrOn(getColorPair(AndBits(EntryAttrs, 7)))}
else {attrOn(getColorPair(1))}
me wstring: msgAcc; msgAcc <+- chX.chr
putStr(msgAcc)
}
}
struct charX {
me int32: chr
me uint: colorCode
me int: chWidth
}
struct lineX{
me charX[list]: chars
me string: printable
me bool: dirty // True if this line needs redisplay.
me uint: startAttrs // Attributes inherited from the previous line.
me uint: width // Width of this line in some unit.
void: fillPrintable(me bool: showColors) <- {
printable <- ""
withEach chX in chars{
printable <- printable + wideCharToMultibyte(chX.chr)
}
}
}
struct EntryX {
their lineX[list]: lines
me uint: attrs
}
struct lineIterator {
me uint: entriesIdx // Index in a "their EntryX[list]"
me uint: linesIdx // Index into an EntryX.lines, which is a "their lineX[list]"
}
#define linesChars(LINE) <%entries[LINE.entriesIdx].lines[LINE.linesIdx].chars%>
#define crntLine() <%entries[currentLine.entriesIdx].lines[currentLine.linesIdx].chars%>
#define chkEd(code) <%if(editOK(shiftRight(AndBits(mgr.entries[mgr.currentLine.entriesIdx].attrs, 240), 4))){code; chg<-onChangeCallback(cmd)}%>
struct linesMngr {
their List<their EntryX>: entries
me uint: widthToCur
me uint: charsToCur
me uint: curMax // Most recent width to cursor
me uint: totalLines
me uint: linesDeleted
me lineIterator: currentLine
me uint: crntRowInWnd
me uint: wndStartY
me uint: wndEndY
me uint: wndHeight
me uint: wndWidth
me bool: insertMode // True <- insert, false <- overwrite
me bool: allDirty
me uint: crntCharWidth() <- {
if(charsToCur==crntLine().size()){ return(1) }
else{return(crntLine()[charsToCur].chWidth)}
}
their EntryX: lastEntry() <- {return(entries[entries.size()-1])}
me uint: numLinesInSet(their lineIterator: l) <- { return (entries[l.entriesIdx].lines.size()) }
me bool: isFirstSet (their lineIterator: l) <- { return (l.entriesIdx==0) }
me bool: isLastSet (their lineIterator: l) <- { return (l.entriesIdx==entries.size()-1) }
me bool: isFirstInSet (their lineIterator: l) <- { return (l.linesIdx==0) }
me bool: isLastInSet (their lineIterator: l) <- { return (l.linesIdx==numLinesInSet(l)-1) }
me bool: isFirstLine (their lineIterator: l) <- { return (isFirstSet(l) and isFirstInSet(l)) }
me bool: isLastLine (their lineIterator: l) <- { return (isLastSet (l) and isLastInSet(l)) }
me bool: nextLine(their lineIterator: l) <- {
if(isLastInSet(l)){
if(isLastSet(l)) {return(false)}
l.entriesIdx <- l.entriesIdx +1
l.linesIdx <- 0
} else {l.linesIdx <- l.linesIdx +1}
return(true)
}
me bool: prevLine(their lineIterator: l) <- {
if(isFirstInSet(l)){
if(isFirstSet(l)) {return(false)}
l.entriesIdx <- l.entriesIdx -1
l.linesIdx <- numLinesInSet(l)-1
} else {l.linesIdx <- l.linesIdx -1}
return(true)
}
their lineX: lineFromNum(me uint: n) <- {
me uint: accum <- 0
withEach ln in entries{
accum <- accum + ln.lines.size()
if(accum>=n){
// not finished BDL
}
}
return(0)
}
me int: calcWidthToCursor(their List<me charX>: line, me uint: charsToCur) <- {
me int: wtc <- 0
withEach p in range 0 .. charsToCur {
wtc <- wtc + line[p].chWidth
}
return(wtc)
}
me void: setCursorByWidth(their List<me charX>: chrs, me uint: maxWidthToCur) <- {
me int: wtc <- 0
me uint: p<-0
if(chrs.size()==0){charsToCur<-0; widthToCur<-0; return();}
withEach count in range 0 .. chrs.size() {
if(wtc+chrs[p].chWidth > maxWidthToCur){break()}
wtc <- wtc +chrs[p].chWidth
p <- p+1
}
charsToCur<-p
widthToCur<-wtc
}
me bool: moveUp() <- {
if(!isFirstLine(currentLine)){
prevLine(currentLine)
setCursorByWidth(crntLine(), curMax)
if(crntRowInWnd>0) {crntRowInWnd <- crntRowInWnd-1}
return(true)
}
return(false)
}
me bool: moveDown() <- {
if(!isLastLine(currentLine)){
nextLine(currentLine)
setCursorByWidth(crntLine(), curMax)
if(crntRowInWnd < wndHeight) {crntRowInWnd <- crntRowInWnd +1}
return(true)
}
return(false)
}
void: moveToTop() <- {
while(moveUp()){}
moveHome()
}
void: moveToBottom() <- {
while(moveDown()){}
moveEnd()
}
void: moveLeft() <- {
if(charsToCur>0){
charsToCur <- charsToCur-1
widthToCur <- widthToCur-crntCharWidth()
curMax <- widthToCur
} else if(!isFirstInSet(currentLine)){
moveUp();
moveEnd();
}
}
void: moveRight() <- {
if(charsToCur < crntLine().size()){
widthToCur <- widthToCur+crntLine()[charsToCur].chWidth
charsToCur <- charsToCur +1
curMax<-widthToCur
} else if(!isLastInSet(currentLine)){
moveDown()
moveHome()
}
}
void: moveHome() <- {
charsToCur<-0
widthToCur<-0
curMax<-widthToCur
}
void: moveEnd() <- {
charsToCur<-crntLine().size()
widthToCur<-calcWidthToCursor(crntLine(), charsToCur)
curMax<-widthToCur
}
void: pageUp() <- {
me int: i <- wndHeight-1
if(i>2){
while(i>0 and moveUp()){i <- i-1}
}
}
void: pageDown() <- {
me int: i <- wndHeight-1
if(i>2){
while(i>0 and moveDown()){i <- i-1}
}
}
void: doInsertKey() <- {} // {insertMode <- !insertMode; change cursor: line <-> block}
void: backspc() <- {if(charsToCur>0 or !isFirstInSet(currentLine)){moveLeft(); doDelete();}}
void: backTab() <- {}
void: doTab() <- {}
void: clearAll() <- {}
void: clearToEOL() <- {crntLine().erase(crntLine().front()+charsToCur, crntLine().end()); entries[currentLine.entriesIdx].lines[currentLine.linesIdx].dirty <- true}
void: occludeHist() <- {} // Toggle
void: prevHist() <- {}
void: nextHist() <- {}
void: copyAll() <- {}
void: pasteString(me string: s) <- {}
void: cycleSaveModes() <- {}
void: insertChar(their charX: chX) <- {
their lineX: line <- entries[currentLine.entriesIdx].lines[currentLine.linesIdx]
if (insertMode){
line.chars.insert(line.chars.front()+charsToCur, chX)
charsToCur <- charsToCur+1
widthToCur <- widthToCur+chX.chWidth
} else {} // TODO: Overwrite mode
curMax<-widthToCur
line.dirty<-true
}
void: doEnter() <- {
their lineX:: newLine
me List<me charX>: CrntLine <- crntLine()
me int: crntLineSize <- CrntLine.size()
withEach pos in range charsToCur .. crntLineSize {newLine.chars.pushLast(CrntLine[pos])}
me lineIterator: nxtLine <- currentLine
nxtLine.linesIdx <- nxtLine.linesIdx + 1
entries[currentLine.entriesIdx].lines.insert(entries[currentLine.entriesIdx].lines.front() + nxtLine.linesIdx, newLine)
CrntLine.resize(charsToCur)
currentLine <- nxtLine
if(crntRowInWnd==wndHeight-1){
allDirty <- true
} else {crntRowInWnd <- crntRowInWnd + 1}
charsToCur <- 0
widthToCur <- 0
curMax <- widthToCur
allDirty <- true
}
void: doDelete() <- {
if(charsToCur==crntLine().size()){ // Combine this line with next one.
if(isLastInSet(currentLine)){return()}
me lineIterator: nxtLine <- currentLine
nextLine(nxtLine)
withEach chr in linesChars(nxtLine){
crntLine().pushLast(chr)
}
entries[nxtLine.entriesIdx].lines.erase(entries[nxtLine.entriesIdx].lines.front() + nxtLine.linesIdx)
linesDeleted <- linesDeleted + 1
totalLines <- totalLines - 1
} else{ crntLine().erase(crntLine().front()+charsToCur);}
widthToCur <- calcWidthToCursor(crntLine(), charsToCur);
curMax <- widthToCur
allDirty <- true
}
me string: fetchBuffer(me string: result) <- {
result<-""
me string: EOL <- "\n"
withEach ln in entries[currentLine.entriesIdx].lines{
if(result != ""){result <- result+EOL[0]}
ln.fillPrintable(false)
result <- result + ln.printable
}
return (result)
}
}
struct posRec{ // Use this to store the position of infons in a parsed string.
me bool: isStart
me bool: isEnd
their void: itemParsed
// posRec(bool IsStart=0, bool IsEnd=0, infonPtr inf=0):isStart(IsStart),isEnd(IsEnd),itemParsed(inf){};
}
struct posRecStore{
me string: s
me Map<me int, me posRec>: ps
their Map<their void, me int>: colorCodes
// none: posRecStore(me string: text <- "", their map<their void, int>: colCode<-0) <- {s<-text; colorCodes<-colCode;}
}
struct readMultiLine {
me List<their EntryX>: bufs
me linesMngr: mgr
me string: result
me uint: cmd
me string: promptChars
me string: message
me bool: readMultiLineGUIMode
me string: charConsts <- " \n"
me int: onChangeCallback(me uint: cmd) <- {return(true)}
me string: submitText() <- {return (mgr.fetchBuffer(result))}
me bool: editOK(me uint: EntryAttrs) <- {
if(EntryAttrs==1){ return(true)}
else if(EntryAttrs<=5){message <- "Item locked."}
else if(EntryAttrs>5){message <- "Item cannot be edited."}
return(false)
}
me void: addUserMesgAndTopBar(me string: msg) <- {
message <- msg
addUserMesg(msg, 3+shiftLeft(6, 4))
}
void: clearEntry(their EntryX: entry) <- {
if(!entry){return()}
mgr.crntRowInWnd <- mgr.crntRowInWnd-entry.lines.size()
mgr.totalLines <- mgr.totalLines - entry.lines.size()
entry.lines.clear()
mgr.linesDeleted <- true
their lineX:: lx
entry.lines.pushLast(lx)
mgr.totalLines <- mgr.totalLines + 1
mgr.crntRowInWnd <- mgr.crntRowInWnd +1
//if(mgr.currentLine.entriesIdx==entry) {mgr.currentLine.linesIdx<-mgr.currentLine.entriesIdx.begin()} // BDL: mgr.currentLine.entriesIdx==entry.lines.linesIdx
}
void: appendTextToEntry(their EntryX: entry, their posRecStore: text) <- {
their lineX:: lx
me List<me uint>: colorStack
me posRec: pr
me int32: chr
me int64: q <- 0
me int64: p <- 0
me uint: nextColor <- 4096 // 0x1000
me uint: colorCode <- 0 //Color 0=default for this entry.
if(text.s[0]!=0){
while(packUTF8Char(text.s.c_str(),p,chr)){
//if(count>2000){print("Infinite loop!\n"); exit(2);}
if(chr==charConsts[1]){ // '\n'
lx.dirty<-true
entry.lines.pushLast(lx)
Allocate(lx)
mgr.totalLines <- mgr.totalLines + 1
} else {
if(text.colorCodes){
itr Map<me int, me posRec>: posRecsItr <- text.ps.find(q)
if(posRecsItr!=text.ps.end()){ // We need to change colors.
pr<-posRecsItr.val
itr Map<their void, me int>: colorCodeItr <- text.colorCodes.find(pr.itemParsed)
me bool: colorCodeExists <- colorCodeItr!=text.colorCodes.end()
if(colorCodeExists){
if(pr.isStart) {
colorStack.pushLast(colorCode)
colorCode<-colorCodeItr.val
}
if(pr.isEnd and colorStack.size()!=0) {
nextColor<-colorStack.last()
colorStack.popLast()
}
}
}
}
lx.chars.pushLast(charX(chr,colorCode,wcwidth(chr)))
if(nextColor < 4096) {colorCode<-nextColor; nextColor<-4096}
}
q<-p
}
}
lx.dirty<-true
entry.lines.pushLast(lx)
mgr.totalLines <- mgr.totalLines + 1
}
void: appendNewEntry(their EntryX: entry, their posRecStore: text) <- {
appendTextToEntry(entry, text)
bufs.pushLast(entry)
mgr.moveToBottom()
mgr.crntRowInWnd <- mgr.crntRowInWnd +1
}
void: addUserMesg(me string: msg, me uint: Flags) <- {
their EntryX:: entry
entry.attrs <- Flags
if(readMultiLineGUIMode){
their posRecStore: text
Allocate(text, msg)
appendNewEntry(entry, text)
}
else {print(msg+"\n")}
}
const uint: promptWidth <- 0
void: refreshDisplay(me uint: Mode) <- {
if(!readMultiLineGUIMode) {return()}
me uint: EntryAttrs <- 0
me uint: winHeight <- mgr.wndEndY-mgr.wndStartY
me lineIterator: rowItr <- mgr.currentLine
if(mgr.crntRowInWnd >= winHeight) {mgr.crntRowInWnd <- winHeight-1}
if(mgr.crntRowInWnd < 0) {mgr.crntRowInWnd <- 0}
me uint: rowInt <- mgr.crntRowInWnd
while(rowInt>0 and !mgr.isFirstLine(rowItr)){rowInt <- rowInt-1; mgr.prevLine(rowItr)}
mgr.crntRowInWnd <- mgr.crntRowInWnd-rowInt // Don't let the first line be below the top line.
rowInt <- 0
their EntryX: prevEntrySetID <- 0
while(rowInt<winHeight){
EntryAttrs <- mgr.entries[rowItr.entriesIdx].attrs
if(rowItr.entriesIdx==mgr.currentLine.entriesIdx) {attrOn(A_BOLD)}
else {attrOff(A_BOLD)} // Highlight the current EntryX
if(mgr.allDirty or mgr.entries[rowItr.entriesIdx].lines[rowItr.linesIdx].dirty){
mgr.entries[rowItr.entriesIdx].lines[rowItr.linesIdx].dirty <- false
attrOn(getColorPair(6) + A_REVERSE)
if(promptWidth>0){
// this sets the margin
if(!(prevEntrySetID === mgr.entries[rowItr.entriesIdx])){
movePutChar(0, rowInt+mgr.wndStartY, promptChars[shiftRight(AndBits(EntryAttrs, 240), 4)])
prevEntrySetID <- mgr.entries[rowItr.entriesIdx]
} else {movePutChar(0, rowInt+mgr.wndStartY, promptChars[0])}
} else {movePutStr(0, rowInt+mgr.wndStartY,"")}
attrOff(A_REVERSE)
if(Mode==1) {attrOn(getColorPair(8))}
else if(EntryAttrs>0) {attrOn(getColorPair(AndBits(EntryAttrs, 7)))}
else {attrOn(getColorPair(1))}
// Print each character
their lineX: lx <- mgr.entries[rowItr.entriesIdx].lines[rowItr.linesIdx]
withEach chX in lx.chars{
putCharX(chX, EntryAttrs)
}
clearToEOL()
}
attrOn(getColorPair(1))
rowInt <- rowInt +1
if(!mgr.nextLine(rowItr)) {break()}
}
mgr.allDirty <- false
if(mgr.linesDeleted and rowInt<mgr.wndHeight){
moveCursor(rowInt+mgr.wndStartY,0)
clearToBottom()
mgr.linesDeleted <- false
}
// message <- message + " crntRowInWnd:" + toString(mgr.crntRowInWnd) + " crntEntry:" + toString(mgr.currentLine.entriesIdx) + " crntLine:" + toString(mgr.currentLine.linesIdx) + " EntryAttr:" + toString(EntryAttrs)
moveCursor(0,0)
attrOff(A_BOLD)
attrOn(A_REVERSE)
me string: msg <- message
me int: h
me int: w
getScreenMaxXY(w, h)
if(msg.size()>=w){msg.resize(w)}
putStr(stringToWString(msg))
withEach p in range msg.size() .. w {putChar(charConsts[0]);}
attrOff(A_REVERSE)
movePutStr(mgr.widthToCur+promptWidth, mgr.crntRowInWnd+mgr.wndStartY, "")
refreshScn()
}
me string: readLines() <- {
if(true){
their EntryX:: ex
ex.attrs <- 0 + shiftLeft(1, 4)
me string: initMesg <- ""
their posRecStore: text
Allocate(text, initMesg)
appendNewEntry(ex, text)
}
mgr.charsToCur <- 0
mgr.widthToCur <- 0
mgr.curMax <- 0
me uint: chg <- 0 // Change status - return from onChangeCallBack()
refreshDisplay(chg)
me bool: done <- false
while(!done){
me charX: chX
me int: h
me int: w
getScreenMaxXY(w, h)
mgr.wndEndY <- h
mgr.wndHeight <- mgr.wndEndY-mgr.wndStartY
mgr.wndWidth <- w
mgr.linesDeleted <- 0
cmd <- getChar()
message <- ""
if(cmd < 32 or cmd == 127 or cmd > 255){
switch(cmd){
case KEY_DOWN: {mgr.moveDown()}
case KEY_UP: {mgr.moveUp()}
case KEY_LEFT: {mgr.moveLeft()}
case KEY_RIGHT: {mgr.moveRight()}
case KEY_HOME: {mgr.moveHome()}
case KEY_BACKSPACE: {chkEd(mgr.backspc())}
case KEY_BTAB: {mgr.backTab()}
case KEY_NPAGE: {mgr.pageDown()}
case KEY_PPAGE: {mgr.pageUp()}
case KEY_END: {mgr.moveEnd()}
case KEY_DC: {chkEd(mgr.doDelete())}
case KEY_IC: {mgr.doInsertKey()}
case KEY_SF: {} // Shift down
case KEY_SR: {} // Shift up
case KEY_SLEFT: {} // Shift Left
case KEY_SRIGHT: {} // Shift Right
//case CTRL_PGUP:case ALT_PGUP: { mgr.moveToTop()} // BDL
//case CTRL_PGDN:case ALT_PGDN: { mgr.moveToBottom()}
case KEY_MOUSE: {}
case KEY_RESIZE: {}
//case KEY_ENTER: {if((chg==1) and (mgr.charsToCur==linesChars(mgr.currentLine).size()) and isLastInSet(mgr.currentLine)) {return(submitText())}chkEd(mgr.doEnter())}
case 1: {} // CTRL-A - Select all
case 2: {mgr.moveLeft()} // CTRL-B - Move back/left
case 3: {} // CTRL-C - Copy
case 4: {done <- true; return(submitText())} // CTRL-D - Done/quit (EOF)
case 5: {mgr.moveEnd()} // CTRL-E - Go to end of line
case 6: {mgr.moveRight()} // CTRL-F - Move forward/right
case 7: {return(submitText())} // CTRL-G - GO. Submit this text for processing.
case 8: {mgr.moveHome()} // CTRL-H - Home
case 9: {mgr.doTab()} // CTRL-I
case 10: {mgr.cycleSaveModes()} // CTRL-J
case 11: {chkEd(mgr.clearToEOL())} // CTRL-K - Kill to end-of-line
case 12: {} // CTRL-L - Clear screen
case 14: {mgr.nextHist()} // CTRL-N - Next in history
case 15: {mgr.occludeHist()} // CTRL-O - Occlude this from history (toggle)
case 16: {mgr.prevHist()} // CTRL-P - Previous in history
case 17: {} // CTRL-Q - Ctrl Q doesn't work on all systems outside raw Mode.
// case 18: {onChangeCallback(cmd)} // CTRL-R - Recompile and Refresh screen
case 19: {} // CTRL-S - Ctrl S doesn't work on all systems outside raw Mode.
case 20: {mgr.moveHome(); return(submitText())} // CTRL-T - Normalize in step-Mode
case 21: {mgr.clearAll()} // CTRL-U - Clear entire line / unclear
case 22: {} // CTRL-V - Paste
case 23: {} // CTRL-W - Toggle word-wrap Mode
case 24: {} // CTRL-X - Cut
case 25: {} // CTRL-Y - Redo
case 26: {} // CTRL-Z - Undo
case 27: {} // ESC
case 127: {chkEd(mgr.backspc())} // Backspace
case 13:{ // CTRL-M - Enter
me uint: attrs <- shiftRight(AndBits((mgr.entries[mgr.currentLine.entriesIdx].attrs), 240), 4)
if(attrs>1 and attrs<=5){
me string: entryText
mgr.fetchBuffer(entryText)
their posRecStore: textStore
Allocate(textStore, entryText)
their EntryX: LastEntry <- mgr.lastEntry()
LastEntry.lines.clear()
mgr.crntRowInWnd <- mgr.crntRowInWnd -1
mgr.linesDeleted <- true
appendTextToEntry(LastEntry, textStore)
mgr.moveToBottom()
break()
} else if(1){ // or (chg==1) and (mgr.charsToCur==linesChars(mgr.currentLine).size()) and isLastInSet(mgr.currentLine)) {
if(attrs>5){message <- "Item cannot be edited."}
else {return(submitText())}
}
chkEd(mgr.doEnter())
}
}
}else{
me int: remaining <- remainingOctets(cmd)
if(remaining==0){
chX.chr <- cmd
chX.chWidth <- 1 // wcwidth(chX.chr)
chkEd(mgr.insertChar(chX))
} else { // finish unicode character
me string: str; str <- cmd;
withEach cnt in range 0 .. remaining {
cmd <- getChar()
str <+- cmd
}
me int64:pos
packUTF8Char(str,pos,chX.chr)
chX.chWidth <- wcwidth(chX.chr)
chkEd(mgr.insertChar(chX))
}
}
refreshDisplay(chg)
}
return(submitText())
}
void: initNCurses() <- {
//std::setlocale(LC_CTYPE, "en_US.UTF-8");
initTerminalControls()
setColorPair(0, -1, -1) // Fgnd/Bgnd for un-parsed entries, etc. (~$Ss>)
setColorPair(1, COLOR_BLUE, -1) // FGnd/BGnd for parsed entries
setColorPair(2, COLOR_GREEN, -1) // Colors for result - good (=)
setColorPair(3, COLOR_MAGENTA,-1) // Colors for result - error (?)
setColorPair(4, COLOR_CYAN, -1) // Colors for messages for user (#)
setColorPair(5, COLOR_BLUE, -1) // Colors for context prompt (:)
setColorPair(6, COLOR_BLUE, -1) // Colors for prompt bar
setColorPair(7, COLOR_GREEN, -1) // Colors for enter = submit
setColorPair(8, COLOR_YELLOW, -1)
setColorPair(9, COLOR_RED, -1)
setColorPair(10, -1, COLOR_BLUE) // Colors for list items
attrOn(getColorPair(1))
setScrollingOK(true)
disableKeypressBuffering()
dontCnvtNewLine()
enableFNKeyDetection(true)
disableKeypressEchoing()
ESCDELAY <- 0
}
none: readMultiLine(me uint: wndStartY, me string: prmptChrs) <- {
readMultiLineGUIMode <- true
mgr.wndStartY <- wndStartY
message <- ""
promptChars <- prmptChrs
mgr.entries <- bufs
mgr.insertMode <- true
mgr.allDirty <- true
mgr.crntRowInWnd <- 0
mgr.totalLines <- 0
}
}