cmd2 icon indicating copy to clipboard operation
cmd2 copied to clipboard

async_alert Doesn't Support Color Reset Ansi Sequences on Windows

Open Chris3606 opened this issue 1 year ago • 4 comments

Steps to Reproduce

Color reset sequences (reset foreground, reset background), etc. do not work on Windows when using async_alert.

Given the following (baseline) code:

from cmd2 import Cmd, Fg, style


class App(Cmd):
    def do_print(self, _):
        self.poutput(style("Hello ", fg=Fg.BLUE) + style("World"))

app = App()
app.cmdloop()

We can generate sensible colored output: image

However, if we take the async printing example and change the first item in the ALERTS array to: style("Hello ", fg=Fg.BLUE) + style("World") (the same text we used in the original example, it fails rather spectacularly:

image

Notes

I believe this is due to a limitation and/or bug in pyreadline3. Its printing function does not support the color escape sequences at all (only 0, the global reset).

Adding support for the escape sequences is fairly trivial (I plan to ensure a PR is submitted to pyreadline for it).

Given that cmd2 is already extending pyreadline3, however, I wanted to submit for consideration that it may be possible to support this via additions to rl_utils. I plan to investigate this further.

Chris3606 avatar Jul 02 '24 21:07 Chris3606