1818@dataclass
1919class FormatNodeOpts :
2020 """ Options for formatting the node """
21- compact : bool = False
21+ verbose : int = 0
2222 short : bool = False
2323 unused : bool = False
24- all : bool = False
2524 raw : bool = False
2625 internal : bool = False
2726
@@ -78,25 +77,26 @@ def format_node(
7877 extra = f"{ pname } (not loaded)"
7978 profiles .append (extra )
8079
81- if not kwargs . get ( "compact" ):
82- yield f"{ Fore .CYAN } File :{ Style .RESET_ALL } { name } "
83- yield f" { Fore . CYAN } Name: { Style . RESET_ALL } { node . Name } [ { node . Type . upper () } ] { node . Description } "
80+ yield f" { Fore . CYAN } File: { Style . RESET_ALL } { name } "
81+ yield f"{ Fore .CYAN } Name :{ Style .RESET_ALL } { node . Name } [ { node . Type . upper () } ] { node . Description } "
82+ if opts . verbose :
8483 tp = ", " .join (profiles ) or None
8584 yield f"{ Fore .CYAN } Profiles:{ Style .RESET_ALL } { tp } "
86- if node .ID :
87- yield f"{ Fore .CYAN } ID:{ Style .RESET_ALL } { node .ID } "
88- yield ""
85+ if node .ID :
86+ yield f"{ Fore .CYAN } ID:{ Style .RESET_ALL } { node .ID } "
87+ yield ""
8988
9089 index_range = None
9190 header = ''
91+ last_is_equal = False
9292
9393 for k in keys :
9494
9595 # Get the index range title
9696 ir = maps .INDEX_RANGES .get_index_range (k )
9797 if index_range != ir :
9898 index_range = ir
99- if not opts .compact :
99+ if opts .verbose :
100100 header = Fore .YELLOW + ir .description + Style .RESET_ALL
101101
102102 obj = node .GetIndexEntry (k )
@@ -107,14 +107,19 @@ def format_node(
107107 if obj == minusobj :
108108 linegen = format_od_object (node , k , short = True )
109109 lines = [remove_color (line ) for line in linegen ]
110- lines [0 ] = Fore .LIGHTBLACK_EX + lines [0 ] + f" { Fore .LIGHTRED_EX } <EQUAL>{ Style .RESET_ALL } "
110+ pre = " " if opts .verbose else ''
111+ lines [0 ] = f"{ pre } { Fore .LIGHTBLACK_EX } { lines [0 ]} { Fore .GREEN } <EQUAL>{ Style .RESET_ALL } "
111112 yield from lines
113+ last_is_equal = True
112114 continue
113115
116+ if last_is_equal and opts .verbose :
117+ yield ""
118+
114119 # Yield the text for the index
115120 lines = list (format_od_object (
116- node , k , short = opts .short , compact = opts .compact , unused = opts .unused ,
117- verbose = opts . all , raw = opts .raw
121+ node , k , short = opts .short , verbose = opts .verbose , unused = opts .unused ,
122+ raw = opts .raw
118123 ))
119124
120125 if opts .internal and lines [- 1 ] == "" :
@@ -133,12 +138,12 @@ def format_node(
133138 obj = node .GetIndexEntry (k )
134139 lines = pformat (obj , width = TERM_COLS ).splitlines ()
135140 yield from lines
136- if not opts .compact :
141+ if opts .verbose :
137142 yield ""
138143
139144
140145def format_od_header (
141- node : Node , index : int , * , unused = False , compact = False , raw = False ,
146+ node : Node , index : int , * , unused = False , verbose = False , raw = False ,
142147 entry : TIndexEntry | None = None
143148) -> tuple [str , dict [str , str ]]:
144149 """Get the print output for a dictionary entry header"""
@@ -194,13 +199,13 @@ def format_od_header(
194199 'name' : f"{ Fore .LIGHTWHITE_EX } { t_name } { Style .RESET_ALL } " ,
195200 'struct' : f"{ Fore .LIGHTYELLOW_EX } [{ t_string .upper ()} ]{ Style .RESET_ALL } " ,
196201 'flags' : f" { Fore .MAGENTA } { t_flags } { Style .RESET_ALL } " if flags else '' ,
197- 'pre' : ' ' if not compact else '' ,
202+ 'pre' : ' ' if verbose else '' ,
198203 }
199204
200205
201206def format_od_object (
202- node : Node , index : int , * , short = False , compact = False ,
203- unused = False , verbose = False , raw = False ,
207+ node : Node , index : int , * , short = False ,
208+ unused = False , verbose : int = 0 , raw = False ,
204209 widths : dict [str , int ]| None = None
205210) -> Generator [str , None , None ]:
206211 """Return the print formatting for an object dictionary entry."""
@@ -211,7 +216,7 @@ def format_od_object(
211216
212217 # Get the header for the entry and output it unless it is empty
213218 line , fields = format_od_header (
214- node , index , unused = unused , compact = compact , entry = param , raw = raw
219+ node , index , unused = unused , verbose = verbose , entry = param , raw = raw
215220 )
216221 if not line :
217222 return
@@ -292,7 +297,7 @@ def format_od_object(
292297 t_comment = f"{ Fore .LIGHTBLACK_EX } /* { t_comment } */{ Style .RESET_ALL } "
293298
294299 # Omit printing the first element unless specifically requested
295- if (not verbose and i == 0
300+ if (verbose < 2 and i == 0
296301 and obj ['struct' ] & OD .MultipleSubindexes
297302 and not t_comment
298303 ):
@@ -335,20 +340,20 @@ def format_od_object(
335340 for infoentry in infos :
336341 yield fmt .format (** infoentry )
337342
338- if not compact and infos :
343+ if verbose and infos :
339344 yield ""
340345
341346
342347def format_diff_nodes (
343- od1 : Node , od2 : Node , * , data = False , raw = False ,
348+ od1 : Node , od2 : Node , * , data = False , raw = False , verbose : int = 0 ,
344349 internal = False , show = False
345350) -> Generator [str , None , None ]:
346351 """ Compare two object dictionaries and return the formatted differences. """
347352
348353 if internal or data :
349354 diffs = jsonod .diff (od1 , od2 , internal = internal )
350355 else :
351- diffs = text_diff (od1 , od2 , data_mode = raw )
356+ diffs = text_diff (od1 , od2 , data_mode = raw , verbose = verbose )
352357
353358 rst = Style .RESET_ALL
354359
@@ -413,7 +418,7 @@ def _pprint(text: str, prefix: str = ' '):
413418 yield f"{ Fore .RED } { chtype } { ppath } { change } { rst } "
414419
415420
416- def text_diff (od1 : Node , od2 : Node , data_mode : bool = False ) -> TDiffNodes :
421+ def text_diff (od1 : Node , od2 : Node , data_mode : bool = False , verbose : int = 0 ) -> TDiffNodes :
417422 """ Compare two object dictionaries as text and return the differences. """
418423
419424 # Get all indices for the nodes
@@ -433,15 +438,15 @@ def text_diff(od1: Node, od2: Node, data_mode: bool=False) -> TDiffNodes:
433438 # Run through the formatting to get the width for the columns
434439 widths : dict [str , int ] = {}
435440 if index in keys1 :
436- list (format_od_object (od1 , index , unused = True , widths = widths ))
441+ list (format_od_object (od1 , index , unused = True , verbose = verbose , widths = widths ))
437442 if index in keys2 :
438- list (format_od_object (od2 , index , unused = True , widths = widths ))
443+ list (format_od_object (od2 , index , unused = True , verbose = verbose , widths = widths ))
439444
440445 if index in keys1 :
441- text1 = list (format_od_object (od1 , index , unused = True , widths = widths ))
446+ text1 = list (format_od_object (od1 , index , unused = True , verbose = verbose , widths = widths ))
442447 entry1 = od1 .GetIndexEntry (index )
443448 if index in keys2 :
444- text2 = list (format_od_object (od2 , index , unused = True , widths = widths ))
449+ text2 = list (format_od_object (od2 , index , unused = True , verbose = verbose , widths = widths ))
445450 entry2 = od2 .GetIndexEntry (index )
446451
447452 if data_mode :
0 commit comments