tmux_styler.Style

tmux styling options.

  1"""
  2tmux styling options.
  3"""
  4
  5from enum import Enum
  6from typing import List
  7from tmux_styler.Colors import Color
  8
  9
 10class TextAttributes(Enum):
 11    """
 12    Text attributes to apply to text.
 13
 14    Attributes:
 15    -----------
 16    `ACS`: Use the terminal alternate character set.
 17
 18    `BRIGHT`: Make the text brighter.
 19    
 20    `BOLD`: Make the text bold.
 21    
 22    `DIM`: Make the text dimmer.
 23    
 24    `UNDERSCORE`: Underline the text.
 25    
 26    `BLINK`: Make the text blink.
 27    
 28    `REVERSE`: Reverse the background and text colors.
 29    
 30    `HIDDEN`: Hide the text.
 31    
 32    `ITALICS`: Make the text italicized.
 33    
 34    `OVERLINE`: Overline the text.
 35    
 36    `STRIKETHROUGH`: Draw a line through the text.
 37    
 38    `DOUBLE_UNDERSCORE`: Double underline the text.
 39    
 40    `CURLY_UNDERSCORE`: Curly underline the text.
 41    
 42    `DOTTED_UNDERSCORE`: Dotted underline the text.
 43    
 44    `DASHED_UNDERSCORE`: Dashed underline the text.
 45    """
 46
 47    ACS = "acs"
 48    """The terminal alternate character set."""
 49    BRIGHT = "bright"
 50    """Make the text brighter."""
 51    BOLD = "bold"
 52    """Make the text bold."""
 53    DIM = "dim"
 54    """Make the text dimmer."""
 55    UNDERSCORE = "underscore"
 56    """Underline the text."""
 57    BLINK = "blink"
 58    """Make the text blink."""
 59    REVERSE = "reverse"
 60    """Reverse the background and text colors."""
 61    HIDDEN = "hidden"
 62    """Hide the text."""
 63    ITALICS = "italics"
 64    """Make the text italicized."""
 65    OVERLINE = "overline"
 66    """Overline the text."""
 67    STRIKETHROUGH = "strikethrough"
 68    """Draw a line through the text."""
 69    DOUBLE_UNDERSCORE = "double-underscore"
 70    """Double underline the text."""
 71    CURLY_UNDERSCORE = "curly-underscore"
 72    """Curly underline the text."""
 73    DOTTED_UNDERSCORE = "dotted-underscore"
 74    """Dotted underline the text."""
 75    DASHED_UNDERSCORE = "dashed-underscore"
 76    """Dashed underline the text."""
 77
 78    def __str__(self):
 79        """
 80        Returns the string representation of the attribute.
 81        """
 82        return self.value
 83
 84
 85class Style:
 86    """
 87    Represents a tmux style.
 88
 89    Attributes:
 90    -----------
 91    `fg`: Color | None
 92        The foreground color, none will default to the inherited color. (default: None)
 93
 94    `bg`: Color | None
 95        The background color, none will default to the inherited color. (default: None)
 96
 97    `attrs`: List[TextAttributes] | None
 98        The text attributes to apply to the text. (default: None)
 99
100    `unset_attrs`: List[TextAttributes] | None
101        The text attributes to unset from the text. This will override any attributes
102        set in attrs. You may want to unset attributes that you've set by default. (default: None)
103    """
104
105    def __init__(self, bg: Color | None = None, fg: Color | None = None,  attrs: List[TextAttributes] | None = None, unset_attrs: List[TextAttributes] | None = None):
106        """
107        Creates a style for use with tmux.
108        """
109        self.fg = fg
110        self.bg = bg
111        self.attrs = attrs
112        self.unset_attrs = unset_attrs
113
114    def __str__(self) -> str:
115        """
116        Returns the format string representation of the entire style.
117        """
118        bg = "" if self.bg is None else "bg={}".format(self.bg)
119        fg = "" if self.fg is None else "fg={}".format(self.fg)
120        attrs = "" if self.attrs is None else f"{' '.join(map(str, self.attrs))}"
121        unset_attrs = "" if self.unset_attrs is None else f"{' '.join(map(lambda x: f'no{str(x)}', self.unset_attrs))}"
122        return ",".join(
123            filter(lambda x: x != "", [fg, bg, attrs, unset_attrs]))
124
125    def apply(self) -> str:
126        """
127        Returns a string that applies all of the attributes in the style (attrs, unset_attrs, and alignment).
128        """
129        attrs = "" if self.attrs is None else f"{' '.join(map(str, self.attrs))}"
130        unset_attrs = "" if self.unset_attrs is None else f"{' '.join(map(lambda x: f'no{str(x)}', self.unset_attrs))}"
131        return ",".join(
132            filter(lambda x: x != "", [attrs, unset_attrs]))
class TextAttributes(enum.Enum):
11class TextAttributes(Enum):
12    """
13    Text attributes to apply to text.
14
15    Attributes:
16    -----------
17    `ACS`: Use the terminal alternate character set.
18
19    `BRIGHT`: Make the text brighter.
20    
21    `BOLD`: Make the text bold.
22    
23    `DIM`: Make the text dimmer.
24    
25    `UNDERSCORE`: Underline the text.
26    
27    `BLINK`: Make the text blink.
28    
29    `REVERSE`: Reverse the background and text colors.
30    
31    `HIDDEN`: Hide the text.
32    
33    `ITALICS`: Make the text italicized.
34    
35    `OVERLINE`: Overline the text.
36    
37    `STRIKETHROUGH`: Draw a line through the text.
38    
39    `DOUBLE_UNDERSCORE`: Double underline the text.
40    
41    `CURLY_UNDERSCORE`: Curly underline the text.
42    
43    `DOTTED_UNDERSCORE`: Dotted underline the text.
44    
45    `DASHED_UNDERSCORE`: Dashed underline the text.
46    """
47
48    ACS = "acs"
49    """The terminal alternate character set."""
50    BRIGHT = "bright"
51    """Make the text brighter."""
52    BOLD = "bold"
53    """Make the text bold."""
54    DIM = "dim"
55    """Make the text dimmer."""
56    UNDERSCORE = "underscore"
57    """Underline the text."""
58    BLINK = "blink"
59    """Make the text blink."""
60    REVERSE = "reverse"
61    """Reverse the background and text colors."""
62    HIDDEN = "hidden"
63    """Hide the text."""
64    ITALICS = "italics"
65    """Make the text italicized."""
66    OVERLINE = "overline"
67    """Overline the text."""
68    STRIKETHROUGH = "strikethrough"
69    """Draw a line through the text."""
70    DOUBLE_UNDERSCORE = "double-underscore"
71    """Double underline the text."""
72    CURLY_UNDERSCORE = "curly-underscore"
73    """Curly underline the text."""
74    DOTTED_UNDERSCORE = "dotted-underscore"
75    """Dotted underline the text."""
76    DASHED_UNDERSCORE = "dashed-underscore"
77    """Dashed underline the text."""
78
79    def __str__(self):
80        """
81        Returns the string representation of the attribute.
82        """
83        return self.value

