forked from UplinkCoder/d-tui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtterminal.d
5762 lines (5116 loc) · 137 KB
/
tterminal.d
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
/**
* D Text User Interface library - TTerminal class
*
* Version: $Id$
*
* Author: Kevin Lamonte, <a href="mailto:[email protected]">[email protected]</a>
*
* License: LGPLv3 or later
*
* Copyright: This module is licensed under the GNU Lesser General
* Public License Version 3. Please see the file "COPYING" in this
* directory for more information about the GNU Lesser General Public
* License Version 3.
*
* Copyright (C) 2013 Kevin Lamonte
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* as published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program; if not, see
* http://www.gnu.org/licenses/, or write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
/*
* TODO:
*
* xterm mouse reporting
* split state machine into ECMA48 and VT52
*
*/
module tui.tterminal;
// Description ---------------------------------------------------------------
// Imports -------------------------------------------------------------------
import std.array;
import std.conv;
import std.file;
import std.format;
import std.string;
import std.utf;
import tui.base;
import tui.ecma;
import tui.codepage;
import tui.tapplication;
import tui.tscroll;
import tui.twidget;
import tui.twindow;
// Defines -------------------------------------------------------------------
private immutable size_t ECMA48_MAX_LINE_LENGTH = 256;
// DEC VT100/VT220 translation maps ------------------------------------------
// US - Normal "international" (ASCII)
private static immutable wchar[128] dec_us_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x0020
];
// VT100 drawing characters
private static immutable wchar[128] dec_special_graphics_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
0x2666, 0x2592, 0x2409, 0x240C, 0x240D, 0x240A, 0x00B0, 0x00B1,
0x2424, 0x240B, 0x2518, 0x2510, 0x250C, 0x2514, 0x253C, 0x23BA,
0x23BB, 0x2500, 0x23BC, 0x23BD, 0x251C, 0x2524, 0x2534, 0x252C,
0x2502, 0x2264, 0x2265, 0x03C0, 0x2260, 0x00A3, 0x00B7, 0x0020
];
// Dec Supplemental (DEC multinational)
private static immutable wchar[128] dec_supplemental_chars = [
0x0080, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087,
0x0088, 0x0089, 0x008A, 0x008B, 0x008C, 0x008D, 0x008E, 0x008F,
0x0090, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096, 0x0097,
0x0098, 0x0099, 0x009A, 0x009B, 0x009C, 0x009D, 0x009E, 0x009F,
0x0020, 0x00A1, 0x00A2, 0x00A3, 0x00A8, 0x00A5, 0x0020, 0x00A7,
0x00A4, 0x00A9, 0x00AA, 0x00AB, 0x0020, 0x0020, 0x0020, 0x0020,
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0020, 0x00B5, 0x00B6, 0x00B7,
0x0020, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x0020, 0x00BF,
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
0x0020, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x0157,
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0178, 0x0020, 0x00DF,
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
0x0020, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x0153,
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FF, 0x0020, 0x0020
];
// UK
private static immutable wchar[128] dec_uk_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x00A3, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x007B, 0x007C, 0x007D, 0x007E, 0x0020
];
// DUTCH
private static immutable wchar[128] dec_nl_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x00A3, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00BE, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x0133, 0x00BD, 0x007C, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00A8, 0x0066, 0x00BC, 0x00B4, 0x0020
];
// FINNISH
private static immutable wchar[128] dec_fi_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00C4, 0x00D6, 0x00C5, 0x00DC, 0x005F,
0x00E9, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00E5, 0x00FC, 0x0020
];
// FRENCH
private static immutable wchar[128] dec_fr_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x00A3, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00E0, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00B0, 0x00E7, 0x00A7, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00E9, 0x00F9, 0x00E8, 0x00A8, 0x0020
];
// FRENCH_CA
private static immutable wchar[128] dec_fr_CA_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00E0, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00E2, 0x00E7, 0x00EA, 0x00EE, 0x005F,
0x00F4, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00E9, 0x00F9, 0x00E8, 0x00FB, 0x0020
];
// GERMAN
private static immutable wchar[128] dec_de_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00A7, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00C4, 0x00D6, 0x00DC, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00FC, 0x00DF, 0x0020
];
// ITALIAN
private static immutable wchar[128] dec_it_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x00A3, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00A7, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00B0, 0x00E7, 0x00E9, 0x005E, 0x005F,
0x00F9, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00E0, 0x00F2, 0x00E8, 0x00EC, 0x0020
];
// NORWEGIAN
private static immutable wchar[128] dec_no_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00C4, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00C6, 0x00D8, 0x00C5, 0x00DC, 0x005F,
0x00E4, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00E6, 0x00F8, 0x00E5, 0x00FC, 0x0020
];
// SPANISH
private static immutable wchar[128] dec_es_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x00A3, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00A7, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00A1, 0x00D1, 0x00BF, 0x005E, 0x005F,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00B0, 0x00F1, 0x00E7, 0x007E, 0x0020
];
// SWEDISH
private static immutable wchar[128] dec_sv_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00C9, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00C4, 0x00D6, 0x00C5, 0x00DC, 0x005F,
0x00E9, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00E5, 0x00FC, 0x0020
];
// SWISS
private static immutable wchar[128] dec_swiss_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x00F9, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x00E0, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x00E9, 0x00E7, 0x00EA, 0x00EE, 0x00E8,
0x00F4, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067,
0x0068, 0x0069, 0x006A, 0x006B, 0x006C, 0x006D, 0x006E, 0x006F,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077,
0x0078, 0x0079, 0x007A, 0x00E4, 0x00F6, 0x00FC, 0x00FB, 0x0020
];
// VT52 drawing characters
private static immutable wchar[128] vt52_special_graphics_chars = [
0x0000, 0x0001, 0x0002, 0x0003, 0x0004, 0x0005, 0x0006, 0x0007,
0x0008, 0x0009, 0x000A, 0x000B, 0x000C, 0x000D, 0x000E, 0x000F,
0x0010, 0x0011, 0x0012, 0x0013, 0x0014, 0x0015, 0x0016, 0x0017,
0x0018, 0x0019, 0x001A, 0x001B, 0x001C, 0x001D, 0x001E, 0x001F,
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027,
0x0028, 0x0029, 0x002A, 0x002B, 0x002C, 0x002D, 0x002E, 0x002F,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037,
0x0038, 0x0039, 0x003A, 0x003B, 0x003C, 0x003D, 0x003E, 0x003F,
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047,
0x0048, 0x0049, 0x004A, 0x004B, 0x004C, 0x004D, 0x004E, 0x004F,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057,
0x0058, 0x0059, 0x005A, 0x005B, 0x005C, 0x005D, 0x0020, 0x0020,
0x0020, 0x2588, 0x215F, 0x2592, 0x2592, 0x2592, 0x00B0, 0x00B1,
0x2190, 0x2026, 0x00F7, 0x2193, 0x23BA, 0x23BA, 0x23BB, 0x23BB,
0x2500, 0x2500, 0x23BC, 0x23BC, 0x2080, 0x2081, 0x2082, 0x2083,
0x2084, 0x2085, 0x2086, 0x2087, 0x2088, 0x2089, 0x00B6, 0x0020
];
// Globals -------------------------------------------------------------------
// Classes -------------------------------------------------------------------
/**
* This implements a complex ANSI ECMA-48/ISO 6429/ANSI X3.64 type
* consoles, including a scrollback buffer.
*
* It currently implements VT100, VT102, VT220, and XTERM with the
* following caveats:
*
* - Smooth scrolling, printing, keyboard locking, keyboard leds, and
* tests from VT100 are not supported.
*
* - User-defined keys (DECUDK), downloadable fonts (DECDLD), and
* VT100/ANSI compatibility mode (DECSCL) from VT220 are not
* supported. (Also, because DECSCL is not supported, it will fail
* the last part of the vttest "Test of VT52 mode" if DeviceType is
* set to VT220.)
*
* - Numeric/application keys from the number pad are not supported
* because they are not exposed from the D-TUI TKeypress API.
*
* - VT52 HOLD SCREEN mode is not supported.
*
* - In VT52 graphics mode, the 3/, 5/, and 7/ characters (fraction
* numerators) are not rendered correctly.
*
* - All data meant for the 'printer' (CSI Pc ? i) is discarded.
*/
private class ECMA48 {
/// This controls what is sent back from the "Device Attributes"
/// function.
public enum DeviceType {
VT100,
VT102,
VT220,
XTERM }
/**
* Return the proper primary Device Attributes string
*
* Returns:
* string to send to remote side that is appropriate for the this.type
*/
private dstring deviceTypeResponse() {
final switch (type) {
case DeviceType.VT100:
// "I am a VT100 with advanced video option" (often VT102)
return "\033[?1;2c";
case DeviceType.VT102:
// "I am a VT102"
return "\033[?6c";
case DeviceType.VT220:
// "I am a VT220" - 7 bit version
if (!s8c1t) {
return "\033[?62;1;6c";
}
// "I am a VT220" - 8 bit version
return "\u009b?62;1;6c";
case DeviceType.XTERM:
// "I am a VT100 with advanced video option" (often VT102)
return "\033[?1;2c";
}
}
/**
* Return the proper TERM for this device type
*
* Returns:
* "TERM=vt100", "TERM=xterm", etc.
*/
public string deviceTypeTerm() {
final switch (type) {
case DeviceType.VT100:
return "TERM=vt100";
case DeviceType.VT102:
return "TERM=vt102";
case DeviceType.VT220:
return "TERM=vt220";
case DeviceType.XTERM:
return "TERM=xterm";
}
}
/**
* Return the proper LANG for this device type. Only XTERM devices know
* about UTF-8, the others are defined by their standard to be either
* 7-bit or 8-bit characters only.
*
* Params:
* baseLang = a base language without UTF-8 flag such as "C" or "en_US"
*
* Returns:
* "LANG=en_US", "LANG=en_US.UTF-8", etc.
*/
public string deviceTypeLang(string baseLang) {
final switch (type) {
case DeviceType.VT100:
return "LANG=" ~ baseLang;
case DeviceType.VT102:
return "LANG=" ~ baseLang;
case DeviceType.VT220:
return "LANG=" ~ baseLang;
case DeviceType.XTERM:
return "LANG=" ~ baseLang ~ ".UTF-8";
}
}
/// The type of emulator to be
private DeviceType type = DeviceType.VT102;
/// This represents a single line of the display buffer
private class DisplayLine {
/// The characters/attributes of the line
public Cell [] chars;
/// Double-width line
public bool doubleWidth = false;
/**
* Double-height line flag:
*
* 0 = single height
* 1 = top half double height
* 2 = bottom half double height
*/
public int doubleHeight = 0;
/// DECSCNM - reverse video. We copy the flag to the line so that
/// reverse-mode scrollback lines still show inverted colors
/// correctly.
public bool reverseColor = false;
/// Constructor sets everything to normal attributes
public this() {
chars.length = ECMA48_MAX_LINE_LENGTH;
for (auto i = 0; i < chars.length; i++) {
chars[i] = new Cell();
chars[i].setTo(currentState.attr);
}
}
}
/**
* Obtain a new blank display line for an external client.
*
* Returns:
* new blank line
*/
public DisplayLine getBlankDisplayLine() {
return new DisplayLine();
}
/// The scrollback buffer characters + attributes
private DisplayLine [] scrollback;
/// The raw display buffer characters + attributes
private DisplayLine [] display;
/// Parser character scan states
enum ScanState {
GROUND,
ESCAPE,
ESCAPE_INTERMEDIATE,
CSI_ENTRY,
CSI_PARAM,
CSI_INTERMEDIATE,
CSI_IGNORE,
DCS_ENTRY,
DCS_INTERMEDIATE,
DCS_PARAM,
DCS_PASSTHROUGH,
DCS_IGNORE,
SOSPMAPC_STRING,
OSC_STRING,
VT52_DIRECT_CURSOR_ADDRESS }
/// Current scanning state
private ScanState scanState;
/// The selected number pad mode (DECKPAM, DECKPNM). We record this, but
/// can't really use it in keypress() because we do not see number pad
/// events from Terminal.processEvents().
enum KeypadMode {
Application,
Numeric }
/// Arrow keys can emit three different sequences (DECCKM or VT52 submode)
enum ArrowKeyMode {
VT52,
ANSI,
VT100 }
/// Available character sets for GL, GR, G0, G1, G2, G3
enum CharacterSet {
US,
UK,
DRAWING,
ROM,
ROM_SPECIAL,
VT52_GRAPHICS,
DEC_SUPPLEMENTAL,
NRC_DUTCH,
NRC_FINNISH,
NRC_FRENCH,
NRC_FRENCH_CA,
NRC_GERMAN,
NRC_ITALIAN,
NRC_NORWEGIAN,
NRC_SPANISH,
NRC_SWEDISH,
NRC_SWISS }
/// Single-shift states used by the C1 control characters SS2 (0x8E) and
/// SS3 (0x8F)
enum Singleshift {
NONE,
SS2,
SS3 }
/// VT220+ lockshift states
enum LockshiftMode {
NONE,
G1_GR,
G2_GR,
G2_GL,
G3_GR,
G3_GL }
/// Physical display width. We start at 80x24, but the user can resize
/// us bigger/smaller.
public int width;
/// Physical display height. We start at 80x24, but the user can resize
/// us bigger/smaller.
public int height;
/// Several functions are supposed to send text directly to the other
/// side. This function is called to deliver that text.
private void function(dstring) remoteFn;
private void delegate(dstring) remoteDg;
/// Top margin of the scrolling region
private int scrollRegionTop;
/// Bottom margin of the scrolling region
private int scrollRegionBottom;
/// Right margin
public uint rightMargin;
/// Last character printed
private dchar repCh;
/**
* VT100-style line wrapping: a character is placed in column 80 (or
* 132), but the line does NOT wrap until another character is written to
* column 1 of the next line, after which the cursor moves to column 2.
*/
private bool wrapLineFlag;
/// VT220 single shift flag
private Singleshift singleshift = Singleshift.NONE;
/// true = insert characters, false = overwrite
private bool insertMode = false;
/// VT52 mode as selected by DECANM. True means VT52, false means ANSI. Default is ANSI.
private bool vt52Mode = false;
/// Visible cursor (DECTCEM)
public bool visibleCursor = true;
/// Screen title
public dstring screenTitle = "";
/// Array of flags that have come in, e.g. '?' (DEC private mode), '=', '>', ...
private char [] csiFlags;
/// Parameter characters being collected
private int [] csiParams;
/// Non-csi collect buffer
private dchar [] collectBuffer;
/// When true, use the G1 character set
private bool shiftOut = false;
/// Horizontal tab stops
private int [] tabStops;
/// S8C1T. True means 8bit controls, false means 7bit controls.
private bool s8c1t = false;
/// Printer mode. True means send all output to printer, which discards it.
private bool printerControllerMode = false;
/// LMN line mode. If true, linefeed() puts the cursor on the first
/// column of the next line. If false, linefeed() puts the cursor one
/// line down on the current line. The default is false.
private bool newLineMode = false;
/// Whether arrow keys send ANSI, VT100, or VT52 sequences
private ArrowKeyMode arrowKeyMode;
/// Whether number pad keys send VT100 or VT52, application or
/// numeric sequences.
private KeypadMode keypadMode;
/// When true, the terminal is in 132-column mode (DECCOLM)
private bool columns132 = false;
/// true = reverse video. Set by DECSCNM.
private bool reverseVideo = false;
/// false = echo characters locally.
private bool fullDuplex = true;
/**
* DECSC/DECRC save/restore a subset of the total state. This class
* encapsulates those specific flags/modes.
*/
private class SaveableState {
/// When true, cursor positions are relative to the scrolling region
public bool originMode = false;
/// The current editing X position
public uint cursorX = 0;
/// The current editing Y position
public uint cursorY = 0;
/// Which character set is currently selected in G0
public CharacterSet g0Charset = CharacterSet.US;
/// Which character set is currently selected in G1
public CharacterSet g1Charset = CharacterSet.DRAWING;
public CharacterSet g2Charset = CharacterSet.US;
public CharacterSet g3Charset = CharacterSet.US;
public CharacterSet grCharset = CharacterSet.DRAWING;
/// The current drawing attributes
public CellAttributes attr;
/// When a lockshift command comes in
public LockshiftMode glLockshift = LockshiftMode.NONE;
public LockshiftMode grLockshift = LockshiftMode.NONE;
/// Line wrap
public bool lineWrap = true;
/// Reset to defaults
public void reset() {
originMode = false;
cursorX = 0;
cursorY = 0;
g0Charset = CharacterSet.US;
g1Charset = CharacterSet.DRAWING;
g2Charset = CharacterSet.US;
g3Charset = CharacterSet.US;
grCharset = CharacterSet.DRAWING;
attr = new CellAttributes();
glLockshift = LockshiftMode.NONE;
grLockshift = LockshiftMode.NONE;
lineWrap = true;
}
/**
* Copy attributes from another instance
*
* Params:
* that = the other instance to match
*/
public void setTo(SaveableState that) {
this.originMode = that.originMode;
this.cursorX = that.cursorX;
this.cursorY = that.cursorY;
this.g0Charset = that.g0Charset;
this.g1Charset = that.g1Charset;
this.g2Charset = that.g2Charset;
this.g3Charset = that.g3Charset;
this.grCharset = that.grCharset;
this.attr = new CellAttributes();
this.attr.setTo(that.attr);
this.glLockshift = that.glLockshift;
this.grLockshift = that.grLockshift;
this.lineWrap = that.lineWrap;
}
/// Constructor
public this() {
reset();
}
}
/// The current terminal state
private SaveableState currentState;
/// The last saved terminal state
private SaveableState savedState;
/**
* Clear the CSI parameters and flags
*/
private void toGround() {
csiParams.length = 0;
csiFlags.length = 0;
collectBuffer.length = 0;
scanState = ScanState.GROUND;
}
/**
* Reset the tab stops list
*/
private void resetTabStops() {
tabStops.length = 0;
for (int i = 0; (i * 8) <= rightMargin; i++) {
tabStops.length++;
tabStops[i] = i * 8;
}
}
/**
* Reset the emulation state
*/
private void reset() {
currentState = new SaveableState();
savedState = new SaveableState();
scanState = ScanState.GROUND;
width = 80;
height = 24;
scrollRegionTop = 0;
scrollRegionBottom = height - 1;
rightMargin = width - 1;
newLineMode = false;
arrowKeyMode = ArrowKeyMode.ANSI;
keypadMode = KeypadMode.Numeric;
wrapLineFlag = false;
// Flags
shiftOut = false;
vt52Mode = false;
insertMode = false;
columns132 = false;
newLineMode = false;
reverseVideo = false;
fullDuplex = true;
visibleCursor = true;
// VT220
singleshift = Singleshift.NONE;
s8c1t = false;
printerControllerMode = false;
// Tab stops
resetTabStops();
// Clear CSI stuff
toGround();
}
/**
* Public constructor
*
* Params:
* type = one of the DeviceType constants to select VT100, VT102, VT220, or XTERM
* remoteFn = function to call to deliver text to the remote side
*/
public this(DeviceType type, void function(dstring) remoteFn) {
this.type = type;
this.remoteFn = remoteFn;
reset();
for (auto i = 0; i < height; i++) {
display ~= new DisplayLine();
}
}
/**
* Public constructor
*
* Params:
* type = one of the DeviceType constants to select VT100, VT102, VT220, or XTERM
* remoteDg = delegate to call to deliver text to the remote side
*/
public this(DeviceType type, void delegate(dstring) remoteDg) {
this.type = type;
this.remoteDg = remoteDg;
reset();
for (auto i = 0; i < height; i++) {
display ~= new DisplayLine();
}
}
/**
* Append a new line to the bottom of the display, adding lines off the
* top to the scrollback buffer.
*/
private void newDisplayLine() {
// Scroll the top line off into the scrollback buffer
scrollback ~= display[0];
display = display[1 .. $];
display ~= new DisplayLine();
display[$ - 1].reverseColor = reverseVideo;
}
/**
* Wraps the current line
*/
private void wrapCurrentLine() {
if (currentState.cursorY == height - 1) {
newDisplayLine();
}
if (currentState.cursorY < height - 1) {
currentState.cursorY++;
}
currentState.cursorX = 0;
}
/**
* Handle a carriage return
*/
private void carriageReturn() {
currentState.cursorX = 0;
wrapLineFlag = false;
}
/**
* Reverse the color of the visible display
*/
private void invertDisplayColors() {
foreach (line; display) {
line.reverseColor = !line.reverseColor;
}
}
/**
* Handle a linefeed
*/
private void linefeed(bool newLineMode) {
int i;
if (currentState.cursorY < scrollRegionBottom) {
// Increment screen y
currentState.cursorY++;
} else {
// Screen y does not increment
/*
* Two cases: either we're inside a scrolling region or not. If
* the scrolling region bottom is the bottom of the screen, then
* push the top line into the buffer. Else scroll the scrolling
* region up.
*/
if ((scrollRegionBottom == height - 1) && (scrollRegionTop == 0)) {
// We're at the bottom of the scroll region, AND the scroll
// region is the entire screen.
// New line
newDisplayLine();
} else {
// We're at the bottom of the scroll region, AND the scroll
// region is NOT the entire screen.
scrollingRegionScrollUp(scrollRegionTop, scrollRegionBottom, 1);
}
}
if (newLineMode == true) {
currentState.cursorX = 0;
}
wrapLineFlag = false;
}
/**
* Prints one character to the display buffer.
*
* Params:
* ch = character to display
*/
private void printCharacter(dchar ch) {
auto rightMargin = this.rightMargin;
// Check if we have double-width, and if so chop at 40/66
// instead of 80/132
if (display[currentState.cursorY].doubleWidth == true) {
rightMargin = ((rightMargin + 1) / 2) - 1;
}
// Check the unusually-complicated line wrapping conditions...
if (currentState.cursorX == rightMargin) {
if (currentState.lineWrap == true) {
/*
* This case happens when: the cursor was already on the
* right margin (either through printing or by an explicit
* placement command), and a character was printed.
*
* The line wraps only when a new character arrives AND the
* cursor is already on the right margin AND has placed a
* character in its cell. Easier to see than to explain.
*/
if (wrapLineFlag == false) {
/*
* This block marks the case that we are in the margin
* and the first character has been received and printed.
*/
wrapLineFlag = true;
} else {
/*
* This block marks the case that we are in the margin
* and the second character has been received and
* printed.
*/
wrapLineFlag = false;
wrapCurrentLine();
}
}
} else if (currentState.cursorX <= rightMargin) {