tmux_styler.Statusbar.Statusbar
1from enum import Enum 2from typing import Any, Dict 3import pickle 4 5from .WindowList import WindowList 6from ..Style import * 7from ..Colors import * 8from ..ContextVars import * 9from .Segment import Segment 10 11 12class SegmentSeparator: 13 """ 14 A segment separator is a character that is displayed between segments. 15 16 Attributes: 17 ----------- 18 `left_thick`: str 19 The left thick separator, used for separating between segments. 20 21 `right_thick`: str 22 The right thick separator, used for separating between segments. 23 24 `left_thin`: str 25 The left thin separator, used for separating between segments of the same background color. 26 27 `right_thin`: str 28 The right thin separator, used for separating between segments of the same background color. 29 """ 30 31 def __init__(self, right_thick: str, left_thick: str, right_thin: str, left_thin: str): 32 """ 33 Creates a SegmentSeparator object. 34 35 Parameters: 36 ----------- 37 `right_thick`: str 38 The "pointing" right thick separator, used for separating between segments. 39 40 `left_thick`: str 41 The "pointing" left thick separator, used for separating between segments. 42 43 `right_thin`: str 44 The "pointing" right thin separator, used for separating between segments of the same background color. 45 46 `left_thin`: str 47 The "pointing" left thin separator, used for separating between segments of the same background color. 48 """ 49 50 self.right_thick = right_thick 51 self.left_thick = left_thick 52 self.right_thin = right_thin 53 self.left_thin = left_thin 54 55 56class Separators(Enum): 57 """ 58 Segment separators using nerd font's extra-powerline-separators 59 https://github.com/ryanoasis/powerline-extra-symbols 60 """ 61 NONE = SegmentSeparator("", "", "", "") 62 """ 63 No defining separator between segments. 64 """ 65 66 ORIGINAL = SegmentSeparator("", "", "", "") 67 """ 68 Original/Arrow separators. i.e. and , and and . 69 """ 70 71 ANGLE = SegmentSeparator("", "", "", "") 72 """ 73 Angle separators, and , and and . Same as Original. 74 """ 75 76 SLASH_FORWARD = SegmentSeparator("", "", "", "") 77 """ 78 Forward slash separators, and , . 79 """ 80 81 SLASH_BACKWARD = SegmentSeparator("", "", "", "") 82 """ 83 Backward slash separators, and , . 84 """ 85 86 ROUND = SegmentSeparator("", "", "", "") 87 """ 88 Round separators, and , and and . 89 """ 90 91 FLAME = SegmentSeparator(" ", " \u2588", " ", " ") 92 """ 93 Flame separators, and , and and . 94 """ 95 96 PIXEL_SQUARES = SegmentSeparator(" ", " \u2588", "", " ") 97 """ 98 Pixel square separators, and , and . 99 """ 100 101 102class Statusbar: 103 """ 104 Represents the tmux statusbar. 105 """ 106 107 segment_data: Dict[str, Dict[str, Any] | None] | None = None 108 """ 109 Specify what functions are available to use as segments. The key is {module}.{function name} and its value is a dict 110 containing the args that will be passed to it. If the value is None, then no args will be passed to the function. 111 Functions included by default in this library or do not need to be prefixed by a module name. A module must be 112 accessible by your python path or in a recognized segment directory. 113 114 Example: 115 ```python 116 statusbar.segment_data = { 117 "some_module.add_numbers": { 118 "x": 1, 119 "y": 2, 120 }, 121 122 } 123 ``` 124 """ 125 126 left_side: tuple[list[Segment], Style] | list[Segment] 127 """ 128 List of Segment objects to display on the left side of the statusbar and optionally, the default style to use for the left side. 129 """ 130 131 right_side: tuple[list[Segment], Style] | list[Segment] 132 """ 133 List of Segment objects to display on the right side of the statusbar and optionally, the default style to use. 134 """ 135 136 left_side_max_length: int = 60 137 """ 138 The maximum length of the left side of the statusbar. Defaults to 60. 139 """ 140 141 right_side_max_length: int = 90 142 """ 143 The maximum length of the right side of the statusbar. Defaults to 90. 144 """ 145 146 window_list: WindowList 147 """ 148 tmux window status list. 149 """ 150 151 _segment_separator: SegmentSeparator = Separators.ORIGINAL.value 152 153 @property 154 def segment_separator(cls) -> SegmentSeparator: 155 """ 156 The segment separator to use. Defaults to the "original" powerline separators. i.e. and , and . 157 """ 158 return cls._segment_separator 159 160 @segment_separator.setter 161 def segment_separator(cls, value: SegmentSeparator | Separators) -> None: 162 if isinstance(value, Separators): 163 cls._segment_separator = value.value 164 else: 165 cls._segment_separator = value 166 167 _left_end_separator: SegmentSeparator | None = None 168 169 @property 170 def left_end_separator(cls) -> SegmentSeparator: 171 """ 172 The segment separator to use at the end of the left side of the statusbar. Defaults to whatever is set in segment_separator. 173 """ 174 return cls._left_end_separator if cls._left_end_separator is not None else cls.segment_separator 175 176 @left_end_separator.setter 177 def left_end_separator(cls, value: SegmentSeparator | Separators) -> None: 178 if isinstance(value, Separators): 179 cls._left_end_separator = value.value 180 else: 181 cls._left_end_separator = value 182 183 _right_end_separator: SegmentSeparator | None = None 184 185 @property 186 def right_end_separator(cls) -> SegmentSeparator: 187 """ 188 The segment separator to use at the end of the right side of the statusbar. Defaults to whatever is set in segment_separator. 189 """ 190 return cls._right_end_separator if cls._right_end_separator is not None else cls.segment_separator 191 192 @right_end_separator.setter 193 def right_end_separator(cls, value: SegmentSeparator | Separators) -> None: 194 if isinstance(value, Separators): 195 cls._right_end_separator = value.value 196 else: 197 cls._right_end_separator = value 198 199 default_bg: Color = NamedColor.TERMINAL 200 """ 201 The default background color for the statusbar. 202 """ 203 204 default_fg: Color = NamedColor.TERMINAL 205 """ 206 The default foreground color for the statusbar. 207 """ 208 209 default_style: Style | None = None 210 """ 211 The default style for the statusbar. 212 213 Segments will inherit from the default style, e.g. if you set bold here, all segments will be bold unless you explictily unset it in that segment's style. 214 """ 215 216 status_interval: int = 1 217 """ 218 The interval in seconds at which the statusbar will be redrawn. 219 """ 220 221 visible: bool = True 222 """ 223 Whether the statusbar is initially visible or not . 224 """ 225 226 def __init__(self, left_side: tuple[list[Segment], Style] | list[Segment], right_side: tuple[list[Segment], Style] | list[Segment], window_list: WindowList): 227 """ 228 Creates the Statusbar object. 229 230 Parameters: 231 ----------- 232 `left_side`: tuple[list[Segment], Style] | list[Segment] 233 List of Segment objects to display on the left side of the statusbar and optionally, the default style to use for the left side. 234 235 `right_side`: tuple[list[Segment], Style] | list[Segment] 236 List of Segment objects to display on the right side of the statusbar and optionally, the default style to use. 237 238 `window_list`: WindowList 239 tmux window list. 240 """ 241 self.left_side = left_side 242 self.right_side = right_side 243 self.window_list = window_list 244 245 def __pickle(self) -> bytes: 246 """ 247 Pickles the Statusbar object and returns the pickled bytes. 248 """ 249 return pickle.dumps(self) 250 251 def __commands(self) -> list[str]: 252 """ 253 Returns the tmux commands to be run to update the statusbar. 254 """ 255 if self.default_style is not None: 256 if self.default_style.bg is not None: 257 self.default_bg = self.default_style.bg 258 if self.default_style.fg is not None: 259 self.default_fg = self.default_style.fg 260 else: 261 self.default_style = Style(self.default_bg, self.default_fg) 262 263 return [ 264 *self.window_list._WindowList__commands(), 265 # visible 266 f'tmux set -g status {"on" if self.visible else "off"}', 267 # interval 268 f'tmux set -g status-interval {self.status_interval}', 269 # Default Style 270 f'tmux set -g status-style "{str(self.default_style)}"', 271 # Lengths 272 f'tmux set -g status-left-length {self.left_side_max_length}', 273 f'tmux set -g status-right-length {self.right_side_max_length}', 274 275 # Left/Right Side 276 'tmux set -g status-left "#(tmux-styler -sl #{window_start_flag})"', 277 f'tmux set -g status-left-style "{str(self.left_side[1]) if isinstance(self.left_side, tuple) else "default"}"', 278 'tmux set -g status-right "#(tmux-styler -sr #{window_end_flag})"', 279 f'tmux set -g status-right-style "{str(self.right_side[1]) if isinstance(self.right_side, tuple) else "default"}"', 280 ]
13class SegmentSeparator: 14 """ 15 A segment separator is a character that is displayed between segments. 16 17 Attributes: 18 ----------- 19 `left_thick`: str 20 The left thick separator, used for separating between segments. 21 22 `right_thick`: str 23 The right thick separator, used for separating between segments. 24 25 `left_thin`: str 26 The left thin separator, used for separating between segments of the same background color. 27 28 `right_thin`: str 29 The right thin separator, used for separating between segments of the same background color. 30 """ 31 32 def __init__(self, right_thick: str, left_thick: str, right_thin: str, left_thin: str): 33 """ 34 Creates a SegmentSeparator object. 35 36 Parameters: 37 ----------- 38 `right_thick`: str 39 The "pointing" right thick separator, used for separating between segments. 40 41 `left_thick`: str 42 The "pointing" left thick separator, used for separating between segments. 43 44 `right_thin`: str 45 The "pointing" right thin separator, used for separating between segments of the same background color. 46 47 `left_thin`: str 48 The "pointing" left thin separator, used for separating between segments of the same background color. 49 """ 50 51 self.right_thick = right_thick 52 self.left_thick = left_thick 53 self.right_thin = right_thin 54 self.left_thin = left_thin
A segment separator is a character that is displayed between segments.
Attributes:
left_thick
: str
The left thick separator, used for separating between segments.
right_thick
: str
The right thick separator, used for separating between segments.
left_thin
: str
The left thin separator, used for separating between segments of the same background color.
right_thin
: str
The right thin separator, used for separating between segments of the same background color.
32 def __init__(self, right_thick: str, left_thick: str, right_thin: str, left_thin: str): 33 """ 34 Creates a SegmentSeparator object. 35 36 Parameters: 37 ----------- 38 `right_thick`: str 39 The "pointing" right thick separator, used for separating between segments. 40 41 `left_thick`: str 42 The "pointing" left thick separator, used for separating between segments. 43 44 `right_thin`: str 45 The "pointing" right thin separator, used for separating between segments of the same background color. 46 47 `left_thin`: str 48 The "pointing" left thin separator, used for separating between segments of the same background color. 49 """ 50 51 self.right_thick = right_thick 52 self.left_thick = left_thick 53 self.right_thin = right_thin 54 self.left_thin = left_thin
Creates a SegmentSeparator object.
Parameters:
right_thick
: str
The "pointing" right thick separator, used for separating between segments.
left_thick
: str
The "pointing" left thick separator, used for separating between segments.
right_thin
: str
The "pointing" right thin separator, used for separating between segments of the same background color.
left_thin
: str
The "pointing" left thin separator, used for separating between segments of the same background color.
57class Separators(Enum): 58 """ 59 Segment separators using nerd font's extra-powerline-separators 60 https://github.com/ryanoasis/powerline-extra-symbols 61 """ 62 NONE = SegmentSeparator("", "", "", "") 63 """ 64 No defining separator between segments. 65 """ 66 67 ORIGINAL = SegmentSeparator("", "", "", "") 68 """ 69 Original/Arrow separators. i.e. and , and and . 70 """ 71 72 ANGLE = SegmentSeparator("", "", "", "") 73 """ 74 Angle separators, and , and and . Same as Original. 75 """ 76 77 SLASH_FORWARD = SegmentSeparator("", "", "", "") 78 """ 79 Forward slash separators, and , . 80 """ 81 82 SLASH_BACKWARD = SegmentSeparator("", "", "", "") 83 """ 84 Backward slash separators, and , . 85 """ 86 87 ROUND = SegmentSeparator("", "", "", "") 88 """ 89 Round separators, and , and and . 90 """ 91 92 FLAME = SegmentSeparator(" ", " \u2588", " ", " ") 93 """ 94 Flame separators, and , and and . 95 """ 96 97 PIXEL_SQUARES = SegmentSeparator(" ", " \u2588", "", " ") 98 """ 99 Pixel square separators, and , and . 100 """
Segment separators using nerd font's extra-powerline-separators https://github.com/ryanoasis/powerline-extra-symbols
Original/Arrow separators. i.e. and , and and .
Angle separators, and , and and . Same as Original.
Forward slash separators, and , .
Backward slash separators, and , .
Pixel square separators, and , and .
Inherited Members
- enum.Enum
- name
- value
103class Statusbar: 104 """ 105 Represents the tmux statusbar. 106 """ 107 108 segment_data: Dict[str, Dict[str, Any] | None] | None = None 109 """ 110 Specify what functions are available to use as segments. The key is {module}.{function name} and its value is a dict 111 containing the args that will be passed to it. If the value is None, then no args will be passed to the function. 112 Functions included by default in this library or do not need to be prefixed by a module name. A module must be 113 accessible by your python path or in a recognized segment directory. 114 115 Example: 116 ```python 117 statusbar.segment_data = { 118 "some_module.add_numbers": { 119 "x": 1, 120 "y": 2, 121 }, 122 123 } 124 ``` 125 """ 126 127 left_side: tuple[list[Segment], Style] | list[Segment] 128 """ 129 List of Segment objects to display on the left side of the statusbar and optionally, the default style to use for the left side. 130 """ 131 132 right_side: tuple[list[Segment], Style] | list[Segment] 133 """ 134 List of Segment objects to display on the right side of the statusbar and optionally, the default style to use. 135 """ 136 137 left_side_max_length: int = 60 138 """ 139 The maximum length of the left side of the statusbar. Defaults to 60. 140 """ 141 142 right_side_max_length: int = 90 143 """ 144 The maximum length of the right side of the statusbar. Defaults to 90. 145 """ 146 147 window_list: WindowList 148 """ 149 tmux window status list. 150 """ 151 152 _segment_separator: SegmentSeparator = Separators.ORIGINAL.value 153 154 @property 155 def segment_separator(cls) -> SegmentSeparator: 156 """ 157 The segment separator to use. Defaults to the "original" powerline separators. i.e. and , and . 158 """ 159 return cls._segment_separator 160 161 @segment_separator.setter 162 def segment_separator(cls, value: SegmentSeparator | Separators) -> None: 163 if isinstance(value, Separators): 164 cls._segment_separator = value.value 165 else: 166 cls._segment_separator = value 167 168 _left_end_separator: SegmentSeparator | None = None 169 170 @property 171 def left_end_separator(cls) -> SegmentSeparator: 172 """ 173 The segment separator to use at the end of the left side of the statusbar. Defaults to whatever is set in segment_separator. 174 """ 175 return cls._left_end_separator if cls._left_end_separator is not None else cls.segment_separator 176 177 @left_end_separator.setter 178 def left_end_separator(cls, value: SegmentSeparator | Separators) -> None: 179 if isinstance(value, Separators): 180 cls._left_end_separator = value.value 181 else: 182 cls._left_end_separator = value 183 184 _right_end_separator: SegmentSeparator | None = None 185 186 @property 187 def right_end_separator(cls) -> SegmentSeparator: 188 """ 189 The segment separator to use at the end of the right side of the statusbar. Defaults to whatever is set in segment_separator. 190 """ 191 return cls._right_end_separator if cls._right_end_separator is not None else cls.segment_separator 192 193 @right_end_separator.setter 194 def right_end_separator(cls, value: SegmentSeparator | Separators) -> None: 195 if isinstance(value, Separators): 196 cls._right_end_separator = value.value 197 else: 198 cls._right_end_separator = value 199 200 default_bg: Color = NamedColor.TERMINAL 201 """ 202 The default background color for the statusbar. 203 """ 204 205 default_fg: Color = NamedColor.TERMINAL 206 """ 207 The default foreground color for the statusbar. 208 """ 209 210 default_style: Style | None = None 211 """ 212 The default style for the statusbar. 213 214 Segments will inherit from the default style, e.g. if you set bold here, all segments will be bold unless you explictily unset it in that segment's style. 215 """ 216 217 status_interval: int = 1 218 """ 219 The interval in seconds at which the statusbar will be redrawn. 220 """ 221 222 visible: bool = True 223 """ 224 Whether the statusbar is initially visible or not . 225 """ 226 227 def __init__(self, left_side: tuple[list[Segment], Style] | list[Segment], right_side: tuple[list[Segment], Style] | list[Segment], window_list: WindowList): 228 """ 229 Creates the Statusbar object. 230 231 Parameters: 232 ----------- 233 `left_side`: tuple[list[Segment], Style] | list[Segment] 234 List of Segment objects to display on the left side of the statusbar and optionally, the default style to use for the left side. 235 236 `right_side`: tuple[list[Segment], Style] | list[Segment] 237 List of Segment objects to display on the right side of the statusbar and optionally, the default style to use. 238 239 `window_list`: WindowList 240 tmux window list. 241 """ 242 self.left_side = left_side 243 self.right_side = right_side 244 self.window_list = window_list 245 246 def __pickle(self) -> bytes: 247 """ 248 Pickles the Statusbar object and returns the pickled bytes. 249 """ 250 return pickle.dumps(self) 251 252 def __commands(self) -> list[str]: 253 """ 254 Returns the tmux commands to be run to update the statusbar. 255 """ 256 if self.default_style is not None: 257 if self.default_style.bg is not None: 258 self.default_bg = self.default_style.bg 259 if self.default_style.fg is not None: 260 self.default_fg = self.default_style.fg 261 else: 262 self.default_style = Style(self.default_bg, self.default_fg) 263 264 return [ 265 *self.window_list._WindowList__commands(), 266 # visible 267 f'tmux set -g status {"on" if self.visible else "off"}', 268 # interval 269 f'tmux set -g status-interval {self.status_interval}', 270 # Default Style 271 f'tmux set -g status-style "{str(self.default_style)}"', 272 # Lengths 273 f'tmux set -g status-left-length {self.left_side_max_length}', 274 f'tmux set -g status-right-length {self.right_side_max_length}', 275 276 # Left/Right Side 277 'tmux set -g status-left "#(tmux-styler -sl #{window_start_flag})"', 278 f'tmux set -g status-left-style "{str(self.left_side[1]) if isinstance(self.left_side, tuple) else "default"}"', 279 'tmux set -g status-right "#(tmux-styler -sr #{window_end_flag})"', 280 f'tmux set -g status-right-style "{str(self.right_side[1]) if isinstance(self.right_side, tuple) else "default"}"', 281 ]
Represents the tmux statusbar.
227 def __init__(self, left_side: tuple[list[Segment], Style] | list[Segment], right_side: tuple[list[Segment], Style] | list[Segment], window_list: WindowList): 228 """ 229 Creates the Statusbar object. 230 231 Parameters: 232 ----------- 233 `left_side`: tuple[list[Segment], Style] | list[Segment] 234 List of Segment objects to display on the left side of the statusbar and optionally, the default style to use for the left side. 235 236 `right_side`: tuple[list[Segment], Style] | list[Segment] 237 List of Segment objects to display on the right side of the statusbar and optionally, the default style to use. 238 239 `window_list`: WindowList 240 tmux window list. 241 """ 242 self.left_side = left_side 243 self.right_side = right_side 244 self.window_list = window_list
Creates the Statusbar object.
Parameters:
left_side
: tuple[list[Segment], Style] | list[Segment]
List of Segment objects to display on the left side of the statusbar and optionally, the default style to use for the left side.
right_side
: tuple[list[Segment], Style] | list[Segment]
List of Segment objects to display on the right side of the statusbar and optionally, the default style to use.
window_list
: WindowList
tmux window list.
Specify what functions are available to use as segments. The key is {module}.{function name} and its value is a dict containing the args that will be passed to it. If the value is None, then no args will be passed to the function. Functions included by default in this library or do not need to be prefixed by a module name. A module must be accessible by your python path or in a recognized segment directory.
Example:
statusbar.segment_data = {
"some_module.add_numbers": {
"x": 1,
"y": 2,
},
}
List of Segment objects to display on the left side of the statusbar and optionally, the default style to use for the left side.
List of Segment objects to display on the right side of the statusbar and optionally, the default style to use.
The maximum length of the left side of the statusbar. Defaults to 60.
The maximum length of the right side of the statusbar. Defaults to 90.
154 @property 155 def segment_separator(cls) -> SegmentSeparator: 156 """ 157 The segment separator to use. Defaults to the "original" powerline separators. i.e. and , and . 158 """ 159 return cls._segment_separator
The segment separator to use. Defaults to the "original" powerline separators. i.e. and , and .
170 @property 171 def left_end_separator(cls) -> SegmentSeparator: 172 """ 173 The segment separator to use at the end of the left side of the statusbar. Defaults to whatever is set in segment_separator. 174 """ 175 return cls._left_end_separator if cls._left_end_separator is not None else cls.segment_separator
The segment separator to use at the end of the left side of the statusbar. Defaults to whatever is set in segment_separator.
186 @property 187 def right_end_separator(cls) -> SegmentSeparator: 188 """ 189 The segment separator to use at the end of the right side of the statusbar. Defaults to whatever is set in segment_separator. 190 """ 191 return cls._right_end_separator if cls._right_end_separator is not None else cls.segment_separator
The segment separator to use at the end of the right side of the statusbar. Defaults to whatever is set in segment_separator.