@@ -493,6 +493,8 @@ class ColorStreamAction(Action):
493493 _stream_cache = {}
494494 _stream = None
495495 _tty = None
496+ default_stream = sys .stderr
497+ force_colors = False
496498
497499 @property
498500 def stream (self ):
@@ -507,7 +509,7 @@ def stream(self, value):
507509 value = self ._stream_cache [value ] = open (value , 'a' , buffering = 0 )
508510
509511 isatty = getattr (value , 'isatty' , None )
510- if isatty and isatty () and os .name != 'java' :
512+ if self . force_colors or ( isatty and isatty () and os .name != 'java' ) :
511513 self ._stream = AnsiToWin32 (value )
512514 self ._tty = True
513515 self .event_colors = EVENT_COLORS
@@ -533,8 +535,11 @@ class CodePrinter(Fields.stream.filename_alignment, ColorStreamAction):
533535 stream (file-like): Stream to write to. Default: ``sys.stderr``.
534536 filename_alignment (int): Default size for the filename column (files are right-aligned). Default: ``40``.
535537 """
536- def __init__ (self , stream = sys .stderr , filename_alignment = DEFAULT_MIN_FILENAME_ALIGNMENT ):
538+ def __init__ (self ,
539+ stream = ColorStreamAction .default_stream , force_colors = False ,
540+ filename_alignment = DEFAULT_MIN_FILENAME_ALIGNMENT ):
537541 self .stream = stream
542+ self .force_colors = force_colors
538543 self .filename_alignment = max (5 , filename_alignment )
539544
540545 def _safe_source (self , event ):
@@ -602,12 +607,12 @@ class VarsPrinter(Fields.names.globals.stream.filename_alignment, ColorStreamAct
602607 filename_alignment (int): Default size for the filaneme column (files are right-aligned). Default: ``40``.
603608 globals (bool): Allow access to globals. Default: ``False`` (only looks at locals).
604609 """
605- default_stream = sys .stderr
606610
607611 def __init__ (self , * names , ** options ):
608612 if not names :
609613 raise TypeError ("Must give at least one name/expression." )
610614 self .stream = options .pop ('stream' , self .default_stream )
615+ self .force_colors = options .pop ('force_colors' , False )
611616 self .filename_alignment = max (5 , options .pop ('filename_alignment' , DEFAULT_MIN_FILENAME_ALIGNMENT ))
612617 self .names = {
613618 name : set (self ._iter_symbols (name ))
0 commit comments