-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSlyEdit_IceStuff.js
942 lines (880 loc) · 39.4 KB
/
SlyEdit_IceStuff.js
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
// $Id: SlyEdit_IceStuff.js,v 1.33 2019/08/15 04:43:33 nightfox Exp $
/* This contains IceEdit-specific functions for SlyEdit.
*
* Author: Eric Oulashin (AKA Nightfox)
* BBS: Digital Distortion
* BBS address: digdist.bbsindex.com
*
* Date User Description
* 2009-06-06 Eric Oulashin Started development
* 2009-08-09 Eric Oulashin More development & testing
* 2009-08-22 Eric Oulashin Version 1.00
* Initial public release
* ... Removed comments ...
* 2019-05-04 Eric Oulashin Updated to use require() instead of load() if possible.
*/
if (typeof(require) === "function")
{
require("sbbsdefs.js", "K_NOCRLF");
require(getScriptDir() + "SlyEdit_Misc.js", "UPPER_LEFT_SINGLE");
}
else
{
load("sbbsdefs.js");
load(getScriptDir() + "SlyEdit_Misc.js");
}
// Read the color configuration file
readColorConfig(gConfigSettings.iceColors.ThemeFilename);
///////////////////////////////////////////////////////////////////////////////////
// Functions
// This function reads the color configuration for Ice style.
//
// Parameters:
// pFilename: The name of the color configuration file
function readColorConfig(pFilename)
{
var colors = readValueSettingConfigFile(pFilename, 512);
if (colors != null)
{
// Make a backup of the menuOptClassicColors setting so we can set it
// back in the Ice color settings object after setting the colors.
var useClassicColorsBackup = gConfigSettings.iceColors.menuOptClassicColors;
gConfigSettings.iceColors = colors;
// Move the general color settings into gConfigSettings.genColors.*
if (EDITOR_STYLE == "ICE")
moveGenColorsToGenSettings(gConfigSettings.iceColors, gConfigSettings);
gConfigSettings.iceColors.menuOptClassicColors = useClassicColorsBackup;
}
}
// Sets up any global screen-related variables needed for Ice style
function globalScreenVarsSetup_IceStyle()
{
gSubjPos.x = 12;
gSubjPos.y = 3;
gSubjScreenLen = +(console.screen_columns * (54/80)).toFixed(0);
}
// Re-draws the screen, in the style of IceEdit.
//
// Parameters:
// pEditLeft: The leftmost column of the edit area
// pEditRight: The rightmost column of the edit area
// pEditTop: The topmost row of the edit area
// pEditBottom: The bottommost row of the edit area
// pEditColor: The edit color
// pInsertMode: The insert mode ("INS" or "OVR")
// pUseQuotes: Whether or not message quoting is enabled
// pEditLinesIndex: The index of the message line at the top of the edit area
// pDisplayEditLines: The function that displays the edit lines
function redrawScreen_IceStyle(pEditLeft, pEditRight, pEditTop, pEditBottom, pEditColor,
pInsertMode, pUseQuotes, pEditLinesIndex, pDisplayEditLines)
{
// Top header
// Generate & display the top border line (Note: Generate this
// border line only once, for efficiency).
if (typeof(redrawScreen_IceStyle.topBorder) == "undefined")
{
redrawScreen_IceStyle.topBorder = UPPER_LEFT_SINGLE;
var innerWidth = console.screen_columns - 2;
for (var i = 0; i < innerWidth; ++i)
redrawScreen_IceStyle.topBorder += HORIZONTAL_SINGLE;
redrawScreen_IceStyle.topBorder += UPPER_RIGHT_SINGLE;
redrawScreen_IceStyle.topBorder = randomTwoColorString(redrawScreen_IceStyle.topBorder,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2);
}
// Print the border line on the screen
console.clear();
console.print(redrawScreen_IceStyle.topBorder);
// Next line
// To name
var lineNum = 2;
console.gotoxy(1, lineNum);
// Calculate the width of the user alias field: 28 characters, based
// on an 80-column screen width.
var fieldWidth = (console.screen_columns * (29/80)).toFixed(0);
var screenText = gToName.substr(0, fieldWidth);
console.print("\1n" + randomTwoColorString(VERTICAL_SINGLE,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2) +
gConfigSettings.iceColors.TopInfoBkgColor + " " +
gConfigSettings.iceColors.TopLabelColor + "TO" +
gConfigSettings.iceColors.TopLabelColonColor + ": " +
gConfigSettings.iceColors.TopToColor + screenText);
fieldWidth -= screenText.length;
for (var i = 0; i < fieldWidth; ++i)
console.print(" ");
// From name
fieldWidth = (console.screen_columns * (29/80)).toFixed(0);
screenText = gFromName.substr(0, fieldWidth);
console.print(" " + gConfigSettings.iceColors.TopLabelColor + "FROM" +
gConfigSettings.iceColors.TopLabelColonColor + ": " +
gConfigSettings.iceColors.TopFromColor + screenText);
fieldWidth -= screenText.length;
for (var i = 0; i < fieldWidth; ++i)
console.print(" ");
// More spaces until the time location
var curpos = console.getxy();
var startX = console.screen_columns - 8;
while (curpos.x < startX)
{
console.print(" ");
++curpos.x;
}
// Time
console.print(" ");
displayTime_IceStyle();
console.print(" " + randomTwoColorString(VERTICAL_SINGLE, gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2));
// Next line: Subject, time left, insert/overwrite mode
++lineNum;
console.gotoxy(1, lineNum);
// Subject
fieldWidth = (console.screen_columns * (54/80)).toFixed(0);
screenText = gMsgSubj.substr(0, fieldWidth);
console.print("\1n" + randomTwoColorString(VERTICAL_SINGLE,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2) +
gConfigSettings.iceColors.TopInfoBkgColor + " " +
gConfigSettings.iceColors.TopLabelColor + "SUBJECT" +
gConfigSettings.iceColors.TopLabelColonColor + ": " +
gConfigSettings.iceColors.TopSubjectColor + screenText);
fieldWidth -= screenText.length;
for (var i = 0; i < fieldWidth; ++i)
console.print(" ");
// Time left
fieldWidth = (console.screen_columns * (4/80)).toFixed(0);
screenText = Math.floor(bbs.time_left / 60).toString().substr(0, fieldWidth);
startX = console.screen_columns - fieldWidth - 10;
// Before outputting the time left, write more spaces until the starting
// horizontal location.
curpos = console.getxy();
while (curpos.x < startX)
{
console.print(" ");
++curpos.x;
}
console.print(" " + gConfigSettings.iceColors.TopLabelColor + "TL" +
gConfigSettings.iceColors.TopLabelColonColor + ": " +
gConfigSettings.iceColors.TopTimeLeftColor, screenText);
fieldWidth -= screenText.length;
for (var i = 0; i < fieldWidth; ++i)
console.print(" ");
// Insert/overwrite mode
console.print(" " + gConfigSettings.iceColors.EditMode + pInsertMode + " n" +
randomTwoColorString(VERTICAL_SINGLE, gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2));
// Next line: Top border for the message area and also includes the user #,
// message area, and node #.
// Generate this border line only once, for efficiency.
if (typeof(redrawScreen_IceStyle.msgAreaBorder) == "undefined")
{
redrawScreen_IceStyle.msgAreaBorder = "n"
+ randomTwoColorString(LEFT_T_SINGLE + HORIZONTAL_SINGLE,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2)
// User #, padded with high-black dim block characters, 5 characters for a screen
// that's 80 characters wide.
+ "h" + THIN_RECTANGLE_LEFT + "#k";
fieldWidth = (console.screen_columns * (5/80)).toFixed(0) - user.number.toString().length;
for (var i = 0; i < fieldWidth; ++i)
redrawScreen_IceStyle.msgAreaBorder += BLOCK1;
redrawScreen_IceStyle.msgAreaBorder += "c" + user.number
+ gConfigSettings.iceColors.BorderColor1
+ THIN_RECTANGLE_RIGHT;
// The message area name should be centered on the line. So, based on its
// length (up to 35 characters), figure out its starting position before
// printing it.
//var msgAreaName = gMsgArea.substr(0, 20); // Used to be 20 characters
var msgAreaName = gMsgArea.substr(0, 35);
// 2 is subtracted from the starting position to leave room for the
// block character and the space.
var startPos = (console.screen_columns/2).toFixed(0) - (msgAreaName.length/2).toFixed(0) - 2;
// Write border characters up to the message area name start position
screenText = "";
for (var i = strip_ctrl(redrawScreen_IceStyle.msgAreaBorder).length; i < startPos; ++i)
screenText += HORIZONTAL_SINGLE;
redrawScreen_IceStyle.msgAreaBorder += randomTwoColorString(screenText,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2);
// Write the message area name
redrawScreen_IceStyle.msgAreaBorder += "h" + gConfigSettings.iceColors.BorderColor1
+ THIN_RECTANGLE_LEFT + " " + iceText(msgAreaName, "w") + " h"
+ gConfigSettings.iceColors.BorderColor1 + THIN_RECTANGLE_RIGHT;
// Calculate the field width for the node number field.
// For the node # field, use 3 characters for a screen 80 characters wide.
fieldWidth = (console.screen_columns * (3/80)).toFixed(0);
// Calculate the horizontal starting position for the node field.
var nodeFieldStartPos = console.screen_columns - fieldWidth - 9;
// Write horizontal border characters up until the point where we'll output
// the node number.
screenText = "";
for (var posX = strip_ctrl(redrawScreen_IceStyle.msgAreaBorder).length; posX < nodeFieldStartPos; ++posX)
screenText += HORIZONTAL_SINGLE;
redrawScreen_IceStyle.msgAreaBorder += randomTwoColorString(screenText,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2);
// Output the node # field
redrawScreen_IceStyle.msgAreaBorder += "h" + gConfigSettings.iceColors.BorderColor1
+ THIN_RECTANGLE_LEFT + iceText("Node", "w") + "nb:hk";
fieldWidth -= bbs.node_num.toString().length;
for (var i = 0; i < fieldWidth; ++i)
redrawScreen_IceStyle.msgAreaBorder += BLOCK1;
redrawScreen_IceStyle.msgAreaBorder += "c" + bbs.node_num
+ gConfigSettings.iceColors.BorderColor1 + THIN_RECTANGLE_RIGHT;
// Write the last 2 characters of top border
redrawScreen_IceStyle.msgAreaBorder += randomTwoColorString(HORIZONTAL_SINGLE + RIGHT_T_SINGLE,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2);
}
// Draw the border line on the screen
++lineNum;
console.gotoxy(1, lineNum);
console.print(redrawScreen_IceStyle.msgAreaBorder);
// Display the bottom message area border and help line
DisplayTextAreaBottomBorder_IceStyle(pEditBottom + 1, pUseQuotes);
DisplayBottomHelpLine_IceStyle(console.screen_rows, pUseQuotes);
// Go to the start of the edit area
console.gotoxy(pEditLeft, pEditTop);
// Write the message text that has been entered thus far.
pDisplayEditLines(pEditTop, pEditLinesIndex);
console.print(pEditColor);
}
function refreshSubjectOnScreen_IceStyle(pX, pY, pLength, pText)
{
console.print("\1n" + gConfigSettings.iceColors.TopInfoBkgColor + gConfigSettings.iceColors.TopSubjectColor);
console.gotoxy(pX, pY);
printf("%-" + pLength + "s", pText.substr(0, pLength));
}
// Displays the first help line for the bottom of the screen, in the style
// of IceEdit.
//
// Parameters:
// pLineNum: The line number on the screen where the text should be placed
// pUseQuotes: Whether or not message quoting is enabled
// pCanChgMsgColor: Whether or not changing the text color is allowed
// The following parameters are not used; this is here to match the function signature of DCTEdit version.
// pEditLeft
// pEditRight
// pInsertMode
function DisplayTextAreaBottomBorder_IceStyle(pLineNum, pUseQuotes, pEditLeft, pEditRight,
pInsertMode, pCanChgMsgColor)
{
// The border will use random bright/normal colors. The colors
// should stay the same each time we draw it, so a "static"
// variable is used for the border text. If that variable has
// not been defined yet, then build it.
if (typeof(DisplayTextAreaBottomBorder_IceStyle.border) == "undefined")
{
// Build the string of CTRL key combinations that will be displayed
var ctrlKeyHelp = "n" + gConfigSettings.iceColors.KeyInfoLabelColor
+ "CTRL nhb(nwAhb)n"
+ gConfigSettings.iceColors.KeyInfoLabelColor + "Abort";
if (pUseQuotes)
{
ctrlKeyHelp += " nhb(nwQhb)n"
+ gConfigSettings.iceColors.KeyInfoLabelColor + "Quote";
}
ctrlKeyHelp += " nhb(nwZhb)n"
+ gConfigSettings.iceColors.KeyInfoLabelColor + "Save";
// Start the border text with the first 2 border characters
// The beginning of this line shows that SlyEdit is registered
// to the sysop. :)
DisplayTextAreaBottomBorder_IceStyle.border =
randomTwoColorString(LOWER_LEFT_SINGLE + HORIZONTAL_SINGLE,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2)
+ "h" + gConfigSettings.iceColors.BorderColor1 + THIN_RECTANGLE_LEFT
+ iceText("Registered To: " + system.operator.substr(0, 20), "w")
+ "h" + gConfigSettings.iceColors.BorderColor1 + THIN_RECTANGLE_RIGHT;
// Append border characters up until the point we'll have to write the CTRL key
// help text.
var screenText = "";
var endPos = console.screen_columns - strip_ctrl(ctrlKeyHelp).length - 3;
var textLen = strip_ctrl(DisplayTextAreaBottomBorder_IceStyle.border).length;
for (var i = textLen+1; i < endPos; ++i)
screenText += HORIZONTAL_SINGLE;
DisplayTextAreaBottomBorder_IceStyle.border += randomTwoColorString(screenText,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2);
// CTRL key help and the remaining 2 characters in the border.
DisplayTextAreaBottomBorder_IceStyle.border += "h" + gConfigSettings.iceColors.BorderColor1
+ THIN_RECTANGLE_LEFT + ctrlKeyHelp + gConfigSettings.iceColors.BorderColor1
+ THIN_RECTANGLE_RIGHT
+ randomTwoColorString(HORIZONTAL_SINGLE + LOWER_RIGHT_SINGLE,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2);
}
// Display the border line on the screen
// If pLineNum is not specified, then default to the 2nd to the last
// line on the screen.
var lineNum = console.screen_rows-1;
if ((typeof(pLineNum) != "undefined") && (pLineNum != null))
lineNum = pLineNum;
console.gotoxy(1, lineNum);
console.print(DisplayTextAreaBottomBorder_IceStyle.border);
}
// Displays the second (lower) help line for the bottom of the screen,
// in the style of IceEdit.
//
// Parameters:
// pLineNum: The line number on the screen where the text should be placed
// The following are not used and are only here to match the DCT-style function:
// pUsingQuotes: Boolean - Whether or not message quoting is enabled.
function DisplayBottomHelpLine_IceStyle(pLineNum, pUsingQuotes)
{
// Construct the help text only once
if (typeof(DisplayBottomHelpLine_IceStyle.helpText) == "undefined")
{
// This line contains the copyright mesage & ESC key help
var screenText = iceText(EDITOR_PROGRAM_NAME + " v", "\1w") + "\1c\1h"
+ EDITOR_VERSION.toString() + " "
+ iceText("Copyright", "\1w") + " \1c\1h" + COPYRIGHT_YEAR + " "
+ iceText("Eric Oulashin", "\1w") + " \1n\1b" + DOT_CHAR + " "
+ iceText("Press ESCape For Help", "\1w");
// Calculate the starting position to center the help text, and front-pad
// DisplayBottomHelpLine_IceStyle.helpText with that many spaces.
var xPos = (console.screen_columns / 2).toFixed(0)
- (strip_ctrl(screenText).length / 2).toFixed(0);
DisplayBottomHelpLine_IceStyle.helpText = "";
for (var i = 0; i < xPos; ++i)
DisplayBottomHelpLine_IceStyle.helpText += " ";
DisplayBottomHelpLine_IceStyle.helpText += screenText;
}
// If pLineNum is not specified, then default to the last line
// on the screen.
var lineNum = console.screen_rows;
if ((typeof(pLineNum) != "undefined") && (pLineNum != null))
lineNum = pLineNum;
// Display the help text on the screen
console.gotoxy(1, lineNum);
console.print(DisplayBottomHelpLine_IceStyle.helpText);
console.print("\1n");
console.cleartoeol();
}
// Updates the insert mode displayd on the screen, for Ice Edit style.
//
// Parameters:
// pEditRight: Not used; this is only here to match the signature of the DCTEdit version.
// pEditBottom: Not used; this is only here to match the signature of the DCTEdit version.
// pInsertMode: The insert mode ("INS" or "OVR")
function updateInsertModeOnScreen_IceStyle(pEditRight, pEditBottom, pInsertMode)
{
console.gotoxy(console.screen_columns-4, 3);
console.print(gConfigSettings.iceColors.TopInfoBkgColor + gConfigSettings.iceColors.EditMode
+ pInsertMode);
}
// Draws the top border of the quote window, IceEdit style.
//
// Parameters:
// pQuoteWinHeight: The height of the quote window
// pEditLeft: The leftmost column of the edit area
// pEditRight: The rightmost column of the edit area
function DrawQuoteWindowTopBorder_IceStyle(pQuoteWinHeight, pEditLeft, pEditRight)
{
// Top border of the quote window
// The border will use random bright/normal colors. The colors
// should stay the same each time we draw it, so a "static"
// variable is used for the border text. If that variable has
// not been defined yet, then build it.
if (typeof(DrawQuoteWindowTopBorder_IceStyle.border) == "undefined")
{
DrawQuoteWindowTopBorder_IceStyle.border = randomTwoColorString(UPPER_LEFT_VSINGLE_HDOUBLE,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2)
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_LEFT
+ gConfigSettings.iceColors.QuoteWinBorderTextColor + "Quote Window"
+ gConfigSettings.iceColors.BorderColor2
+ THIN_RECTANGLE_RIGHT;
// The border from here to the end of the line: Random high/low blue
var screenText = "";
for (var posX = pEditLeft+16; posX <= pEditRight; ++posX)
screenText += HORIZONTAL_DOUBLE;
screenText += UPPER_RIGHT_VSINGLE_HDOUBLE;
DrawQuoteWindowTopBorder_IceStyle.border += randomTwoColorString(screenText,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2);
}
// Draw the border line on the screen
console.gotoxy(pEditLeft, console.screen_rows - pQuoteWinHeight + 1);
console.print(DrawQuoteWindowTopBorder_IceStyle.border);
}
// Draws the bottom border of the quote window, IceEdit style. Note:
// The cursor should be placed at the start of the line (leftmost screen
// column on the screen line where the border should be drawn).
//
// Parameters:
// pEditLeft: The leftmost column of the edit area
// pEditRight: The rightmost column of the edit area
function DrawQuoteWindowBottomBorder_IceStyle(pEditLeft, pEditRight)
{
// The border will use random bright/normal colors. The colors
// should stay the same each time we draw it, so a "static"
// variable is used for the border text. If that variable has
// not been defined yet, then build it.
if (typeof(DrawQuoteWindowBottomBorder_IceStyle.border) == "undefined")
{
DrawQuoteWindowBottomBorder_IceStyle.border = randomTwoColorString(LOWER_LEFT_VSINGLE_HDOUBLE,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2)
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_LEFT
+ gConfigSettings.iceColors.QuoteWinBorderTextColor + "^Q/ESC=End"
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_RIGHT
+ gConfigSettings.iceColors.BorderColor1 + HORIZONTAL_DOUBLE
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_LEFT
+ gConfigSettings.iceColors.QuoteWinBorderTextColor + "CR=Accept"
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_RIGHT
+ gConfigSettings.iceColors.BorderColor1 + HORIZONTAL_DOUBLE
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_LEFT
+ gConfigSettings.iceColors.QuoteWinBorderTextColor + "Up/Down/PgUp/PgDn=Scroll"
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_RIGHT
+ gConfigSettings.iceColors.BorderColor1 + HORIZONTAL_DOUBLE
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_LEFT
+ gConfigSettings.iceColors.QuoteWinBorderTextColor + "F/L=First/Last pg"
+ gConfigSettings.iceColors.BorderColor2 + THIN_RECTANGLE_RIGHT;
// The border from here to the end of the line: Random high/low blue
var screenText = "";
for (var posX = pEditLeft + 73; posX <= pEditRight; ++posX)
screenText += HORIZONTAL_DOUBLE;
screenText += LOWER_RIGHT_VSINGLE_HDOUBLE;
DrawQuoteWindowBottomBorder_IceStyle.border += randomTwoColorString(screenText,
gConfigSettings.iceColors.BorderColor1,
gConfigSettings.iceColors.BorderColor2);
}
// Draw the border line on the screen
console.print(DrawQuoteWindowBottomBorder_IceStyle.border);
}
// Prompts the user for a yes/no question, IceEdit-style. Note that
// the cursor should be position where it needs to be before calling
// this function.
//
// Parameters:
// pQuestion: The question to ask, without the trailing "?"
// pDefaultYes: Whether to default to "yes" (true/false). If false, this
// will default to "no".
function promptYesNo_IceStyle(pQuestion, pDefaultYes)
{
var userResponse = pDefaultYes;
// Print the question, and highlight "yes" or "no", depending on
// the value of pDefaultYes.
console.print(iceText(pQuestion + "? ", "w"));
displayIceYesNoText(pDefaultYes);
// yesNoX contains the horizontal position for the "Yes" & "No" text.
const yesNoX = strip_ctrl(pQuestion).length + 3;
// Input loop
var userInput = "";
var continueOn = true;
while (continueOn)
{
// Move the cursor to the start of the "Yes" or "No" text (whichever
// one is currently selected).
console.gotoxy(userResponse ? yesNoX : yesNoX+7, console.screen_rows);
// Get a keypress from the user and take appropriate action.
userInput = getUserKey(K_UPPER|K_NOECHO|K_NOCRLF|K_NOSPIN, gConfigSettings);
// If userInput is blank, then the timeout was hit, so exit the loop.
// Also exit the loop of the user pressed enter.
if ((userInput == "") || (userInput == KEY_ENTER))
continueOn = false;
else if (userInput == "Y")
{
userResponse = true;
continueOn = false;
}
else if (userInput == "N")
{
userResponse = false;
continueOn = false;
}
// Left or right arrow key: Toggle userResponse and update the
// yes/no text with the appropriate colors
else if ((userInput == KEY_LEFT) || (userInput == KEY_RIGHT))
{
// Move the cursor to the start of the "Yes" and "No" text, and
// update the text depending on the value of userResponse.
console.gotoxy(yesNoX, console.screen_rows);
userResponse = !userResponse;
displayIceYesNoText(userResponse);
}
}
return userResponse;
}
// Displays the time on the screen.
//
// Parameters:
// pTimeStr: The time to display (optional). If this is omitted,
// then this funtion will get the current time.
function displayTime_IceStyle(pTimeStr)
{
console.gotoxy(console.screen_columns-7, 2);
if (pTimeStr == null)
console.print("n" + gConfigSettings.iceColors.TopInfoBkgColor + gConfigSettings.iceColors.TopTimeColor + getCurrentTimeStr());
else
console.print("n" + gConfigSettings.iceColors.TopInfoBkgColor + gConfigSettings.iceColors.TopTimeColor + pTimeStr);
}
// Displays the number of minutes remaining on the screen.
function displayTimeRemaining_IceStyle()
{
var fieldWidth = (console.screen_columns * (4/80)).toFixed(0);
var formatStr = "n" + gConfigSettings.iceColors.TopInfoBkgColor
+ gConfigSettings.iceColors.TopTimeLeftColor + "%-"
+ fieldWidth + "s";
var startX = console.screen_columns - fieldWidth - 5;
console.gotoxy(startX, 3);
var timeStr = Math.floor(bbs.time_left / 60).toString().substr(0, fieldWidth);
printf(formatStr, timeStr);
}
// For IceEdit mode: This function takes a string and returns a copy
// of the string with uppercase letters dim and the rest bright for
// a given color.
//
// Parameters:
// pString: The string to convert
// pColor: The Synchronet color code to use as the base text color.
// pBkgColor: Optional - The background color (a Synchronet color code).
// Defaults to normal white.
function iceText(pString, pColor, pBkgColor)
{
// Return if an invalid string is passed in.
if (typeof(pString) == "undefined")
return "";
if (pString == null)
return "";
// Set the color. Default to blue.
var color = "b";
if ((typeof(pColor) != "undefined") && (pColor != null))
color = pColor;
// Set the background color. Default to normal black.
var bkgColor = "nk";
if ((typeof(pBkgColor) != "undefined") && (pBkgColor != null))
bkgColor = pBkgColor;
// Create a copy of the string without any control characters,
// and then add our coloring to it.
pString = strip_ctrl(pString);
var returnString = "n" + bkgColor + color;
var lastColor = "n" + color;
var character = "";
for (var i = 0; i < pString.length; ++i)
{
character = pString.charAt(i);
// Upper-case letters: Make it dim with the passed-in color.
if (character.match(/[A-Z]/) != null)
{
// If the last color was not the normal color, then append
// the normal color to returnString.
if (lastColor != "n" + color)
returnString += "n" + bkgColor + color;
lastColor = "n" + color;
}
// Lower-case letter: Make it bright with the passed-in color.
else if (character.match(/[a-z]/) != null)
{
// If this is the first character or if the last color was
// not the bright color, then append the bright color to
// returnString.
if ((i == 0) || (lastColor != ("h" + color)))
returnString += "h" + color;
lastColor = "h" + color;
}
// Number: Make it bright cyan
else if (character.match(/[0-9]/) != null)
{
// If the last color was not bright cyan, then append
// bright cyan to returnString.
if (lastColor != "hc")
returnString += "hc";
lastColor = "hc";
}
// All else: Make it bright blue
else
{
// If the last color was not bright cyan, then append
// bright cyan to returnString.
if (lastColor != "hb")
returnString += "hb";
lastColor = "hb";
}
// Append the character from pString.
returnString += character;
}
return returnString;
}
// Displays & handles the input loop for the IceEdit menu.
//
// Parameters:
// pY: The line number on the screen for the menu
// pCanCrossPost: Whether or not cross-posting is allowed
//
// Return value: One of the ESC_MENU values, based on the
// user's response.
function doIceESCMenu(pY, pCanCrossPost)
{
// The chosen action will be returned from this function
var chosenAction = ESC_MENU_EDIT_MESSAGE;
// IceEdit ESC menu item return values
var ICE_ESC_MENU_SAVE = 0;
var ICE_ESC_MENU_ABORT = 1;
var ICE_ESC_MENU_EDIT = 2;
var ICE_ESC_MENU_SETTINGS = 3;
var ICE_ESC_MENU_HELP = 4;
var ICE_ESC_MENU_SPELL_CHECK = 5;
var ICE_ESC_MENU_CROSS_POST = 6;
var promptText = "Select An Option: ";
console.gotoxy(1, pY);
console.print(iceText(promptText, "\1w"));
console.cleartoeol("\1n");
// Input loop
var lastMenuItem = (pCanCrossPost ? ICE_ESC_MENU_CROSS_POST : ICE_ESC_MENU_SPELL_CHECK);
var userChoice = ICE_ESC_MENU_SAVE;
var userInput;
var continueOn = true;
while (continueOn)
{
console.gotoxy(promptText.length, pY);
// Display the options, with the correct one highlighted.
switch (userChoice)
{
case ICE_ESC_MENU_SAVE:
console.print(iceStyledPromptText("Save", true) + "\1n ");
console.print(iceStyledPromptText("Abort", false) + "\1n ");
console.print(iceStyledPromptText("Edit", false) + "\1n ");
console.print(iceStyledPromptText("Settings", false) + "\1n ");
console.print(iceStyledPromptText("Help", false) + "\1n ");
console.print(iceStyledPromptText("sPlchk", false));
if (pCanCrossPost)
console.print("\1n " + iceStyledPromptText("Cross-post", false));
break;
case ICE_ESC_MENU_ABORT:
console.print(iceStyledPromptText("Save", false) + "\1n ");
console.print(iceStyledPromptText("Abort", true) + "\1n ");
console.print(iceStyledPromptText("Edit", false) + "\1n ");
console.print(iceStyledPromptText("Settings", false) + "\1n ");
console.print(iceStyledPromptText("Help", false) + "\1n ");
console.print(iceStyledPromptText("sPlchk", false));
if (pCanCrossPost)
console.print("\1n " + iceStyledPromptText("Cross-post", false));
break;
case ICE_ESC_MENU_EDIT:
console.print(iceStyledPromptText("Save", false) + "\1n ");
console.print(iceStyledPromptText("Abort", false) + "\1n ");
console.print(iceStyledPromptText("Edit", true) + "\1n ");
console.print(iceStyledPromptText("Settings", false) + "\1n ");
console.print(iceStyledPromptText("Help", false) + "\1n ");
console.print(iceStyledPromptText("sPlchk", false));
if (pCanCrossPost)
console.print("\1n " + iceStyledPromptText("Cross-post", false));
break;
case ICE_ESC_MENU_SETTINGS:
console.print(iceStyledPromptText("Save", false) + "\1n ");
console.print(iceStyledPromptText("Abort", false) + "\1n ");
console.print(iceStyledPromptText("Edit", false) + "\1n ");
console.print(iceStyledPromptText("Settings", true) + "\1n ");
console.print(iceStyledPromptText("Help", false) + "\1n ");
console.print(iceStyledPromptText("sPlchk", false));
if (pCanCrossPost)
console.print("\1n " + iceStyledPromptText("Cross-post", false));
break;
case ICE_ESC_MENU_HELP:
console.print(iceStyledPromptText("Save", false) + "\1n ");
console.print(iceStyledPromptText("Abort", false) + "\1n ");
console.print(iceStyledPromptText("Edit", false) + "\1n ");
console.print(iceStyledPromptText("Settings", false) + "\1n ");
console.print(iceStyledPromptText("Help", true) + "\1n ");
console.print(iceStyledPromptText("sPlchk", false));
if (pCanCrossPost)
console.print("\1n " + iceStyledPromptText("Cross-post", false));
break;
case ICE_ESC_MENU_SPELL_CHECK:
console.print(iceStyledPromptText("Save", false) + "\1n ");
console.print(iceStyledPromptText("Abort", false) + "\1n ");
console.print(iceStyledPromptText("Edit", false) + "\1n ");
console.print(iceStyledPromptText("Settings", false) + "\1n ");
console.print(iceStyledPromptText("Help", false) + "\1n ");
console.print(iceStyledPromptText("sPlchk", true));
if (pCanCrossPost)
console.print("\1n " + iceStyledPromptText("Cross-post", false));
break;
break;
case ICE_ESC_MENU_CROSS_POST:
console.print(iceStyledPromptText("Save", false) + "\1n ");
console.print(iceStyledPromptText("Abort", false) + "\1n ");
console.print(iceStyledPromptText("Edit", false) + "\1n ");
console.print(iceStyledPromptText("Settings", false) + "\1n ");
console.print(iceStyledPromptText("Help", false) + "\1n ");
console.print(iceStyledPromptText("sPlchk", false) + "\1n ");
console.print(iceStyledPromptText("Cross-post", true));
break;
}
// Get the user's choice
userInput = getUserKey(K_UPPER|K_NOECHO|K_NOCRLF|K_NOSPIN, gConfigSettings);
switch (userInput)
{
case KEY_UP:
case KEY_LEFT:
--userChoice;
if (userChoice < ICE_ESC_MENU_SAVE)
userChoice = lastMenuItem;
break;
case KEY_DOWN:
case KEY_RIGHT:
++userChoice;
if (userChoice > lastMenuItem)
userChoice = ICE_ESC_MENU_SAVE;
break;
case "S": // Save
userChoice = ICE_ESC_MENU_SAVE;
continueOn = false;
break;
case "A": // Abort
userChoice = ICE_ESC_MENU_ABORT;
continueOn = false;
break;
case KEY_ESC: // Go back to editing the message
case "E": // Go back to editing the message
userChoice = ICE_ESC_MENU_EDIT;
continueOn = false;
break;
case "H": // Help
userChoice = ICE_ESC_MENU_HELP;
continueOn = false;
break;
case "C": // Cross-post
if (pCanCrossPost)
{
userChoice = ICE_ESC_MENU_CROSS_POST;
continueOn = false;
}
break;
case "P": // Spell check
userChoice = ICE_ESC_MENU_SPELL_CHECK;
continueOn = false;
break;
case KEY_ENTER: // Accept the current choice
continueOn = false;
break;
default:
break;
}
}
// Make sure special text attributes are cleared.
console.print("\1n");
// Now that the user has made a choice, set userAction
switch (userChoice)
{
case ICE_ESC_MENU_SAVE:
chosenAction = ESC_MENU_SAVE;
break;
case ICE_ESC_MENU_ABORT:
chosenAction = ESC_MENU_ABORT;
break;
case ICE_ESC_MENU_EDIT:
chosenAction = ESC_MENU_EDIT_MESSAGE;
break;
case ICE_ESC_MENU_SETTINGS:
chosenAction = ESC_MENU_USER_SETTINGS;
break;
case ICE_ESC_MENU_HELP:
chosenAction = ESC_MENU_HELP_COMMAND_LIST;
break;
case ICE_ESC_MENU_SPELL_CHECK:
chosenAction = ESC_MENU_SPELL_CHECK;
break;
case ICE_ESC_MENU_CROSS_POST:
chosenAction = ESC_MENU_CROSS_POST_MESSAGE;
break;
}
return chosenAction;
}
// Returns text to be used in prompts, such as the ESC menu, etc.
//
// Parameters:
// pText: The text to display
// pHighlight: Whether or not to use highlight colors
//
// Return value: The styled text
function iceStyledPromptText(pText, pHighlight)
{
var styledText;
if (gConfigSettings.iceColors.menuOptClassicColors)
{
if (pHighlight)
styledText = gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_LEFT
+ gConfigSettings.iceColors.SelectedOptionTextColor + pText
+ gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_RIGHT;
else
styledText = gConfigSettings.iceColors.UnselectedOptionBorderColor + THIN_RECTANGLE_LEFT
+ iceText(pText, "w") + gConfigSettings.iceColors.UnselectedOptionBorderColor
+ THIN_RECTANGLE_RIGHT;
}
else
{
if (pHighlight)
styledText = gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_LEFT
+ "n4hy" + pText.substr(0, 1) + "c" + pText.substr(1) + "n"
+ gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_RIGHT;
else
styledText = gConfigSettings.iceColors.UnselectedOptionBorderColor + THIN_RECTANGLE_LEFT
+ iceText(pText, "c") + gConfigSettings.iceColors.UnselectedOptionBorderColor
+ THIN_RECTANGLE_RIGHT;
}
return styledText;
}
// Displays yes/no options in Ice style.
//
// Parameters:
// pYesSelected: Whether or not the "yes" option is to be selected.
function displayIceYesNoText(pYesSelected)
{
if (pYesSelected)
{
if (gConfigSettings.iceColors.menuOptClassicColors)
{
console.print(gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_LEFT +
gConfigSettings.iceColors.SelectedOptionTextColor + "YES" +
gConfigSettings.iceColors.SelectedOptionBorderColor +
THIN_RECTANGLE_RIGHT + gConfigSettings.iceColors.UnselectedOptionBorderColor +
" " + THIN_RECTANGLE_LEFT + gConfigSettings.iceColors.UnselectedOptionTextColor +
"NO" + gConfigSettings.iceColors.UnselectedOptionBorderColor +
THIN_RECTANGLE_RIGHT + "n");
}
else
{
console.print(gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_LEFT +
"n4hyYcesn" + gConfigSettings.iceColors.SelectedOptionBorderColor +
THIN_RECTANGLE_RIGHT + gConfigSettings.iceColors.UnselectedOptionBorderColor +
" " + THIN_RECTANGLE_LEFT + "nhcNnco" +
gConfigSettings.iceColors.UnselectedOptionBorderColor + THIN_RECTANGLE_RIGHT +
"n");
}
}
else
{
if (gConfigSettings.iceColors.menuOptClassicColors)
{
console.print(gConfigSettings.iceColors.UnselectedOptionBorderColor + THIN_RECTANGLE_LEFT +
gConfigSettings.iceColors.UnselectedOptionTextColor + "YES" +
gConfigSettings.iceColors.UnselectedOptionBorderColor + THIN_RECTANGLE_RIGHT +
" " + gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_LEFT +
gConfigSettings.iceColors.SelectedOptionTextColor + "NO" +
gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_RIGHT +
"n");
}
else
{
console.print(gConfigSettings.iceColors.UnselectedOptionBorderColor + THIN_RECTANGLE_LEFT +
"nhcYnces" + gConfigSettings.iceColors.UnselectedOptionBorderColor +
THIN_RECTANGLE_RIGHT + " " + gConfigSettings.iceColors.SelectedOptionBorderColor +
THIN_RECTANGLE_LEFT + "n4hyNcon" +
gConfigSettings.iceColors.SelectedOptionBorderColor + THIN_RECTANGLE_RIGHT +
"n");
}
}
}
// Returns the the script's execution directory.
// The code in this function is a trick that was created by Deuce, suggested
// by Rob Swindell as a way to detect which directory the script was executed
// in. I've shortened the code a little.
function getScriptDir()
{
var startup_path = '.';
try { throw dig.dist(dist); } catch(e) { startup_path = e.fileName; }
return(backslash(startup_path.replace(/[\/\\][^\/\\]*$/,'')));
}