Debian Codegraph @

xterm.c

raw
1 /* $Id: xterm.c,v 1.87 2024/12/05 00:43:14 tom Exp $ */
2
3 #include <vttest.h>
4 #include <esc.h>
5 #include <ttymodes.h>
6
7 #define Pause(secs) fflush(stdout); sleep(secs)
8
9 static int do_decaln;
10
11 static int
12 toggle_color(MENU_ARGS)
13 {
14 do_colors = !do_colors;
15 return MENU_NOHOLD;
16 }
17
18 static int
19 toggle_decaln(MENU_ARGS)
20 {
21 do_decaln = !do_decaln;
22 return MENU_NOHOLD;
23 }
24
25 static void
26 check_rc(int row, int col)
27 {
28 char *report;
29 char *params;
30 char expected[80];
31
32 sprintf(expected, "%d;%dR", row, col);
33
34 set_tty_raw(TRUE);
35 set_tty_echo(FALSE);
36 do_csi("6n");
37 report = get_reply();
38 restore_ttymodes();
39
40 vt_move(row, 1);
41 el(2);
42 if ((params = skip_csi(report)) == NULL
43 || strcmp(params, expected) != 0) {
44 printxx("cursor save/restore %s, got \"%s\", expected \"%s\"",
45 SHOW_FAILURE, params, expected);
46 } else {
47 printxx("cursor save/restore %s", SHOW_SUCCESS);
48 }
49 }
50
51 static void
52 begin_altscreen(MENU_ARGS, const char *explain, int except_tite)
53 {
54 vt_move(1, 1);
55 println(the_title);
56 vt_move(3, 1);
57 println(explain);
58 vt_move(4, 1);
59 println("The next screen will be filled with E's down to the prompt.");
60 if (except_tite) {
61 vt_move(5, 1);
62 println("unless titeInhibit resource is set, or alternate-screen is disabled.");
63 }
64 vt_move(7, 5);
65 }
66
67 static void
68 fill_altscreen(void)
69 {
70 vt_move(12, 1);
71 if (do_decaln) {
72 println("This message should not be here.");
73 decaln(); /* fill the screen */
74 } else {
75 int y, x;
76
77 for (y = 0; y < max_lines; ++y) {
78 cup(y + 1, 1);
79 for (x = 0; x < min_cols; ++x)
80 putchar('E');
81 }
82 vt_move(12, 1);
83 }
84 }
85
86 static void
87 finish_altscreen(void)
88 {
89 vt_move(4, 1);
90 el(2);
91 println("The original screen should be restored except for this line.");
92 vt_move(max_lines - 2, 1);
93 }
94
95 static int
96 test_altscrn_47(MENU_ARGS)
97 {
98 begin_altscreen(PASS_ARGS,
99 "Test private setmode 47 (to/from alternate screen)",
100 0);
101 decsc();
102 cup(max_lines - 2, 1);
103 holdit();
104
105 if (do_colors)
106 set_colors(WHITE_ON_BLUE);
107
108 sm("?47");
109 fill_altscreen();
110 vt_move(15, 7);
111 decsc();
112 cup(max_lines - 2, 1);
113 ed(0);
114 holdit();
115
116 rm("?47");
117 vt_move(max_lines - 2, 1);
118 decrc();
119 check_rc(7, 5);
120 finish_altscreen();
121
122 if (do_colors)
123 reset_colors();
124
125 return MENU_HOLD;
126 }
127
128 static int
129 test_altscrn_1047(MENU_ARGS)
130 {
131 begin_altscreen(PASS_ARGS,
132 "Test private setmode 1047 (to/from alternate screen)",
133 1);
134 decsc();
135 vt_move(9, 7); /* move away from the place we saved with DECSC */
136 sm("?1048"); /* this saves the cursor position */
137 cup(max_lines - 2, 1);
138 holdit();
139
140 if (do_colors)
141 set_colors(WHITE_ON_BLUE);
142
143 sm("?1047");
144 fill_altscreen();
145 vt_move(15, 7);
146 decsc();
147 cup(max_lines - 2, 1);
148 ed(0);
149 holdit();
150
151 rm("?1047");
152 vt_move(max_lines - 2, 1);
153 decrc();
154 rm("?1048");
155 check_rc(9, 7);
156 finish_altscreen();
157
158 if (do_colors)
159 reset_colors();
160
161 return MENU_HOLD;
162 }
163
164 static int
165 test_altscrn_1049(MENU_ARGS)
166 {
167 begin_altscreen(PASS_ARGS,
168 "Test private setmode 1049 (to/from alternate screen)",
169 1);
170 decsc();
171 cup(max_lines - 2, 1);
172 holdit(); /* cursor location will be one line down */
173
174 if (do_colors)
175 set_colors(WHITE_ON_BLUE);
176
177 sm("?1049"); /* this saves the cursor location */
178 fill_altscreen();
179 cup(max_lines - 2, 1);
180 ed(0);
181 holdit();
182
183 vt_move(max_lines - 2, 1);
184 rm("?1049");
185 decrc();
186 check_rc(max_lines - 1, 1);
187 finish_altscreen();
188
189 if (do_colors)
190 reset_colors();
191
192 return MENU_HOLD;
193 }
194
195 /*
196 * XTerm implements an alternate screen, which is used to save the command-line
197 * screen to restore it after running a full-screen application.
198 *
199 * The original scheme used separate save/restore-cursor and clear-screen
200 * operations in conjunction with a toggle to/from the alternate screen
201 * (private setmode 47). Since not all users want the feature, xterm also
202 * implements the titeInhibit resource to make it populate the $TERMCAP
203 * variable without the ti/te (smcup/rmcup) strings which hold those sequences.
204 * The limitation of titeInhibit is that it cannot work for terminfo, because
205 * that information is read from a file rather than the environment. I
206 * implemented a corresponding set of strings for private setmode 1047 and 1048
207 * to model the termcap behavior in terminfo.
208 *
209 * The behavior of the save/restore cursor operations still proved
210 * unsatisfactory since users would (even in the original private setmode 47)
211 * occasionally run shell programs from within their full-screen application
212 * which would do a save-cursor to a different location, causing the final
213 * restore-cursor to place the cursor in an unexpected location. The private
214 * setmode 1049 works around this by using a separate memory location to store
215 * its version of the cursor location.
216 */
217 static int
218 tst_altscrn(MENU_ARGS)
219 {
220 static char txt_do_colors[80];
221 static char txt_do_decaln[80];
222 /* *INDENT-OFF* */
223 static MENU my_menu[] = {
224 { "Exit", NULL },
225 { txt_do_colors, toggle_color },
226 { txt_do_decaln, toggle_decaln },
227 { "Switch to/from alternate screen (xterm)", test_altscrn_47 },
228 { "Improved alternate screen (XFree86 xterm mode 1047)", test_altscrn_1047 },
229 { "Better alternate screen (XFree86 xterm mode 1049)", test_altscrn_1049 },
230 { "", NULL }
231 };
232 /* *INDENT-ON* */
233
234 int save_colors = do_colors;
235
236 do_decaln = 1;
237
238 do {
239 sprintf(txt_do_colors, "%s after switching to alternate",
240 do_colors ? "Color" : "Do not color");
241 sprintf(txt_do_decaln, "%s after switching to alternate",
242 do_decaln ? "Use DECALN" : "Do not use DECALN");
243 vt_clear(2);
244 __(title(0), println("XTERM Alternate-Screen features"));
245 __(title(2), println("Choose test type:"));
246 } while (menu(my_menu));
247
248 if (do_colors && !save_colors)
249 reset_colors();
250 do_colors = save_colors;
251
252 return MENU_NOHOLD;
253 }
254
255 #define NUMFONTS 7
256
257 static int
258 tst_modify_font(MENU_ARGS)
259 {
260 char temp[BUF_SIZE];
261
262 vt_move(1, 1);
263 println("Please enter the font name.");
264 println("You can use '#' number to set fonts relative (with +/- sign) and");
265 println("absolute (with a number) based on the current font's position in");
266 println("the font-menu. Examples:");
267 println(" \"fixed\" to set the current font to \"fixed\"");
268 println(" \"#fixed\" to set the current font to \"fixed\"");
269 println(" \"#-fixed\" to set the previous font to \"fixed\"");
270 println(" \"#-2 fixed\" to set the next-previous font to \"fixed\"");
271 println(" \"#+fixed\" to set the following font to \"fixed\"");
272 vt_move(11, 1);
273 printxx(">");
274 inputline(temp);
275 do_osc("50;%s", temp);
276 return MENU_HOLD;
277 }
278
279 static int
280 tst_report_font(MENU_ARGS)
281 {
282 int n;
283 char *report;
284 int row = 1;
285 int col = 1;
286
287 set_tty_raw(TRUE);
288 set_tty_echo(FALSE);
289
290 vt_move(row, col);
291 println("Current font:");
292 ++row;
293
294 vt_move(row, col + 6);
295 do_osc("50;?");
296 report = get_reply();
297 row = chrprint2(report, row, col);
298
299 ++row;
300 vt_move(row, col);
301 println("Absolute fonts:");
302 ++row;
303
304 for (n = 0; n < NUMFONTS; ++n) {
305 vt_move(row, col);
306 do_osc("50;?%d", n);
307 report = get_reply();
308 if (strchr(report, ';') != NULL) {
309 printxx(" %2d: ", n);
310 row = chrprint2(report, row, col);
311 }
312 }
313
314 ++row;
315
316 vt_move(row, col);
317 println("Relative fonts (bell may sound):");
318 ++row;
319
320 for (n = -NUMFONTS; n < NUMFONTS; ++n) {
321 vt_move(row, col);
322 do_osc("50;?%c%d", n >= 0 ? '+' : '-', n >= 0 ? n : -n);
323 report = get_reply();
324 if (strchr(report, ';') != NULL) {
325 printxx(" %2d: ", n);
326 row = chrprint2(report, row, col);
327 } else if (n >= 0) {
328 break;
329 }
330 }
331
332 restore_ttymodes();
333 return MENU_HOLD;
334 }
335
336 static int
337 tst_font(MENU_ARGS)
338 {
339 /* *INDENT-OFF* */
340 static MENU my_menu[] = {
341 { "Exit", NULL },
342 { "Modify font", tst_modify_font },
343 { "Report font(s)", tst_report_font },
344 { "", NULL }
345 };
346 /* *INDENT-ON* */
347
348 do {
349 vt_clear(2);
350 __(title(0), println("XTERM Font features"));
351 __(title(2), println("Choose test type:"));
352 } while (menu(my_menu));
353 return MENU_NOHOLD;
354 }
355
356 static int
357 test_modify_ops(MENU_ARGS)
358 {
359 int n;
360 int wide, high;
361 char temp[100];
362
363 vt_move(1, 1);
364 println("Test of Window modifying.");
365
366 brc(2, 't'); /* iconify window */
367 println("Iconify");
368 Pause(2);
369
370 brc(1, 't'); /* de-iconify window */
371 println("De-Iconify");
372 Pause(1);
373
374 ed(2);
375 for (n = 0; n <= 200; n += 5) {
376 sprintf(temp, "Position (%d,%d)", n, n * 2);
377 println(temp);
378 esc("K"); /* Erase to end of line */
379 brc3(3, n, n * 2, 't');
380 fflush(stdout);
381 }
382 holdit();
383
384 ed(2);
385 brc3(3, 0, 0, 't');
386
387 for (n = 0; n <= 200; n += 10) {
388 wide = n + 20;
389 high = n + 50;
390 brc3(4, high, wide, 't');
391 sprintf(temp, "%d x %d pixels", high, wide);
392 println(temp);
393 fflush(stdout);
394 }
395 holdit();
396
397 ed(2);
398 for (n = 0; n <= 200; n += 10) {
399 high = n + 50;
400 brc3(4, high, 0, 't');
401 sprintf(temp, "%d x (screen-width) pixels", high);
402 println(temp);
403 fflush(stdout);
404 }
405 holdit();
406
407 ed(2);
408 for (n = 0; n <= 300; n += 10) {
409 wide = n + 50;
410 brc3(4, 0, wide, 't');
411 sprintf(temp, "(screen-height) x %d pixels", wide);
412 println(temp);
413 fflush(stdout);
414 }
415 holdit();
416
417 while (n >= 200) {
418 wide = n + 50;
419 high = 500 - n;
420 brc3(4, high, wide, 't');
421 sprintf(temp, "%d x %d pixels", high, wide);
422 println(temp);
423 fflush(stdout);
424 n -= 5;
425 }
426 holdit();
427
428 while (n <= 300) {
429 wide = n + 50;
430 high = 500 - n;
431 brc3(4, high, wide, 't');
432 sprintf(temp, "%d x %d pixels", high, wide);
433 println(temp);
434 fflush(stdout);
435 n += 5;
436 }
437 holdit();
438
439 ed(2);
440 for (n = 5; n <= 20; n++) {
441 wide = n * 4;
442 high = n + 5;
443 brc3(8, high, wide, 't');
444 sprintf(temp, "%d x %d chars", high, wide);
445 while ((int) strlen(temp) < wide - 1)
446 strcat(temp, ".");
447 println(temp);
448 fflush(stdout);
449 }
450 holdit();
451
452 ed(2);
453 for (n = 5; n <= 24; n++) {
454 high = n;
455 brc3(8, high, 0, 't');
456 sprintf(temp, "%d x (screen-width) chars", high);
457 println(temp);
458 fflush(stdout);
459 }
460 holdit();
461
462 ed(2);
463 for (n = 5; n <= 80; n++) {
464 wide = n;
465 brc3(8, 0, wide, 't');
466 sprintf(temp, "(screen-height) x %d chars", wide);
467 println(temp);
468 fflush(stdout);
469 }
470 holdit();
471
472 brc3(3, 200, 200, 't');
473 brc3(8, 24, 80, 't');
474 println("Reset to 24 x 80");
475
476 ed(2);
477 println("Lower");
478 brc(6, 't');
479 holdit();
480
481 ed(2);
482 println("Raise");
483 brc(5, 't');
484
485 /*
486 * That window resizing can cause a terminal emulator to send lots of
487 * SIGWINCH's, which may be queued up for delivery (and interrupt subsequent
488 * system calls). Check if we can successfully receive replies from the
489 * terminal before proceeding.
490 */
491 set_tty_raw(TRUE);
492 set_tty_echo(FALSE);
493 vt_move(20, 1);
494 pause_replay();
495 printxx("Working");
496 for (n = 0; n < 20; ++n) {
497 char *report;
498 char expect[20];
499 printxx(".");
500 fflush(stdout);
501 do_csi("6n");
502 sprintf(expect, "20;%dR", n + 9);
503 report = get_reply();
504 fflush(stdout);
505 if (LOG_ENABLED) {
506 fprintf(log_fp, NOTE_STR "expect '%s'\n", expect);
507 }
508 if (report != NULL
509 && (report = skip_csi(report)) != NULL
510 && !strcmp(report, expect)) {
511 break;
512 }
513 if (LOG_ENABLED)
514 fflush(log_fp);
515 zleep(1000);
516 }
517 resume_replay();
518 restore_ttymodes();
519 return MENU_HOLD;
520 }
521
522 static int
523 test_report_ops(MENU_ARGS)
524 {
525 /* *INDENT-OFF* */
526 static struct {
527 int csi_or_osc;
528 int pprefix;
529 const char *params;
530 const char *testing;
531 } table[] = {
532 { 0, 0, "11", "state of window (normal/iconified)" },
533 { 0, 1, "13", "position of window in pixels" },
534 { 0, 1, "13;2", "position of text-area in pixels" },
535 { 0, 1, "14", "size of text-area in pixels" },
536 { 0, 1, "14;2", "size of window in pixels" },
537 { 0, 1, "15", "size of screen in pixels" },
538 { 0, 1, "16", "size of character in pixels" },
539 { 0, 1, "18", "size of window in chars" },
540 { 1, 0, "20", "icon label" },
541 { 1, 0, "21", "window label" },
542 };
543 /* *INDENT-ON* */
544
545 int row = 3;
546 int col = 10;
547 int test = 0;
548
549 vt_move(1, 1);
550 println("Test of Window reporting.");
551 fflush(stdout);
552 set_tty_raw(TRUE);
553 set_tty_echo(FALSE);
554
555 for (test = 0; test < TABLESIZE(table); ++test) {
556 char *report;
557 const char *params;
558 char buffer[80];
559
560 if (row + 3 > max_lines - 3) {
561 restore_ttymodes();
562 vt_move(row, 1);
563 holdit();
564 vt_move(row = 3, 1);
565 vt_clear(0);
566 set_tty_raw(TRUE);
567 set_tty_echo(FALSE);
568 }
569
570 vt_move(row++, 1);
571 printxx("Report %s (%s):", table[test].testing, table[test].params);
572 vt_move(row, col);
573 do_csi("%st", table[test].params);
574 report = get_reply();
575 row = chrprint2(report, row, col);
576 vt_move(row++, col);
577
578 if (!strcmp(table[test].params, "11")) {
579 params = skip_csi(report);
580 if (params != NULL
581 && isdigit(CharOf(*params))
582 && !strcmp(params + 1, "t")) {
583 switch (*params) {
584 case '1':
585 params = "normal";
586 break;
587 case '2':
588 params = "icon";
589 break;
590 default:
591 params = "?";
592 }
593 } else {
594 params = "?";
595 }
596 } else if (table[test].csi_or_osc) {
597 params = skip_osc(report);
598 if (params == NULL)
599 params = "?";
600 else if (!strip_suffix(report, st_input()))
601 params = "?";
602 else if (*params == 'L')
603 params = "icon label";
604 else if (*params == 'l')
605 params = "window label";
606 else
607 params = "?";
608 } else {
609 params = skip_csi(report);
610 if (params != NULL && table[test].pprefix) {
611 if (params[0] == table[test].params[1]
612 && params[1] == ';'
613 && strip_suffix(report, "t")) {
614 int high;
615 int wide;
616 int skip;
617 if (sscanf(params, "%d;%d;%d", &skip, &high, &wide) == 3
618 && high > 0 && wide > 0) {
619 sprintf(buffer, "%d high, %d wide", high, wide);
620 params = buffer;
621 } else {
622 params = "?";
623 }
624 } else
625 params = "?";
626 } else {
627 params = "? BUG";
628 }
629 }
630 if (*params == '?')
631 printxx("ERR");
632 else
633 printxx("OK: %s", params);
634 fflush(stdout);
635 }
636
637 vt_move(20, 1);
638 restore_ttymodes();
639 return MENU_HOLD;
640 }
641
642 /* Set window title */
643 static int
644 test_window_name(MENU_ARGS)
645 {
646 char temp[BUF_SIZE];
647
648 vt_move(1, 1);
649 println("Please enter the new window name. Newer xterms may beep when setting the title.");
650 inputline(temp);
651 do_osc("0;%s", temp);
652 return MENU_NOHOLD;
653 }
654
655 static int
656 tst_xterm_VERSION(MENU_ARGS)
657 {
658 int step;
659
660 set_tty_raw(TRUE);
661 set_tty_echo(FALSE);
662
663 vt_move(1, 1);
664 println("Both testcases should all get the same response");
665 for (step = -1; step <= 0; ++step) {
666 char *report;
667 int row, col;
668
669 vt_move(row = 3 + step, col = 3);
670 if (step >= 0)
671 do_csi(">%dq", step);
672 else
673 do_csi(">q");
674 report = get_reply();
675 if ((report = skip_dcs(report)) != NULL
676 && strip_terminator(report)
677 && !strncmp(report, ">|", 2)) {
678 printxx(SHOW_SUCCESS);
679 vt_move(row, col + 3);
680 chrprint2(report + 2, row, col + 3);
681 } else {
682 printxx(SHOW_FAILURE);
683 }
684 }
685
686 vt_move(20, 1);
687 restore_ttymodes();
688 return MENU_HOLD;
689 }
690
691 static int
692 tst_XTTITLEPOS(MENU_ARGS)
693 {
694 int now, top;
695 int row = 3;
696 int first = -1;
697 int last = -1;
698 int seen = -1;
699 char *report;
700 char expect;
701 char ignore;
702
703 vt_move(1, 1);
704 println(the_title);
705
706 set_tty_raw(TRUE);
707 set_tty_echo(FALSE);
708
709 vt_move(3, 3);
710 do {
711 do_csi("#S");
712 report = get_reply();
713 if ((report = skip_csi(report)) != NULL
714 && sscanf(report, "%d;%d#%c%c", &now, &top, &expect, &ignore) == 3
715 && now >= seen
716 && now >= 0
717 && top > now
718 && expect == 'S') {
719 vt_move(row++, 3);
720 printxx("[%d:%d] " SHOW_SUCCESS, now, top);
721 if (first < 0) {
722 first = now;
723 seen = now;
724 last = top;
725 }
726 seen++;
727 do_csi("22;0t");
728 do_osc("0;Title stack %d", seen);
729 zleep(200);
730 } else {
731 printxx(SHOW_FAILURE);
732 break;
733 }
734 } while (seen + 1 < last);
735
736 while (seen-- > first) {
737 do_csi("23;0t");
738 do_csi("#S");
739 report = get_reply();
740 if ((report = skip_csi(report)) != NULL
741 && sscanf(report, "%d;%d#%c%c", &now, &top, &expect, &ignore) == 3
742 && now <= seen
743 && now >= 0
744 && top == last
745 && expect == 'S') {
746 vt_move(--row, 30);
747 printxx("[%d:%d] " SHOW_SUCCESS, now, last);
748 zleep(200);
749 } else {
750 printxx(SHOW_FAILURE);
751 break;
752 }
753 }
754
755 vt_move(20, 1);
756 restore_ttymodes();
757 return MENU_HOLD;
758 }
759
760 #define DATA(name,level) { name, #name, level }
761
762 /*
763 * xterm's DECRQM codes are based on VT320/VT420/VT520, but there are a few
764 * conflicting modes (adapted from rxvt), as well as xterm's extensions.
765 * Those are reflected in the naming conventions.
766 *
767 * The names chosen here are short, to keep display alignment.
768 */
769 #define XT_MSE_X10 9
770 #define XT_TOOLBAR 10
771 #define XT_CBLINK 12
772 #define XT_OPTBLNK 13
773 #define XT_XORBLNK 14
774 #define XT_SCRLBAR 30
775 #define XT_FONTSWT 35
776 #define XT_TEK4014 38
777 #define XT_80_132 40
778 #define XT_CURSES 41
779 #define XT_MARBELL 44
780 #define XT_REVWRAP 45
781 #define XT_LOGGING 46
782 #define XT_ALTSCRN 47
783 #define XT_MSE_X11 1000
784 #define XT_MSE_HL 1001
785 #define XT_MSE_BTN 1002
786 #define XT_MSE_ANY 1003
787 #define XT_MSE_WIN 1004
788 #define XT_MSE_UTF 1005
789 #define XT_MSE_SGR 1006
790 #define XT_ALTSCRL 1007
791 #define XT_TTY_OUT 1010
792 #define XT_SCRLKEY 1011
793 #define XT_FASTSCR 1014
794 #define XT_SGR_PXL 1016
795 #define XT_IN_8BIT 1034
796 #define XT_NUMLOCK 1035
797 #define XT_METAESC 1036
798 #define XT_DELTDEL 1037
799 #define XT_ALT_ESC 1039
800 #define XT_KEEPSEL 1040
801 #define XT_SELTCLP 1041
802 #define XT_BELLURG 1042
803 #define XT_POPBELL 1043
804 #define XT_OLDCLIP 1044
805 #define XT_ALTS_OK 1046
806 #define XT_ALTS_47 1047
807 #define XT_ALTS_SC 1048
808 #define XT_EXTSCRN 1049
809 #define XT_KT_TCAP 1050
810 #define XT_KT_SUN 1051
811 #define XT_KT_HP 1052
812 #define XT_KT_SCO 1053
813 #define XT_KT_OLD 1060
814 #define XT_KT_PC 1061
815 #define RL_BTN1 2001
816 #define RL_BTN2 2002
817 #define RL_DBTN3 2003
818 #define RL_BRACKET 2004
819 #define RL_QUOTE 2005
820 #define RL_LIT_NL 2006
821
822 static int
823 tst_xterm_DECRPM(MENU_ARGS)
824 {
825 /* *INDENT-OFF* */
826 RQM_DATA dec_modes[] = { /* this list is sorted by code, not name */
827 DATA( DECCKM, 3 /* cursor keys */),
828 DATA( DECANM, 3 /* ANSI */),
829 DATA( DECCOLM, 3 /* column */),
830 DATA( DECSCLM, 3 /* scrolling */),
831 DATA( DECSCNM, 3 /* screen */),
832 DATA( DECOM, 3 /* origin */),
833 DATA( DECAWM, 3 /* autowrap */),
834 DATA( DECARM, 3 /* autorepeat */),
835 DATA( XT_MSE_X10, 3 /* X10 mouse */),
836 DATA( XT_TOOLBAR, 3 /* rxvt toolbar vs DECEDM */),
837 DATA( DECLTM, 3 /* line transmit */),
838 DATA( XT_CBLINK, 3 /* att610: Start/stop blinking cursor */),
839 DATA( XT_OPTBLNK, 3 /* blink-option via menu/resource */),
840 DATA( XT_XORBLNK, 3 /* enable XOR or blinking cursoor control */),
841 DATA( DECEKEM, 3 /* edit key execution */),
842 DATA( DECPFF, 3 /* print form feed */),
843 DATA( DECPEX, 3 /* printer extent */),
844 DATA( DECTCEM, 3 /* text cursor enable */),
845 DATA( XT_SCRLBAR, 3 /* rxvt scrollbar */),
846 DATA( DECRLM, 5 /* left-to-right */),
847 DATA( XT_FONTSWT, 3 /* rxvt font-switching vs DECTEK */),
848 DATA( XT_TEK4014, 3 /* Tektronix 4014 */),
849 DATA( DECHEM, 5 /* Hebrew encoding */),
850 DATA( XT_80_132, 3 /* 80/132 mode */),
851 DATA( XT_CURSES, 3 /* curses hack */),
852 DATA( DECNRCM, 3 /* national replacement character set */),
853 DATA( DECGEPM, 3 /* graphics expanded print */),
854 DATA( XT_MARBELL, 3 /* margin bell vs DECGPCM */),
855 DATA( XT_REVWRAP, 3 /* reverse-wrap vs DECGPCS */),
856 DATA( XT_LOGGING, 3 /* logging vs DECGPBM */),
857 DATA( XT_ALTSCRN, 3 /* alternate screen vs DECGRPM */),
858 DATA( DEC131TM, 3 /* VT131 transmit */),
859 DATA( DECNAKB, 5 /* Greek/N-A Keyboard Mapping */),
860 DATA( DECHCCM, 3 /* horizontal cursor coupling (disabled) */),
861 DATA( DECVCCM, 3 /* vertical cursor coupling */),
862 DATA( DECPCCM, 3 /* page cursor coupling */),
863 DATA( DECNKM, 3 /* numeric keypad */),
864 DATA( DECBKM, 3 /* backarrow key */),
865 DATA( DECKBUM, 3 /* keyboard usage */),
866 DATA( DECLRMM, 4 /* left/right margin mode (VT420) */),
867 DATA( DECXRLM, 3 /* transmit rate linking */),
868 DATA( DECKPM, 4 /* keyboard positioning */),
869 DATA( DECNCSM, 5 /* no clearing screen on column change */),
870 DATA( DECRLCM, 5 /* right-to-left copy */),
871 DATA( DECCRTSM, 5 /* CRT save */),
872 DATA( DECARSM, 5 /* auto resize */),
873 DATA( DECMCM, 5 /* modem control */),
874 DATA( DECAAM, 5 /* auto answerback */),
875 DATA( DECCANSM, 5 /* conceal answerback */),
876 DATA( DECNULM, 5 /* null */),
877 DATA( DECHDPXM, 5 /* half duplex */),
878 DATA( DECESKM, 5 /* enable secondary keyboard language */),
879 DATA( DECOSCNM, 5 /* overscan */),
880 DATA( DECFWM, 5 /* framed windows */),
881 DATA( DECRPL, 5 /* review previous lines */),
882 DATA( DECHWUM, 5 /* host wake-up mode (CRT and energy saver) */),
883 DATA( DECATCUM, 5 /* alternate text color underline */),
884 DATA( DECATCBM, 5 /* alternate text color blink */),
885 DATA( DECBBSM, 5 /* bold and blink style */),
886 DATA( DECECM, 5 /* erase color */),
887 DATA( XT_MSE_X11, 3 /* VT200 mouse */),
888 DATA( XT_MSE_HL, 3 /* VT200 highlight mouse */),
889 DATA( XT_MSE_BTN, 3 /* button-event mouse */),
890 DATA( XT_MSE_ANY, 3 /* any-event mouse */),
891 DATA( XT_MSE_WIN, 3 /* focus-event mouse */),
892 DATA( XT_MSE_UTF, 3 /* UTF-8 extended mouse-coordinates */),
893 DATA( XT_MSE_SGR, 3 /* SGR-style extended mouse-coordinates */),
894 DATA( XT_ALTSCRL, 3 /* alternate-scroll */),
895 DATA( XT_TTY_OUT, 3 /* rxvt scroll tty output */),
896 DATA( XT_SCRLKEY, 3 /* rxvt scroll key */),
897 DATA( XT_FASTSCR, 3 /* fast-scroll mode */),
898 DATA( XT_SGR_PXL, 3 /* SGR mouse pixel mode */),
899 DATA( XT_IN_8BIT, 3 /* input eight bits */),
900 DATA( XT_NUMLOCK, 3 /* real num lock */),
901 DATA( XT_METAESC, 3 /* meta sends escape */),
902 DATA( XT_DELTDEL, 3 /* delete is del */),
903 DATA( XT_ALT_ESC, 3 /* alt sends escape */),
904 DATA( XT_KEEPSEL, 3 /* keep selection */),
905 DATA( XT_SELTCLP, 3 /* select to clipboard */),
906 DATA( XT_BELLURG, 3 /* bell is urgent */),
907 DATA( XT_POPBELL, 3 /* pop on bell */),
908 DATA( XT_ALTS_OK, 3 /* enable alt-screen switching */),
909 DATA( XT_ALTS_47, 3 /* first extended alt-screen */),
910 DATA( XT_ALTS_SC, 3 /* save cursor for first extended alt-screen */),
911 DATA( XT_EXTSCRN, 3 /* second extended alt-screen */),
912 DATA( RL_BTN1, 3 /* click1 emit Esc seq to move point*/),
913 DATA( RL_BTN2, 3 /* press2 emit Esc seq to move point*/),
914 DATA( RL_DBTN3, 3 /* Double click-3 deletes */),
915 DATA( RL_BRACKET, 3 /* Surround paste by escapes */),
916 DATA( RL_QUOTE, 3 /* Quote each char during paste */),
917 DATA( RL_LIT_NL, 3 /* Paste "\n" as C-j */),
918 };
919 /* *INDENT-ON* */
920
921 int old_DECRPM = set_DECRPM(3);
922 int code = any_RQM(PASS_ARGS, dec_modes, TABLESIZE(dec_modes), 1);
923
924 set_DECRPM(old_DECRPM);
925 return code;
926 }
927
928 static int
929 rpt_XTQMODKEYS(MENU_ARGS)
930 {
931 int n;
932 char full_title[80];
933 char command[80];
934 static const char *resource[] =
935 {
936 "modifyKeyboard",
937 "modifyCursorKeys",
938 "modifyFunctionKeys",
939 "modifyOtherKeys",
940 };
941 for (n = 0; n < 4; ++n) {
942 int code = (n == 3) ? 4 : n;
943 sprintf(full_title, "%s (%s)", the_title, resource[n]);
944 sprintf(command, ">%dm", code);
945 vt_move(1, 1);
946 vt_clear(0);
947 any_decrqss(full_title, command);
948 holdit();
949 }
950 return MENU_NOHOLD;
951 }
952
953 static int
954 rpt_XTSMTITLE(MENU_ARGS)
955 {
956 int n;
957 static const char *message[] =
958 {
959 "Set window/icon labels using hexadecimal",
960 "Query window/icon labels using hexadecimal",
961 "Set window/icon labels using UTF-8",
962 "Query window/icon labels using UTF-8"
963 };
964
965 for (n = 0; n < 4; ++n) {
966 char full_title[80];
967 char command[80];
968
969 sprintf(full_title, "%s (%s)", the_title, message[n]);
970 vt_move(1, 1);
971 vt_clear(0);
972 sprintf(command, ">%dt", n);
973 /* set the value */
974 do_csi(">%dt", n);
975 any_decrqss(full_title, command);
976 zleep(500);
977 /* reset the value */
978 do_csi(">%dT", n);
979 any_decrqss(full_title, command);
980 holdit();
981 }
982 return MENU_NOHOLD;
983 }
984
985 static int
986 tst_xterm_DECRQSS(MENU_ARGS)
987 {
988 /* *INDENT-OFF* */
989 static MENU my_menu[] = {
990 { "Exit", NULL },
991 { "Test VT520 features (DECRQSS)", tst_vt520_DECRQSS },
992 { "Query Key Modifier Options", rpt_XTQMODKEYS },
993 { "Query Title Modes", rpt_XTSMTITLE },
994 { "", NULL }
995 };
996 /* *INDENT-ON* */
997
998 do {
999 vt_clear(2);
1000 __(title(0), printxx("XTerm Status-Strings Reports"));
1001 __(title(2), println("Choose test type:"));
1002 } while (menu(my_menu));
1003 return MENU_NOHOLD;
1004 }
1005
1006 /*
1007 * Show mouse-modes, offered as an option in the mouse test-screens (since that
1008 * is really where these can be tested).
1009 */
1010 void
1011 show_mousemodes(void)
1012 {
1013 /* *INDENT-OFF* */
1014 RQM_DATA mouse_modes[] = { /* this list is sorted by code, not name */
1015 DATA( XT_MSE_X10, 3 /* X10 mouse */),
1016 DATA( XT_MSE_X11, 3 /* VT200 mouse */),
1017 DATA( XT_MSE_HL, 3 /* VT200 highlight mouse */),
1018 DATA( XT_MSE_BTN, 3 /* button-event mouse */),
1019 DATA( XT_MSE_ANY, 3 /* any-event mouse */),
1020 DATA( XT_MSE_WIN, 3 /* focus-event mouse */),
1021 DATA( XT_MSE_UTF, 3 /* UTF-8 extended mouse-coordinates */),
1022 DATA( XT_MSE_SGR, 3 /* SGR-style extended mouse-coordinates */),
1023 };
1024 /* *INDENT-ON* */
1025
1026 int old_DECRPM = set_DECRPM(3);
1027 vt_clear(2);
1028 (void) any_RQM("mouse modes", mouse_modes, TABLESIZE(mouse_modes), 1);
1029 set_DECRPM(old_DECRPM);
1030 holdit();
1031 }
1032
1033 #undef DATA
1034 static int
1035 tst_xterm_reports(MENU_ARGS)
1036 {
1037 /* *INDENT-OFF* */
1038 static MENU my_menu[] = {
1039 { "Exit", NULL },
1040 { "Test VT520 features", tst_vt520_reports },
1041 { "Report version (XTVERSION)", tst_xterm_VERSION },
1042 { "Request Mode (DECRQM)/Report Mode (DECRPM)", tst_xterm_DECRPM },
1043 { "Status-String Report (DECRQSS)", tst_xterm_DECRQSS },
1044 { "Title-Stack Position", tst_XTTITLEPOS },
1045 { "", NULL }
1046 };
1047 /* *INDENT-ON* */
1048
1049 do {
1050 vt_clear(2);
1051 __(title(0), println("XTERM miscellaneous reports"));
1052 __(title(2), println("Choose test type:"));
1053 } while (menu(my_menu));
1054 return MENU_NOHOLD;
1055 }
1056
1057 /*
1058 * xterm (and derived programs such as hpterm, dtterm, rxvt) are the most
1059 * widely used vt100 near-compatible terminal emulators (other than modem
1060 * programs). dtterm emulates a vt220, as does XFree86 xterm. DECterm
1061 * emulates a vt320.
1062 */
1063 int
1064 tst_xterm(MENU_ARGS)
1065 {
1066 /* *INDENT-OFF* */
1067 static MENU my_menu[] = {
1068 { "Exit", NULL },
1069 { "Test VT520 features", tst_vt520 },
1070 { "Test reporting functions", tst_xterm_reports },
1071 { "Set window title", test_window_name },
1072 { "Font features", tst_font },
1073 { "Mouse features", tst_mouse },
1074 { "Tektronix 4014 features", tst_tek4014 },
1075 { "Alternate-Screen features (xterm)", tst_altscrn },
1076 { "Window modify-operations (dtterm)", test_modify_ops },
1077 { "Window report-operations (dtterm)", test_report_ops },
1078 { "", NULL }
1079 };
1080 /* *INDENT-ON* */
1081
1082 do {
1083 vt_clear(2);
1084 __(title(0), println("XTERM special features"));
1085 __(title(2), println("Choose test type:"));
1086 } while (menu(my_menu));
1087 return MENU_NOHOLD;
1088 }