I process input (from sources such as ls -la --color, for example) and underline certain sections of the text. I donโt process these inputs character-by-character, but with a lot of regular expressions, which makes it difficult to keep track of the fact that the substring that I am affecting is already colored or in bold. If I have a red block of text, and I want to emphasize part of it, I could do something like:
s/(123)/\033[4m\1\033[0m/g
(My expressions are much more complex, in fact, received, processed by themselves, and then broken and analyzed. This is not something that can be done by changing the expression specified here.)
The code above will replace all 123 cases with [UNDERLINE_START] 123 [FORMAT_RESET]. Unfortunately, reset also disables text coloring. This would save me a big headache if I could just turn off the underline when that's all I want to turn off, but I'm sure there is no way to do this. Can someone tell me I'm wrong?
EDIT: I could simplify the question by asking: if I want to turn off the underline, can I do this without affecting the current color of the text, since that color could have been set long before my script even started to run, and I have no way determine what color is it?
source share