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

Fix terminal colors not displaying properly on Windows #424

Merged
merged 2 commits into from Nov 30, 2018
Merged

Fix terminal colors not displaying properly on Windows #424

merged 2 commits into from Nov 30, 2018

Conversation

GhostofGoes
Copy link
Contributor

Currently, text colors do not render if using bandit in a Windows terminal interface (both PowerShell and CMD).

Example:
bandit_old_bad_colors

This PR resolves that issue by patching stdout using colorama when running on Windows. Colorama will intercept any ANSI escape codes and convert them to the proper Windows console API calls to change text color (as far as I understand it at least, I'm not a colorama developer).

Example with the fix applied:
bandit_new_good_colors

Caveats: this adds a dependency on colorama for Windows. It is a very common dependency for Windows Python programs with a CLI interface, is actively maintained, and is licensed under BSD-3.

Copy link
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we'd have a CI env running on Windows to test for any breakage there. But Travis-CI for Windows is beta at best.

I applied these changes and tested on Windows 2012 Server command prompt and see the colors now.

@ericwb ericwb merged commit 40988fd into PyCQA:master Nov 30, 2018
@GhostofGoes
Copy link
Contributor Author

GhostofGoes commented Nov 30, 2018

Might want to look into Appveyor, it's like TravisCI but for Windows specifically. And like Travis, it's free for open-source.

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 this pull request may close these issues.

None yet

2 participants