Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mute status messages unless --verbose is used #121

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions abi3audit/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,9 @@ def main() -> None:
if args.debug:
logging.root.setLevel("DEBUG")

if args.verbose:
status.initiate()

specs = []
for spec in args.specs:
try:
Expand Down
37 changes: 35 additions & 2 deletions abi3audit/_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,42 @@

import os
import sys
from typing import Literal
from types import TracebackType
from typing import Any, Literal

from rich.console import Console
from rich.status import Status


class StatusWrapper:
_status: Status | None

def __init__(self, console: Console) -> None:
self._console = console
self._status = None

def __enter__(self) -> StatusWrapper:
if self._status:
self._status.__enter__()
return self

def __exit__(
self,
exc_type: type[BaseException] | None,
exc_val: BaseException | None,
exc_tb: TracebackType | None,
) -> Any:
if self._status:
return self._status.__exit__(exc_type, exc_val, exc_tb)
return False

def initiate(self) -> None:
self._status = self._console.status("[green]Processing inputs", spinner="clock")

def update(self, s: str) -> None:
if self._status:
self._status.update(s)


# TODO: Remove this once rich's NO_COLOR handling is fixed.
# See: https://github.com/Textualize/rich/issues/2549
Expand All @@ -19,4 +52,4 @@
_color_system = "auto"

console = Console(log_path=False, file=sys.stderr, color_system=_color_system)
status = console.status("[green]Processing inputs", spinner="clock")
status = StatusWrapper(console)
Loading