Multi line low level line refresh. * * Rewrite the currently edited line accordingly to the buffer content, * cursor position, and number of columns of the terminal. */
| 2267 | * Rewrite the currently edited line accordingly to the buffer content, |
| 2268 | * cursor position, and number of columns of the terminal. */ |
| 2269 | static void refreshMultiLine(struct linenoiseState* l) { |
| 2270 | if (!l->render) { |
| 2271 | return; |
| 2272 | } |
| 2273 | char seq[64]; |
| 2274 | int plen = linenoiseComputeRenderWidth(l->prompt, strlen(l->prompt)); |
| 2275 | // utf8 in prompt, get render width |
| 2276 | size_t rows, cols; |
| 2277 | int new_cursor_row, new_cursor_x; |
| 2278 | positionToColAndRow(l->pos, new_cursor_row, new_cursor_x, rows, cols, l); |
| 2279 | int col; /* colum position, zero-based. */ |
| 2280 | int old_rows = l->maxrows ? l->maxrows : 1; |
| 2281 | int fd = l->ofd; |
| 2282 | auto render_buf = l->buf; |
| 2283 | auto render_len = l->len; |
| 2284 | uint64_t render_start = 0; |
| 2285 | uint64_t render_end = render_len; |
| 2286 | if (l->clear_screen) { |
| 2287 | l->oldpos = 0; |
| 2288 | old_rows = 0; |
| 2289 | l->clear_screen = false; |
| 2290 | } |
| 2291 | if (rows > l->rows) { |
| 2292 | // the text does not fit in the terminal (too many rows) |
| 2293 | // enable scrolling mode |
| 2294 | // check if, given the current y_scroll, the cursor is visible |
| 2295 | // display range is [y_scroll, y_scroll + l->rows] |
| 2296 | if (new_cursor_row < int(l->y_scroll) + 1) { |
| 2297 | l->y_scroll = new_cursor_row - 1; |
| 2298 | } else if (new_cursor_row > int(l->y_scroll) + int(l->rows)) { |
| 2299 | l->y_scroll = new_cursor_row - l->rows; |
| 2300 | } |
| 2301 | // display only characters up to the current scroll position |
| 2302 | if (l->y_scroll == 0) { |
| 2303 | render_start = 0; |
| 2304 | } else { |
| 2305 | render_start = colAndRowToPosition(l->y_scroll, 0, l); |
| 2306 | } |
| 2307 | if (l->y_scroll + l->rows >= rows) { |
| 2308 | render_end = l->len; |
| 2309 | } else { |
| 2310 | render_end = colAndRowToPosition(l->y_scroll + l->rows, 99999, l); |
| 2311 | } |
| 2312 | new_cursor_row -= l->y_scroll; |
| 2313 | render_buf += render_start; |
| 2314 | render_len = render_end - render_start; |
| 2315 | lndebug("truncate to rows %d - %d (render bytes %d to %d)", l->y_scroll, |
| 2316 | l->y_scroll + l->rows, render_start, render_end); |
| 2317 | rows = l->rows; |
| 2318 | } else { |
| 2319 | l->y_scroll = 0; |
| 2320 | } |
| 2321 | |
| 2322 | /* Update maxrows if needed. */ |
| 2323 | if (rows > l->maxrows) { |
| 2324 | l->maxrows = rows; |
| 2325 | } |
| 2326 |
no test coverage detected