Subversion Repositories HelenOS

Rev

Rev 4337 | Rev 4346 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 4337 Rev 4338
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>
-
 
47
#include <console/style.h>
46
 
48
 
47
#include "serial_console.h"
49
#include "serial_console.h"
48
 
50
 
49
#define MAX_CONTROL 20
51
#define MAX_CONTROL 20
50
 
52
 
-
 
53
static void serial_sgr(const unsigned int mode);
-
 
54
 
51
static int width;
55
static int width;
52
static int height;
56
static int height;
-
 
57
static bool color = true;   /** True if producing color output. */
53
static putc_function_t putc_function;
58
static putc_function_t putc_function;
54
 
59
 
55
/* Allow only 1 connection */
60
/* Allow only 1 connection */
56
static int client_connected = 0;
61
static int client_connected = 0;
57
 
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
 
58
void serial_puts(char *str)
97
void serial_puts(char *str)
59
{
98
{
60
    while (*str)
99
    while (*str)
61
        putc_function(*(str++));
100
        putc_function(*(str++));
62
}
101
}
Line 64... Line 103...
64
void serial_goto(const unsigned int row, const unsigned int col)
103
void serial_goto(const unsigned int row, const unsigned int col)
65
{
104
{
66
    if ((row > height) || (col > width))
105
    if ((row > height) || (col > width))
67
        return;
106
        return;
68
   
107
   
69
    char control[20];
108
    char control[MAX_CONTROL];
70
    snprintf(control, 20, "\033[%u;%uf", row + 1, col + 1);
109
    snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1);
71
    serial_puts(control);
110
    serial_puts(control);
72
}
111
}
73
 
112
 
74
void serial_clrscr(void)
113
void serial_clrscr(void)
75
{
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
 
76
    serial_puts("\033[2J");
122
    serial_puts("\033[2J");
77
}
123
}
78
 
124
 
79
void serial_scroll(int i)
125
void serial_scroll(int i)
80
{
126
{
Line 87... Line 133...
87
        while (i++)
133
        while (i++)
88
            serial_puts("\033M");
134
            serial_puts("\033M");
89
    }
135
    }
90
}
136
}
91
 
137
 
-
 
138
/** ECMA-48 Set Graphics Rendition. */
92
void serial_set_style(const unsigned int mode)
139
static void serial_sgr(const unsigned int mode)
93
{
140
{
94
    char control[MAX_CONTROL];
141
    char control[MAX_CONTROL];
95
    snprintf(control, MAX_CONTROL, "\033[%um", mode);
142
    snprintf(control, MAX_CONTROL, "\033[%um", mode);
96
    serial_puts(control);
143
    serial_puts(control);
97
}
144
}
Line 134... Line 181...
134
    int lastrow = 0;
181
    int lastrow = 0;
135
    int newcol;
182
    int newcol;
136
    int newrow;
183
    int newrow;
137
    int fgcolor;
184
    int fgcolor;
138
    int bgcolor;
185
    int bgcolor;
-
 
186
    int style;
139
    int i;
187
    int i;
140
   
188
   
141
    if (client_connected) {
189
    if (client_connected) {
142
        ipc_answer_0(iid, ELIMIT);
190
        ipc_answer_0(iid, ELIMIT);
143
        return;
191
        return;
Line 184... Line 232...
184
        case FB_CLEAR:
232
        case FB_CLEAR:
185
            serial_clrscr();
233
            serial_clrscr();
186
            retval = 0;
234
            retval = 0;
187
            break;
235
            break;
188
        case FB_SET_STYLE:
236
        case FB_SET_STYLE:
-
 
237
            style =  IPC_GET_ARG1(call);
-
 
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
                }
-
 
244
                serial_sgr(SGR_BOLD);
-
 
245
            } else {
-
 
246
                if (color) {
-
 
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
            }
-
 
253
            retval = 0;
-
 
254
            break;
-
 
255
        case FB_SET_COLOR:
-
 
256
            fgcolor = IPC_GET_ARG1(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 {
-
 
264
                if (fgcolor < bgcolor)
-
 
265
                    serial_sgr(SGR_RESET);
-
 
266
                else
-
 
267
                    serial_sgr(SGR_REVERSE);
-
 
268
            }
-
 
269
            retval = 0;
-
 
270
            break;
-
 
271
        case FB_SET_RGB_COLOR:
189
            fgcolor = IPC_GET_ARG1(call);
272
            fgcolor = IPC_GET_ARG1(call);
190
            bgcolor = IPC_GET_ARG2(call);
273
            bgcolor = IPC_GET_ARG2(call);
191
            if (fgcolor < bgcolor)
274
            if (fgcolor < bgcolor)
192
                serial_set_style(0);
275
                serial_sgr(SGR_REVERSE_OFF);
193
            else
276
            else
194
                serial_set_style(7);
277
                serial_sgr(SGR_REVERSE);
195
            retval = 0;
278
            retval = 0;
196
            break;
279
            break;
197
        case FB_SCROLL:
280
        case FB_SCROLL:
198
            i = IPC_GET_ARG1(call);
281
            i = IPC_GET_ARG1(call);
199
            if ((i > height) || (i < -height)) {
282
            if ((i > height) || (i < -height)) {