@@ -206,11 +206,11 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
206
206
# To make an attribute settable with the "do_set" command, add it to this ...
207
207
self .settable = \
208
208
{
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 )),
214
214
'continuation_prompt' : 'On 2nd+ line of input' ,
215
215
'debug' : 'Show full error stack on error' ,
216
216
'echo' : 'Echo command issued into output' ,
@@ -366,7 +366,7 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
366
366
else :
367
367
# Here is the meaning of the various flags we are using with the less command:
368
368
# -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)
370
370
# -X disables sending the termcap initialization and deinitialization strings to the terminal
371
371
# -F causes less to automatically exit if the entire file can be displayed on the first screen
372
372
self .pager = 'less -RXF'
@@ -395,38 +395,38 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
395
395
# ----- Methods related to presenting output to the user -----
396
396
397
397
@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
401
401
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 """
405
405
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
412
412
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 ))
415
415
416
416
def _completion_supported (self ) -> bool :
417
417
"""Return whether tab completion is supported"""
418
418
return self .use_rawinput and self .completekey and rl_type != RlType .NONE
419
419
420
420
@property
421
421
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.
423
423
424
424
Used by transcript testing to make it easier and more reliable when users are doing things like coloring the
425
425
prompt using ANSI color codes.
426
426
427
427
:return: prompt stripped of any ANSI escape codes
428
428
"""
429
- return ansi .strip_ansi (self .prompt )
429
+ return ansi .strip_style (self .prompt )
430
430
431
431
def poutput (self , msg : Any = '' , * , end : str = '\n ' ) -> None :
432
432
"""Print message to self.stdout and appends a newline by default
@@ -439,7 +439,7 @@ def poutput(self, msg: Any = '', *, end: str = '\n') -> None:
439
439
:param end: string appended after the end of the message, default a newline
440
440
"""
441
441
try :
442
- ansi .ansi_aware_write (self .stdout , "{}{}" .format (msg , end ))
442
+ ansi .style_aware_write (self .stdout , "{}{}" .format (msg , end ))
443
443
except BrokenPipeError :
444
444
# This occurs if a command's output is being piped to another
445
445
# 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) ->
462
462
final_msg = ansi .style_error (msg )
463
463
else :
464
464
final_msg = "{}" .format (msg )
465
- ansi .ansi_aware_write (sys .stderr , final_msg + end )
465
+ ansi .style_aware_write (sys .stderr , final_msg + end )
466
466
467
467
def pwarning (self , msg : Any = '' , * , end : str = '\n ' , apply_style : bool = True ) -> None :
468
468
"""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:
551
551
# Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
552
552
# Also only attempt to use a pager if actually running in a real fully functional terminal
553
553
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 )
556
556
msg_str += end
557
557
558
558
pager = self .pager
@@ -1096,7 +1096,7 @@ def _display_matches_gnu_readline(self, substitution: str, matches: List[str],
1096
1096
longest_match_length = 0
1097
1097
1098
1098
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 )
1100
1100
if cur_length > longest_match_length :
1101
1101
longest_match_length = cur_length
1102
1102
else :
@@ -2653,7 +2653,7 @@ def _print_topics(self, header: str, cmds: List[str], verbose: bool) -> None:
2653
2653
widest = 0
2654
2654
# measure the commands
2655
2655
for command in cmds :
2656
- width = ansi .ansi_safe_wcswidth (command )
2656
+ width = ansi .style_aware_wcswidth (command )
2657
2657
if width > widest :
2658
2658
widest = width
2659
2659
# add a 4-space pad
@@ -3737,7 +3737,7 @@ class TestMyAppCase(Cmd2TestCase):
3737
3737
test_results = runner .run (testcase )
3738
3738
execution_time = time .time () - start_time
3739
3739
if test_results .wasSuccessful ():
3740
- ansi .ansi_aware_write (sys .stderr , stream .read ())
3740
+ ansi .style_aware_write (sys .stderr , stream .read ())
3741
3741
finish_msg = ' {0} transcript{1} passed in {2:.3f} seconds ' .format (num_transcripts , plural , execution_time )
3742
3742
finish_msg = ansi .style_success (utils .align_center (finish_msg , fill_char = '=' ))
3743
3743
self .poutput (finish_msg )
0 commit comments