summaryrefslogtreecommitdiff
path: root/cmd2
diff options
context:
space:
mode:
authorKevin Van Brunt <kmvanbrunt@gmail.com>2018-11-16 09:21:53 -0500
committerKevin Van Brunt <kmvanbrunt@gmail.com>2018-11-16 09:21:53 -0500
commita827431b9633f0083bf8dc1b290817d12da0c2cc (patch)
tree7e6393c393bd10b81dc4a12747323f215adb1101 /cmd2
parent61da7e5f7887f0d163c5d41abcae1209d3ad3580 (diff)
downloadcmd2-git-a827431b9633f0083bf8dc1b290817d12da0c2cc.tar.gz
Renamed display_width to ansi_safe_wcswidth
Diffstat (limited to 'cmd2')
-rw-r--r--cmd2/cmd2.py8
-rw-r--r--cmd2/utils.py5
2 files changed, 7 insertions, 6 deletions
diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py
index 9254612d..2a617a75 100644
--- a/cmd2/cmd2.py
+++ b/cmd2/cmd2.py
@@ -1301,7 +1301,7 @@ class Cmd(cmd.Cmd):
longest_match_length = 0
for cur_match in matches_to_display:
- cur_length = utils.display_width(cur_match)
+ cur_length = utils.ansi_safe_wcswidth(cur_match)
if cur_length > longest_match_length:
longest_match_length = cur_length
else:
@@ -2661,7 +2661,7 @@ class Cmd(cmd.Cmd):
widest = 0
# measure the commands
for command in cmds:
- width = utils.display_width(command)
+ width = utils.ansi_safe_wcswidth(command)
if width > widest:
widest = width
# add a 4-space pad
@@ -3478,13 +3478,13 @@ a..b, a:b, a:, ..b items by indices (inclusive)
if update_terminal:
# Get the display width of the prompt
- prompt_width = utils.display_width(current_prompt)
+ prompt_width = utils.ansi_safe_wcswidth(current_prompt)
# Get the size of the terminal
terminal_size = shutil.get_terminal_size()
# Figure out how many lines the prompt and user input take up
- total_str_size = prompt_width + utils.display_width(readline.get_line_buffer())
+ total_str_size = prompt_width + utils.ansi_safe_wcswidth(readline.get_line_buffer())
num_input_lines = int(total_str_size / terminal_size.columns) + 1
# Get the cursor's offset from the beginning of the first input line
diff --git a/cmd2/utils.py b/cmd2/utils.py
index 909332ae..a09e8785 100644
--- a/cmd2/utils.py
+++ b/cmd2/utils.py
@@ -22,9 +22,10 @@ def strip_ansi(text: str) -> str:
return constants.ANSI_ESCAPE_RE.sub('', text)
-def display_width(text: str) -> int:
+def ansi_safe_wcswidth(text: str) -> int:
"""
- Return the printable length of a string. This can be different than character count in unicode strings.
+ 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