Bug 108521
Summary: | [util-linux] column -s X -t fails when there are colour escapes before X | ||
---|---|---|---|
Product: | Tools | Reporter: | Simon Kohlmeyer (simon.kohlmeyer) |
Component: | Other | Assignee: | Tools.Other (tools_other) |
Status: | NEW --- | ||
Severity: | normal | CC: | lkml, skibyte |
Priority: | P1 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | 4.2.5 | Subsystem: | |
Regression: | No | Bisected commit-id: | |
Attachments: | Patch that fixes the issue with HAVE_WIDECHAR |
Description
Simon Kohlmeyer
2015-11-27 00:08:51 UTC
The column from bsdmainutils available in debian does not have this problem. I'm on arch using util-linux 2.27. Quote from man wcswidth (which is used in column): The wcswidth() function returns the number of columns needed to represent the wide-character string pointed to by s, but at most n wide characters. If a nonprintable wide character occurs among these characters, -1 is returned. bsdmainutil uses /* Like wcswidth(), but ignores non-printing characters. */ int width(const wchar_t *wcs) { int w, cw; for (w = 0; *wcs != L'\0'; wcs++) if ((cw = wcwidth(*wcs)) > 0) w += cw; return (w); } Created attachment 195581 [details]
Patch that fixes the issue with HAVE_WIDECHAR
Without HAVE_WIDECHAR, -s and -t don't seem to work at all:
echo 'bXfoo\nbarXfoo' | ./column -s X -t
bXfoo
barXfoo
(I changed #define HAVE_WIDECHAR 1 to #undef HAVE_WIDECHAR in config.h. I'm no autotools expert, please advise if this doesn't do the trick)
I tried to make the new function work with and without HAVE_WIDECHAR defined and could confirm that it correctly strips out control sequences in both cases.
Looks like my patch doesn't work after all. Sorry. I've switched over to another workaround in the meantime This bug has been fixed in util-linux 2.28 with the following commit: commit 683ddbd5c4a7c28db878bd5b2387c7cff2504967 Author: Karel Zak <kzak@redhat.com> Date: Wed Jan 13 10:08:39 2016 +0100 column: ignore non-printable chars echo -e '\033[33mb\033[mXFoo\n\033[33mbar\033[mXFoo' | column -s X -t old version: b Foo bar Foo fixed version: b Foo bar Foo References: https://github.com/karelzak/util-linux/issues/252 |