kennethreitz / crayons

Text UI colors for Python.
https://pypi.python.org/pypi/crayons
MIT License
424 stars 30 forks source link

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

Closed rookiebulls closed 4 years ago

rookiebulls commented 7 years ago

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 commented 7 years ago

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

rookiebulls commented 7 years ago

@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 commented 7 years ago

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 commented 4 years ago

This was fixed with #12.