Skip to content

Commit 7197cb0

Browse files
authored
released at 0.2.8
1 parent ef1c20a commit 7197cb0

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

kirc.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include <sys/ioctl.h>
1919

2020
#define CTCP_CMDS "ACTION VERSION TIME CLIENTINFO PING"
21-
#define VERSION "0.2.7"
21+
#define VERSION "0.2.8"
2222
#define MSG_MAX 512
2323
#define CHA_MAX 200
2424
#define NIC_MAX 26
@@ -294,35 +294,30 @@ static void refreshLine(struct State *l) {
294294
int fd = STDOUT_FILENO;
295295
char *buf = l->buf;
296296
size_t lenb = l->lenb;
297-
size_t lenu8 = l->lenu8;
298297
size_t posu8 = l->posu8;
298+
size_t ch = plenu8, txtlenb = 0;
299299
struct abuf ab;
300300
l->cols = getColumns(STDIN_FILENO, STDOUT_FILENO);
301301
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);
306303
posu8--;
307304
}
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);
312307
abInit(&ab);
313308
snprintf(seq, sizeof(seq), "\r");
314309
abAppend(&ab, seq, strnlen(seq, MSG_MAX));
315-
abAppend(&ab,l->prompt, l->plenb);
310+
abAppend(&ab, l->prompt, l->plenb);
316311
abAppend(&ab, "> ", 2);
317-
abAppend(&ab, buf, lenb);
312+
abAppend(&ab, buf, txtlenb);
318313
snprintf(seq, sizeof(seq), "\x1b[0K");
319314
abAppend(&ab, seq, strnlen(seq, MSG_MAX));
320315
if (posu8 + plenu8) {
321316
snprintf(seq, sizeof(seq), "\r\x1b[%dC", (int)(posu8 + plenu8));
322317
} else {
323318
snprintf(seq, sizeof(seq), "\r");
324319
}
325-
abAppend(&ab, seq, strlen(seq));
320+
abAppend(&ab, seq, strnlen(seq, MSG_MAX));
326321
if (write(fd, ab.b, ab.len) == -1) {}
327322
abFree(&ab);
328323
}

0 commit comments

Comments
 (0)