Skip to content
Open
Show file tree
Hide file tree
Changes from 3 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
12 changes: 9 additions & 3 deletions src/huggingface_hub/cli/_output.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@

import click

from huggingface_hub import constants
from huggingface_hub.errors import ConfirmationError
from huggingface_hub.utils import ANSI, StatusLine, disable_progress_bars, is_agent, tabulate
from huggingface_hub.utils import ANSI, StatusLine, disable_progress_bars, enable_progress_bars, is_agent, tabulate


class OutputFormat(str, Enum):
Expand Down Expand Up @@ -65,8 +66,13 @@ def set_mode(self, mode: OutputFormat = OutputFormat.auto) -> None:
if mode == OutputFormat.auto:
mode = OutputFormat.agent if is_agent() else OutputFormat.human
self.mode = mode
if mode != OutputFormat.human:
disable_progress_bars()
human = mode == OutputFormat.human
ANSI.set_enabled(human)
if constants.HF_HUB_DISABLE_PROGRESS_BARS is None: # env var has priority
if human:
Comment thread
hanouticelina marked this conversation as resolved.
Outdated
enable_progress_bars()
else:
disable_progress_bars()

def set_no_truncate(self, no_truncate: bool) -> None:
"""Toggle off cell truncation for human table output."""
Expand Down
10 changes: 8 additions & 2 deletions src/huggingface_hub/utils/_terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@ class ANSI:
_reset = "\u001b[0m"
_underline = "\u001b[4m"
_yellow = "\u001b[33m"
_enabled: bool | None = None # None: fall back to agent detection (callers outside the `hf` CLI)

@classmethod
def set_enabled(cls, enabled: bool) -> None:
cls._enabled = enabled

@classmethod
def blue(cls, s: str) -> str:
Expand Down Expand Up @@ -99,10 +104,11 @@ def yellow(cls, s: str) -> str:

@classmethod
def _format(cls, s: str, code: str) -> str:
if os.environ.get("NO_COLOR") or is_agent():
if os.environ.get("NO_COLOR"):
# See https://no-color.org/
return s
return f"{code}{s}{cls._reset}"
enabled = cls._enabled if cls._enabled is not None else not is_agent()
return f"{code}{s}{cls._reset}" if enabled else s


def select_choice(prompt: str, choices: list[str]) -> int:
Expand Down
Loading