Skip to content

Commit 4a55334

Browse files
committed
style(_progress[bar]): Remove brackets from progress bar rendering
why: Cleaner visual output β€” block characters provide natural boundaries. what: - Remove [ ] from render_bar() return value - Remove [ ] from _color_bar() in _build_extra() - Remove [ ] from marching bar in _spin() - Update doctests and unit tests to match bracketless output - Update BAR_WIDTH comment to drop bracket reference
1 parent ad1d016 commit 4a55334

File tree

2 files changed

+16
-24
lines changed

2 files changed

+16
-24
lines changed

β€Žsrc/tmuxp/cli/_progress.pyβ€Ž

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
# Spinner frames (braille pattern)
3535
SPINNER_FRAMES = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
3636

37-
BAR_WIDTH = 10 # inner fill cells; total visual width is width + 2 for brackets
37+
BAR_WIDTH = 10 # inner fill character count
3838
DEFAULT_OUTPUT_LINES = 3 # default spinner panel height (lines of script output)
3939

4040
PROGRESS_PRESETS: dict[str, str] = {
@@ -64,26 +64,26 @@ def render_bar(done: int, total: int, width: int = BAR_WIDTH) -> str:
6464
Returns
6565
-------
6666
str
67-
A bracket-enclosed bar like ``"[β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘]"``.
67+
A bar like ``"β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘"``.
6868
Returns ``""`` when *total* <= 0 or *width* <= 0.
6969
7070
Examples
7171
--------
7272
>>> render_bar(0, 10)
73-
'[β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]'
73+
'β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘'
7474
>>> render_bar(5, 10)
75-
'[β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘]'
75+
'β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘'
7676
>>> render_bar(10, 10)
77-
'[β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ]'
77+
'β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ'
7878
>>> render_bar(0, 0)
7979
''
8080
>>> render_bar(3, 10, width=5)
81-
'[β–ˆβ–‘β–‘β–‘β–‘]'
81+
'β–ˆβ–‘β–‘β–‘β–‘'
8282
"""
8383
if total <= 0 or width <= 0:
8484
return ""
8585
filled = min(width, int(done / total * width))
86-
return "[" + "β–ˆ" * filled + "β–‘" * (width - filled) + "]"
86+
return "β–ˆ" * filled + "β–‘" * (width - filled)
8787

8888

8989
class _SafeFormatMap(dict): # type: ignore[type-arg]
@@ -637,11 +637,9 @@ def _spin(self) -> None:
637637
# Marching bar: sweep a 2-cell highlight across the bar
638638
p = march_pos % max(1, BAR_WIDTH - 1)
639639
march_bar = (
640-
"["
641-
+ self.colors.muted("β–‘" * p)
640+
self.colors.muted("β–‘" * p)
642641
+ self.colors.warning("β–‘β–‘")
643642
+ self.colors.muted("β–‘" * max(0, BAR_WIDTH - p - 2))
644-
+ "]"
645643
)
646644
extra: dict[str, t.Any] = {
647645
"bar": march_bar,
@@ -712,7 +710,7 @@ def _build_extra(self) -> dict[str, t.Any]:
712710
... )
713711
>>> extra = spinner._build_extra()
714712
>>> extra["bar"]
715-
'[β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]'
713+
'β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘'
716714
>>> extra["status_icon"]
717715
''
718716
"""
@@ -739,12 +737,7 @@ def _color_bar(plain: str) -> str:
739737
return plain
740738
filled = plain.count("β–ˆ")
741739
empty = plain.count("β–‘")
742-
return (
743-
"["
744-
+ self.colors.success("β–ˆ" * filled)
745-
+ self.colors.muted("β–‘" * empty)
746-
+ "]"
747-
)
740+
return self.colors.success("β–ˆ" * filled) + self.colors.muted("β–‘" * empty)
748741

749742
return {
750743
"bar": _color_bar(composite_bar),

β€Žtests/cli/test_progress.pyβ€Ž

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -487,17 +487,17 @@ def test_spinner_progress_format_none_uses_inline() -> None:
487487

488488
def test_render_bar_empty() -> None:
489489
"""render_bar with done=0 produces an all-empty bar."""
490-
assert render_bar(0, 10) == "[β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘]"
490+
assert render_bar(0, 10) == "β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘β–‘"
491491

492492

493493
def test_render_bar_half() -> None:
494494
"""render_bar with done=5, total=10 fills exactly half."""
495-
assert render_bar(5, 10) == "[β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘]"
495+
assert render_bar(5, 10) == "β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–‘β–‘β–‘β–‘β–‘"
496496

497497

498498
def test_render_bar_full() -> None:
499499
"""render_bar with done=total fills the entire bar."""
500-
assert render_bar(10, 10) == "[β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ]"
500+
assert render_bar(10, 10) == "β–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆβ–ˆ"
501501

502502

503503
def test_render_bar_zero_total() -> None:
@@ -507,13 +507,13 @@ def test_render_bar_zero_total() -> None:
507507

508508
def test_render_bar_custom_width() -> None:
509509
"""render_bar with custom width produces bar of that inner width."""
510-
assert render_bar(3, 10, width=5) == "[β–ˆβ–‘β–‘β–‘β–‘]"
510+
assert render_bar(3, 10, width=5) == "β–ˆβ–‘β–‘β–‘β–‘"
511511

512512

513513
def test_render_bar_width_constant() -> None:
514514
"""BAR_WIDTH is the default inner width used by render_bar."""
515515
bar = render_bar(0, 10)
516-
assert len(bar) == BAR_WIDTH + 2 # inner + 2 brackets
516+
assert len(bar) == BAR_WIDTH
517517

518518

519519
# BuildTree new token tests
@@ -679,7 +679,6 @@ def test_spinner_bar_token_no_color() -> None:
679679
)
680680
spinner.on_build_event({"event": "pane_creating", "pane_num": 1, "pane_total": 2})
681681

682-
assert "[" in spinner.message
683682
assert "β–‘" in spinner.message or "β–ˆ" in spinner.message
684683

685684

@@ -706,7 +705,7 @@ def test_spinner_pane_bar_preset() -> None:
706705
spinner.on_build_event({"event": "window_done"})
707706

708707
assert "2/4" in spinner.message
709-
assert "[" in spinner.message
708+
assert "β–‘" in spinner.message or "β–ˆ" in spinner.message
710709

711710

712711
def test_spinner_before_script_event_via_events() -> None:

0 commit comments

Comments
Β (0)