terminal.py 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright Materialize, Inc. and contributors. All rights reserved.
  2. #
  3. # Use of this software is governed by the Business Source License
  4. # included in the LICENSE file at the root of this repository.
  5. #
  6. # As of the Change Date specified in that file, in accordance with
  7. # the Business Source License, use of this software will be governed
  8. # by the Apache License, Version 2.0.
  9. """Terminal utilities."""
  10. COLOR_GREEN = "\033[92m"
  11. COLOR_RED = "\033[91m"
  12. COLOR_BLUE = "\033[34m"
  13. COLOR_CYAN = "\033[36m"
  14. COLOR_OK = COLOR_GREEN
  15. COLOR_ERROR = COLOR_RED
  16. COLOR_GOOD = COLOR_GREEN
  17. COLOR_BAD = COLOR_RED
  18. STYLE_BOLD = "\033[1m"
  19. _END_FORMATTING = "\033[0m"
  20. def with_formatting(text: str, formatting: str) -> str:
  21. return with_formattings(text, [formatting])
  22. def with_conditional_formatting(text: str, formatting: str, condition: bool) -> str:
  23. if condition:
  24. return with_formatting(text, formatting)
  25. return text
  26. def with_formattings(text: str, formattings: list[str]) -> str:
  27. formatting = "".join(formattings)
  28. return f"{formatting}{text}{_END_FORMATTING}"