mirror of
https://github.com/enjoy-digital/litex.git
synced 2025-01-04 09:52:26 -05:00
gen/fhdl/hierarchy: Add with_colors parameters to allow enabling/disabling colors.
This commit is contained in:
parent
4497569118
commit
4a1486b1db
1 changed files with 13 additions and 9 deletions
|
@ -14,11 +14,15 @@ class LiteXHierarchyExplorer:
|
|||
tree_ident = "│ "
|
||||
tree_entry = "└─── "
|
||||
|
||||
def __init__(self, top, depth=None):
|
||||
self.top = top
|
||||
self.depth = depth
|
||||
def __init__(self, top, depth=None, with_colors=True):
|
||||
self.top = top
|
||||
self.depth = depth
|
||||
self.with_colors = with_colors
|
||||
|
||||
def get_tree(self, module, ident=0, with_modules=True, with_instances=True):
|
||||
def _colorer(self, s, color="bright"):
|
||||
return colorer(s=s, color=color, enable=self.with_colors)
|
||||
|
||||
def get_tree(self, module, ident=0, with_modules=True, with_instances=True, with_colors=True):
|
||||
r = ""
|
||||
names = set()
|
||||
names.add(None)
|
||||
|
@ -31,7 +35,7 @@ class LiteXHierarchyExplorer:
|
|||
n += 1
|
||||
names.add(name)
|
||||
if with_modules:
|
||||
r += f"{self.tree_ident*ident}{self.tree_entry}{colorer(name, 'cyan')} ({mod.__class__.__name__})\n"
|
||||
r += f"{self.tree_ident*ident}{self.tree_entry}{self._colorer(name, 'cyan')} ({mod.__class__.__name__})\n"
|
||||
if (self.depth is None) or (ident < self.depth):
|
||||
r += self.get_tree(mod, ident + 1)
|
||||
|
||||
|
@ -44,13 +48,13 @@ class LiteXHierarchyExplorer:
|
|||
if s in v._fragment.specials:
|
||||
show = False
|
||||
if show:
|
||||
r += f"{self.tree_ident*ident}{self.tree_entry}{colorer(f'[{s.of}]', 'yellow')}\n"
|
||||
r += f"{self.tree_ident*ident}{self.tree_entry}{self._colorer(f'[{s.of}]', 'yellow')}\n"
|
||||
return r
|
||||
|
||||
def __repr__(self):
|
||||
r = "\n"
|
||||
r += f"{colorer(self.top.__class__.__name__, 'underline')}\n"
|
||||
r += f"{self._colorer(self.top.__class__.__name__, 'underline')}\n"
|
||||
r += self.get_tree(self.top)
|
||||
r += f"{colorer('* ', 'cyan')}: Generated name.\n"
|
||||
r += f"{colorer('[]', 'yellow')}: BlackBox.\n"
|
||||
r += f"{self._colorer('* ', 'cyan')}: Generated name.\n"
|
||||
r += f"{self._colorer('[]', 'yellow')}: BlackBox.\n"
|
||||
return r
|
||||
|
|
Loading…
Reference in a new issue