Ignore:
Timestamp:
2011-03-22T20:43:01Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
f2d665b4
Parents:
e7ffdd3
Message:

Fix paging for non-hex mode (i.e. when input may contain newlines)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/cmds/modules/cat/cat.c

    re7ffdd3 rac897e8  
    5757static const char *hexchars = "0123456789abcdef";
    5858
    59 static size_t chars_per_screen = 0;
     59static bool paging_enabled = false;
    6060static size_t chars_remaining = 0;
     61static size_t lines_remaining = 0;
     62static sysarg_t console_cols = 0;
     63static sysarg_t console_rows = 0;
    6164
    6265static struct option const long_options[] = {
     
    97100static void waitprompt()
    98101{
    99         sysarg_t rows, cols;
    100         if (console_get_size(fphone(stdout), &cols, &rows) == EOK) {
    101                 console_set_pos(fphone(stdout), 0, rows-1);
    102         }
     102        console_set_pos(fphone(stdout), 0, console_rows-1);
    103103        console_set_color(fphone(stdout), COLOR_BLUE, COLOR_WHITE, 0);
    104104        printf("Press any key to continue");
     
    125125{
    126126        console_clear(fphone(stdout));
    127         chars_remaining = chars_per_screen;
     127        chars_remaining = console_cols;
     128        lines_remaining = console_rows-1;
    128129}
    129130
     
    131132{
    132133        putchar(c);
    133         if (chars_per_screen > 0) {
     134        if (paging_enabled) {
    134135                chars_remaining--;
    135                 if (chars_remaining == 0) {
     136                if (c == '\n' || chars_remaining == 0) {
     137                        chars_remaining = console_cols;
     138                        lines_remaining--;
     139                }
     140                if (lines_remaining == 0) {
    136141                        fflush(stdout);
    137142                        waitprompt();
     
    259264                        return CMD_FAILURE;
    260265                }
    261                 chars_per_screen = cols * (rows-1);
     266                console_cols = cols;
     267                console_rows = rows;
     268                paging_enabled = true;
    262269                newpage();
    263270        }
Note: See TracChangeset for help on using the changeset viewer.