fix(examples): keep the gap after the status icons
- commit
- ac13ee3b972505c81c1f147e525537de7f08a6b2
- author
- brice · · 2026-10-09 07:38 UTC
- parent
- 0c98ac0
- signature
- GPG Verified
CD88F9E564E0102646FB6077A1A07C7C7C3E349D· arch-gpg Verified for the committer email
1 file · +11 -2
M examples/modules/status.py +11 -2
| @@ -89,6 +89,16 @@ def foreground(hex_color): | |||
| 89 | 89 | return f"\033[38;2;{int(h[0:2], 16)};{int(h[2:4], 16)};{int(h[4:6], 16)}m" | |
| 90 | 90 | ||
| 91 | 91 | ||
| 92 | + | def background(hex_color): | |
| 93 | + | h = hex_color.lstrip("#") | |
| 94 | + | return f"\033[48;2;{int(h[0:2], 16)};{int(h[2:4], 16)};{int(h[4:6], 16)}m" | |
| 95 | + | ||
| 96 | + | ||
| 97 | + | # The bar drops blank cells at the end of a module; one painted with the bar's | |
| 98 | + | # own background is kept, and keeps the last icon off the next module. | |
| 99 | + | GAP = background(os.environ.get("NEFERBAR_BACKGROUND", "#000000")) + " " + "\033[0m" | |
| 100 | + | ||
| 101 | + | ||
| 92 | 102 | # --- volume ------------------------------------------------------------------ | |
| 93 | 103 | ||
| 94 | 104 | class Volume: | |
| @@ -302,8 +312,7 @@ class Module: | |||
| 302 | 312 | def draw(self): | |
| 303 | 313 | # One icon per part, separated by a space: part i is at column 2*i. | |
| 304 | 314 | self.cols = {2 * i: part for i, part in enumerate(self.parts)} | |
| 305 | - | # A trailing space keeps the last icon off the next module. | |
| 306 | - | frame = " ".join(part.icon() for part in self.parts) + " " | |
| 315 | + | frame = " ".join(part.icon() for part in self.parts) + GAP | |
| 307 | 316 | if frame != self.last_frame: | |
| 308 | 317 | self.last_frame = frame | |
| 309 | 318 | print(frame, flush=True) | |
| @@ -89,6 +89,16 @@ def foreground(hex_color): | |||||
| 89 | return f"\033[38;2;{int(h[0:2], 16)};{int(h[2:4], 16)};{int(h[4:6], 16)}m" | 89 | return f"\033[38;2;{int(h[0:2], 16)};{int(h[2:4], 16)};{int(h[4:6], 16)}m" | ||
| 90 | 90 | ||||
| 91 | 91 | ||||
| 92 | + | def background(hex_color): | |||
| 93 | + | h = hex_color.lstrip("#") | |||
| 94 | + | return f"\033[48;2;{int(h[0:2], 16)};{int(h[2:4], 16)};{int(h[4:6], 16)}m" | |||
| 95 | + | ||||
| 96 | + | ||||
| 97 | + | # The bar drops blank cells at the end of a module; one painted with the bar's | |||
| 98 | + | # own background is kept, and keeps the last icon off the next module. | |||
| 99 | + | GAP = background(os.environ.get("NEFERBAR_BACKGROUND", "#000000")) + " " + "\033[0m" | |||
| 100 | + | ||||
| 101 | + | ||||
| 92 | # --- volume ------------------------------------------------------------------ | 102 | # --- volume ------------------------------------------------------------------ | ||
| 93 | 103 | ||||
| 94 | class Volume: | 104 | class Volume: | ||
| @@ -302,8 +312,7 @@ class Module: | |||||
| 302 | def draw(self): | 312 | def draw(self): | ||
| 303 | # One icon per part, separated by a space: part i is at column 2*i. | 313 | # One icon per part, separated by a space: part i is at column 2*i. | ||
| 304 | self.cols = {2 * i: part for i, part in enumerate(self.parts)} | 314 | self.cols = {2 * i: part for i, part in enumerate(self.parts)} | ||
| 305 | - | # A trailing space keeps the last icon off the next module. | 315 | + | frame = " ".join(part.icon() for part in self.parts) + GAP |
| 306 | - | frame = " ".join(part.icon() for part in self.parts) + " " | |||
| 307 | if frame != self.last_frame: | 316 | if frame != self.last_frame: | ||
| 308 | self.last_frame = frame | 317 | self.last_frame = frame | ||
| 309 | print(frame, flush=True) | 318 | print(frame, flush=True) | ||