cmd2
cmd2 copied to clipboard
async_alert Doesn't Support Color Reset Ansi Sequences on Windows
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:
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:
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.