This source file includes following definitions.
- get_control_data
- restore
- async_restore
- async_set_attributes_from_default
- main
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 #include <config.h>
19
20
21 #include "term-style-control.h"
22
23 #include <stdbool.h>
24 #include <stdio.h>
25 #include <string.h>
26 #include <unistd.h>
27
28 #include "full-write.h"
29
30
31
32
33
34
35
36
37
38
39
40 static const char set_underline_on[] = "\033[4m";
41 static const char set_underline_off[] = "\033[24m";
42 static const char set_foreground_color_red[] = "\033[31m";
43 static const char set_foreground_color_default[] = "\033[39m";
44
45 struct term_style_user_data
46 {
47
48
49 bool volatile red_and_underline;
50
51 struct term_style_control_data ctrl_data;
52 };
53
54 static struct term_style_control_data *
55 get_control_data (struct term_style_user_data *user_data)
56 {
57 return &user_data->ctrl_data;
58 }
59
60 static void
61 restore (struct term_style_user_data *user_data)
62 {
63 fputs (set_underline_off, stdout);
64 fputs (set_foreground_color_default, stdout);
65 fflush (stdout);
66 }
67
68 static _GL_ASYNC_SAFE void
69 async_restore (struct term_style_user_data *user_data)
70 {
71
72 full_write (STDOUT_FILENO, set_underline_off,
73 strlen (set_underline_off));
74 full_write (STDOUT_FILENO, set_foreground_color_default,
75 strlen (set_foreground_color_default));
76 }
77
78 static _GL_ASYNC_SAFE void
79 async_set_attributes_from_default (struct term_style_user_data *user_data)
80 {
81
82 if (user_data->red_and_underline)
83 {
84 full_write (STDOUT_FILENO, set_underline_on,
85 strlen (set_underline_on));
86 full_write (STDOUT_FILENO, set_foreground_color_red,
87 strlen (set_foreground_color_red));
88 }
89 }
90
91 static const struct term_style_controller controller =
92 {
93 get_control_data,
94 restore,
95 async_restore,
96 async_set_attributes_from_default
97 };
98
99 int
100 main (int argc, char *argv[])
101 {
102 struct term_style_user_data user_data;
103
104
105 user_data.red_and_underline = false;
106
107 activate_term_style_controller (&controller, &user_data, STDOUT_FILENO,
108 TTYCTL_AUTO);
109
110 for (;;)
111 {
112
113 activate_term_non_default_mode (&controller, &user_data);
114
115
116
117
118 user_data.red_and_underline = true;
119 fputs (set_underline_on, stdout);
120 fputs (set_foreground_color_red, stdout);
121 fflush (stdout);
122
123 fputs ("y", stdout);
124 fflush (stdout);
125
126
127 user_data.red_and_underline = false;
128 fputs (set_underline_off, stdout);
129 fputs (set_foreground_color_default, stdout);
130 fflush (stdout);
131
132
133 deactivate_term_non_default_mode (&controller, &user_data);
134
135 fputs ("\n", stdout);
136 fflush (stdout);
137 }
138 }