tmux_styler.Colors
tmux supported color types.
1""" 2tmux supported color types. 3""" 4 5from enum import Enum 6import re 7import abc 8 9 10class Color(metaclass=abc.ABCMeta): 11 """ 12 An abstract base class for all colors. 13 """ 14 15 @abc.abstractmethod 16 def __str__(self) -> str: 17 """ 18 Returns the string representation of the Color object. 19 """ 20 pass 21 22 23class Color256(Color): 24 """ 25 Represents an Xterm color value in the range of 0 to 255. 26 See: https://www.ditig.com/256-colors-cheat-sheet/ 27 28 Attributes: 29 ----------- 30 `value`: int 31 The integer value of the color. 32 33 Raises: 34 ------- 35 ValueError: 36 If the value is less than 0 or greater than 255. 37 """ 38 39 def __init__(self, value: int): 40 """ 41 Initializes a new instance of Color256. 42 43 Parameters: 44 ---------- 45 `value`: int 46 The integer value of the color. 47 """ 48 if value < 0 or value > 255: 49 raise ValueError('Color256 value must be between 0 and 255') 50 self.value = value 51 52 def __str__(self) -> str: 53 """ 54 Returns the string representation of the Color256 object. 55 """ 56 return f"colour{str(self.value)}" 57 58 59class HexColor(Color): 60 """ 61 Represents a hexadecimal color code in the format #RRGGBB. 62 63 Attributes: 64 ----------- 65 `value`: str 66 The hexadecimal color code. 67 68 Raises: 69 ------- 70 ValueError: 71 If the hex code is not in the format #RRGGBB. 72 """ 73 74 def __init__(self, hex: str): 75 """ 76 Initializes a new instance of HexColor. 77 78 Parameters: 79 ---------- 80 `hex`: str 81 The hexadecimal color code. 82 """ 83 HEX_COLOR_REGEX = re.compile(r'^#[0-9a-fA-F]{6}$') 84 if not HEX_COLOR_REGEX.match(hex): 85 raise ValueError( 86 'HexColor value is not a valid hexadecimal color code') 87 self.value = hex 88 89 def __str__(self) -> str: 90 """ 91 Returns the string representation of the HexColor object. 92 """ 93 return "#" + self.value 94 95 96class _NamedColorMeta(type(Color), type(Enum)): 97 pass 98 99 100class NamedColor(Color, Enum, metaclass=_NamedColorMeta): 101 """ 102 An enumeration of valid named colors. 103 104 TERMINAL and DEFAULT are special values. 105 TERMINAL will appear transparent when used as a background color and as your terminal's text color when used as a foreground color. 106 DEFAULT will use the default background or foreground color of the statusbar. 107 """ 108 BLACK = "black" 109 RED = "red" 110 GREEN = "green" 111 YELLOW = "yellow" 112 BLUE = "blue" 113 MAGENTA = "magenta" 114 CYAN = "cyan" 115 WHITE = "white" 116 TERMINAL = "terminal" 117 DEFAULT = "default" 118 119 def __str__(self) -> str: 120 """ 121 Returns the string representation of a named color. 122 """ 123 return self.value
11class Color(metaclass=abc.ABCMeta): 12 """ 13 An abstract base class for all colors. 14 """ 15 16 @abc.abstractmethod 17 def __str__(self) -> str: 18 """ 19 Returns the string representation of the Color object. 20 """ 21 pass
An abstract base class for all colors.
24class Color256(Color): 25 """ 26 Represents an Xterm color value in the range of 0 to 255. 27 See: https://www.ditig.com/256-colors-cheat-sheet/ 28 29 Attributes: 30 ----------- 31 `value`: int 32 The integer value of the color. 33 34 Raises: 35 ------- 36 ValueError: 37 If the value is less than 0 or greater than 255. 38 """ 39 40 def __init__(self, value: int): 41 """ 42 Initializes a new instance of Color256. 43 44 Parameters: 45 ---------- 46 `value`: int 47 The integer value of the color. 48 """ 49 if value < 0 or value > 255: 50 raise ValueError('Color256 value must be between 0 and 255') 51 self.value = value 52 53 def __str__(self) -> str: 54 """ 55 Returns the string representation of the Color256 object. 56 """ 57 return f"colour{str(self.value)}"
Represents an Xterm color value in the range of 0 to 255. See: https://www.ditig.com/256-colors-cheat-sheet/
Attributes:
value
: int
The integer value of the color.
Raises:
ValueError: If the value is less than 0 or greater than 255.
60class HexColor(Color): 61 """ 62 Represents a hexadecimal color code in the format #RRGGBB. 63 64 Attributes: 65 ----------- 66 `value`: str 67 The hexadecimal color code. 68 69 Raises: 70 ------- 71 ValueError: 72 If the hex code is not in the format #RRGGBB. 73 """ 74 75 def __init__(self, hex: str): 76 """ 77 Initializes a new instance of HexColor. 78 79 Parameters: 80 ---------- 81 `hex`: str 82 The hexadecimal color code. 83 """ 84 HEX_COLOR_REGEX = re.compile(r'^#[0-9a-fA-F]{6}$') 85 if not HEX_COLOR_REGEX.match(hex): 86 raise ValueError( 87 'HexColor value is not a valid hexadecimal color code') 88 self.value = hex 89 90 def __str__(self) -> str: 91 """ 92 Returns the string representation of the HexColor object. 93 """ 94 return "#" + self.value
Represents a hexadecimal color code in the format #RRGGBB.
Attributes:
value
: str
The hexadecimal color code.
Raises:
ValueError: If the hex code is not in the format #RRGGBB.
75 def __init__(self, hex: str): 76 """ 77 Initializes a new instance of HexColor. 78 79 Parameters: 80 ---------- 81 `hex`: str 82 The hexadecimal color code. 83 """ 84 HEX_COLOR_REGEX = re.compile(r'^#[0-9a-fA-F]{6}$') 85 if not HEX_COLOR_REGEX.match(hex): 86 raise ValueError( 87 'HexColor value is not a valid hexadecimal color code') 88 self.value = hex
Initializes a new instance of HexColor.
Parameters:
hex
: str
The hexadecimal color code.
101class NamedColor(Color, Enum, metaclass=_NamedColorMeta): 102 """ 103 An enumeration of valid named colors. 104 105 TERMINAL and DEFAULT are special values. 106 TERMINAL will appear transparent when used as a background color and as your terminal's text color when used as a foreground color. 107 DEFAULT will use the default background or foreground color of the statusbar. 108 """ 109 BLACK = "black" 110 RED = "red" 111 GREEN = "green" 112 YELLOW = "yellow" 113 BLUE = "blue" 114 MAGENTA = "magenta" 115 CYAN = "cyan" 116 WHITE = "white" 117 TERMINAL = "terminal" 118 DEFAULT = "default" 119 120 def __str__(self) -> str: 121 """ 122 Returns the string representation of a named color. 123 """ 124 return self.value
An enumeration of valid named colors.
TERMINAL and DEFAULT are special values. TERMINAL will appear transparent when used as a background color and as your terminal's text color when used as a foreground color. DEFAULT will use the default background or foreground color of the statusbar.
Inherited Members
- enum.Enum
- name
- value