How can I print colored pyfiglet text in windows cmd

5.5k Views Asked by At

Hello so I am using Python and I want to print out the name of the program with color while using figlet_format so I got it working fine in vscode but when I try to run the file in cmd it prints this:

[34m _   _      _ _
| | | | ___| | | ___
| |_| |/ _ \ | |/ _ \
|  _  |  __/ | | (_) |
|_| |_|\___|_|_|\___/

[0m

insted of printing what it prints in vscode:

enter image description here

So I was wondering if there is a way to print color in cmd while using pyfiglet, this is my code:

from termcolor import colored
from pyfiglet import figlet_format

print((colored(figlet_format("Hello"), color="blue")))
2

There are 2 best solutions below

1
Laurent LAPORTE On BEST ANSWER

On Windows, you need to install Colorama.

Makes ANSI escape character sequences (for producing colored terminal text and cursor positioning) work under MS Windows.

0
Edgardo Obregón On

You can also try this new library Printy Just released version 1.2.0 as a cross-platform library.

Check it out: Printy on github

It is based on flags so you can do stuff like

from printy import printy

# with global flags, this will apply a bold (B) red (r) color and an underline (U) to the whole text
printy("Hello world", "rBU")

# with inline formats, this will apply a dim(D)
#blue (b) to the word 'Hello' and a striked (S)
#yellow (y) to the word 'world', the rest will remain as the predefined format
printy("this is a [bD]Hello@ [yS]world@ text")

enter image description here