Text attributes to apply to text.

Attributes:

ACS: Use the terminal alternate character set.

BRIGHT: Make the text brighter.

BOLD: Make the text bold.

DIM: Make the text dimmer.

UNDERSCORE: Underline the text.

BLINK: Make the text blink.

REVERSE: Reverse the background and text colors.

HIDDEN: Hide the text.

ITALICS: Make the text italicized.

OVERLINE: Overline the text.

STRIKETHROUGH: Draw a line through the text.

DOUBLE_UNDERSCORE: Double underline the text.

CURLY_UNDERSCORE: Curly underline the text.

DOTTED_UNDERSCORE: Dotted underline the text.

DASHED_UNDERSCORE: Dashed underline the text.

ACS = <TextAttributes.ACS: 'acs'>

The terminal alternate character set.

BRIGHT = <TextAttributes.BRIGHT: 'bright'>

Make the text brighter.

BOLD = <TextAttributes.BOLD: 'bold'>

Make the text bold.

DIM = <TextAttributes.DIM: 'dim'>

Make the text dimmer.

UNDERSCORE = <TextAttributes.UNDERSCORE: 'underscore'>

Underline the text.

REVERSE = <TextAttributes.REVERSE: 'reverse'>

Reverse the background and text colors.

HIDDEN = <TextAttributes.HIDDEN: 'hidden'>

Hide the text.

ITALICS = <TextAttributes.ITALICS: 'italics'>

Make the text italicized.

OVERLINE = <TextAttributes.OVERLINE: 'overline'>

Overline the text.

STRIKETHROUGH = <TextAttributes.STRIKETHROUGH: 'strikethrough'>

Draw a line through the text.

