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

Why don't I get any colored text on windows #4

Closed
rookiebulls opened this issue Jan 24, 2017 · 4 comments
Closed

Why don't I get any colored text on windows #4

rookiebulls opened this issue Jan 24, 2017 · 4 comments
Labels

Comments

@rookiebulls
Copy link

I have to use colorama to "init" before using crayons to output some colored text on windows, otherwise the console just output some ANSI code, without any color.

@caizixian
Copy link
Contributor

Could you please paste your code and elaborate on the environment you use (which terminal, etc)

@rookiebulls
Copy link
Author

rookiebulls commented Feb 16, 2017

@caizixian I am using cmd.exe on Windows 7, just some test code in the python shell.

>>>import crayons
>>>print crayons.red('this is red')
>>>here output some ANSI code
>>>import colorama
>>>colorama.init()
>>>print crayons.red('this is red')
>>>now it output some red color text

Please see the image below.
p70213-081923

@caizixian
Copy link
Contributor

caizixian commented Feb 16, 2017

cmd.exe of Windows 7 doesn't support ANSI escape sequences.

This topic on superuser might helps if you want these be intepreted by cmd.exe natively http://superuser.com/questions/413073/windows-console-with-ansi-colors-handling/

So pure crayons might not works under cmd.exe of Windows 7.

However according to the documentation of colorama

This has the upshot of providing a simple cross-platform API for printing colored terminal text from Python, and has the happy side-effect that existing applications or libraries which use ANSI sequences to produce colored output on Linux or Macs can now also work on Windows, simply by calling colorama.init().

Yes, calling colorama.init() will convert subsequent ANSI sequences to corresponding win32 calls, and therefore make crayons work again.

@kennethreitz any idea on this?

@MasterOdin
Copy link
Collaborator

This was fixed with #12.

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

No branches or pull requests

4 participants