Skip to content

Commit

Permalink
Improve terminal logic
Browse files Browse the repository at this point in the history
  • Loading branch information
ofek committed Oct 8, 2023
1 parent 6a1f8dc commit e1f44ac
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 2 additions & 8 deletions src/hatch/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
14 changes: 7 additions & 7 deletions src/hatch/cli/terminal.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def __init__(
self,
console: Console,
*,
tty: bool,
is_interactive: bool,
verbosity: int,
spinner_style: str,
waiting_style: Style,
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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()
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit e1f44ac

Please sign in to comment.