Changeset 3cefd70 in mainline


Ignore:
Timestamp:
2011-03-24T21:30:41Z (13 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
47f7adfc
Parents:
5ea37b1
git-author:
Martin Sucha <> (2011-03-24 21:30:41)
git-committer:
Jakub Jermar <jakub@…> (2011-03-24 21:30:41)
Message:

Improve paging options of 'cat'.

File:
1 edited

Legend:

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

    r5ea37b1 r3cefd70  
    3939#include <io/color.h>
    4040#include <io/style.h>
     41#include <io/keycode.h>
    4142#include <errno.h>
    4243#include <vfs/vfs.h>
     
    6263static sysarg_t console_cols = 0;
    6364static sysarg_t console_rows = 0;
     65static bool should_quit = false;
    6466
    6567static struct option const long_options[] = {
     
    102104        console_set_pos(fphone(stdout), 0, console_rows-1);
    103105        console_set_color(fphone(stdout), COLOR_BLUE, COLOR_WHITE, 0);
    104         printf("Press any key to continue");
     106        printf("ENTER/SPACE/PAGE DOWN - next page, "
     107               "ESC/Q - quit, C - continue unpaged");
    105108        fflush(stdout);
    106109        console_set_style(fphone(stdout), STYLE_NORMAL);
     
    116119                }
    117120                if (ev.type == KEY_PRESS) {
    118                         return;
     121                        if (ev.key == KC_ESCAPE || ev.key == KC_Q) {
     122                                should_quit = true;
     123                                return;
     124                        }
     125                        if (ev.key == KC_C) {
     126                                paging_enabled = false;
     127                                return;
     128                        }
     129                        if (ev.key == KC_ENTER || ev.key == KC_SPACE ||
     130                            ev.key == KC_PAGE_DOWN) {
     131                                return;
     132                        }
    119133                }
    120134        }
     
    177191                        buff[bytes] = '\0';
    178192                        offset = 0;
    179                         for (i = 0; i < bytes; i++) {
     193                        for (i = 0; i < bytes && !should_quit; i++) {
    180194                                if (hex) {
    181195                                        paged_char(hexchars[((uint8_t)buff[i])/16]);
     
    194208                        reads++;
    195209                }
    196         } while (bytes > 0);
     210        } while (bytes > 0 && !should_quit);
    197211
    198212        close(fd);
     
    225239        console_cols = 0;
    226240        console_rows = 0;
     241        should_quit = false;
    227242
    228243        argc = cli_count_args(argv);
     
    278293        }
    279294
    280         for (i = optind; argv[i] != NULL; i++)
     295        for (i = optind; argv[i] != NULL && !should_quit; i++)
    281296                ret += cat_file(argv[i], buffer, hex);
    282297
Note: See TracChangeset for help on using the changeset viewer.