From: Junio C Hamano Date: Fri, 11 Oct 2019 01:42:20 GMT Subject: Re: [PATCH 01/11] graph: automatically track visible width of `strbuf` Message-ID: In-Reply-To: <20191010230550.GA42541@generichostname> Denton Liu writes: > static int calculate_width(const struct strbuf *row) > { > int in_termcode = 0; > int width = 0; > int i; > > for (i = 0; i < row.len; i++) { > if (row.buf[i] == '\033') > in_termcode = 1; > > if (!in_termcode) > width++; > else if (row.buf[i] == 'm') > in_termcode = 0; > } > } Not every byte that is outside the escape sequence contributes to one display columns. You would want to take a look at utf8_width() for inspiration.