misc.python.materialize.terminal

Terminal utilities.

 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
10"""Terminal utilities."""
11
12
13COLOR_GREEN = "\033[92m"
14COLOR_RED = "\033[91m"
15COLOR_BLUE = "\033[34m"
16COLOR_CYAN = "\033[36m"
17COLOR_OK = COLOR_GREEN
18COLOR_ERROR = COLOR_RED
19COLOR_GOOD = COLOR_GREEN
20COLOR_BAD = COLOR_RED
21STYLE_BOLD = "\033[1m"
22_END_FORMATTING = "\033[0m"
23
24
25def with_formatting(text: str, formatting: str) -> str:
26    return with_formattings(text, [formatting])
27
28
29def with_conditional_formatting(text: str, formatting: str, condition: bool) -> str:
30    if condition:
31        return with_formatting(text, formatting)
32
33    return text
34
35
36def with_formattings(text: str, formattings: list[str]) -> str:
37    formatting = "".join(formattings)
38    return f"{formatting}{text}{_END_FORMATTING}"
COLOR_GREEN = '\x1b[92m'
COLOR_RED = '\x1b[91m'
COLOR_BLUE = '\x1b[34m'
COLOR_CYAN = '\x1b[36m'
COLOR_OK = '\x1b[92m'
COLOR_ERROR = '\x1b[91m'
COLOR_GOOD = '\x1b[92m'
COLOR_BAD = '\x1b[91m'
STYLE_BOLD = '\x1b[1m'
def with_formatting(text: str, formatting: str) -> str:
26def with_formatting(text: str, formatting: str) -> str:
27    return with_formattings(text, [formatting])
def with_conditional_formatting(text: str, formatting: str, condition: bool) -> str:
30def with_conditional_formatting(text: str, formatting: str, condition: bool) -> str:
31    if condition:
32        return with_formatting(text, formatting)
33
34    return text
def with_formattings(text: str, formattings: list[str]) -> str:
37def with_formattings(text: str, formattings: list[str]) -> str:
38    formatting = "".join(formattings)
39    return f"{formatting}{text}{_END_FORMATTING}"