Changes in uspace/app/bdsh/input.c [da2bd08:3041fef1] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/input.c
rda2bd08 r3041fef1 125 125 int i; 126 126 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); 128 129 printf("%ls", ti->buffer + start); 129 130 for (i = 0; i < pad; ++i) … … 134 135 static char *tinput_get_str(tinput_t *ti) 135 136 { 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); 145 138 } 146 139 147 140 static void tinput_position_caret(tinput_t *ti) 148 141 { 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. */ 147 static 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; 150 157 } 151 158 … … 153 160 { 154 161 int i; 162 int new_width, new_height; 155 163 156 164 if (ti->nc == INPUT_MAX) 157 165 return; 158 166 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 } 161 174 162 175 for (i = ti->nc; i > ti->pos; --i) … … 169 182 170 183 tinput_display_tail(ti, ti->pos - 1, 0); 184 tinput_update_origin(ti); 171 185 tinput_position_caret(ti); 172 186 } … … 247 261 } 248 262 263 static 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 249 276 static void tinput_seek_max(tinput_t *ti, seek_dir_t dir) 250 277 { … … 306 333 tinput_set_str(ti, ti->history[ti->hpos]); 307 334 tinput_display_tail(ti, 0, pad); 335 tinput_update_origin(ti); 308 336 tinput_position_caret(ti); 309 337 } … … 330 358 ti->pos = 0; 331 359 ti->nc = 0; 360 ti->buffer[0] = '\0'; 332 361 333 362 while (true) { … … 348 377 tinput_seek_word(ti, seek_forward); 349 378 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; 350 385 } 351 386 } … … 389 424 390 425 done: 426 ti->pos = ti->nc; 427 tinput_position_caret(ti); 391 428 putchar('\n'); 392 429
Note:
See TracChangeset
for help on using the changeset viewer.