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) -> Generator [str , None , None ]:
205210 """Return the print formatting for an object dictionary entry."""
206211
@@ -210,7 +215,7 @@ def format_od_object(
210215
211216 # Get the header for the entry and output it unless it is empty
212217 line , fmt = format_od_header (
213- node , index , unused = unused , compact = compact , entry = param , raw = raw
218+ node , index , unused = unused , verbose = verbose , entry = param , raw = raw
214219 )
215220 if not line :
216221 return
@@ -278,7 +283,7 @@ def format_od_object(
278283 t_comment = f"{ Fore .LIGHTBLACK_EX } /* { t_comment } */{ Style .RESET_ALL } "
279284
280285 # Omit printing the first element unless specifically requested
281- if (not verbose and i == 0
286+ if (verbose < 2 and i == 0
282287 and obj ['struct' ] & OD .MultipleSubindexes
283288 and not t_comment
284289 ):
@@ -317,20 +322,20 @@ def format_od_object(
317322 for infoentry in infos :
318323 yield fmt .format (** infoentry )
319324
320- if not compact and infos :
325+ if verbose and infos :
321326 yield ""
322327
323328
324329def format_diff_nodes (
325- od1 : Node , od2 : Node , * , data = False , raw = False ,
330+ od1 : Node , od2 : Node , * , data = False , raw = False , verbose : int = 0 ,
326331 internal = False , show = False
327332) -> Generator [str , None , None ]:
328333 """ Compare two object dictionaries and return the formatted differences. """
329334
330335 if internal or data :
331336 diffs = jsonod .diff (od1 , od2 , internal = internal )
332337 else :
333- diffs = text_diff (od1 , od2 , data_mode = raw )
338+ diffs = text_diff (od1 , od2 , data_mode = raw , verbose = verbose )
334339
335340 rst = Style .RESET_ALL
336341
@@ -395,7 +400,7 @@ def _pprint(text: str, prefix: str = ' '):
395400 yield f"{ Fore .RED } { chtype } { ppath } { change } { rst } "
396401
397402
398- def text_diff (od1 : Node , od2 : Node , data_mode : bool = False ) -> TDiffNodes :
403+ def text_diff (od1 : Node , od2 : Node , data_mode : bool = False , verbose : int = 0 ) -> TDiffNodes :
399404 """ Compare two object dictionaries as text and return the differences. """
400405
401406 # Get all indices for the nodes
@@ -412,10 +417,10 @@ def text_diff(od1: Node, od2: Node, data_mode: bool=False) -> TDiffNodes:
412417 entry1 : TIndexEntry = {}
413418 entry2 : TIndexEntry = {}
414419 if index in keys1 :
415- text1 = list (format_od_object (od1 , index , unused = True ))
420+ text1 = list (format_od_object (od1 , index , unused = True , verbose = verbose ))
416421 entry1 = od1 .GetIndexEntry (index )
417422 if index in keys2 :
418- text2 = list (format_od_object (od2 , index , unused = True ))
423+ text2 = list (format_od_object (od2 , index , unused = True , verbose = verbose ))
419424 entry2 = od2 .GetIndexEntry (index )
420425
421426 if data_mode :
0 commit comments