|
18 | 18 | #include <sys/ioctl.h>
|
19 | 19 |
|
20 | 20 | #define CTCP_CMDS "ACTION VERSION TIME CLIENTINFO PING"
|
21 |
| -#define VERSION "0.2.7" |
| 21 | +#define VERSION "0.2.8" |
22 | 22 | #define MSG_MAX 512
|
23 | 23 | #define CHA_MAX 200
|
24 | 24 | #define NIC_MAX 26
|
@@ -294,35 +294,30 @@ static void refreshLine(struct State *l) {
|
294 | 294 | int fd = STDOUT_FILENO;
|
295 | 295 | char *buf = l->buf;
|
296 | 296 | size_t lenb = l->lenb;
|
297 |
| - size_t lenu8 = l->lenu8; |
298 | 297 | size_t posu8 = l->posu8;
|
| 298 | + size_t ch = plenu8, txtlenb = 0; |
299 | 299 | struct abuf ab;
|
300 | 300 | l->cols = getColumns(STDIN_FILENO, STDOUT_FILENO);
|
301 | 301 | while ((plenu8 + posu8) >= l->cols) {
|
302 |
| - size_t movedBy = u8Next(buf, 0); |
303 |
| - buf += movedBy; |
304 |
| - lenb += movedBy; |
305 |
| - lenu8--; |
| 302 | + buf += u8Next(buf, 0); |
306 | 303 | posu8--;
|
307 | 304 | }
|
308 |
| - while ((plenu8 + lenu8) > l->cols) { |
309 |
| - lenu8--; |
310 |
| - lenb = u8Prev(buf, lenb); |
311 |
| - } |
| 305 | + while (txtlenb < lenb && ch++ < l->cols) |
| 306 | + txtlenb += u8Next(buf, 0); |
312 | 307 | abInit(&ab);
|
313 | 308 | snprintf(seq, sizeof(seq), "\r");
|
314 | 309 | abAppend(&ab, seq, strnlen(seq, MSG_MAX));
|
315 |
| - abAppend(&ab,l->prompt, l->plenb); |
| 310 | + abAppend(&ab, l->prompt, l->plenb); |
316 | 311 | abAppend(&ab, "> ", 2);
|
317 |
| - abAppend(&ab, buf, lenb); |
| 312 | + abAppend(&ab, buf, txtlenb); |
318 | 313 | snprintf(seq, sizeof(seq), "\x1b[0K");
|
319 | 314 | abAppend(&ab, seq, strnlen(seq, MSG_MAX));
|
320 | 315 | if (posu8 + plenu8) {
|
321 | 316 | snprintf(seq, sizeof(seq), "\r\x1b[%dC", (int)(posu8 + plenu8));
|
322 | 317 | } else {
|
323 | 318 | snprintf(seq, sizeof(seq), "\r");
|
324 | 319 | }
|
325 |
| - abAppend(&ab, seq, strlen(seq)); |
| 320 | + abAppend(&ab, seq, strnlen(seq, MSG_MAX)); |
326 | 321 | if (write(fd, ab.b, ab.len) == -1) {}
|
327 | 322 | abFree(&ab);
|
328 | 323 | }
|
|
0 commit comments