"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Christian Weisgerber <naddy@mips.inka.de>
Subject:
Re: tog: fix display of lines ending in \r\n
To:
gameoftrees@openbsd.org
Date:
Sat, 12 Dec 2020 00:09:12 +0100

Download raw body.

Thread
Christian Weisgerber:

> Alternatively,
> (2) tog continues to pass the control character to curses, but when
>     calculating the column width, tog takes into account that curses
>     will change the character into a printable representation.
> 
> Below is a quick proof-of-concept that uses approach (2).

Here's a variant that at least isn't outright wrong.

diff 9f6bb280654be7061fc00305743f6ace71f9a1cb /home/naddy/got
blob - 99232045ade1a4d37286e512dd4999368a1b89b5
file + tog/tog.c
--- tog/tog.c
+++ tog/tog.c
@@ -35,6 +35,7 @@
 #include <unistd.h>
 #include <limits.h>
 #include <wchar.h>
+#include <wctype.h>
 #include <time.h>
 #include <pthread.h>
 #include <libgen.h>
@@ -1193,6 +1194,10 @@ format_line(wchar_t **wlinep, int *widthp, const char 
 				if (cols + width > wlimit)
 					break;
 				cols += width;
+			} else if (iswcntrl(wline[i])) {
+				if (cols + 2 > wlimit)
+					break;
+				cols += 2;
 			}
 			i++;
 		} else {
-- 
Christian "naddy" Weisgerber                          naddy@mips.inka.de