Last active
June 26, 2020 14:44
-
-
Save trongnghia203/c65d5d12d82b0ccaeb8c67f412783821 to your computer and use it in GitHub Desktop.
Python: Print colored text
This file contains 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 characters
#!/usr/bin/env python | |
# Author: Nghia Le <trongnghia203@gmail.com> | |
# Description: | |
# - Yes/[No] Confirm to exit bash script | |
# | |
import os | |
def _wrap_with(code): | |
def inner(text, bold=True): | |
c = code | |
# if os.environ.get('FABRIC_DISABLE_COLORS'): | |
# return text | |
if bold: | |
c = "1;%s" % c | |
return "\033[%sm%s\033[0m" % (c, text) | |
return inner | |
red = _wrap_with('31') | |
green = _wrap_with('32') | |
yellow = _wrap_with('33') | |
blue = _wrap_with('34') | |
magenta = _wrap_with('35') | |
cyan = _wrap_with('36') | |
white = _wrap_with('37') | |
def print_sample(): | |
print(red('This is a red colored text')) | |
print(green('This is a green colored text')) | |
print(yellow('This is a yellow colored text')) | |
print(magenta('This is a magenta colored text')) | |
print(cyan('This is a cyan colored text')) | |
print(white('This is a white colored text')) | |
if __name__ == "__main__": | |
print_sample() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment