Rev 3767 | Rev 4142 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3767 | Rev 3769 | ||
---|---|---|---|
Line 41... | Line 41... | ||
41 | #include <ipc/ipc.h> |
41 | #include <ipc/ipc.h> |
42 | #include <async.h> |
42 | #include <async.h> |
43 | #include <ipc/fb.h> |
43 | #include <ipc/fb.h> |
44 | #include <bool.h> |
44 | #include <bool.h> |
45 | #include <errno.h> |
45 | #include <errno.h> |
- | 46 | #include <console/color.h> |
|
46 | #include <console/style.h> |
47 | #include <console/style.h> |
47 | 48 | ||
48 | #include "serial_console.h" |
49 | #include "serial_console.h" |
49 | 50 | ||
50 | #define MAX_CONTROL 20 |
51 | #define MAX_CONTROL 20 |
51 | 52 | ||
- | 53 | static void serial_sgr(const unsigned int mode); |
|
- | 54 | ||
52 | static int width; |
55 | static int width; |
53 | static int height; |
56 | static int height; |
- | 57 | static bool color = true; /** True if producing color output. */ |
|
54 | static putc_function_t putc_function; |
58 | static putc_function_t putc_function; |
55 | 59 | ||
56 | /* Allow only 1 connection */ |
60 | /* Allow only 1 connection */ |
57 | static int client_connected = 0; |
61 | static int client_connected = 0; |
58 | 62 | ||
- | 63 | enum sgr_color_index { |
|
- | 64 | CI_BLACK = 0, |
|
- | 65 | CI_RED = 1, |
|
- | 66 | CI_GREEN = 2, |
|
- | 67 | CI_BROWN = 3, |
|
- | 68 | CI_BLUE = 4, |
|
- | 69 | CI_MAGENTA = 5, |
|
- | 70 | CI_CYAN = 6, |
|
- | 71 | CI_WHITE = 7, |
|
- | 72 | }; |
|
- | 73 | ||
- | 74 | enum sgr_command { |
|
- | 75 | SGR_RESET = 0, |
|
- | 76 | SGR_BOLD = 1, |
|
- | 77 | SGR_BLINK = 5, |
|
- | 78 | SGR_REVERSE = 7, |
|
- | 79 | SGR_NORMAL_INT = 22, |
|
- | 80 | SGR_BLINK_OFF = 25, |
|
- | 81 | SGR_REVERSE_OFF = 27, |
|
- | 82 | SGR_FGCOLOR = 30, |
|
- | 83 | SGR_BGCOLOR = 40 |
|
- | 84 | }; |
|
- | 85 | ||
- | 86 | static int color_map[] = { |
|
- | 87 | [COLOR_BLACK] = CI_BLACK, |
|
- | 88 | [COLOR_BLUE] = CI_RED, |
|
- | 89 | [COLOR_GREEN] = CI_GREEN, |
|
- | 90 | [COLOR_CYAN] = CI_CYAN, |
|
- | 91 | [COLOR_RED] = CI_RED, |
|
- | 92 | [COLOR_MAGENTA] = CI_MAGENTA, |
|
- | 93 | [COLOR_YELLOW] = CI_BROWN, |
|
- | 94 | [COLOR_WHITE] = CI_WHITE |
|
- | 95 | }; |
|
- | 96 | ||
59 | void serial_puts(char *str) |
97 | void serial_puts(char *str) |
60 | { |
98 | { |
61 | while (*str) |
99 | while (*str) |
62 | putc_function(*(str++)); |
100 | putc_function(*(str++)); |
63 | } |
101 | } |
Line 65... | Line 103... | ||
65 | void serial_goto(const unsigned int row, const unsigned int col) |
103 | void serial_goto(const unsigned int row, const unsigned int col) |
66 | { |
104 | { |
67 | if ((row > height) || (col > width)) |
105 | if ((row > height) || (col > width)) |
68 | return; |
106 | return; |
69 | 107 | ||
70 | char control[20]; |
108 | char control[MAX_CONTROL]; |
71 | snprintf(control, 20, "\033[%u;%uf", row + 1, col + 1); |
109 | snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1); |
72 | serial_puts(control); |
110 | serial_puts(control); |
73 | } |
111 | } |
74 | 112 | ||
75 | void serial_clrscr(void) |
113 | void serial_clrscr(void) |
76 | { |
114 | { |
- | 115 | /* Initialize graphic rendition attributes. */ |
|
- | 116 | serial_sgr(SGR_RESET); |
|
- | 117 | if (color) { |
|
- | 118 | serial_sgr(SGR_FGCOLOR + CI_BLACK); |
|
- | 119 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
|
- | 120 | } |
|
- | 121 | ||
77 | serial_puts("\033[2J"); |
122 | serial_puts("\033[2J"); |
78 | } |
123 | } |
79 | 124 | ||
80 | void serial_scroll(int i) |
125 | void serial_scroll(int i) |
81 | { |
126 | { |
Line 188... | Line 233... | ||
188 | serial_clrscr(); |
233 | serial_clrscr(); |
189 | retval = 0; |
234 | retval = 0; |
190 | break; |
235 | break; |
191 | case FB_SET_STYLE: |
236 | case FB_SET_STYLE: |
192 | style = IPC_GET_ARG1(call); |
237 | style = IPC_GET_ARG1(call); |
193 | if (style == STYLE_EMPHASIS) |
238 | if (style == STYLE_EMPHASIS) { |
- | 239 | if (color) { |
|
- | 240 | serial_sgr(SGR_RESET); |
|
- | 241 | serial_sgr(SGR_FGCOLOR + CI_RED); |
|
- | 242 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
|
- | 243 | } |
|
194 | serial_sgr(1); |
244 | serial_sgr(SGR_BOLD); |
195 | else |
245 | } else { |
- | 246 | if (color) { |
|
196 | serial_sgr(0); |
247 | serial_sgr(SGR_RESET); |
- | 248 | serial_sgr(SGR_FGCOLOR + CI_BLACK); |
|
- | 249 | serial_sgr(SGR_BGCOLOR + CI_WHITE); |
|
- | 250 | } |
|
- | 251 | serial_sgr(SGR_NORMAL_INT); |
|
- | 252 | } |
|
197 | retval = 0; |
253 | retval = 0; |
198 | break; |
254 | break; |
199 | case FB_SET_COLOR: |
255 | case FB_SET_COLOR: |
200 | fgcolor = IPC_GET_ARG1(call); |
256 | fgcolor = IPC_GET_ARG1(call); |
201 | bgcolor = IPC_GET_ARG2(call); |
257 | bgcolor = IPC_GET_ARG2(call); |
- | 258 | ||
- | 259 | if (color) { |
|
- | 260 | serial_sgr(SGR_RESET); |
|
- | 261 | serial_sgr(SGR_FGCOLOR + color_map[fgcolor]); |
|
- | 262 | serial_sgr(SGR_BGCOLOR + color_map[bgcolor]); |
|
- | 263 | } else { |
|
202 | if (fgcolor < bgcolor) |
264 | if (fgcolor < bgcolor) |
203 | serial_sgr(0); |
265 | serial_sgr(SGR_RESET); |
204 | else |
266 | else |
205 | serial_sgr(7); |
267 | serial_sgr(SGR_REVERSE); |
- | 268 | } |
|
206 | retval = 0; |
269 | retval = 0; |
207 | break; |
270 | break; |
208 | case FB_SET_RGB_COLOR: |
271 | case FB_SET_RGB_COLOR: |
209 | fgcolor = IPC_GET_ARG1(call); |
272 | fgcolor = IPC_GET_ARG1(call); |
210 | bgcolor = IPC_GET_ARG2(call); |
273 | bgcolor = IPC_GET_ARG2(call); |
211 | if (fgcolor < bgcolor) |
274 | if (fgcolor < bgcolor) |
212 | serial_sgr(0); |
275 | serial_sgr(SGR_REVERSE_OFF); |
213 | else |
276 | else |
214 | serial_sgr(7); |
277 | serial_sgr(SGR_REVERSE); |
215 | retval = 0; |
278 | retval = 0; |
216 | break; |
279 | break; |
217 | case FB_SCROLL: |
280 | case FB_SCROLL: |
218 | i = IPC_GET_ARG1(call); |
281 | i = IPC_GET_ARG1(call); |
219 | if ((i > height) || (i < -height)) { |
282 | if ((i > height) || (i < -height)) { |