@@ -206,11 +206,11 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
206206 # To make an attribute settable with the "do_set" command, add it to this ...
207207 self .settable = \
208208 {
209- # allow_ansi is a special case in which it's an application-wide setting defined in ansi.py
210- 'allow_ansi ' : ('Allow ANSI escape sequences in output '
211- '(valid values: {}, {}, {})' .format (ansi .ANSI_TERMINAL ,
212- ansi .ANSI_ALWAYS ,
213- ansi .ANSI_NEVER )),
209+ # allow_style is a special case in which it's an application-wide setting defined in ansi.py
210+ 'allow_style ' : ('Allow ANSI text style sequences in output '
211+ '(valid values: {}, {}, {})' .format (ansi .STYLE_TERMINAL ,
212+ ansi .STYLE_ALWAYS ,
213+ ansi .STYLE_NEVER )),
214214 'continuation_prompt' : 'On 2nd+ line of input' ,
215215 'debug' : 'Show full error stack on error' ,
216216 'echo' : 'Echo command issued into output' ,
@@ -366,7 +366,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
366366 else :
367367 # Here is the meaning of the various flags we are using with the less command:
368368 # -S causes lines longer than the screen width to be chopped (truncated) rather than wrapped
369- # -R causes ANSI "color " escape sequences to be output in raw form (i.e. colors are displayed)
369+ # -R causes ANSI "style " escape sequences to be output in raw form (i.e. colors are displayed)
370370 # -X disables sending the termcap initialization and deinitialization strings to the terminal
371371 # -F causes less to automatically exit if the entire file can be displayed on the first screen
372372 self .pager = 'less -RXF'
@@ -395,38 +395,38 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
395395 # ----- Methods related to presenting output to the user -----
396396
397397 @property
398- def allow_ansi (self ) -> str :
399- """Read-only property needed to support do_set when it reads allow_ansi """
400- return ansi .allow_ansi
398+ def allow_style (self ) -> str :
399+ """Read-only property needed to support do_set when it reads allow_style """
400+ return ansi .allow_style
401401
402- @allow_ansi .setter
403- def allow_ansi (self , new_val : str ) -> None :
404- """Setter property needed to support do_set when it updates allow_ansi """
402+ @allow_style .setter
403+ def allow_style (self , new_val : str ) -> None :
404+ """Setter property needed to support do_set when it updates allow_style """
405405 new_val = new_val .lower ()
406- if new_val == ansi .ANSI_TERMINAL .lower ():
407- ansi .allow_ansi = ansi .ANSI_TERMINAL
408- elif new_val == ansi .ANSI_ALWAYS .lower ():
409- ansi .allow_ansi = ansi .ANSI_ALWAYS
410- elif new_val == ansi .ANSI_NEVER .lower ():
411- ansi .allow_ansi = ansi .ANSI_NEVER
406+ if new_val == ansi .STYLE_TERMINAL .lower ():
407+ ansi .allow_style = ansi .STYLE_TERMINAL
408+ elif new_val == ansi .STYLE_ALWAYS .lower ():
409+ ansi .allow_style = ansi .STYLE_ALWAYS
410+ elif new_val == ansi .STYLE_NEVER .lower ():
411+ ansi .allow_style = ansi .STYLE_NEVER
412412 else :
413- self .perror ('Invalid value: {} (valid values: {}, {}, {})' .format (new_val , ansi .ANSI_TERMINAL ,
414- ansi .ANSI_ALWAYS , ansi .ANSI_NEVER ))
413+ self .perror ('Invalid value: {} (valid values: {}, {}, {})' .format (new_val , ansi .STYLE_TERMINAL ,
414+ ansi .STYLE_ALWAYS , ansi .STYLE_NEVER ))
415415
416416 def _completion_supported (self ) -> bool :
417417 """Return whether tab completion is supported"""
418418 return self .use_rawinput and self .completekey and rl_type != RlType .NONE
419419
420420 @property
421421 def visible_prompt (self ) -> str :
422- """Read-only property to get the visible prompt with any ANSI escape codes stripped.
422+ """Read-only property to get the visible prompt with any ANSI style escape codes stripped.
423423
424424 Used by transcript testing to make it easier and more reliable when users are doing things like coloring the
425425 prompt using ANSI color codes.
426426
427427 :return: prompt stripped of any ANSI escape codes
428428 """
429- return ansi .strip_ansi (self .prompt )
429+ return ansi .strip_style (self .prompt )
430430
431431 def poutput (self , msg : Any = '' , * , end : str = '\n ' ) -> None :
432432 """Print message to self.stdout and appends a newline by default
@@ -439,7 +439,7 @@ def poutput(self, msg: Any = '', *, end: str = '\n') -> None:
439439 :param end: string appended after the end of the message, default a newline
440440 """
441441 try :
442- ansi .ansi_aware_write (self .stdout , "{}{}" .format (msg , end ))
442+ ansi .style_aware_write (self .stdout , "{}{}" .format (msg , end ))
443443 except BrokenPipeError :
444444 # This occurs if a command's output is being piped to another
445445 # process and that process closes before the command is
@@ -462,7 +462,7 @@ def perror(self, msg: Any = '', *, end: str = '\n', apply_style: bool = True) ->
462462 final_msg = ansi .style_error (msg )
463463 else :
464464 final_msg = "{}" .format (msg )
465- ansi .ansi_aware_write (sys .stderr , final_msg + end )
465+ ansi .style_aware_write (sys .stderr , final_msg + end )
466466
467467 def pwarning (self , msg : Any = '' , * , end : str = '\n ' , apply_style : bool = True ) -> None :
468468 """Wraps perror, but applies ansi.style_warning by default
@@ -551,8 +551,8 @@ def ppaged(self, msg: Any, *, end: str = '\n', chop: bool = False) -> None:
551551 # Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
552552 # Also only attempt to use a pager if actually running in a real fully functional terminal
553553 if functional_terminal and not self ._redirecting and not self .in_pyscript () and not self .in_script ():
554- if ansi .allow_ansi .lower () == ansi .ANSI_NEVER .lower ():
555- msg_str = ansi .strip_ansi (msg_str )
554+ if ansi .allow_style .lower () == ansi .STYLE_NEVER .lower ():
555+ msg_str = ansi .strip_style (msg_str )
556556 msg_str += end
557557
558558 pager = self .pager
@@ -1096,7 +1096,7 @@ def _display_matches_gnu_readline(self, substitution: str, matches: List[str],
10961096 longest_match_length = 0
10971097
10981098 for cur_match in matches_to_display :
1099- cur_length = ansi .ansi_safe_wcswidth (cur_match )
1099+ cur_length = ansi .style_aware_wcswidth (cur_match )
11001100 if cur_length > longest_match_length :
11011101 longest_match_length = cur_length
11021102 else :
@@ -2653,7 +2653,7 @@ def _print_topics(self, header: str, cmds: List[str], verbose: bool) -> None:
26532653 widest = 0
26542654 # measure the commands
26552655 for command in cmds :
2656- width = ansi .ansi_safe_wcswidth (command )
2656+ width = ansi .style_aware_wcswidth (command )
26572657 if width > widest :
26582658 widest = width
26592659 # add a 4-space pad
@@ -3737,7 +3737,7 @@ class TestMyAppCase(Cmd2TestCase):
37373737 test_results = runner .run (testcase )
37383738 execution_time = time .time () - start_time
37393739 if test_results .wasSuccessful ():
3740- ansi .ansi_aware_write (sys .stderr , stream .read ())
3740+ ansi .style_aware_write (sys .stderr , stream .read ())
37413741 finish_msg = ' {0} transcript{1} passed in {2:.3f} seconds ' .format (num_transcripts , plural , execution_time )
37423742 finish_msg = ansi .style_success (utils .align_center (finish_msg , fill_char = '=' ))
37433743 self .poutput (finish_msg )
0 commit comments