A console script that allows you to easily update multiple git repositories at once
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

42 řádky
1.3 KiB

  1. # -*- coding: utf-8 -*-
  2. #
  3. # Copyright (C) 2011-2014 Ben Kurtovic <ben.kurtovic@gmail.com>
  4. # See the LICENSE file for details.
  5. import re
  6. __all__ = ["out", "bold", "red", "green", "yellow", "blue"]
  7. # Text formatting functions:
  8. bold = lambda t: _style_text(t, "bold")
  9. red = lambda t: _style_text(t, "red")
  10. green = lambda t: _style_text(t, "green")
  11. yellow = lambda t: _style_text(t, "yellow")
  12. blue = lambda t: _style_text(t, "blue")
  13. def _style_text(text, effect):
  14. """Give a text string a certain effect, such as boldness, or a color."""
  15. ansi = { # ANSI escape codes to make terminal output fancy
  16. "reset": "\x1b[0m",
  17. "bold": "\x1b[1m",
  18. "red": "\x1b[1m\x1b[31m",
  19. "green": "\x1b[1m\x1b[32m",
  20. "yellow": "\x1b[1m\x1b[33m",
  21. "blue": "\x1b[1m\x1b[34m",
  22. }
  23. try: # Pad text with effect, unless effect does not exist
  24. return ansi[effect] + text + ansi["reset"]
  25. except KeyError:
  26. return text
  27. def out(indent, msg):
  28. """Print a message at a given indentation level."""
  29. width = 4 # Amount to indent at each level
  30. if indent == 0:
  31. spacing = "\n"
  32. else:
  33. spacing = " " * width * indent
  34. msg = re.sub(r"\s+", " ", msg) # Collapse multiple spaces into one
  35. print(spacing + msg)