summaryrefslogtreecommitdiff
path: root/column.c
diff options
context:
space:
mode:
authorRené Scharfe <l.s.r@web.de>2019-10-13 12:49:50 (GMT)
committerJunio C Hamano <gitster@pobox.com>2019-10-15 01:54:15 (GMT)
commita81e42d23588188c49f9b6e519f99a734a5aacb9 (patch)
treed7a551b322d1bb6ced8344b0627edc8f801f2643 /column.c
parent5fa0f5238b0cd46cfe7f6fa76c3f526ea98148d9 (diff)
downloadgit-a81e42d23588188c49f9b6e519f99a734a5aacb9.zip
git-a81e42d23588188c49f9b6e519f99a734a5aacb9.tar.gz
git-a81e42d23588188c49f9b6e519f99a734a5aacb9.tar.bz2
column: use utf8_strnwidth() to strip out ANSI color escapes
Make use of utf8_strnwidth()'s feature to skip ANSI escape sequences instead of open-coding it. This shortens the code and makes it more consistent. This changes the behavior, though: The old code skips all kinds of Control Sequence Introducer sequences, while utf8_strnwidth() only skips the Select Graphic Rendition kind, i.e. those ending with "m". They are used for specifying color and font attributes like boldness. The only other kind of escape sequence we print in Git is Erase in Line, ending with "K". That's not used for columnar output, so this difference actually doesn't matter here. Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'column.c')
-rw-r--r--column.c13
1 files changed, 1 insertions, 12 deletions
diff --git a/column.c b/column.c
index 7a17c14..4a38eed 100644
--- a/column.c
+++ b/column.c
@@ -23,18 +23,7 @@ struct column_data {
/* return length of 's' in letters, ANSI escapes stripped */
static int item_length(const char *s)
{
- int len, i = 0;
- struct strbuf str = STRBUF_INIT;
-
- strbuf_addstr(&str, s);
- while ((s = strstr(str.buf + i, "\033[")) != NULL) {
- int len = strspn(s + 2, "0123456789;");
- i = s - str.buf;
- strbuf_remove(&str, i, len + 3); /* \033[<len><func char> */
- }
- len = utf8_strwidth(str.buf);
- strbuf_release(&str);
- return len;
+ return utf8_strnwidth(s, -1, 1);
}
/*