summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-26 17:44:25 -0400
committerKevin Van Brunt <kmvanbrunt@gmail.com>2019-06-26 17:44:25 -0400
commit2f9aab59acbbfc177a924afe7601b9021a4b1399 (patch)
tree11f2fde6c1e9d74956d6f287dcf221649d5233f1 /cmd2
parent92f8e3d616c836748638a19ad954c7e050059f21 (diff)
downloadcmd2-git-2f9aab59acbbfc177a924afe7601b9021a4b1399.tar.gz
Renamed colors setting to allow_ansi
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/ansi.py16
-rw-r--r--cmd2/cmd2.py10
-rw-r--r--cmd2/constants.py2
3 files changed, 14 insertions, 14 deletions
diff --git a/cmd2/ansi.py b/cmd2/ansi.py
index 8980b1d4..7ae9016e 100644
--- a/cmd2/ansi.py
+++ b/cmd2/ansi.py
@@ -1,5 +1,5 @@
# coding=utf-8
-"""Support for ANSI escape codes which are used for things like applying style to text"""
+"""Support for ANSI escape sequences which are used for things like applying style to text"""
import functools
import re
from typing import Any
@@ -8,7 +8,7 @@ import colorama
from colorama import Fore, Back, Style
from wcwidth import wcswidth
-# Regular expression to match ANSI escape codes
+# Regular expression to match ANSI escape sequences
ANSI_ESCAPE_RE = re.compile(r'\x1b[^m]*m')
# Foreground color presets
@@ -55,10 +55,10 @@ BG_COLORS = {
def strip_ansi(text: str) -> str:
- """Strip ANSI escape codes from a string.
+ """Strip ANSI escape sequences from a string.
- :param text: string which may contain ANSI escape codes
- :return: the same string with any ANSI escape codes removed
+ :param text: string which may contain ANSI escape sequences
+ :return: the same string with any ANSI escape sequences removed
"""
return ANSI_ESCAPE_RE.sub('', text)
@@ -69,11 +69,11 @@ def ansi_safe_wcswidth(text: str) -> int:
:param text: the string being measured
"""
- # Strip ANSI escape codes since they cause wcswidth to return -1
+ # Strip ANSI escape sequences since they cause wcswidth to return -1
return wcswidth(strip_ansi(text))
-# ANSI escape strings not provided by colorama
+# ANSI escape sequences not provided by colorama
UNDERLINE_ENABLE = colorama.ansi.code_to_chars(4)
UNDERLINE_DISABLE = colorama.ansi.code_to_chars(24)
@@ -122,7 +122,7 @@ def style(text: Any, *, fg: str = '', bg: str = '', bold: bool = False, underlin
additions.append(UNDERLINE_ENABLE)
removals.append(UNDERLINE_DISABLE)
- # Combine the ANSI escape strings with the text
+ # Combine the ANSI escape sequences with the text
return "".join(additions) + text + "".join(removals)
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index c92a32ec..609a9e02 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -374,7 +374,7 @@ class Cmd(cmd.Cmd):
self.quit_on_sigint = False # Quit the loop on interrupt instead of just resetting prompt
# Attributes which ARE dynamically settable at runtime
- self.colors = constants.ANSI_TERMINAL
+ self.allow_ansi = constants.ANSI_TERMINAL
self.continuation_prompt = '> '
self.debug = False
self.echo = False
@@ -385,7 +385,7 @@ class Cmd(cmd.Cmd):
self.timing = False # Prints elapsed time for each command
# To make an attribute settable with the "do_set" command, add it to this ...
- self.settable = {'colors': 'Allow colorized output (valid values: Terminal, Always, Never)',
+ self.settable = {'allow_ansi': 'Allow ANSI escape sequences in output (valid values: Terminal, Always, Never)',
'continuation_prompt': 'On 2nd+ line of input',
'debug': 'Show full error stack on error',
'echo': 'Echo command issued into output',
@@ -581,8 +581,8 @@ class Cmd(cmd.Cmd):
Honor the current colors setting, which requires us to check whether the fileobject is a tty.
"""
- if self.colors.lower() == constants.ANSI_NEVER.lower() or \
- (self.colors.lower() == constants.ANSI_TERMINAL.lower() and not fileobj.isatty()):
+ if self.allow_ansi.lower() == constants.ANSI_NEVER.lower() or \
+ (self.allow_ansi.lower() == constants.ANSI_TERMINAL.lower() and not fileobj.isatty()):
msg = ansi.strip_ansi(msg)
fileobj.write(msg)
@@ -691,7 +691,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 self.colors.lower() == constants.ANSI_NEVER.lower():
+ if self.allow_ansi.lower() == constants.ANSI_NEVER.lower():
msg_str = ansi.strip_ansi(msg_str)
pager = self.pager
diff --git a/cmd2/constants.py b/cmd2/constants.py
index ac8822c0..ed196f22 100644
--- a/cmd2/constants.py
+++ b/cmd2/constants.py
@@ -17,7 +17,7 @@ LINE_FEED = '\n'
DEFAULT_SHORTCUTS = {'?': 'help', '!': 'shell', '@': 'run_script', '@@': '_relative_run_script'}
-# Values for cmd2 setting that determines when to allow ANSI escape codes
+# Values for cmd2's allow_ansi setting
ANSI_NEVER = 'Never'
ANSI_TERMINAL = 'Terminal'
ANSI_ALWAYS = 'Always'