summaryrefslogtreecommitdiff
path: root/cmd2/utils.py
diff options
context:
space:
mode:
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r--cmd2/utils.py62
1 files changed, 0 insertions, 62 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py
index a5b7f43f..812fa227 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -12,71 +12,9 @@ import threading
import unicodedata
from typing import Any, Iterable, List, Optional, TextIO, Union
-from colorama import Style
-from wcwidth import wcswidth
-
from . import constants
-def strip_ansi(text: str) -> str:
- """Strip ANSI escape codes from a string.
-
- :param text: string which may contain ANSI escape codes
- :return: the same string with any ANSI escape codes removed
- """
- return constants.ANSI_ESCAPE_RE.sub('', text)
-
-
-def ansi_safe_wcswidth(text: str) -> int:
- """
- Wraps wcswidth to make it compatible with colored strings
-
- :param text: the string being measured
- """
- # Strip ANSI escape codes since they cause wcswidth to return -1
- return wcswidth(strip_ansi(text))
-
-
-def style(text: Any, *, fg: str = '', bg: str = '', bold: bool = False, underline: bool = False) -> str:
- """
- Applies style to text
-
- :param text: Any object compatible with str.format()
- :param fg: foreground color. Accepts color names like 'red' or 'blue'
- :param bg: background color. Accepts color names like 'red' or 'blue'
- :param bold: apply the bold style if True. Defaults to False.
- :param underline: apply the underline style if True. Defaults to False.
- """
- values = []
- text = "{}".format(text)
- if fg:
- try:
- values.append(constants.FG_COLORS[fg.lower()])
- except KeyError:
- raise ValueError('Color {} does not exist.'.format(fg))
- if bg:
- try:
- values.append(constants.BG_COLORS[bg.lower()])
- except KeyError:
- raise ValueError('Color {} does not exist.'.format(bg))
- if bold:
- values.append(Style.BRIGHT)
- if underline:
- values.append(constants.Underline.ENABLE)
-
- values.append(text)
- if fg:
- values.append(constants.FG_COLORS['reset'])
- if bg:
- values.append(constants.BG_COLORS['reset'])
- if bold:
- values.append(Style.NORMAL)
- if underline:
- values.append(constants.Underline.DISABLE)
-
- return "".join(values)
-
-
def is_quoted(arg: str) -> bool:
"""
Checks if a string is quoted