diff options
author | Todd Leonhardt <todd.leonhardt@gmail.com> | 2019-06-29 14:13:55 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-06-29 14:13:55 -0400 |
commit | d9ec6f775335133f7b9dc5c33c76eac942243397 (patch) | |
tree | 20a2ef40c3e1868accb97201fc0b5ea913cb0878 /cmd2/utils.py | |
parent | bef07746e33da9def33d814913891384a545a95c (diff) | |
parent | 83e418844cbf72250d180d9c529b5ec44c4e7d3d (diff) | |
download | cmd2-git-d9ec6f775335133f7b9dc5c33c76eac942243397.tar.gz |
Merge pull request #704 from python-cmd2/feature/revisit-color-support
#698 - Revisiting Color Support
Diffstat (limited to 'cmd2/utils.py')
-rw-r--r-- | cmd2/utils.py | 23 |
1 files changed, 1 insertions, 22 deletions
diff --git a/cmd2/utils.py b/cmd2/utils.py index 3e28641d..812fa227 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -12,30 +12,9 @@ import threading import unicodedata from typing import Any, Iterable, List, Optional, TextIO, Union -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 is_quoted(arg: str) -> bool: """ Checks if a string is quoted @@ -382,7 +361,7 @@ def center_text(msg: str, *, pad: str = ' ') -> str: """Centers text horizontally for display within the current terminal, optionally padding both sides. :param msg: message to display in the center - :param pad: (optional) if provided, the first character will be used to pad both sides of the message + :param pad: if provided, the first character will be used to pad both sides of the message :return: centered message, optionally padded on both sides with pad_char """ term_width = shutil.get_terminal_size().columns |