Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/terminal/terminal.c

    r77ffa01 rb48e680f  
    4141#include <fbfont/font-8x16.h>
    4242#include <io/chargrid.h>
     43#include <fibril.h>
    4344#include <gfx/bitmap.h>
    4445#include <gfx/context.h>
     
    8788static void term_set_rgb_color(con_srv_t *, pixel_t, pixel_t);
    8889static void term_set_cursor_visibility(con_srv_t *, bool);
     90static errno_t term_set_caption(con_srv_t *, const char *);
    8991static errno_t term_get_event(con_srv_t *, cons_event_t *);
    9092static errno_t term_map(con_srv_t *, sysarg_t, sysarg_t, charfield_t **);
     
    108110        .set_rgb_color = term_set_rgb_color,
    109111        .set_cursor_visibility = term_set_cursor_visibility,
     112        .set_caption = term_set_caption,
    110113        .get_event = term_get_event,
    111114        .map = term_map,
     
    128131};
    129132
     133static errno_t terminal_wait_fibril(void *);
     134
    130135static terminal_t *srv_to_terminal(con_srv_t *srv)
    131136{
     
    133138}
    134139
    135 static void getterm(const char *svc, const char *app)
    136 {
    137         task_spawnl(NULL, NULL, APP_GETTERM, APP_GETTERM, svc,
     140static errno_t getterm(task_wait_t *wait, const char *svc, const char *app)
     141{
     142        return task_spawnl(NULL, wait, APP_GETTERM, APP_GETTERM, svc,
    138143            LOCFS_MOUNT_POINT, "--msg", "--wait", "--", app, NULL);
    139144}
     
    141146static pixel_t color_table[16] = {
    142147        [COLOR_BLACK]       = PIXEL(255, 0, 0, 0),
    143         [COLOR_BLUE]        = PIXEL(255, 0, 0, 240),
    144         [COLOR_GREEN]       = PIXEL(255, 0, 240, 0),
    145         [COLOR_CYAN]        = PIXEL(255, 0, 240, 240),
    146         [COLOR_RED]         = PIXEL(255, 240, 0, 0),
    147         [COLOR_MAGENTA]     = PIXEL(255, 240, 0, 240),
    148         [COLOR_YELLOW]      = PIXEL(255, 240, 240, 0),
    149         [COLOR_WHITE]       = PIXEL(255, 240, 240, 240),
    150 
    151         [COLOR_BLACK + 8]   = PIXEL(255, 0, 0, 0),
    152         [COLOR_BLUE + 8]    = PIXEL(255, 0, 0, 255),
    153         [COLOR_GREEN + 8]   = PIXEL(255, 0, 255, 0),
    154         [COLOR_CYAN + 8]    = PIXEL(255, 0, 255, 255),
    155         [COLOR_RED + 8]     = PIXEL(255, 255, 0, 0),
    156         [COLOR_MAGENTA + 8] = PIXEL(255, 255, 0, 255),
    157         [COLOR_YELLOW + 8]  = PIXEL(255, 255, 255, 0),
     148        [COLOR_BLUE]        = PIXEL(255, 0, 0, 170),
     149        [COLOR_GREEN]       = PIXEL(255, 0, 170, 0),
     150        [COLOR_CYAN]        = PIXEL(255, 0, 170, 170),
     151        [COLOR_RED]         = PIXEL(255, 170, 0, 0),
     152        [COLOR_MAGENTA]     = PIXEL(255, 170, 0, 170),
     153        [COLOR_YELLOW]      = PIXEL(255, 170, 85, 0),
     154        [COLOR_WHITE]       = PIXEL(255, 170, 170, 170),
     155
     156        [COLOR_BLACK + 8]   = PIXEL(255, 85, 85, 85),
     157        [COLOR_BLUE + 8]    = PIXEL(255, 85, 85, 255),
     158        [COLOR_GREEN + 8]   = PIXEL(255, 85, 255, 85),
     159        [COLOR_CYAN + 8]    = PIXEL(255, 85, 255, 255),
     160        [COLOR_RED + 8]     = PIXEL(255, 255, 85, 85),
     161        [COLOR_MAGENTA + 8] = PIXEL(255, 255, 85, 255),
     162        [COLOR_YELLOW + 8]  = PIXEL(255, 255, 255, 85),
    158163        [COLOR_WHITE + 8]   = PIXEL(255, 255, 255, 255),
    159164};
     
    165170                switch (attrs.val.style) {
    166171                case STYLE_NORMAL:
    167                         *bgcolor = color_table[COLOR_WHITE];
     172                        *bgcolor = color_table[COLOR_WHITE + 8];
    168173                        *fgcolor = color_table[COLOR_BLACK];
    169174                        break;
    170175                case STYLE_EMPHASIS:
    171                         *bgcolor = color_table[COLOR_WHITE];
    172                         *fgcolor = color_table[COLOR_RED];
     176                        *bgcolor = color_table[COLOR_WHITE + 8];
     177                        *fgcolor = color_table[COLOR_RED + 8];
    173178                        break;
    174179                case STYLE_INVERTED:
    175180                        *bgcolor = color_table[COLOR_BLACK];
    176                         *fgcolor = color_table[COLOR_WHITE];
     181                        *fgcolor = color_table[COLOR_WHITE + 8];
    177182                        break;
    178183                case STYLE_SELECTED:
    179                         *bgcolor = color_table[COLOR_RED];
    180                         *fgcolor = color_table[COLOR_WHITE];
     184                        *bgcolor = color_table[COLOR_RED + 8];
     185                        *fgcolor = color_table[COLOR_WHITE + 8];
    181186                        break;
    182187                }
    183188                break;
    184189        case CHAR_ATTR_INDEX:
    185                 *bgcolor = color_table[(attrs.val.index.bgcolor & 7) |
    186                     ((attrs.val.index.attr & CATTR_BRIGHT) ? 8 : 0)];
     190                *bgcolor = color_table[(attrs.val.index.bgcolor & 7)];
    187191                *fgcolor = color_table[(attrs.val.index.fgcolor & 7) |
    188192                    ((attrs.val.index.attr & CATTR_BRIGHT) ? 8 : 0)];
     
    643647}
    644648
     649static errno_t term_set_caption(con_srv_t *srv, const char *caption)
     650{
     651        terminal_t *term = srv_to_terminal(srv);
     652        const char *cap;
     653
     654        fibril_mutex_lock(&term->mtx);
     655
     656        if (str_size(caption) > 0)
     657                cap = caption;
     658        else
     659                cap = "Terminal";
     660
     661        ui_window_set_caption(term->window, cap);
     662        fibril_mutex_unlock(&term->mtx);
     663
     664        term_update(term);
     665        gfx_update(term->gc);
     666        return EOK;
     667}
     668
    645669static errno_t term_get_event(con_srv_t *srv, cons_event_t *event)
    646670{
     
    805829        terminal_t *term = (terminal_t *) arg;
    806830
    807         (void) term;
    808 
    809         // XXX This is not really a clean way of terminating
    810         exit(0);
     831        ui_quit(term->ui);
    811832}
    812833
     
    843864        sysarg_t sy = -term->off.y;
    844865
    845         if (event->type == POS_PRESS || event->type == POS_RELEASE) {
     866        if (event->type == POS_PRESS || event->type == POS_RELEASE ||
     867            event->type == POS_DCLICK) {
    846868                cevent.type = CEV_POS;
    847869                cevent.ev.pos.type = event->type;
     
    888910
    889911errno_t terminal_create(const char *display_spec, sysarg_t width,
    890     sysarg_t height, terminal_flags_t flags, terminal_t **rterm)
     912    sysarg_t height, terminal_flags_t flags, const char *command,
     913    terminal_t **rterm)
    891914{
    892915        terminal_t *term;
     
    10131036
    10141037        list_append(&term->link, &terms);
    1015         getterm(vc, "/app/bdsh");
     1038        rc = getterm(&term->wait, vc, command);
     1039        if (rc != EOK)
     1040                goto error;
     1041
     1042        term->wfid = fibril_create(terminal_wait_fibril, term);
     1043        if (term->wfid == 0)
     1044                goto error;
     1045
     1046        fibril_add_ready(term->wfid);
    10161047
    10171048        term->is_focused = true;
     
    10391070}
    10401071
     1072static errno_t terminal_wait_fibril(void *arg)
     1073{
     1074        terminal_t *term = (terminal_t *)arg;
     1075        task_exit_t texit;
     1076        int retval;
     1077
     1078        /*
     1079         * XXX There is no way to break the sleep if the task does not
     1080         * exit.
     1081         */
     1082        (void) task_wait(&term->wait, &texit, &retval);
     1083        ui_quit(term->ui);
     1084        return EOK;
     1085}
     1086
    10411087/** @}
    10421088 */
Note: See TracChangeset for help on using the changeset viewer.