Skip to content

Commit

Permalink
Look for $SHLVL when determining whether in a terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
shreve committed Jun 10, 2024
1 parent bbf7f87 commit 0a9efa8
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/mads/environ/in_out.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,22 @@ class InOut(BaseSettings):

term: str | None = None
force_terminal: bool | None = None
shlvl: int | None = None

@computed_field
def is_terminal(self) -> bool:
if self.force_terminal is not None:
return self.force_terminal
return self.is_atty
return bool(self.is_atty or self.is_subshell)

@computed_field
def is_atty(self) -> bool:
return sys.stdout.isatty()

@computed_field
def is_subshell(self) -> bool:
return self.shlvl is not None and self.shlvl > 1

@computed_field
def is_interactive(self) -> bool:
return self.is_atty and not self.is_dumb
Expand Down

0 comments on commit 0a9efa8

Please sign in to comment.