From e1f44acf38332b2e36e28ba0f993487632ace16f Mon Sep 17 00:00:00 2001 From: Ofek Lev Date: Sun, 8 Oct 2023 13:51:46 -0400 Subject: [PATCH] Improve terminal logic --- src/hatch/cli/__init__.py | 10 ++-------- src/hatch/cli/terminal.py | 14 +++++++------- 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/hatch/cli/__init__.py b/src/hatch/cli/__init__.py index bc07b49e4..45e6c6726 100644 --- a/src/hatch/cli/__init__.py +++ b/src/hatch/cli/__init__.py @@ -96,14 +96,8 @@ def hatch(ctx: click.Context, env_name, project, verbose, quiet, color, interact | | | | (_| | || (__| | | | \\_| |_/\\__,_|\\__\\___|_| |_| """ - if color is None: - if os.environ.get(AppEnvVars.NO_COLOR) == '1': - color = False - elif os.environ.get(AppEnvVars.FORCE_COLOR) == '1': - color = True - - if interactive is None: - interactive = not running_in_ci() + if interactive is None and running_in_ci(): + interactive = False app = Application(ctx.exit, verbose - quiet, color, interactive) diff --git a/src/hatch/cli/terminal.py b/src/hatch/cli/terminal.py index 44522ce7b..0244a2977 100644 --- a/src/hatch/cli/terminal.py +++ b/src/hatch/cli/terminal.py @@ -40,7 +40,7 @@ def __init__( self, console: Console, *, - tty: bool, + is_interactive: bool, verbosity: int, spinner_style: str, waiting_style: Style, @@ -49,7 +49,7 @@ def __init__( finalizer: Callable, ): self.__console = console - self.__tty = tty + self.__is_interactive = is_interactive self.__verbosity = verbosity self.__spinner_style = spinner_style self.__waiting_style = waiting_style @@ -85,7 +85,7 @@ def __enter__(self) -> BorrowedStatus: return self message, _ = self.__messages[-1] - if not self.__tty: + if not self.__is_interactive: self.__output(message) return self @@ -108,7 +108,7 @@ def __exit__(self, exc_type, exc_val, exc_tb): self.__output(Text(final_text, style=self.__success_style)) - if not self.__tty: + if not self.__is_interactive: return self.__status.stop() @@ -136,8 +136,8 @@ def __init__(self, verbosity, enable_color, interactive): self.verbosity = verbosity self.interactive = interactive self.console = Console( - force_terminal=enable_color, - no_color=enable_color is False, + force_interactive=interactive, + no_color=enable_color, markup=False, emoji=False, highlight=False, @@ -284,7 +284,7 @@ def display_table(self, title, columns, *, show_lines=False, column_options=None def status(self) -> BorrowedStatus: return BorrowedStatus( self.console, - tty=self.interactive and self.console.is_terminal, + is_interactive=self.console.is_interactive, verbosity=self.verbosity, spinner_style=self._style_spinner, waiting_style=self._style_level_waiting,