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. * * Flags is REFRESH_* macros. The function can just remove the old * prompt, just write it, or both. */
| 1213 | * Flags is REFRESH_* macros. The function can just remove the old |
| 1214 | * prompt, just write it, or both. */ |
| 1215 | static void refreshMultiLine(struct linenoiseState *l, int flags) { |
| 1216 | char seq[64]; |
| 1217 | size_t pcollen = promptTextColumnLen(l->prompt, strlen(l->prompt)); |
| 1218 | int colpos = columnPosForMultiLine(l->buf, l->len, l->len, l->cols, pcollen); |
| 1219 | int colpos2; /* cursor column position. */ |
| 1220 | int rows = (pcollen + colpos + l->cols - 1) / l->cols; /* rows used by current buf. */ |
| 1221 | int rpos = (pcollen + l->oldcolpos + l->cols) / l->cols; /* cursor relative row. */ |
| 1222 | int rpos2; /* rpos after refresh. */ |
| 1223 | int col; /* column position, zero-based. */ |
| 1224 | int old_rows = l->oldrows; |
| 1225 | int fd = l->ofd, j; |
| 1226 | std::string ab; |
| 1227 | l->oldrows = rows; |
| 1228 | |
| 1229 | /* First step: clear all the lines used before. To do so start by |
| 1230 | * going to the last row. */ |
| 1231 | if (flags & REFRESH_CLEAN) { |
| 1232 | if (old_rows - rpos > 0) { |
| 1233 | snprintf(seq,64,"\x1b[%dB", old_rows-rpos); |
| 1234 | ab.append(seq); |
| 1235 | } |
| 1236 | |
| 1237 | /* Now for every row clear it, go up. */ |
| 1238 | for (j = 0; j < old_rows - 1; j++) { |
| 1239 | snprintf(seq,64,"\r\x1b[0K\x1b[1A"); |
| 1240 | ab.append(seq); |
| 1241 | } |
| 1242 | } |
| 1243 | |
| 1244 | if (flags & REFRESH_ALL) { |
| 1245 | /* Clean the top line. */ |
| 1246 | snprintf(seq,64,"\r\x1b[0K"); |
| 1247 | ab.append(seq); |
| 1248 | } |
| 1249 | |
| 1250 | /* Get column length to cursor position */ |
| 1251 | colpos2 = columnPosForMultiLine(l->buf, l->len, l->pos, l->cols, pcollen); |
| 1252 | |
| 1253 | if (flags & REFRESH_WRITE) { |
| 1254 | /* Write the prompt and the current buffer content */ |
| 1255 | ab.append(l->prompt); |
| 1256 | if (maskmode == 1) { |
| 1257 | for (unsigned int i = 0; i < l->len; ++i) { |
| 1258 | ab.append("*"); |
| 1259 | } |
| 1260 | } else { |
| 1261 | ab.append(l->buf, l->len); |
| 1262 | } |
| 1263 | |
| 1264 | /* Show hits if any. */ |
| 1265 | refreshShowHints(ab, l, pcollen); |
| 1266 | |
| 1267 | /* If we are at the very end of the screen with our prompt, we need to |
| 1268 | * emit a newline and move the prompt to the first column. */ |
| 1269 | if (l->pos && l->pos == l->len && (colpos2 + pcollen) % l->cols == 0) { |
| 1270 | ab.append("\n"); |
| 1271 | snprintf(seq,64,"\r"); |
| 1272 | ab.append(seq); |
no test coverage detected