Changeset 9f1362d4 in mainline for uspace/app


Ignore:
Timestamp:
2010-04-19T19:58:18Z (15 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
369a5f8
Parents:
caad59a
Message:

console output improvements

  • define new generic styles (STYLE_INVERTED for inverted print and STYLE_SELECTION for selections), use them primarily instead of specifying colors or RGBs
  • use console_set_style(fphone(stdout), STYLE_NORMAL) as the correct mean for reseting console settings (instead of specifying conrete hardcoded colors)
  • rename console_goto() to console_set_pos() (consistency with console_get_pos())
  • use semantically correct unsigned types for console sizes and cursor positions (instead of signed types)
  • use unsigned types for sizes and positions in libclui
  • top: nicer screen redrawing (do not use console_clear() which causes flickering, but repaint the screen properly — not entirely finished yet)
  • initialize mouse pointer coordinates (so the mouse cursor does not behave erratic after boot, unfortunatelly this does not solve ticket #223)
Location:
uspace/app
Files:
5 edited

Legend:

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

    rcaad59a r9f1362d4  
    4040#include <vfs/vfs.h>
    4141#include <io/console.h>
    42 #include <io/color.h>
     42#include <io/style.h>
    4343#include <io/keycode.h>
    4444#include <errno.h>
     
    100100static bool cursor_visible;
    101101
    102 static int scr_rows, scr_columns;
     102static ipcarg_t scr_rows;
     103static ipcarg_t scr_columns;
    103104
    104105#define ROW_BUF_SIZE 4096
     
    505506        asprintf(&str, "%s: %s", prompt, init_value);
    506507        status_display(str);
    507         console_goto(con, 1 + str_length(str), scr_rows - 1);
     508        console_set_pos(con, 1 + str_length(str), scr_rows - 1);
    508509        free(str);
    509510
    510         console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
     511        console_set_style(con, STYLE_INVERTED);
    511512
    512513        max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt));
     
    552553        str = wstr_to_astr(buffer);
    553554
    554         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     555        console_set_style(con, STYLE_NORMAL);
    555556
    556557        return str;
     
    671672{
    672673        int sh_rows, rows;
    673         int i, j;
    674674
    675675        sheet_get_num_rows(&doc.sh, &sh_rows);
     
    678678        /* Draw rows from the sheet. */
    679679
    680         console_goto(con, 0, 0);
     680        console_set_pos(con, 0, 0);
    681681        pane_row_range_display(0, rows);
    682682
    683683        /* Clear the remaining rows if file is short. */
    684 
     684       
     685        int i;
     686        ipcarg_t j;
    685687        for (i = rows; i < pane.rows; ++i) {
    686                 console_goto(con, 0, i);
     688                console_set_pos(con, 0, i);
    687689                for (j = 0; j < scr_columns; ++j)
    688690                        putchar(' ');
     
    736738        /* Draw rows from the sheet. */
    737739
    738         console_goto(con, 0, 0);
     740        console_set_pos(con, 0, 0);
    739741        for (i = r0; i < r1; ++i) {
    740742                /* Starting point for row display */
     
    756758                    coord_cmp(&rbc, &csel_end) < 0) {
    757759                        fflush(stdout);
    758                         console_set_color(con, COLOR_BLACK, COLOR_RED, 0);
     760                        console_set_style(con, STYLE_SELECTED);
    759761                        fflush(stdout);
    760762                }
    761763
    762                 console_goto(con, 0, i);
     764                console_set_pos(con, 0, i);
    763765                size = str_size(row_buf);
    764766                pos = 0;
     
    767769                        if ((csel_start.row == rbc.row) && (csel_start.column == s_column)) {
    768770                                fflush(stdout);
    769                                 console_set_color(con, COLOR_BLACK, COLOR_RED, 0);
     771                                console_set_style(con, STYLE_SELECTED);
    770772                                fflush(stdout);
    771773                        }
     
    773775                        if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    774776                                fflush(stdout);
    775                                 console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     777                                console_set_style(con, STYLE_NORMAL);
    776778                                fflush(stdout);
    777779                        }
     
    793795                if ((csel_end.row == rbc.row) && (csel_end.column == s_column)) {
    794796                        fflush(stdout);
    795                         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     797                        console_set_style(con, STYLE_NORMAL);
    796798                        fflush(stdout);
    797799                }
     
    807809                        putchar(' ');
    808810                fflush(stdout);
    809                 console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     811                console_set_style(con, STYLE_NORMAL);
    810812        }
    811813
     
    824826        const char *fname = (doc.file_name != NULL) ? doc.file_name : "<unnamed>";
    825827
    826         console_goto(con, 0, scr_rows - 1);
    827         console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
     828        console_set_pos(con, 0, scr_rows - 1);
     829        console_set_style(con, STYLE_INVERTED);
    828830        int n = printf(" %d, %d: File '%s'. Ctrl-Q Quit  Ctrl-S Save  "
    829831            "Ctrl-E Save As", coord.row, coord.column, fname);
    830832        printf("%*s", scr_columns - 1 - n, "");
    831833        fflush(stdout);
    832         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     834        console_set_style(con, STYLE_NORMAL);
    833835
    834836        pane.rflags |= REDRAW_CARET;
     
    844846
    845847        spt_get_coord(&caret_pt, &coord);
    846         console_goto(con, coord.column - pane.sh_column,
     848        console_set_pos(con, coord.column - pane.sh_column,
    847849            coord.row - pane.sh_row);
    848850}
     
    11491151static void status_display(char const *str)
    11501152{
    1151         console_goto(con, 0, scr_rows - 1);
    1152         console_set_color(con, COLOR_WHITE, COLOR_BLACK, 0);
     1153        console_set_pos(con, 0, scr_rows - 1);
     1154        console_set_style(con, STYLE_INVERTED);
    11531155        printf(" %*s ", -(scr_columns - 3), str);
    11541156        fflush(stdout);
    1155         console_set_color(con, COLOR_BLACK, COLOR_WHITE, 0);
     1157        console_set_style(con, STYLE_NORMAL);
    11561158
    11571159        pane.rflags |= REDRAW_CARET;
  • uspace/app/tester/console/console1.c

    rcaad59a r9f1362d4  
    5353                fflush(stdout);
    5454                console_set_style(fphone(stdout), STYLE_NORMAL);
    55                 printf("normal ");
     55                printf(" normal ");
    5656                fflush(stdout);
    5757                console_set_style(fphone(stdout), STYLE_EMPHASIS);
    58                 printf("emphasized");
     58                printf(" emphasized ");
     59                fflush(stdout);
     60                console_set_style(fphone(stdout), STYLE_INVERTED);
     61                printf(" inverted ");
     62                fflush(stdout);
     63                console_set_style(fphone(stdout), STYLE_SELECTED);
     64                printf(" selected ");
    5965                fflush(stdout);
    6066                console_set_style(fphone(stdout), STYLE_NORMAL);
    61                 printf(".\n");
     67                printf("\n");
    6268               
    6369                unsigned int i;
     
    7379                        }
    7480                        fflush(stdout);
    75                         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     81                        console_set_style(fphone(stdout), STYLE_NORMAL);
    7682                        putchar('\n');
    7783                }
     
    8692                        }
    8793                        fflush(stdout);
    88                         console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     94                        console_set_style(fphone(stdout), STYLE_NORMAL);
    8995                        putchar('\n');
    9096                }
     
    94100                for (i = 0; i < 255; i += 16) {
    95101                        fflush(stdout);
    96                         console_set_rgb_color(fphone(stdout), 0xffffff, i << 16);
     102                        console_set_rgb_color(fphone(stdout), (255 - i) << 16, i << 16);
    97103                        putchar('X');
    98104                }
     
    103109                for (i = 0; i < 255; i += 16) {
    104110                        fflush(stdout);
    105                         console_set_rgb_color(fphone(stdout), 0xffffff, i << 8);
     111                        console_set_rgb_color(fphone(stdout), (255 - i) << 8, i << 8);
    106112                        putchar('X');
    107113                }
     
    112118                for (i = 0; i < 255; i += 16) {
    113119                        fflush(stdout);
    114                         console_set_rgb_color(fphone(stdout), 0xffffff, i);
     120                        console_set_rgb_color(fphone(stdout), 255 - i, i);
    115121                        putchar('X');
    116122                }
    117123                fflush(stdout);
    118                 console_set_color(fphone(stdout), COLOR_BLACK, COLOR_WHITE, 0);
     124                console_set_style(fphone(stdout), STYLE_NORMAL);
    119125                putchar('\n');
    120126        }
  • uspace/app/tetris/screen.c

    rcaad59a r9f1362d4  
    5353#include <vfs/vfs.h>
    5454#include <async.h>
     55#include <bool.h>
     56#include <io/console.h>
     57#include <io/style.h>
    5558#include "screen.h"
    5659#include "tetris.h"
    57 #include <io/console.h>
    5860
    5961#define STOP  (B_COLS - 3)
     
    6365static int isset;               /* true => terminal is in game mode */
    6466
    65 static int use_color;           /* true => use colors */
     67static bool use_color;          /* true => use colors */
    6668
    6769static const struct shape *lastshape;
     
    8183{
    8284        fflush(stdout);
    83         console_set_rgb_color(fphone(stdout), 0xf0f0f0,
     85        console_set_rgb_color(fphone(stdout), 0xffffff,
    8486            use_color ? color : 0x000000);
    8587}
     
    8890{
    8991        fflush(stdout);
    90         console_set_rgb_color(fphone(stdout), 0, 0xf0f0f0);
     92        console_set_style(fphone(stdout), STYLE_NORMAL);
    9193}
    9294
     
    118120}
    119121
    120 void moveto(int r, int c)
     122void moveto(ipcarg_t r, ipcarg_t c)
    121123{
    122124        fflush(stdout);
    123         console_goto(fphone(stdout), c, r);
     125        console_set_pos(fphone(stdout), c, r);
    124126}
    125127
     
    131133}
    132134
    133 static int get_display_color_sup(void)
    134 {
    135         int rc;
    136         int ccap;
    137 
    138         rc = console_get_color_cap(fphone(stdout), &ccap);
     135static bool get_display_color_sup(void)
     136{
     137        ipcarg_t ccap;
     138        int rc = console_get_color_cap(fphone(stdout), &ccap);
     139       
    139140        if (rc != 0)
    140                 return 0;
    141 
     141                return false;
     142       
    142143        return (ccap >= CONSOLE_CCAP_RGB);
    143144}
     
    308309 * (We need its length in case we have to overwrite with blanks.)
    309310 */
    310 void scr_msg(char *s, int set)
     311void scr_msg(char *s, bool set)
    311312{
    312313        int l = str_size(s);
  • uspace/app/tetris/screen.h

    rcaad59a r9f1362d4  
    4848
    4949#include <sys/types.h>
     50#include <ipc/ipc.h>
    5051#include <async.h>
     52#include <bool.h>
    5153
    5254typedef struct {
    53         int ws_row;
    54         int ws_col;
     55        ipcarg_t ws_row;
     56        ipcarg_t ws_col;
    5557} winsize_t;
    5658
    5759extern winsize_t winsize;
    5860
    59 extern void moveto(int r, int c);
     61extern void moveto(ipcarg_t r, ipcarg_t c);
    6062extern void clear_screen(void);
    6163
     
    6567extern void scr_end(void);
    6668extern void scr_init(void);
    67 extern void scr_msg(char *, int);
     69extern void scr_msg(char *, bool);
    6870extern void scr_set(void);
    6971extern void scr_update(void);
  • uspace/app/top/screen.c

    rcaad59a r9f1362d4  
    3737
    3838#include <stdio.h>
     39#include <ipc/ipc.h>
    3940#include <io/console.h>
     41#include <io/style.h>
    4042#include <vfs/vfs.h>
    4143#include <stdarg.h>
     
    4547#include "top.h"
    4648
    47 #define WHITE  0xf0f0f0
    48 #define BLACK  0x000000
    49 
    50 static int rows;
    51 static int colls;
    52 static int up_rows;
     49static ipcarg_t warn_col = 0;
     50static ipcarg_t warn_row = 0;
     51
     52static void screen_style_normal(void)
     53{
     54        fflush(stdout);
     55        console_set_style(fphone(stdout), STYLE_NORMAL);
     56}
     57
     58static void screen_style_inverted(void)
     59{
     60        fflush(stdout);
     61        console_set_style(fphone(stdout), STYLE_INVERTED);
     62}
     63
     64static void screen_moveto(ipcarg_t col, ipcarg_t row)
     65{
     66        fflush(stdout);
     67        console_set_pos(fphone(stdout), col, row);
     68}
     69
     70static void screen_get_pos(ipcarg_t *col, ipcarg_t *row)
     71{
     72        fflush(stdout);
     73        console_get_pos(fphone(stdout), col, row);
     74}
     75
     76static void screen_get_size(ipcarg_t *col, ipcarg_t *row)
     77{
     78        fflush(stdout);
     79        console_get_size(fphone(stdout), col, row);
     80}
     81
     82static void screen_restart(bool clear)
     83{
     84        screen_style_normal();
     85       
     86        if (clear) {
     87                fflush(stdout);
     88                console_clear(fphone(stdout));
     89        }
     90       
     91        screen_moveto(0, 0);
     92}
     93
     94static void screen_newline(void)
     95{
     96        ipcarg_t cols;
     97        ipcarg_t rows;
     98        screen_get_size(&cols, &rows);
     99       
     100        ipcarg_t c;
     101        ipcarg_t r;
     102        screen_get_pos(&c, &r);
     103       
     104        ipcarg_t i;
     105        for (i = c + 1; i < cols; i++)
     106                puts(" ");
     107       
     108        if (r + 1 < rows)
     109                puts("\n");
     110}
     111
     112void screen_init(void)
     113{
     114        fflush(stdout);
     115        console_cursor_visibility(fphone(stdout), false);
     116       
     117        screen_restart(true);
     118}
     119
     120void screen_done(void)
     121{
     122        screen_restart(true);
     123       
     124        fflush(stdout);
     125        console_cursor_visibility(fphone(stdout), true);
     126}
    53127
    54128static void print_float(fixed_float ffloat, unsigned int precision)
     
    64138}
    65139
    66 static void screen_resume_normal(void)
    67 {
    68         fflush(stdout);
    69         console_set_rgb_color(fphone(stdout), 0, WHITE);
    70 }
    71 
    72 static void screen_moveto(int r, int c)
    73 {
    74         fflush(stdout);
    75         console_goto(fphone(stdout), c, r);
    76 }
    77 
    78 static void screen_clear(void)
    79 {
    80         console_clear(fphone(stdout));
    81         screen_moveto(0, 0);
    82         up_rows = 0;
    83         fflush(stdout);
    84 }
    85 
    86 void screen_init(void)
    87 {
    88         console_cursor_visibility(fphone(stdout), 0);
    89         screen_resume_normal();
    90         screen_clear();
    91        
    92         console_get_size(fphone(stdout), &colls, &rows);
    93 }
    94 
    95 void screen_done(void)
    96 {
    97         screen_resume_normal();
    98         screen_clear();
    99         console_cursor_visibility(fphone(stdout), 1);
    100 }
    101 
    102 static inline void print_time(data_t *data)
    103 {
    104         printf("%02lu:%02lu:%02lu ", data->hours, data->minutes, data->seconds);
    105 }
    106 
    107 static inline void print_uptime(data_t *data)
    108 {
    109         printf("up %u days, %02u:%02u:%02u, ", data->udays, data->uhours,
    110             data->uminutes, data->useconds);
    111 }
    112 
    113 static inline void print_load(data_t *data)
    114 {
    115         printf("load avarage: ");
     140static inline void print_global_head(data_t *data)
     141{
     142        printf("top - %02lu:%02lu:%02lu up %u days, %02u:%02u:%02u, load avarage:",
     143            data->hours, data->minutes, data->seconds,
     144            data->udays, data->uhours, data->uminutes, data->useconds);
    116145       
    117146        size_t i;
    118147        for (i = 0; i < data->load_count; i++) {
     148                puts(" ");
    119149                stats_print_load_fragment(data->load[i], 2);
    120                 printf(" ");
    121         }
     150        }
     151       
     152        screen_newline();
    122153}
    123154
     
    125156{
    126157        printf("tasks: %u total", data->tasks_count);
     158        screen_newline();
    127159}
    128160
     
    137169        size_t invalid = 0;
    138170       
    139        
    140171        size_t i;
    141172        for (i = 0; i < data->threads_count; i++) {
     
    167198            "%u other, %u invalid",
    168199            total, running, ready, sleeping, lingering, other, invalid);
     200        screen_newline();
    169201}
    170202
     
    178210                            data->cpus[i].id, data->cpus[i].frequency_mhz,
    179211                            data->cpus[i].busy_ticks, data->cpus[i].idle_ticks);
    180                         printf(", idle: ");
     212                        puts(", idle: ");
    181213                        print_float(data->cpus_perc[i].idle, 2);
    182                         printf("%%, busy: ");
     214                        puts("%, busy: ");
    183215                        print_float(data->cpus_perc[i].busy, 2);
    184                         printf("%%\n");
     216                        puts("%");
    185217                } else
    186                         printf("cpu%u inactive\n", data->cpus[i].id);
    187                
    188                 up_rows++;
     218                        printf("cpu%u inactive", data->cpus[i].id);
     219               
     220                screen_newline();
    189221        }
    190222}
     
    209241            PRIu64 "%c used, %" PRIu64 "%c free", total, total_suffix,
    210242            unavail, unavail_suffix, used, used_suffix, free, free_suffix);
    211 }
    212 
    213 static inline void print_tasks(data_t *data, int row)
    214 {
    215         size_t i;
    216         for (i = 0; i < data->tasks_count; i++, row++) {
    217                 if (row > rows)
    218                         break;
    219                
     243        screen_newline();
     244}
     245
     246static inline void print_task_head(void)
     247{
     248        screen_style_inverted();
     249        printf("      ID  Threads      Mem      %%Mem %%uCycles %%kCycles  Name");
     250        screen_newline();
     251        screen_style_normal();
     252}
     253
     254static inline void print_tasks(data_t *data)
     255{
     256        ipcarg_t cols;
     257        ipcarg_t rows;
     258        screen_get_size(&cols, &rows);
     259       
     260        ipcarg_t col;
     261        ipcarg_t row;
     262        screen_get_pos(&col, &row);
     263       
     264        size_t i;
     265        for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) {
    220266                uint64_t virtmem;
    221267                char virtmem_suffix;
     
    224270                printf("%8" PRIu64 " %8u %8" PRIu64 "%c ", data->tasks[i].task_id,
    225271                    data->tasks[i].threads, virtmem, virtmem_suffix);
    226                 printf("   ");
     272                puts("   ");
    227273                print_float(data->tasks_perc[i].virtmem, 2);
    228                 printf("%%   ");
     274                puts("%   ");
    229275                print_float(data->tasks_perc[i].ucycles, 2);
    230                 printf("%%   ");
     276                puts("%   ");
    231277                print_float(data->tasks_perc[i].kcycles, 2);
    232                 printf("%% %s\n", data->tasks[i].name);
    233         }
    234 }
    235 
    236 static inline void print_task_head(void)
    237 {
    238         fflush(stdout);
    239         console_set_rgb_color(fphone(stdout), WHITE, BLACK);
    240        
    241         printf("      ID  Threads      Mem      %%Mem %%uCycles %%kCycles  Name");
    242        
    243         int i;
    244         for (i = 61; i < colls; ++i)
    245                 printf(" ");
    246        
    247         fflush(stdout);
    248         console_set_rgb_color(fphone(stdout), BLACK, WHITE);
     278                printf("%% %s", data->tasks[i].name);
     279               
     280                screen_newline();
     281        }
    249282}
    250283
    251284static inline void print_ipc_head(void)
    252285{
    253         fflush(stdout);
    254         console_set_rgb_color(fphone(stdout), WHITE, BLACK);
    255        
     286        screen_style_inverted();
    256287        printf("      ID Calls sent Calls recv Answs sent Answs recv  IRQn recv       Forw Name");
    257        
    258         int i;
    259         for (i = 80; i < colls; ++i)
    260                 printf(" ");
    261        
    262         fflush(stdout);
    263         console_set_rgb_color(fphone(stdout), BLACK, WHITE);
    264 }
    265 
    266 static inline void print_ipc(data_t *data, int row)
    267 {
    268         size_t i;
    269         for (i = 0; i < data->tasks_count; i++, row++) {
    270                 if (row > rows)
    271                         break;
    272                
     288        screen_newline();
     289        screen_style_normal();
     290}
     291
     292static inline void print_ipc(data_t *data)
     293{
     294        ipcarg_t cols;
     295        ipcarg_t rows;
     296        screen_get_size(&cols, &rows);
     297       
     298        ipcarg_t col;
     299        ipcarg_t row;
     300        screen_get_pos(&col, &row);
     301       
     302        size_t i;
     303        for (i = 0; (i < data->tasks_count) && (row < rows); i++, row++) {
    273304                printf("%8" PRIu64 " %10" PRIu64 " %10" PRIu64 " %10" PRIu64
    274                      " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %s\n",
     305                     " %10" PRIu64 " %10" PRIu64 " %10" PRIu64 " %s",
    275306                     data->tasks[i].task_id, data->tasks[i].ipc_info.call_sent,
    276307                     data->tasks[i].ipc_info.call_recieved,
     
    279310                     data->tasks[i].ipc_info.irq_notif_recieved,
    280311                     data->tasks[i].ipc_info.forwarded, data->tasks[i].name);
     312               
     313                screen_newline();
    281314        }
    282315}
     
    284317void print_data(data_t *data)
    285318{
    286         screen_clear();
    287         fflush(stdout);
    288        
    289         printf("top - ");
    290         print_time(data);
    291         print_uptime(data);
    292         print_load(data);
    293        
    294         printf("\n");
    295         up_rows++;
    296        
     319        screen_restart(false);
     320        print_global_head(data);
    297321        print_task_summary(data);
    298        
    299         printf("\n");
    300         up_rows++;
    301        
    302322        print_thread_summary(data);
    303        
    304         printf("\n");
    305         up_rows++;
    306        
    307323        print_cpu_info(data);
    308324        print_physmem_info(data);
    309325       
    310         printf("\n");
    311         up_rows++;
    312        
    313326        /* Empty row for warnings */
    314         printf("\n");
     327        screen_get_pos(&warn_col, &warn_row);
     328        screen_newline();
    315329       
    316330        if (operation_type == OP_IPC) {
    317331                print_ipc_head();
    318                 printf("\n");
    319                 print_ipc(data, up_rows);
     332                print_ipc(data);
    320333        } else {
    321334                print_task_head();
    322                 printf("\n");
    323                 print_tasks(data, up_rows);
     335                print_tasks(data);
    324336        }
    325337       
     
    329341void print_warning(const char *fmt, ...)
    330342{
    331         screen_moveto(up_rows, 0);
     343        screen_moveto(warn_col, warn_row);
    332344       
    333345        va_list args;
     
    336348        va_end(args);
    337349       
     350        screen_newline();
    338351        fflush(stdout);
    339352}
Note: See TracChangeset for help on using the changeset viewer.