Skip to content

Commit

Permalink
Moved ISATTY value to 'globals_' for global access
Browse files Browse the repository at this point in the history
  • Loading branch information
GhostOps77 committed May 4, 2024
1 parent 7096ed6 commit 4f81e6a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
9 changes: 2 additions & 7 deletions click_repl/_repl.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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).
Expand Down Expand Up @@ -122,7 +117,7 @@ def get_command() -> str:
break

if not command:
if isatty:
if ISATTY:
continue
else:
break
Expand Down
3 changes: 1 addition & 2 deletions click_repl/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -26,7 +26,6 @@

__all__ = ["ReplContext", "pass_context"]

ISATTY = sys.stdin.isatty()

_PromptSession: TypeAlias = PromptSession[Dict[str, Any]]

Expand Down
4 changes: 4 additions & 0 deletions click_repl/globals_.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from __future__ import annotations

import sys
from typing import TYPE_CHECKING, NoReturn

from ._ctx_stack import _context_stack
Expand All @@ -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.
Expand Down

0 comments on commit 4f81e6a

Please sign in to comment.