Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/input.c

    rb67c7d64 re228280  
    3939#include <errno.h>
    4040#include <assert.h>
     41#include <macros.h>
    4142#include <bool.h>
    4243
     
    125126        int i;
    126127
    127         console_goto(fphone(stdout), ti->col0 + start, ti->row0);
     128        console_goto(fphone(stdout), (ti->col0 + start) % ti->con_cols,
     129            ti->row0 + (ti->col0 + start) / ti->con_cols);
    128130        printf("%ls", ti->buffer + start);
    129131        for (i = 0; i < pad; ++i)
     
    139141static void tinput_position_caret(tinput_t *ti)
    140142{
    141         console_goto(fphone(stdout), ti->col0 + ti->pos, ti->row0);
     143        console_goto(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
     144            ti->row0 + (ti->col0 + ti->pos) / ti->con_cols);
     145}
     146
     147/** Update row0 in case the screen could have scrolled. */
     148static void tinput_update_origin(tinput_t *ti)
     149{
     150        int width, rows;
     151
     152        width = ti->col0 + ti->nc;
     153        rows = (width / ti->con_cols) + 1;
     154 
     155        /* Update row0 if the screen scrolled. */
     156        if (ti->row0 + rows > ti->con_rows)
     157                ti->row0 = ti->con_rows - rows;
    142158}
    143159
     
    145161{
    146162        int i;
     163        int new_width, new_height;
    147164
    148165        if (ti->nc == INPUT_MAX)
    149166                return;
    150167
    151         if (ti->col0 + ti->nc >= ti->con_cols - 1)
    152                 return;
     168        new_width = ti->col0 + ti->nc + 1;
     169        if (new_width % ti->con_cols == 0) {
     170                /* Advancing to new line. */
     171                new_height = (new_width / ti->con_cols) + 1;
     172                if (new_height >= ti->con_rows)
     173                        return; /* Disallow text longer than 1 page for now. */
     174        }
    153175
    154176        for (i = ti->nc; i > ti->pos; --i)
     
    161183
    162184        tinput_display_tail(ti, ti->pos - 1, 0);
     185        tinput_update_origin(ti);
    163186        tinput_position_caret(ti);
    164187}
     
    239262}
    240263
     264static void tinput_seek_vertical(tinput_t *ti, seek_dir_t dir)
     265{
     266        if (dir == seek_forward)
     267                ti->pos = min(ti->pos + ti->con_cols, ti->nc);
     268        else
     269                ti->pos = max(0, ti->pos - ti->con_cols);
     270
     271        tinput_position_caret(ti);
     272}
     273
    241274static void tinput_seek_max(tinput_t *ti, seek_dir_t dir)
    242275{
     
    298331        tinput_set_str(ti, ti->history[ti->hpos]);
    299332        tinput_display_tail(ti, 0, pad);
     333        tinput_update_origin(ti);
    300334        tinput_position_caret(ti);
    301335}
     
    322356        ti->pos = 0;
    323357        ti->nc = 0;
     358        ti->buffer[0] = '\0';
    324359
    325360        while (true) {
     
    340375                                tinput_seek_word(ti, seek_forward);
    341376                                break;
     377                        case KC_UP:
     378                                tinput_seek_vertical(ti, seek_backward);
     379                                break;
     380                        case KC_DOWN:
     381                                tinput_seek_vertical(ti, seek_forward);
     382                                break;
    342383                        }
    343384                }
     
    381422
    382423done:
     424        ti->pos = ti->nc;
     425        tinput_position_caret(ti);
    383426        putchar('\n');
    384427
Note: See TracChangeset for help on using the changeset viewer.