Skip to content

Commit 8e15eb9

Browse files
authored
add LOGBAR_ANITMATION env control (#37)
Signed-off-by: Qubitium <qubitium@modelcloud.ai>
1 parent 359247c commit 8e15eb9

4 files changed

Lines changed: 44 additions & 2 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
- Stackable progress bars that stay anchored while your logs flow freely.
2424
- Built-in styling for progress bar fills, colors, gradients, and head glyphs.
2525
- Animated progress titles with a subtle sweeping highlight.
26+
Set `LOGBAR_ANIMATION=0` to disable the highlight animation.
2627
- Column-aware table printer with spans, width hints, and `fit` sizing.
2728
- Zero dependencies; works anywhere Python runs.
2829

@@ -128,7 +129,7 @@ with log.spinner("Loading model") as spinner:
128129
warm_up()
129130
```
130131

131-
The rolling bar animates automatically while attached. Close it explicitly with `spinner.close()` if you are not using the context manager.
132+
The rolling bar animates automatically while attached. Close it explicitly with `spinner.close()` if you are not using the context manager. Set `LOGBAR_ANIMATION=0` to disable the title highlight sweep on progress labels.
132133

133134
### Multiple Progress Bars
134135

logbar/progress.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,15 @@
44
# Contact: qubitium@modelcloud.ai, x.com/qubitium
55

66
import datetime
7+
import os
78
import re
89
import sys
910
import time
1011
import threading
1112
from contextlib import contextmanager, nullcontext
1213
from dataclasses import dataclass, replace
1314
from enum import Enum
15+
from functools import lru_cache
1416
from typing import Iterable, Optional, Union, TYPE_CHECKING, Sequence
1517
from warnings import warn
1618

@@ -74,6 +76,12 @@ def _iter_ansi_tokens(text: str):
7476
i += 1
7577

7678

79+
@lru_cache(maxsize=1)
80+
def _env_animation_enabled() -> bool:
81+
value = os.environ.get("LOGBAR_ANIMATION", "1")
82+
return str(value).strip().lower() not in {"0", "false", "off", "no"}
83+
84+
7785
def _fg_256(code: int) -> str:
7886
return f"\033[38;5;{code}m"
7987

@@ -878,6 +886,8 @@ def _truncate_ansi(self, text: str, limit: int) -> str:
878886
return ''.join(result)
879887

880888
def _should_animate_title(self) -> bool:
889+
if not _env_animation_enabled():
890+
return False
881891
isatty = getattr(sys.stdout, "isatty", None)
882892
if not callable(isatty):
883893
return False

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "LogBar"
7-
version = "0.2.2"
7+
version = "0.2.3"
88
description = "A unified Logger and ProgressBar util with zero dependencies."
99
readme = "README.md"
1010
requires-python = ">=3"

tests/test_progress.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# SPDX-License-Identifier: Apache-2.0
44
# Contact: qubitium@modelcloud.ai, x.com/qubitium
55

6+
import subprocess
67
import random
78
import re
89
import sys
@@ -139,6 +140,36 @@ def test_title_animation_skips_ansi_sequences(self):
139140
with redirect_stdout(StringIO()):
140141
pb.close()
141142

143+
def test_title_animation_respects_logbar_animation_env(self):
144+
script = (
145+
"from types import SimpleNamespace\n"
146+
"import sys\n"
147+
"from logbar.progress import ProgressBar\n"
148+
"pb = ProgressBar(range(1)).manual()\n"
149+
"sys.stdout = SimpleNamespace(isatty=lambda: True, write=lambda *_: None, flush=lambda: None)\n"
150+
"sys.__stdout__.write('1\\n' if pb._should_animate_title() else '0\\n')\n"
151+
)
152+
153+
enabled = subprocess.run(
154+
[sys.executable, "-c", script],
155+
cwd="/root/LogBar",
156+
capture_output=True,
157+
text=True,
158+
env={},
159+
check=True,
160+
)
161+
self.assertEqual(enabled.stdout.strip(), "1")
162+
163+
disabled = subprocess.run(
164+
[sys.executable, "-c", script],
165+
cwd="/root/LogBar",
166+
capture_output=True,
167+
text=True,
168+
env={"LOGBAR_ANIMATION": "0"},
169+
check=True,
170+
)
171+
self.assertEqual(disabled.stdout.strip(), "0")
172+
142173
def test_draw_respects_terminal_width(self):
143174
pb = log.pb(100).title("TITLE").subtitle("SUBTITLE").manual()
144175
pb.current_iter_step = 50

0 commit comments

Comments
 (0)