From: Stefan Sperling Subject: Re: tog: fix display of lines ending in \r\n To: Christian Weisgerber , gameoftrees@openbsd.org Date: Thu, 10 Dec 2020 23:52:04 +0100 On Thu, Dec 10, 2020 at 11:34:21PM +0100, Stefan Sperling wrote: > On Thu, Dec 10, 2020 at 11:17:48PM +0100, Christian Weisgerber wrote: > > Stefan Sperling: > > > > > What specific problem are you looking at? > > > > tog's log view dealing with the attached repository. > > > > There are two ESC characters in the commit message. They are escaped > > to "^[", but then the next line is offset by 4 characters. > > > > This would be consistent with ESC being handled as a zero-width > > character, and a later instance (curses itself?) turning them into > > visible sequences. > > One thing we could do is this. Keeps the display intact, at least. For some reason, Tab is both whitespace and control character :-/ This version fixes all Tabs in diffs being replaced by '?'. diff 0e61ae21efda7ecccd19cccda1393f80ca90f9fd 5ec52daf04c1e30b62cc53dd4b51767bb4c20132 blob - ee044a71602208bed395a517f0354d580be3407f blob + cc5cc30aef358c4400940c48e94d842f5b3a264a --- tog/tog.c +++ tog/tog.c @@ -19,6 +19,7 @@ #include #include +#include #include #define _XOPEN_SOURCE_EXTENDED #include @@ -1175,8 +1176,12 @@ format_line(wchar_t **wlinep, int *widthp, const char i = 0; while (i < wlen) { - int width = wcwidth(wline[i]); + int width; + if (!iswspace(wline[i]) && iswcntrl(wline[i])) + wline[i] = L'?'; + + width = wcwidth(wline[i]); if (width == 0) { i++; continue;