gmni

a gemini line mode client
git clone https://git.clttr.info/gmni.git
Log (Feed) | Files | Refs (Tags) | README | LICENSE

commit d5421dd9e0039b128be37d7b2925932633a31c90
parent 4f04fb45e267cb2e6a189b60e83d703b85104c72
Author: Ondřej Fiala <temp.xanomes@volny.cz>
Date:   Sat,  5 Feb 2022 12:44:52 +0100

gmnlm: strip control sequences from plaintext rendering

Diffstat:
Msrc/gmnlm.c | 6+++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/src/gmnlm.c b/src/gmnlm.c @@ -1012,7 +1012,6 @@ repeat: static bool display_plaintext(struct browser *browser, struct gemini_response *resp) { - // TODO: Strip ANSI escape sequences struct winsize ws; int row = 0, col = 0; ioctl(fileno(browser->tty), TIOCGWINSZ, &ws); @@ -1027,6 +1026,11 @@ display_plaintext(struct browser *browser, struct gemini_response *resp) if (n < 0) { n = 0; } + for (int i = 0; i < n; i++) { + if (iscntrl(buf[i]) && (buf[i] < '\t' || buf[i] > '\v')) { + buf[i] = '.'; + } + } ssize_t w = 0; while (w < (ssize_t)n) { ssize_t x = fwrite(&buf[w], 1, n - w, browser->tty);