Changeset fb69f39 in mainline


Ignore:
Timestamp:
2009-01-01T19:47:54Z (15 years ago)
Author:
Jiri Svoboda <jirik.svoboda@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
8b4d6cb
Parents:
7122bc7
Message:

Color support in serial fb driver.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/srv/fb/serial_console.c

    r7122bc7 rfb69f39  
    4444#include <bool.h>
    4545#include <errno.h>
     46#include <console/color.h>
    4647#include <console/style.h>
    4748
     
    4950
    5051#define MAX_CONTROL 20
     52
     53static void serial_sgr(const unsigned int mode);
    5154
    5255static int width;
    5356static int height;
     57static bool color = true;       /** True if producing color output. */
    5458static putc_function_t putc_function;
    5559
     
    5761static int client_connected = 0;
    5862
     63enum 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
     74enum 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
     86static 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
    5997void serial_puts(char *str)
    6098{
     
    68106                return;
    69107       
    70         char control[20];
    71         snprintf(control, 20, "\033[%u;%uf", row + 1, col + 1);
     108        char control[MAX_CONTROL];
     109        snprintf(control, MAX_CONTROL, "\033[%u;%uf", row + 1, col + 1);
    72110        serial_puts(control);
    73111}
     
    75113void serial_clrscr(void)
    76114{
     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
    77122        serial_puts("\033[2J");
    78123}
     
    191236                case FB_SET_STYLE:
    192237                        style =  IPC_GET_ARG1(call);
    193                         if (style == STYLE_EMPHASIS)
    194                                 serial_sgr(1);
    195                         else
    196                                 serial_sgr(0);
     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                        }
    197253                        retval = 0;
    198254                        break;
     
    200256                        fgcolor = IPC_GET_ARG1(call);
    201257                        bgcolor = IPC_GET_ARG2(call);
    202                         if (fgcolor < bgcolor)
    203                                 serial_sgr(0);
    204                         else
    205                                 serial_sgr(7);
     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                        }
    206269                        retval = 0;
    207270                        break;
     
    210273                        bgcolor = IPC_GET_ARG2(call);
    211274                        if (fgcolor < bgcolor)
    212                                 serial_sgr(0);
     275                                serial_sgr(SGR_REVERSE_OFF);
    213276                        else
    214                                 serial_sgr(7);
     277                                serial_sgr(SGR_REVERSE);
    215278                        retval = 0;
    216279                        break;
Note: See TracChangeset for help on using the changeset viewer.