color_printing.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. from functools import wraps
  2. import time
  3. def cprint(text_in: str, color: str):
  4. """[summary]
  5. Args:
  6. text_in (str): Any text string you want to print.
  7. color (str): 'dark_gray', 'r', 'g', 'y', 'b', 'p', 'c', 'gray'
  8. """
  9. color_dict = {'dark_gray': '30', 'r': '31', 'g': '32',
  10. 'y': '33', 'b': '34', 'p': '35', 'c': '36', 'gray': '37'}
  11. header = f'\033[1;{color_dict[color]}m'
  12. end = '\033[0m'
  13. print(header+text_in+end)
  14. def cstr(text_in: str, color: str):
  15. """[summary]
  16. Args:
  17. text_in (str): Any text string you want to return with color.
  18. color (str): 'dark_gray', 'r', 'g', 'y', 'b', 'p', 'c', 'gray'
  19. """
  20. color_dict = {'dark_gray': '30', 'r': '31', 'g': '32',
  21. 'y': '33', 'b': '34', 'p': '35', 'c': '36', 'gray': '37'}
  22. header = f'\033[1;{color_dict[color]}m'
  23. end = '\033[0m'
  24. return header+text_in+end
  25. INFO = "INFO"
  26. WARNING = "WARNING"
  27. ERROR = "ERROR"
  28. STATUS = "STATUS"
  29. def log_print(p_type: str, text_in):
  30. """Print colorful log message on screen
  31. Args:
  32. p_type (str): Three types: INFO, WARNING, ERROR
  33. text_in (str): Any text message you want to print.
  34. """
  35. type_dict: dict = {"INFO": 'y', "WARNING": 'b',
  36. "ERROR": 'r', "STATUS": 'c'}
  37. cprint('\n'+p_type+': '+text_in, type_dict[p_type])