Determine the print-size of a string containing escape characters

  ansi-escape, c++

I’m trying to make a progress bar which would resize according to the space left on screen. The progress bar consist of a title string followed by the bar and few trailing numbers:

15:23:11 [SampleElement] SampleElement.cpp:25: Finding bin index... [###########] 100% (14K it/s)

In principle this is a pretty straight forward task since the print-size can be directly deduced by the size of the title + the size of the pBar.

However when the title string contains escape characters (like colors for example) doing title.size() does not only returns the printed size on screen, but also the non printed characters. My question is: Is there a way we can simply compute the print-size of any string?

Source: Windows Questions C++

LEAVE A COMMENT