Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4bcc509

Browse files
refactor: migrate all CLI output to rich and remove emojis (#36)
This PR standardizes the application's output handling by replacing Python's native `print()` with `rich.console.print()`. This change ensures thread safety, consistent styling across environments, and better handling of standard streams (stdout vs stderr). Changes: - src/git_pulsar/daemon.py: Refactor logging and status updates to use a global console instance. - src/git_pulsar/ops.py: Convert interactive prompts and feedback to `rich`. - src/git_pulsar/service.py: Standardize service installation feedback. - tests/test_ops.py: Update mocks to target the new console object and match new output strings. Visual Changes: - Replaced non-standard emojis (❌, ✅, 🚀) with professional text labels ([ERROR], [SUCCESS], [INFO]) to improve terminal compatibility and professional presentation.
1 parent 9fce452 commit 4bcc509

4 files changed

Lines changed: 144 additions & 91 deletions

File tree

src/git_pulsar/daemon.py

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@
3535
logger = logging.getLogger(APP_NAME)
3636
logger.setLevel(logging.INFO)
3737

38+
console = Console()
39+
err_console = Console(stderr=True)
40+
3841

3942
@dataclass
4043
class CoreConfig:
@@ -78,16 +81,13 @@ def load(cls) -> "Config":
7881
instance.daemon = DaemonConfig(**data["daemon"])
7982

8083
except tomllib.TOMLDecodeError as e:
81-
print(
82-
f"FATAL: Config syntax error in {CONFIG_FILE}:\n {e}",
83-
file=sys.stderr,
84+
err_console.print(
85+
f"[bold red]FATAL:[/bold red] Config syntax "
86+
f"error in {CONFIG_FILE}:\n {e}"
8487
)
8588
sys.exit(1)
8689
except Exception as e:
87-
print(
88-
f"❌ Config Error: {e}",
89-
file=sys.stderr,
90-
)
90+
err_console.print(f"[bold red]Config Error:[/bold red] {e}")
9191
# We assume other errors might be recoverable or partial
9292

9393
return instance
@@ -187,7 +187,10 @@ def is_repo_busy(repo_path: Path, interactive: bool = False) -> bool:
187187
msg = f"Stale lock detected in {repo_path.name} ({age_hours:.1f}h old)."
188188
logger.warning(msg)
189189
if interactive:
190-
print(f"⚠️ {msg}\n Run 'rm {lock_file}' to fix.")
190+
console.print(
191+
f"[bold yellow]WARNING:[/bold yellow] {msg}\n "
192+
f"Run 'rm {lock_file}' to fix."
193+
)
191194
else:
192195
SYSTEM.notify("Pulsar Warning", f"Stale lock in {repo_path.name}")
193196
return True
@@ -308,21 +311,22 @@ def _attempt_push(repo: GitRepo, refspec: str, interactive: bool) -> None:
308311
cmd = ["push", remote_name, refspec]
309312

310313
if interactive:
311-
console = Console()
312314
with console.status(
313315
f"[bold blue]Pushing {repo.path.name}...[/bold blue]", spinner="dots"
314316
):
315317
# capture=True suppresses the "Enumerating objects..." wall of text
316318
repo._run(cmd, capture=True, env=env)
317-
console.print(f"[bold green]✔ {repo.path.name}: Pushed.[/bold green]")
319+
console.print(
320+
f"[bold green]SUCCESS:[/bold green] {repo.path.name}: Pushed."
321+
)
318322
else:
319323
# Background mode: log to file/stderr
320324
repo._run(cmd, capture=True, env=env)
321325
logger.info(f"SUCCESS {repo.path.name}: Pushed.")
322326

323327
except Exception as e:
324328
if interactive:
325-
Console().print(f"[bold red]PUSH ERROR {repo.path.name}: {e}[/bold red]")
329+
console.print(f"[bold red]PUSH ERROR {repo.path.name}:[/bold red] {e}")
326330
else:
327331
logger.error(f"PUSH ERROR {repo.path.name}: {e}")
328332

@@ -422,7 +426,10 @@ def main(interactive: bool = False) -> None:
422426

423427
if not REGISTRY_FILE.exists():
424428
if interactive:
425-
print("Registry empty. Run 'git-pulsar' in a repo to register it.")
429+
console.print(
430+
"[yellow]Registry empty. Run 'git-pulsar' in "
431+
"a repo to register it.[/yellow]"
432+
)
426433
return
427434

428435
with open(REGISTRY_FILE, "r") as f:

0 commit comments

Comments
 (0)