Fork of the espurna firmware for `mhsw` switches
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB

  1. from __future__ import print_function
  2. import os
  3. import sys
  4. class Color(object):
  5. BOLD = "\x1b[1;1m"
  6. BLACK = "\x1b[1;30m"
  7. RED = "\x1b[1;31m"
  8. GREEN = "\x1b[1;32m"
  9. YELLOW = "\x1b[1;33m"
  10. BLUE = "\x1b[1;34m"
  11. MAGENTA = "\x1b[1;35m"
  12. CYAN = "\x1b[1;36m"
  13. WHITE = "\x1b[1;37m"
  14. LIGHT_GREY = "\x1b[0;30m"
  15. LIGHT_RED = "\x1b[0;31m"
  16. LIGHT_GREEN = "\x1b[0;32m"
  17. LIGHT_YELLOW = "\x1b[0;33m"
  18. LIGHT_BLUE = "\x1b[0;34m"
  19. LIGHT_MAGENTA = "\x1b[0;35m"
  20. LIGHT_CYAN = "\x1b[0;36m"
  21. LIGHT_WHITE = "\x1b[0;37m"
  22. def clr(color, text):
  23. return color + str(text) + "\x1b[0m"
  24. def print_warning(message, color=Color.LIGHT_YELLOW):
  25. print(clr(color, message), file=sys.stderr)
  26. def print_filler(fill, color=Color.WHITE, err=False, width_default=80):
  27. width = width_default
  28. try:
  29. width = int(os.environ["COLUMNS"])
  30. except (KeyError, ValueError):
  31. pass
  32. if len(fill) > 1:
  33. fill = fill[0]
  34. out = sys.stderr if err else sys.stdout
  35. print(clr(color, fill * width), file=out)