@@ -374,7 +374,6 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
374374 self .quit_on_sigint = False # Quit the loop on interrupt instead of just resetting prompt
375375
376376 # Attributes which ARE dynamically settable at runtime
377- self .allow_ansi = constants .ANSI_TERMINAL
378377 self .continuation_prompt = '> '
379378 self .debug = False
380379 self .echo = False
@@ -385,16 +384,20 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
385384 self .timing = False # Prints elapsed time for each command
386385
387386 # To make an attribute settable with the "do_set" command, add it to this ...
388- self .settable = {'allow_ansi' : 'Allow ANSI escape sequences in output (valid values: Terminal, Always, Never)' ,
389- 'continuation_prompt' : 'On 2nd+ line of input' ,
390- 'debug' : 'Show full error stack on error' ,
391- 'echo' : 'Echo command issued into output' ,
392- 'editor' : 'Program used by ``edit``' ,
393- 'feedback_to_output' : 'Include nonessentials in `|`, `>` results' ,
394- 'locals_in_py' : 'Allow access to your application in py via self' ,
395- 'prompt' : 'The prompt issued to solicit input' ,
396- 'quiet' : "Don't print nonessential feedback" ,
397- 'timing' : 'Report execution times' }
387+ self .settable = \
388+ {
389+ # allow_ansi is a special case in which it's an application-wide setting defined in ansi.py
390+ 'allow_ansi' : 'Allow ANSI escape sequences in output (valid values: Terminal, Always, Never)' ,
391+ 'continuation_prompt' : 'On 2nd+ line of input' ,
392+ 'debug' : 'Show full error stack on error' ,
393+ 'echo' : 'Echo command issued into output' ,
394+ 'editor' : 'Program used by ``edit``' ,
395+ 'feedback_to_output' : 'Include nonessentials in `|`, `>` results' ,
396+ 'locals_in_py' : 'Allow access to your application in py via self' ,
397+ 'prompt' : 'The prompt issued to solicit input' ,
398+ 'quiet' : "Don't print nonessential feedback" ,
399+ 'timing' : 'Report execution times'
400+ }
398401
399402 # Commands to exclude from the help menu and tab completion
400403 self .hidden_commands = ['eof' , '_relative_load' , '_relative_run_script' ]
@@ -550,6 +553,16 @@ def __init__(self, completekey: str = 'tab', stdin=None, stdout=None, *,
550553
551554 # ----- Methods related to presenting output to the user -----
552555
556+ @property
557+ def allow_ansi (self ) -> str :
558+ """Read-only property needed to support do_set when it reads allow_ansi"""
559+ return ansi .allow_ansi
560+
561+ @allow_ansi .setter
562+ def allow_ansi (self , new_val : str ) -> None :
563+ """Read-only property needed to support do_set when it sets allow_ansi"""
564+ ansi .allow_ansi = new_val
565+
553566 @property
554567 def visible_prompt (self ) -> str :
555568 """Read-only property to get the visible prompt with any ANSI escape codes stripped.
@@ -581,8 +594,8 @@ def _decolorized_write(self, fileobj: IO, msg: str) -> None:
581594
582595 Honor the current colors setting, which requires us to check whether the fileobject is a tty.
583596 """
584- if self .allow_ansi .lower () == constants .ANSI_NEVER .lower () or \
585- (self .allow_ansi .lower () == constants .ANSI_TERMINAL .lower () and not fileobj .isatty ()):
597+ if ansi .allow_ansi .lower () == ansi .ANSI_NEVER .lower () or \
598+ (ansi .allow_ansi .lower () == ansi .ANSI_TERMINAL .lower () and not fileobj .isatty ()):
586599 msg = ansi .strip_ansi (msg )
587600 fileobj .write (msg )
588601
@@ -612,7 +625,7 @@ def perror(self, msg: Any, *, end: str = '\n', apply_style: bool = True) -> None
612625
613626 :param msg: message to print (anything convertible to a str with '{}'.format() is OK)
614627 :param end: string appended after the end of the message, default a newline
615- :param apply_style: If True, then ErrorStyle will be applied to the message text. Set to False in cases
628+ :param apply_style: If True, then ansi.style_error will be applied to the message text. Set to False in cases
616629 where the message text already has the desired style. Defaults to True.
617630 """
618631 if apply_style :
@@ -691,7 +704,7 @@ def ppaged(self, msg: str, end: str = '\n', chop: bool = False) -> None:
691704 # Don't attempt to use a pager that can block if redirecting or running a script (either text or Python)
692705 # Also only attempt to use a pager if actually running in a real fully functional terminal
693706 if functional_terminal and not self ._redirecting and not self ._in_py and not self ._script_dir :
694- if self .allow_ansi .lower () == constants .ANSI_NEVER .lower ():
707+ if ansi .allow_ansi .lower () == ansi .ANSI_NEVER .lower ():
695708 msg_str = ansi .strip_ansi (msg_str )
696709
697710 pager = self .pager
0 commit comments