Debian Codegraph @

status.c

raw
1 /* $Id: status.c,v 1.12 2024/12/05 00:40:24 tom Exp $ */
2
3 #include <vttest.h>
4 #include <esc.h>
5 #include <ttymodes.h>
6
7 static void
8 restore_status(void)
9 {
10 decsasd(0); /* main display */
11 decssdt(1); /* indicator (default) */
12 restore_ttymodes();
13 }
14
15 static int
16 simple_statusline(MENU_ARGS)
17 {
18 static char text[] = "TEXT IN THE STATUS LINE";
19
20 vt_move(1, 1);
21 println("This is a simple test of the status-line");
22 println("");
23
24 decssdt(2);
25 decsasd(1);
26 tprintf("%s", text);
27 decsasd(0);
28 printxx("There should be %s\r\n", text);
29 holdit();
30
31 decssdt(0);
32 println("There should be no status line");
33 holdit();
34
35 decssdt(1);
36 println("The status line should be normal (i.e., indicator)");
37 holdit();
38
39 restore_status();
40 return MENU_NOHOLD;
41 }
42
43 static int
44 SGR_statusline(MENU_ARGS)
45 {
46 vt_move(1, 1);
47 println("This test writes SGR controls to the status-line");
48 holdit();
49
50 decssdt(2);
51 decsasd(1);
52
53 el(2);
54 cup(1, 1);
55 sgr("1");
56 tprintf("BOLD ");
57 sgr("0;4");
58 tprintf("Underlined ");
59 sgr("0;7");
60 tprintf("Reverse ");
61 sgr("0;5");
62 tprintf("Blink ");
63 sgr("0");
64 tprintf("NORMAL text ");
65
66 decsasd(0);
67 holdit();
68
69 restore_status();
70 holdit();
71
72 restore_status();
73 return MENU_NOHOLD;
74 }
75
76 static int
77 CUP_statusline(MENU_ARGS)
78 {
79 static struct {
80 const char *codes;
81 const char *value;
82 } table[] = {
83 {
84 "0;1", "First "
85 },
86 {
87 "0;4", "Second "
88 },
89 {
90 "0;7", "Third "
91 },
92 {
93 "0;5", "Fourth "
94 },
95 {
96 "0", "Last word"
97 },
98 };
99 size_t last;
100
101 vt_move(1, 1);
102 println("This test demonstrates cursor-movement in the status-line");
103 holdit();
104
105 decssdt(2);
106 decsasd(1);
107
108 /*
109 * Write the words in reverse-order, using cursor-addressing.
110 * We could also do something with backspacing, insert/delete, but this
111 * suffices to illustrate.
112 */
113 el(2);
114 for (last = TABLESIZE(table); last != 0; --last) {
115 size_t j;
116 int cols = 0;
117 for (j = 0; j + 1 < last; ++j) {
118 cols += (int) strlen(table[j].value);
119 }
120 hpa(1 + cols);
121 sgr(table[last - 1].codes);
122 tprintf("%s", table[last - 1].value);
123 }
124
125 decsasd(0);
126 holdit();
127
128 restore_status();
129 holdit();
130
131 restore_status();
132 return MENU_NOHOLD;
133 }
134
135 /* VT200 & up
136 *
137 * CSI Ps $ } DECSASD Select active status display
138 * Ps = 0 select main display
139 * Ps = 1 select status line
140 * Moves cursor to selected display area. This command will be ignored
141 * unless the status line has been enabled by CSI 2 $ ~. When the
142 * status line has been selected cursor remains there until the main
143 * display is reselected by CSI 0 $ }.
144 *
145 * CSI Ps $ ~ DECSSDT Select Status Line Type
146 * Ps meaning
147 * 0 no status line (empty)
148 * 1 indicator line
149 * 2 host-writable line
150 */
151 int
152 tst_statusline(MENU_ARGS)
153 {
154 /* *INDENT-OFF* */
155 static MENU my_menu[] = {
156 { "Exit", NULL },
157 { "Simple Status line Test", simple_statusline },
158 { "Test Graphic-Rendition in Status line", SGR_statusline },
159 { "Test Cursor-movement in Status line", CUP_statusline },
160 { "", NULL }
161 };
162 /* *INDENT-ON* */
163
164 do {
165 vt_clear(2);
166 __(title(0), println(the_title));
167 __(title(2), println("Choose test type:"));
168 } while (menu(my_menu));
169 decssdt(0);
170 return MENU_NOHOLD;
171 }