Ignore:
File:
1 edited

Legend:

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

    rda2bd08 r3041fef1  
    125125        int i;
    126126
    127         console_goto(fphone(stdout), ti->col0 + start, ti->row0);
     127        console_goto(fphone(stdout), (ti->col0 + start) % ti->con_cols,
     128            ti->row0 + (ti->col0 + start) / ti->con_cols);
    128129        printf("%ls", ti->buffer + start);
    129130        for (i = 0; i < pad; ++i)
     
    134135static char *tinput_get_str(tinput_t *ti)
    135136{
    136         char *str;
    137 
    138         str = malloc(STR_BOUNDS(ti->nc) + 1);
    139         if (str == NULL)
    140                 return NULL;
    141 
    142         wstr_nstr(str, ti->buffer, STR_BOUNDS(ti->nc) + 1);
    143 
    144         return str;
     137        return wstr_to_astr(ti->buffer);
    145138}
    146139
    147140static void tinput_position_caret(tinput_t *ti)
    148141{
    149         console_goto(fphone(stdout), ti->col0 + ti->pos, ti->row0);
     142        console_goto(fphone(stdout), (ti->col0 + ti->pos) % ti->con_cols,
     143            ti->row0 + (ti->col0 + ti->pos) / ti->con_cols);
     144}
     145
     146/** Update row0 in case the screen could have scrolled. */
     147static void tinput_update_origin(tinput_t *ti)
     148{
     149        int width, rows;
     150
     151        width = ti->col0 + ti->nc;
     152        rows = (width / ti->con_cols) + 1;
     153 
     154        /* Update row0 if the screen scrolled. */
     155        if (ti->row0 + rows > ti->con_rows)
     156                ti->row0 = ti->con_rows - rows;
    150157}
    151158
     
    153160{
    154161        int i;
     162        int new_width, new_height;
    155163
    156164        if (ti->nc == INPUT_MAX)
    157165                return;
    158166
    159         if (ti->col0 + ti->nc >= ti->con_cols - 1)
    160                 return;
     167        new_width = ti->col0 + ti->nc + 1;
     168        if (new_width % ti->con_cols == 0) {
     169                /* Advancing to new line. */
     170                new_height = (new_width / ti->con_cols) + 1;
     171                if (new_height >= ti->con_rows)
     172                        return; /* Disallow text longer than 1 page for now. */
     173        }
    161174
    162175        for (i = ti->nc; i > ti->pos; --i)
     
    169182
    170183        tinput_display_tail(ti, ti->pos - 1, 0);
     184        tinput_update_origin(ti);
    171185        tinput_position_caret(ti);
    172186}
     
    247261}
    248262
     263static void tinput_seek_vertical(tinput_t *ti, seek_dir_t dir)
     264{
     265        if (dir == seek_forward) {
     266                if (ti->pos + ti->con_cols <= ti->nc)
     267                        ti->pos = ti->pos + ti->con_cols;
     268        } else {
     269                if (ti->pos - ti->con_cols >= 0)
     270                        ti->pos = ti->pos - ti->con_cols;
     271        }
     272
     273        tinput_position_caret(ti);
     274}
     275
    249276static void tinput_seek_max(tinput_t *ti, seek_dir_t dir)
    250277{
     
    306333        tinput_set_str(ti, ti->history[ti->hpos]);
    307334        tinput_display_tail(ti, 0, pad);
     335        tinput_update_origin(ti);
    308336        tinput_position_caret(ti);
    309337}
     
    330358        ti->pos = 0;
    331359        ti->nc = 0;
     360        ti->buffer[0] = '\0';
    332361
    333362        while (true) {
     
    348377                                tinput_seek_word(ti, seek_forward);
    349378                                break;
     379                        case KC_UP:
     380                                tinput_seek_vertical(ti, seek_backward);
     381                                break;
     382                        case KC_DOWN:
     383                                tinput_seek_vertical(ti, seek_forward);
     384                                break;
    350385                        }
    351386                }
     
    389424
    390425done:
     426        ti->pos = ti->nc;
     427        tinput_position_caret(ti);
    391428        putchar('\n');
    392429
Note: See TracChangeset for help on using the changeset viewer.