summaryrefslogtreecommitdiff
path: root/cmd2/ansi.py
diff options
context:
space:
mode:
authorxNinjaKittyx <xNinjaKittyx@users.noreply.github.com>2020-12-15 17:21:33 -0800
committerxNinjaKittyx <xNinjaKittyx@users.noreply.github.com>2020-12-15 18:20:13 -0800
commit9aa54a5b27468d61337528cb1e1b5b9b11a80978 (patch)
tree567693115cc101efb9254a96d96d80e9f9ccd557 /cmd2/ansi.py
parent03c65c60b39e369958b056c5c844d36d515c8a63 (diff)
downloadcmd2-git-ci_improvements.tar.gz
Adds pre-commit config to run various lintersci_improvements
This ads black, isort, pyupgrade, and flake8 to pre-commit-config.yaml There are also some small changes to travis.yml and tasks.py to reduce some repeated configurations that should be consolidated into setup.cfg. Most other changes are automated by the linter scripts.
Diffstat (limited to 'cmd2/ansi.py')
-rw-r--r--cmd2/ansi.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/cmd2/ansi.py b/cmd2/ansi.py
index f172b87f..9d7ce0ee 100644
--- a/cmd2/ansi.py
+++ b/cmd2/ansi.py
@@ -59,6 +59,7 @@ class ColorBase(Enum):
value: anything that when cast to a string returns an ANSI sequence
"""
+
def __str__(self) -> str:
"""
Return ANSI color sequence instead of enum name
@@ -92,6 +93,7 @@ class ColorBase(Enum):
# noinspection PyPep8Naming
class fg(ColorBase):
"""Enum class for foreground colors"""
+
black = Fore.BLACK
red = Fore.RED
green = Fore.GREEN
@@ -115,6 +117,7 @@ class fg(ColorBase):
# noinspection PyPep8Naming
class bg(ColorBase):
"""Enum class for background colors"""
+
black = Back.BLACK
red = Back.RED
green = Back.GREEN
@@ -184,8 +187,7 @@ def style_aware_write(fileobj: IO, msg: str) -> None:
:param fileobj: the file object being written to
:param msg: the string being written
"""
- if allow_style.lower() == STYLE_NEVER.lower() or \
- (allow_style.lower() == STYLE_TERMINAL.lower() and not fileobj.isatty()):
+ if allow_style.lower() == STYLE_NEVER.lower() or (allow_style.lower() == STYLE_TERMINAL.lower() and not fileobj.isatty()):
msg = strip_style(msg)
fileobj.write(msg)
@@ -227,8 +229,15 @@ def bg_lookup(bg_name: Union[str, bg]) -> str:
# noinspection PyShadowingNames
-def style(text: Any, *, fg: Union[str, fg] = '', bg: Union[str, bg] = '', bold: bool = False,
- dim: bool = False, underline: bool = False) -> str:
+def style(
+ text: Any,
+ *,
+ fg: Union[str, fg] = '',
+ bg: Union[str, bg] = '',
+ bold: bool = False,
+ dim: bool = False,
+ underline: bool = False
+) -> str:
"""
Apply ANSI colors and/or styles to a string and return it.
The styling is self contained which means that at the end of the string reset code(s) are issued
@@ -302,6 +311,7 @@ def async_alert_str(*, terminal_columns: int, prompt: str, line: str, cursor_off
:return: the correct string so that the alert message appears to the user to be printed above the current line.
"""
from colorama import Cursor
+
# Split the prompt lines since it can contain newline characters.
prompt_lines = prompt.splitlines()