From 801bab847341fb9a35d10f1d0b4a629a4fc8f14c Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Thu, 19 Dec 2019 16:04:06 -0500 Subject: Changed allow_ansi to allow_style for accuracy in what types of ANSI escape sequences are handled --- cmd2/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index 9dd7a30b..ddb9f3b5 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -641,7 +641,7 @@ def align_text(text: str, alignment: TextAlignment, *, fill_char: str = ' ', width: Optional[int] = None, tab_width: int = 4) -> str: """ Align text for display within a given width. Supports characters with display widths greater than 1. - ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is + ANSI style sequences are safely ignored and do not count toward the display width. This means colored text is supported. If text has line breaks, then each line is aligned independently. There are convenience wrappers around this function: align_left(), align_center(), and align_right() @@ -688,7 +688,7 @@ def align_text(text: str, alignment: TextAlignment, *, fill_char: str = ' ', text_buf.write('\n') # Use ansi_safe_wcswidth to support characters with display widths - # greater than 1 as well as ANSI escape sequences + # greater than 1 as well as ANSI style sequences line_width = ansi.ansi_safe_wcswidth(line) if line_width == -1: raise(ValueError("Text to align contains an unprintable character")) @@ -728,7 +728,7 @@ def align_text(text: str, alignment: TextAlignment, *, fill_char: str = ' ', def align_left(text: str, *, fill_char: str = ' ', width: Optional[int] = None, tab_width: int = 4) -> str: """ Left align text for display within a given width. Supports characters with display widths greater than 1. - ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is + ANSI style sequences are safely ignored and do not count toward the display width. This means colored text is supported. If text has line breaks, then each line is aligned independently. :param text: text to left align (can contain multiple lines) @@ -746,7 +746,7 @@ def align_left(text: str, *, fill_char: str = ' ', width: Optional[int] = None, def align_center(text: str, *, fill_char: str = ' ', width: Optional[int] = None, tab_width: int = 4) -> str: """ Center text for display within a given width. Supports characters with display widths greater than 1. - ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is + ANSI style sequences are safely ignored and do not count toward the display width. This means colored text is supported. If text has line breaks, then each line is aligned independently. :param text: text to center (can contain multiple lines) @@ -764,7 +764,7 @@ def align_center(text: str, *, fill_char: str = ' ', width: Optional[int] = None def align_right(text: str, *, fill_char: str = ' ', width: Optional[int] = None, tab_width: int = 4) -> str: """ Right align text for display within a given width. Supports characters with display widths greater than 1. - ANSI escape sequences are safely ignored and do not count toward the display width. This means colored text is + ANSI style sequences are safely ignored and do not count toward the display width. This means colored text is supported. If text has line breaks, then each line is aligned independently. :param text: text to right align (can contain multiple lines) -- cgit v1.2.1 From b0e5aabad9c902ee5d664bf58885245060114f61 Mon Sep 17 00:00:00 2001 From: Kevin Van Brunt Date: Thu, 19 Dec 2019 17:00:29 -0500 Subject: Renamed ansi_safe_wcswidth() to style_aware_wcswidth() Renamed ansi_aware_write() to style_aware_write() --- cmd2/utils.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'cmd2/utils.py') diff --git a/cmd2/utils.py b/cmd2/utils.py index ddb9f3b5..ffbe5a64 100644 --- a/cmd2/utils.py +++ b/cmd2/utils.py @@ -669,7 +669,7 @@ def align_text(text: str, alignment: TextAlignment, *, fill_char: str = ' ', if len(fill_char) != 1: raise TypeError("Fill character must be exactly one character long") - fill_char_width = ansi.ansi_safe_wcswidth(fill_char) + fill_char_width = ansi.style_aware_wcswidth(fill_char) if fill_char_width == -1: raise (ValueError("Fill character is an unprintable character")) @@ -687,9 +687,9 @@ def align_text(text: str, alignment: TextAlignment, *, fill_char: str = ' ', if index > 0: text_buf.write('\n') - # Use ansi_safe_wcswidth to support characters with display widths + # Use style_aware_wcswidth to support characters with display widths # greater than 1 as well as ANSI style sequences - line_width = ansi.ansi_safe_wcswidth(line) + line_width = ansi.style_aware_wcswidth(line) if line_width == -1: raise(ValueError("Text to align contains an unprintable character")) @@ -717,8 +717,8 @@ def align_text(text: str, alignment: TextAlignment, *, fill_char: str = ' ', # In cases where the fill character display width didn't divide evenly into # the gaps being filled, pad the remainder with spaces. - left_fill += ' ' * (left_fill_width - ansi.ansi_safe_wcswidth(left_fill)) - right_fill += ' ' * (right_fill_width - ansi.ansi_safe_wcswidth(right_fill)) + left_fill += ' ' * (left_fill_width - ansi.style_aware_wcswidth(left_fill)) + right_fill += ' ' * (right_fill_width - ansi.style_aware_wcswidth(right_fill)) text_buf.write(left_fill + line + right_fill) -- cgit v1.2.1