Skip to content

Instantly share code, notes, and snippets.

@clementsjj
Last active January 10, 2020 16:23
Show Gist options
  • Select an option

  • Save clementsjj/c0184c58df7661ff2ee3920b4bdad9bf to your computer and use it in GitHub Desktop.

Select an option

Save clementsjj/c0184c58df7661ff2ee3920b4bdad9bf to your computer and use it in GitHub Desktop.

Revisions

  1. clementsjj revised this gist Jan 10, 2020. 1 changed file with 24 additions and 1 deletion.
    25 changes: 24 additions & 1 deletion colorize-python.py
    Original file line number Diff line number Diff line change
    @@ -13,4 +13,27 @@ def colorize(color, text):
    return colortext

    print(colorize(f['red'], 'Hello, World!')
    # Hello, World! (In Red)
    # Hello, World! (In Red)


    # Alternatively, a function wrapper for each specific color can easily be dropped into any project...
    def red(text):
    # Will print in Red
    colortext = f'\033[31m{text}\033[00m'
    return colortext


    def blue(text):
    # Will Print in Blue
    colortext = f'\033[34m{text}\033[00m'
    return colortext


    def magenta(text):
    colortext = f'\033[35m{text}\033[00m'
    return colortext


    def cyan(text):
    colortext = f'\033[36m{text}\033[00m'
    return colortext
  2. clementsjj created this gist Dec 4, 2019.
    16 changes: 16 additions & 0 deletions colorize-python.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,16 @@
    f = {'red':'31m',
    'green':'32m',
    'yellow':'33m',
    'blue':'34m',
    'magenta':'35m',
    'cyan':'36m',
    'lightgray':'37m',
    'darkgray':'90m',
    'white':'97m'}

    def colorize(color, text):
    colortext=f'\033[{color}{text}\033[00m'
    return colortext

    print(colorize(f['red'], 'Hello, World!')
    # Hello, World! (In Red)