From: Trans Date: 2008-12-06T06:54:10+09:00 Subject: Re: AnsiString (#185) > Make a subclass of String (or delegate) that tracks "embedded" ANSI   > codes along with the text. The class should add methods for wrapping   > the text in ANSI codes. Implement as much of the core String API as   > possible. So for example: > >     s1 = AnsiString.new("Hi") >     s2 = AnsiString.new("there!) > >     s1.red    # wrap text in red/escape ANSI codes >     s1.blue   # wrap text in blue/escape ANSI codes Make that 's2.blue'. >     s3 = s1 + ' ' + s2  #=> New AnsiString >     s3.to_str           #=> "\e[31mHi\e[0m \e[34mthere!\e[0m" I've found it pretty challenging to keep the ANSI codes in sync with the text while still being able to manipulate the text like a normal string. I'm curious to see how other people approach it. T.