Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Colorama with internal solution for windows legacy mode #1991

Closed
willmcgugan opened this issue Feb 22, 2022 · 1 comment · Fixed by #1993
Closed

Replace Colorama with internal solution for windows legacy mode #1991

willmcgugan opened this issue Feb 22, 2022 · 1 comment · Fixed by #1993
Assignees

Comments

@willmcgugan
Copy link
Collaborator

willmcgugan commented Feb 22, 2022

Colorama is a wonderful hack that wraps stdout to process ansi codes. It is problematic today because it is essentially a global setting and interferes with the ability to enable ansi escape sequences with newer Windows.

We should replace Colorama with equivalent functionality within Rich itself that generates the appropriate win32 api calls. This will hopefully be a little faster, and give us much more granular control over when to enable it.

I think we can do this at the Segment level. In Console, there is a _render_buffer method which renders segments in to text with ansi codes. I think we can generate the appropriate calls to the win32 api call here, if self.legacy_windows is True.

Since the win32 calls are only available on Windows, this should probably implemented within a conditional import. Perhaps _windows_renderer.py

See the Win32 docs for a reference on the appropriate API calls. It may also be worth referring to the colorama source.

https://docs.microsoft.com/en-us/windows/console/console-screen-buffers#character-attributes

I suggested we might have to process ansi codes to extract the win32 calls. On reflection I don't think we will need this. There is enough information in the Segment object that we don't need to parse anything. This should make it significantly faster.

@github-actions
Copy link

github-actions bot commented Mar 9, 2022

Did I solve your problem?

Why not buy the devs a coffee to say thanks?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants