From aa3942d2d121ae3cab753d892a81eae53e03b870 Mon Sep 17 00:00:00 2001 From: Peter Stephenson Date: Wed, 25 Mar 2009 09:51:43 +0000 Subject: Michael Hwang: 26776: improved column alignment with print -c -P --- Src/builtin.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'Src/builtin.c') diff --git a/Src/builtin.c b/Src/builtin.c index 95aca06fd..b715e9782 100644 --- a/Src/builtin.c +++ b/Src/builtin.c @@ -3741,6 +3741,23 @@ bin_print(char *name, char **args, Options ops, int func) memset(&mbs, 0, sizeof(mbstate_t)); while (l > 0) { + /* + * Prevent misaligned columns due to escape sequences by + * skipping over them. Octals \033 and \233 are the + * possible escape characters recognized by ANSI. + * + * It ought to be possible to do this in the case + * of prompt expansion by propagating the information + * about escape sequences (currently we strip this + * out). + */ + if (*aptr == '\033' || *aptr == '\233') { + for (aptr++, l--; l && !isalpha(*aptr); aptr++, l--); + aptr++; + l--; + continue; + } + wchar_t wc; size_t cnt = mbrtowc(&wc, aptr, l, &mbs); int wcw; -- cgit 1.4.1