summaryrefslogtreecommitdiff
path: root/cmd2/cmd2.py
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-09-23 22:18:19 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-09-23 22:18:19 -0400
commit265e598594b650936730279506e9f072adf2ea01 (patch)
tree7d6bec563986b4f17326abbebc9ac4fca0dce88f /cmd2/cmd2.py
parentb72edb07d59d45d4006dc596218a52d54396378a (diff)
downloadcmd2-git-265e598594b650936730279506e9f072adf2ea01.tar.gz
Added in_script() and in_pyscript() to cmd2.Cmd class
Diffstat (limited to 'cmd2/cmd2.py')
-rwxr-xr-xcmd2/cmd2.py22
1 files changed, 15 insertions, 7 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 6bfcfdc8..d353af14 100755
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -626,11 +626,6 @@ class Cmd(cmd.Cmd):
"""
return ansi.strip_ansi(self.prompt)
- @property
- def aliases(self) -> Dict[str, str]:
- """Read-only property to access the aliases stored in the StatementParser."""
- return self.statement_parser.aliases
-
def poutput(self, msg: Any, *, end: str = '\n') -> None:
"""Print message to self.stdout and appends a newline by default
@@ -744,7 +739,7 @@ class Cmd(cmd.Cmd):
# Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
# Also only attempt to use a pager if actually running in a real fully functional terminal
- if functional_terminal and not self._redirecting and not self._in_py and not self._script_dir:
+ if functional_terminal and not self._redirecting and not self.in_pyscript() and not self.in_script():
if ansi.allow_ansi.lower() == ansi.ANSI_NEVER.lower():
msg_str = ansi.strip_ansi(msg_str)
@@ -1606,6 +1601,19 @@ class Cmd(cmd.Cmd):
tokens_to_parse = raw_tokens if preserve_quotes else tokens
return completer.complete_command(tokens_to_parse, text, line, begidx, endidx)
+ def in_script(self) -> bool:
+ """Return whether a text script is running"""
+ return self._current_script_dir is not None
+
+ def in_pyscript(self) -> bool:
+ """Return whether a pyscript is running"""
+ return self._in_py
+
+ @property
+ def aliases(self) -> Dict[str, str]:
+ """Read-only property to access the aliases stored in the StatementParser"""
+ return self.statement_parser.aliases
+
def get_names(self):
"""Return an alphabetized list of names comprising the attributes of the cmd2 class instance."""
return dir(self)
@@ -3228,7 +3236,7 @@ class Cmd(cmd.Cmd):
:return: True if running of commands should stop
"""
from .py_bridge import PyBridge
- if self._in_py:
+ if self.in_pyscript():
err = "Recursively entering interactive Python consoles is not allowed."
self.perror(err)
return