hubvault.entry.style
ANSI-aware CLI styling helpers for hubvault.entry.
This module centralizes optional terminal styling so command implementations do not need to repeat environment checks or ad hoc color branching. Styling stays strictly optional and can be disabled completely through standard or repository-specific environment variables.
The module contains:
colors_enabled()- Decide whether ANSI styling should be emittedstyle_text()- Style one text fragment when colors are enabledecho()- Click-backed output helper with centralized color handling
Example:
>>> style_text("hello", tone="success")
'\x1b...hello\x1b[0m'
>>> style_text("hello", tone="success", env={"NO_COLOR": "1"})
'hello'
Note
Styling is disabled whenever NO_COLOR or HUBVAULT_NO_COLOR is
present in the environment.
colors_enabled
- hubvault.entry.style.colors_enabled(env: Mapping[str, str] | None = None) bool[source]
Return whether CLI ANSI styling is enabled.
- Parameters:
env (Optional[Mapping[str, str]], optional) – Environment mapping to inspect. Defaults to
os.environ- Returns:
Truewhen styling may be emitted- Return type:
bool
Example:
>>> colors_enabled(env={}) True >>> colors_enabled(env={"HUBVAULT_NO_COLOR": "1"}) False
style_text
- hubvault.entry.style.style_text(text: object, tone: str | None = None, env: Mapping[str, str] | None = None, **style_kwargs: object) str[source]
Style one text fragment when ANSI output is enabled.
- Parameters:
text (object) – Source text fragment
tone (Optional[str], optional) – Named style tone such as
"success"or"error"env (Optional[Mapping[str, str]], optional) – Environment mapping used for color-disable detection
style_kwargs (object) – Extra
click.style()keyword arguments
- Returns:
Styled or plain text
- Return type:
str
Example:
>>> style_text("warning", tone="warning", env={"NO_COLOR": "1"}) 'warning'
echo
- hubvault.entry.style.echo(message: object | None = None, tone: str | None = None, file: IO | None = None, err: bool = False, nl: bool = True, color: bool | None = None, env: Mapping[str, str] | None = None, **style_kwargs: object) None[source]
Emit CLI output with centralized optional ANSI styling.
- Parameters:
message (Optional[object]) – Text to print
tone (Optional[str], optional) – Named style tone such as
"success"or"error"file (Optional[IO], optional) – Optional output stream
err (bool, optional) – Whether to write to stderr, defaults to
Falsenl (bool, optional) – Whether to append a trailing newline, defaults to
Truecolor (Optional[bool], optional) – Explicit Click color mode. When omitted, color is disabled automatically if the environment requests plain output.
env (Optional[Mapping[str, str]], optional) – Environment mapping used for color-disable detection
style_kwargs (object) – Extra
click.style()keyword arguments
- Returns:
None.- Return type:
None
Example:
>>> echo("plain output", env={"NO_COLOR": "1"})