diff --git a/src/mads/environ/in_out.py b/src/mads/environ/in_out.py index a8f1851..479d7ec 100644 --- a/src/mads/environ/in_out.py +++ b/src/mads/environ/in_out.py @@ -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 @@ -40,6 +45,7 @@ def __rich_repr__(self): yield "is_terminal", self.is_terminal yield "force_terminal", self.force_terminal, None yield "is_atty", self.is_atty, True + yield "is_subshell", self.is_subshell yield "is_interactive", self.is_interactive @classmethod