aboutsummaryrefslogtreecommitdiffstats
path: root/kirc.c
diff options
context:
space:
mode:
authorMichael Czigler <37268479+mcpcpc@users.noreply.github.com>2021-07-15 20:59:47 -0400
committerGitHub <noreply@github.com>2021-07-15 20:59:47 -0400
commit7197cb089298e158165c2d236e696dffe06123c3 (patch)
tree6c57b1b99624b23773bc38d621d5b626f8865bfa /kirc.c
parentreleased at 0.2.7 (diff)
downloadkirc-7197cb089298e158165c2d236e696dffe06123c3.tar.gz
kirc-7197cb089298e158165c2d236e696dffe06123c3.tar.bz2
kirc-7197cb089298e158165c2d236e696dffe06123c3.tar.xz
kirc-7197cb089298e158165c2d236e696dffe06123c3.tar.zst
kirc-7197cb089298e158165c2d236e696dffe06123c3.zip
released at 0.2.8
Diffstat (limited to 'kirc.c')
-rw-r--r--kirc.c21
1 files changed, 8 insertions, 13 deletions
diff --git a/kirc.c b/kirc.c
index 065924a..b9bb307 100644
--- a/kirc.c
+++ b/kirc.c
@@ -18,7 +18,7 @@
#include <sys/ioctl.h>
#define CTCP_CMDS "ACTION VERSION TIME CLIENTINFO PING"
-#define VERSION "0.2.7"
+#define VERSION "0.2.8"
#define MSG_MAX 512
#define CHA_MAX 200
#define NIC_MAX 26
@@ -294,27 +294,22 @@ static void refreshLine(struct State *l) {
int fd = STDOUT_FILENO;
char *buf = l->buf;
size_t lenb = l->lenb;
- size_t lenu8 = l->lenu8;
size_t posu8 = l->posu8;
+ size_t ch = plenu8, txtlenb = 0;
struct abuf ab;
l->cols = getColumns(STDIN_FILENO, STDOUT_FILENO);
while ((plenu8 + posu8) >= l->cols) {
- size_t movedBy = u8Next(buf, 0);
- buf += movedBy;
- lenb += movedBy;
- lenu8--;
+ buf += u8Next(buf, 0);
posu8--;
}
- while ((plenu8 + lenu8) > l->cols) {
- lenu8--;
- lenb = u8Prev(buf, lenb);
- }
+ while (txtlenb < lenb && ch++ < l->cols)
+ txtlenb += u8Next(buf, 0);
abInit(&ab);
snprintf(seq, sizeof(seq), "\r");
abAppend(&ab, seq, strnlen(seq, MSG_MAX));
- abAppend(&ab,l->prompt, l->plenb);
+ abAppend(&ab, l->prompt, l->plenb);
abAppend(&ab, "> ", 2);
- abAppend(&ab, buf, lenb);
+ abAppend(&ab, buf, txtlenb);
snprintf(seq, sizeof(seq), "\x1b[0K");
abAppend(&ab, seq, strnlen(seq, MSG_MAX));
if (posu8 + plenu8) {
@@ -322,7 +317,7 @@ static void refreshLine(struct State *l) {
} else {
snprintf(seq, sizeof(seq), "\r");
}
- abAppend(&ab, seq, strlen(seq));
+ abAppend(&ab, seq, strnlen(seq, MSG_MAX));
if (write(fd, ab.b, ab.len) == -1) {}
abFree(&ab);
}