DOUBLE_UNDERSCORE = <TextAttributes.DOUBLE_UNDERSCORE: 'double-underscore'>

Double underline the text.

CURLY_UNDERSCORE = <TextAttributes.CURLY_UNDERSCORE: 'curly-underscore'>

Curly underline the text.

DOTTED_UNDERSCORE = <TextAttributes.DOTTED_UNDERSCORE: 'dotted-underscore'>

Dotted underline the text.

DASHED_UNDERSCORE = <TextAttributes.DASHED_UNDERSCORE: 'dashed-underscore'>

Dashed underline the text.

Inherited Members
enum.Enum
name
value
class Style:
 86class Style:
 87    """
 88    Represents a tmux style.
 89
 90    Attributes:
 91    -----------
 92    `fg`: Color | None
 93        The foreground color, none will default to the inherited color. (default: None)
 94
 95    `bg`: Color | None
 96        The background color, none will default to the inherited color. (default: None)
 97
 98    `attrs`: List[TextAttributes] | None
 99        The text attributes to apply to the text. (default: None)
100
101    `unset_attrs`: List[TextAttributes] | None
102        The text attributes to unset from the text. This will override any attributes
103        set in attrs. You may want to unset attributes that you've set by default. (default: None)
104    """
105
106    def __init__(self, bg: Color | None = None, fg: Color | None = None,  attrs: List[TextAttributes] | None = None, unset_attrs: List[TextAttributes] | None = None):
107        """
108        Creates a style for use with tmux.
109        """
110        self.fg = fg
111        self.bg = bg
112        self.attrs = attrs
113        self.unset_attrs = unset_attrs
114
115    def __str__(self) -> str:
116        """
117        Returns the format string representation of the entire style.
118        """
119        bg = "" if self.bg is None else "bg={}".format(self.bg)
120        fg = "" if self.fg is None else "fg={}".format(self.fg)
121        attrs = "" if self.attrs is None else f"{' '.join(map(str, self.attrs))}"
122        unset_attrs = "" if self.unset_attrs is None else f"{' '.join(map(lambda x: f'no{str(x)}', self.unset_attrs))}"
123        return ",".join(
124            filter(lambda x: x != "", [fg, bg, attrs, unset_attrs]))
125
126    def apply(self) -> str:
127        """
128        Returns a string that applies all of the attributes in the style (attrs, unset_attrs, and alignment).
129        """
130        attrs = "" if self.attrs is None else f"{' '.join(map(str, self.attrs))}"
131        unset_attrs = "" if self.unset_attrs is None else f"{' '.join(map(lambda x: f'no{str(x)}', self.unset_attrs))}"
132        return ",".join(
133            filter(lambda x: x != "", [attrs, unset_attrs]))

Represents a tmux style.

Attributes:

fg: Color | None The foreground color, none will default to the inherited color. (default: None)

bg: Color | None The background color, none will default to the inherited color. (default: None)

attrs: List[TextAttributes] | None The text attributes to apply to the text. (default: None)

unset_attrs: List[TextAttributes] | None The text attributes to unset from the text. This will override any attributes set in attrs. You may want to unset attributes that you've set by default. (default: None)

Style( bg: tmux_styler.Colors.Color | None = None, fg: tmux_styler.Colors.Color | None = None, attrs: Optional[List[TextAttributes]] = None, unset_attrs: Optional[List[TextAttributes]] = None)
106    def __init__(self, bg: Color | None = None, fg: Color | None = None,  attrs: List[TextAttributes] | None = None, unset_attrs: List[TextAttributes] | None = None):
107        """
108        Creates a style for use with tmux.
109        """
110        self.fg = fg
111        self.bg = bg
112        self.attrs = attrs
113        self.unset_attrs = unset_attrs

Creates a style for use with tmux.

fg
bg
attrs
unset_attrs
def apply(self) -> str:
126    def apply(self) -> str:
127        """
128        Returns a string that applies all of the attributes in the style (attrs, unset_attrs, and alignment).
129        """
130        attrs = "" if self.attrs is None else f"{' '.join(map(str, self.attrs))}"
131        unset_attrs = "" if self.unset_attrs is None else f"{' '.join(map(lambda x: f'no{str(x)}', self.unset_attrs))}"
132        return ",".join(
133            filter(lambda x: x != "", [attrs, unset_attrs]))

Returns a string that applies all of the attributes in the style (attrs, unset_attrs, and alignment).