@@ -90,20 +90,18 @@ def strip_style(text: str) -> str:
9090 return ANSI_STYLE_RE .sub ('' , text )
9191
9292
93- def ansi_safe_wcswidth (text : str ) -> int :
93+ def style_aware_wcswidth (text : str ) -> int :
9494 """
9595 Wrap wcswidth to make it compatible with strings that contains ANSI style sequences
96-
9796 :param text: the string being measured
9897 """
9998 # Strip ANSI style sequences since they cause wcswidth to return -1
10099 return wcswidth (strip_style (text ))
101100
102101
103- def ansi_aware_write (fileobj : IO , msg : str ) -> None :
102+ def style_aware_write (fileobj : IO , msg : str ) -> None :
104103 """
105104 Write a string to a fileobject and strip its ANSI style sequences if required by allow_style setting
106-
107105 :param fileobj: the file object being written to
108106 :param msg: the string being written
109107 """
@@ -114,8 +112,8 @@ def ansi_aware_write(fileobj: IO, msg: str) -> None:
114112
115113
116114def fg_lookup (fg_name : str ) -> str :
117- """Look up ANSI escape codes based on foreground color name.
118-
115+ """
116+ Look up ANSI escape codes based on foreground color name.
119117 :param fg_name: foreground color name to look up ANSI escape code(s) for
120118 :return: ANSI escape code(s) associated with this color
121119 :raises ValueError if the color cannot be found
@@ -128,8 +126,8 @@ def fg_lookup(fg_name: str) -> str:
128126
129127
130128def bg_lookup (bg_name : str ) -> str :
131- """Look up ANSI escape codes based on background color name.
132-
129+ """
130+ Look up ANSI escape codes based on background color name.
133131 :param bg_name: background color name to look up ANSI escape code(s) for
134132 :return: ANSI escape code(s) associated with this color
135133 :raises ValueError if the color cannot be found
@@ -142,8 +140,8 @@ def bg_lookup(bg_name: str) -> str:
142140
143141
144142def style (text : Any , * , fg : str = '' , bg : str = '' , bold : bool = False , underline : bool = False ) -> str :
145- """Styles a string with ANSI colors and/or styles and returns the new string.
146-
143+ """
144+ Apply ANSI colors and/or styles to a string and return it.
147145 The styling is self contained which means that at the end of the string reset code(s) are issued
148146 to undo whatever styling was done at the beginning.
149147
@@ -210,14 +208,14 @@ def async_alert_str(*, terminal_columns: int, prompt: str, line: str, cursor_off
210208 # That will be included in the input lines calculations since that is where the cursor is.
211209 num_prompt_terminal_lines = 0
212210 for line in prompt_lines [:- 1 ]:
213- line_width = ansi_safe_wcswidth (line )
211+ line_width = style_aware_wcswidth (line )
214212 num_prompt_terminal_lines += int (line_width / terminal_columns ) + 1
215213
216214 # Now calculate how many terminal lines are take up by the input
217215 last_prompt_line = prompt_lines [- 1 ]
218- last_prompt_line_width = ansi_safe_wcswidth (last_prompt_line )
216+ last_prompt_line_width = style_aware_wcswidth (last_prompt_line )
219217
220- input_width = last_prompt_line_width + ansi_safe_wcswidth (line )
218+ input_width = last_prompt_line_width + style_aware_wcswidth (line )
221219
222220 num_input_terminal_lines = int (input_width / terminal_columns ) + 1
223221
0 commit comments