@@ -436,6 +436,9 @@ def __str__(self):
436436 formatter .print_instruction (self , False )
437437 return output .getvalue ()
438438
439+ def get_dis_theme ():
440+ from _colorize import get_theme
441+ return get_theme ().dis
439442
440443class Formatter :
441444
@@ -478,8 +481,9 @@ def print_instruction(self, instr, mark_as_current=False):
478481 False , None , None , instr .positions ),
479482 False )
480483
481- def print_instruction_line (self , instr , mark_as_current ) :
484+ def print_instruction_line (self , instr : Instruction , mark_as_current : bool ) -> None :
482485 """Format instruction details for inclusion in disassembly output."""
486+ theme = get_dis_theme ()
483487 lineno_width = self .lineno_width
484488 offset_width = self .offset_width
485489 label_width = self .label_width
@@ -527,7 +531,7 @@ def print_instruction_line(self, instr, mark_as_current):
527531 else :
528532 fields .append (' ' )
529533 # Column: Opcode name
530- fields .append (instr .opname . ljust (_OPNAME_WIDTH ))
534+ fields .append (f" { theme . color_by_opname ( instr .opname ) } { instr . opname . ljust (_OPNAME_WIDTH )} { theme . reset } " )
531535 # Column: Opcode argument
532536 if instr .arg is not None :
533537 # If opname is longer than _OPNAME_WIDTH, we allow it to overflow into
@@ -537,19 +541,20 @@ def print_instruction_line(self, instr, mark_as_current):
537541 fields .append (repr (instr .arg ).rjust (_OPARG_WIDTH - opname_excess ))
538542 # Column: Opcode argument details
539543 if instr .argrepr :
540- fields .append (' (' + instr .argrepr + ') ' )
544+ fields .append (f' { theme . argument_detail } (' + instr .argrepr + f') { theme . reset } ' )
541545 print (' ' .join (fields ).rstrip (), file = self .file )
542546
543547 def print_exception_table (self , exception_entries ):
544548 file = self .file
549+ theme = get_dis_theme ()
545550 if exception_entries :
546551 print ("ExceptionTable:" , file = file )
547552 for entry in exception_entries :
548553 lasti = " lasti" if entry .lasti else ""
549554 start = entry .start_label
550555 end = entry .end_label
551556 target = entry .target_label
552- print (f" L{ start } to L{ end } -> L{ target } [{ entry .depth } ]{ lasti } " , file = file )
557+ print (f" { theme . exception_label } L{ start } { theme . reset } to { theme . exception_label } L{ end } { theme . reset } -> { theme . exception_label } L{ target } { theme . reset } [{ entry .depth } ]{ lasti } " , file = file )
553558
554559
555560class ArgResolver :
@@ -833,13 +838,14 @@ def disassemble(co, lasti=-1, *, file=None, show_caches=False, adaptive=False,
833838
834839def _disassemble_recursive (co , * , file = None , depth = None , show_caches = False , adaptive = False , show_offsets = False , show_positions = False ):
835840 disassemble (co , file = file , show_caches = show_caches , adaptive = adaptive , show_offsets = show_offsets , show_positions = show_positions )
841+ theme = get_dis_theme ()
836842 if depth is None or depth > 0 :
837843 if depth is not None :
838844 depth = depth - 1
839845 for x in co .co_consts :
840846 if hasattr (x , 'co_code' ):
841847 print (file = file )
842- print (" Disassembly of %r:" % ( x ,) , file = file )
848+ print (f" { theme . label_bg } { theme . label_fg } Disassembly of { x !r } : { theme . reset } " , file = file )
843849 _disassemble_recursive (
844850 x , file = file , depth = depth , show_caches = show_caches ,
845851 adaptive = adaptive , show_offsets = show_offsets , show_positions = show_positions
0 commit comments