From 4f81e6adb7dc576b51dc2af66890750cc579c84b Mon Sep 17 00:00:00 2001 From: Ghost Ops <72981180+GhostOps77@users.noreply.github.com> Date: Sat, 4 May 2024 19:14:52 +0530 Subject: [PATCH] Moved ISATTY value to 'globals_' for global access --- click_repl/_repl.py | 9 ++------- click_repl/core.py | 3 +-- click_repl/globals_.py | 4 ++++ 3 files changed, 7 insertions(+), 9 deletions(-) diff --git a/click_repl/_repl.py b/click_repl/_repl.py index 743049b..0445182 100644 --- a/click_repl/_repl.py +++ b/click_repl/_repl.py @@ -9,15 +9,12 @@ from .exceptions import CommandLineParserError, ExitReplException, InvalidGroupFormat from .utils import _execute_internal_and_sys_cmds from .core import ReplContext -from .globals_ import get_current_repl_ctx +from .globals_ import ISATTY, get_current_repl_ctx __all__ = ["bootstrap_prompt", "register_repl", "repl"] -ISATTY = sys.stdin.isatty() - - def bootstrap_prompt( group, prompt_kwargs, @@ -77,8 +74,6 @@ def repl( f"an optional argument '{param.name}' in REPL mode" ) - isatty = sys.stdin.isatty() - # Delete the REPL command from those available, as we don't want to allow # nesting REPLs (note: pass `None` to `pop` as we don't want to error if # REPL command already not present for some reason). @@ -122,7 +117,7 @@ def get_command() -> str: break if not command: - if isatty: + if ISATTY: continue else: break diff --git a/click_repl/core.py b/click_repl/core.py index aef5e0e..50ad81c 100644 --- a/click_repl/core.py +++ b/click_repl/core.py @@ -13,7 +13,7 @@ from typing_extensions import Concatenate, Final, ParamSpec, TypeAlias, TypedDict from ._ctx_stack import _pop_context, _push_context -from .globals_ import get_current_repl_ctx +from .globals_ import ISATTY, get_current_repl_ctx if TYPE_CHECKING: from prompt_toolkit.formatted_text import AnyFormattedText @@ -26,7 +26,6 @@ __all__ = ["ReplContext", "pass_context"] -ISATTY = sys.stdin.isatty() _PromptSession: TypeAlias = PromptSession[Dict[str, Any]] diff --git a/click_repl/globals_.py b/click_repl/globals_.py index 92508cf..6a73652 100644 --- a/click_repl/globals_.py +++ b/click_repl/globals_.py @@ -1,5 +1,6 @@ from __future__ import annotations +import sys from typing import TYPE_CHECKING, NoReturn from ._ctx_stack import _context_stack @@ -8,6 +9,9 @@ from .core import ReplContext +ISATTY = sys.stdin.isatty() + + def get_current_repl_ctx(silent: bool = False) -> ReplContext | NoReturn | None: """ Retrieves the current click-repl context.