예제 #1
0
    def unset_option(self, option: str) -> "Style":
        try:
            index = self._options.index(option)
        except IndexError:
            return self

        del self._options[index]

        self._color = Color(self._foreground, self._background, self._options)
예제 #2
0
    def __init__(
        self,
        foreground: Optional[str] = None,
        background: Optional["str"] = None,
        options: Optional[List[str]] = None,
    ) -> None:
        self._foreground = foreground or ""
        self._background = background or ""
        self._options = options or []

        self._color = Color(self._foreground, self._background, self._options)
예제 #3
0
def test_degrade_true_colors(foreground, background, options, expected, environ):
    os.environ["COLORTERM"] = ""

    color = Color(foreground, background, options)

    assert color.apply(" ") == expected
예제 #4
0
def test_true_color_support(foreground, background, options, expected):
    color = Color(foreground, background, options)

    assert color.apply(" ") == expected
예제 #5
0
def test_ansi_colors(foreground, background, options, expected):
    color = Color(foreground, background, options)

    assert color.apply(" ") == expected
예제 #6
0
class Style:
    def __init__(
        self,
        foreground: Optional[str] = None,
        background: Optional["str"] = None,
        options: Optional[List[str]] = None,
    ) -> None:
        self._foreground = foreground or ""
        self._background = background or ""
        self._options = options or []

        self._color = Color(self._foreground, self._background, self._options)

    def foreground(self, foreground: str) -> "Style":
        self._color = Color(foreground, self._background, self._options)
        self._foreground = foreground

        return self

    def background(self, background: str) -> "Style":
        self._color = Color(self._foreground, background, self._options)
        self._background = background

        return self

    def bold(self, bold: bool = True) -> "Style":
        return self.set_option("bold") if bold else self.unset_option("bold")

    def dark(self, dark: bool = True) -> "Style":
        return self.set_option("dark") if dark else self.unset_option("dark")

    def underlines(self, underlined: bool = True) -> "Style":
        return (self.set_option("underline")
                if underlined else self.unset_option("underline"))

    def italic(self, italic: bool = True) -> "Style":
        return self.set_option("italic") if italic else self.unset_option(
            "italic")

    def blinking(self, blinking: bool = True) -> "Style":
        return self.set_option("blink") if blinking else self.unset_option(
            "blink")

    def inverse(self, inverse: bool = True) -> "Style":
        return self.set_option("reverse") if inverse else self.unset_option(
            "reverse")

    def hidden(self, hidden: bool = True) -> "Style":
        return self.set_option("conceal") if hidden else self.unset_option(
            "conceal")

    def set_option(self, option: str) -> "Style":
        self._options.append(option)
        self._color = Color(self._foreground, self._background, self._options)

        return self

    def unset_option(self, option: str) -> "Style":
        try:
            index = self._options.index(option)
        except IndexError:
            return self

        del self._options[index]

        self._color = Color(self._foreground, self._background, self._options)

    def apply(self, text: str) -> str:
        return self._color.apply(text)
예제 #7
0
    def set_option(self, option: str) -> "Style":
        self._options.append(option)
        self._color = Color(self._foreground, self._background, self._options)

        return self
예제 #8
0
    def background(self, background: str) -> "Style":
        self._color = Color(self._foreground, background, self._options)
        self._background = background

        return self