Last active
May 23, 2024 12:37
Revisions
-
dideler revised this gist
Nov 30, 2018 . 1 changed file with 3 additions and 3 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -5,14 +5,14 @@ Straight-up For example, using a dictionary: ```python ansi = {'underline': '\033[4m', 'bold': '\033[1m', 'end':'\033[0m'} print '{[bold]}Hello World{[end]}'.format(ansi, ansi) ``` Or you can also create a class with enable/disable methods: ```python class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' @@ -39,7 +39,7 @@ Libraries #### [termcolor](http://pypi.python.org/pypi/termcolor) E.g.: ```python from termcolor import colored print colored('hello', 'red'), colored('world', 'green') -
dideler revised this gist
Oct 6, 2012 . No changes.There are no files selected for viewing
-
dideler created this gist
Oct 1, 2012 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,56 @@ Most (or all) of these methods make use of ANSI escape sequences. Straight-up ----------- For example, using a dictionary: ``` ansi = {'underline': '\033[4m', 'bold': '\033[1m', 'end':'\033[0m'} print '{[bold]}Hello World{[end]}'.format(ansi, ansi) ``` Or you can also create a class with enable/disable methods: ``` class bcolors: HEADER = '\033[95m' OKBLUE = '\033[94m' OKGREEN = '\033[92m' WARNING = '\033[93m' FAIL = '\033[91m' ENDC = '\033[0m' def disable(self): self.HEADER = '' self.OKBLUE = '' self.OKGREEN = '' self.WARNING = '' self.FAIL = '' self.ENDC = '' print '{.HEADER}Hello World{.ENDC}'.format(bcolors, bcolors) ``` This will work on *NIX, MacOS, and Windows (provided you enable [ansi.sys](http://support.microsoft.com/kb/101875)). There are ANSI codes for setting the colour, moving the cursor, and more. Libraries --------- #### [termcolor](http://pypi.python.org/pypi/termcolor) E.g.: ``` from termcolor import colored print colored('hello', 'red'), colored('world', 'green') ``` - has minimal Windows support #### [colorama](http://pypi.python.org/pypi/colorama) - has Windows support! #### [blessings](http://pypi.python.org/pypi/blessings/) - no support for Windows command prompt #### [curses](http://docs.python.org/library/curses.html)