From e02fc7427d617598f9ecc749c015dbe70be3b9d5 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Mon, 15 Jun 2026 23:47:40 +1000 Subject: [PATCH] feat: allow disabling print prefix --- src/caelestia/subcommands/install.py | 6 +++--- src/caelestia/utils/io.py | 32 ++++++++++++++-------------- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/caelestia/subcommands/install.py b/src/caelestia/subcommands/install.py index 3f32825d..a8bc8301 100644 --- a/src/caelestia/subcommands/install.py +++ b/src/caelestia/subcommands/install.py @@ -125,11 +125,11 @@ class Command: if not comp_arr: return - print(format_msg(PROMPT_COLOUR, "Components to enable?")) + print(format_msg(PROMPT_COLOUR, True, "Components to enable?")) max_idx_w = len(str(len(comp_arr))) for i, comp in enumerate(comp_arr): - print(format_msg(PROMPT_COLOUR, f" {i + 1:<{max_idx_w}}\t{comp}")) - print(format_msg(PROMPT_COLOUR, "[A]ll or (1 2 3, 1-3, ^4)")) + print(format_msg(PROMPT_COLOUR, True, f" {i + 1:<{max_idx_w}}\t{comp}")) + print(format_msg(PROMPT_COLOUR, True, "[A]ll or (1 2 3, 1-3, ^4)")) def _valid_v(v: str) -> int: try: diff --git a/src/caelestia/utils/io.py b/src/caelestia/utils/io.py index c9389bd9..0a575d74 100644 --- a/src/caelestia/utils/io.py +++ b/src/caelestia/utils/io.py @@ -31,28 +31,28 @@ def log_exception(func): return wrapper -def format_msg(colour: int, msg: str) -> str: - return f"\033[{colour}m:: {msg}\033[0m" +def format_msg(colour: int, prefix: bool, msg: str) -> str: + return f"\033[{colour}m{':: ' if prefix else ''}{msg}\033[0m" -def log(msg: str) -> None: - print(format_msg(LOG_COLOUR, msg)) +def log(msg: str, prefix: bool = True) -> None: + print(format_msg(LOG_COLOUR, prefix, msg)) -def info(msg: str) -> None: - print(format_msg(INFO_COLOUR, msg)) +def info(msg: str, prefix: bool = True) -> None: + print(format_msg(INFO_COLOUR, prefix, msg)) -def warn(msg: str) -> None: - print(format_msg(WARNING_COLOUR, f"Warning: {msg}")) +def warn(msg: str, prefix: bool = True) -> None: + print(format_msg(WARNING_COLOUR, prefix, f"Warning: {msg}")) -def error(err: str | Exception) -> None: - print(format_msg(ERROR_COLOUR, f"Error: {err}"), file=sys.stderr) +def error(err: str | Exception, prefix: bool = True) -> None: + print(format_msg(ERROR_COLOUR, prefix, f"Error: {err}"), file=sys.stderr) -def fatal(err: str | Exception) -> Never: - print(format_msg(ERROR_COLOUR, f"Fatal: {err}"), file=sys.stderr) +def fatal(err: str | Exception, prefix: bool = True) -> Never: + print(format_msg(ERROR_COLOUR, prefix, f"Fatal: {err}"), file=sys.stderr) sys.exit(1) @@ -68,13 +68,13 @@ def _input(prompt: str) -> str: raise KeyboardInterrupt() -def prompt(msg: str, end: str = " ") -> str: - return _input(format_msg(PROMPT_COLOUR, msg) + end) +def prompt(msg: str, prefix: bool = True, end: str = " ") -> str: + return _input(format_msg(PROMPT_COLOUR, prefix, msg) + end) -def confirm(msg: str, default: bool = True) -> bool: +def confirm(msg: str, prefix: bool = True, default: bool = True) -> bool: suffix = " [Y/n]" if default else " [y/N]" - answer = prompt(msg + suffix).strip().lower() + answer = prompt(msg + suffix, prefix=prefix).strip().lower() if not answer: return default return answer in ("y", "yes")