summaryrefslogtreecommitdiff
path: root/cmd2/ansi.py
diff options
context:
space:
mode:
authorTodd Leonhardt <todd.leonhardt@gmail.com>2021-01-31 22:29:57 -0500
committerTodd Leonhardt <todd.leonhardt@gmail.com>2021-01-31 22:29:57 -0500
commitf456b802754c3d1095b488d670bebba21018d823 (patch)
treebf7011f585a8a35ab4cc7ff98aaeebed4de87f84 /cmd2/ansi.py
parent918200c02d392c17862fff81bbf58820ed15c725 (diff)
downloadcmd2-git-f456b802754c3d1095b488d670bebba21018d823.tar.gz
Add black for automatic code format
Diffstat (limited to 'cmd2/ansi.py')
-rw-r--r--cmd2/ansi.py26
1 files changed, 16 insertions, 10 deletions
diff --git a/cmd2/ansi.py b/cmd2/ansi.py
index 2a3ed01e..1299c8ce 100644
--- a/cmd2/ansi.py
+++ b/cmd2/ansi.py
@@ -5,9 +5,7 @@ setting the window title, and asynchronous alerts.
"""
import functools
import re
-from enum import (
- Enum,
-)
+from enum import Enum
from typing import (
IO,
Any,
@@ -21,9 +19,7 @@ from colorama import (
Fore,
Style,
)
-from wcwidth import (
- wcswidth,
-)
+from wcwidth import wcswidth
# On Windows, filter ANSI escape codes out of text sent to stdout/stderr, and replace them with equivalent Win32 calls
colorama.init(strip=False)
@@ -72,6 +68,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
@@ -105,6 +102,7 @@ class ColorBase(Enum):
# noinspection PyPep8Naming
class fg(ColorBase):
"""Enum class for foreground colors"""
+
black = Fore.BLACK
red = Fore.RED
green = Fore.GREEN
@@ -128,6 +126,7 @@ class fg(ColorBase):
# noinspection PyPep8Naming
class bg(ColorBase):
"""Enum class for background colors"""
+
black = Back.BLACK
red = Back.RED
green = Back.GREEN
@@ -197,8 +196,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)
@@ -240,8 +238,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
@@ -315,6 +320,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()