11import io
2+ from typing import Any
23
34from zarr .core .group import AsyncGroup
45
@@ -15,13 +16,19 @@ def __init__(self, tree: rich.tree.Tree) -> None:
1516 self .tree = tree
1617
1718 def __repr__ (self ) -> str :
18- console = rich .console .Console (file = io .StringIO ())
19+ terminal = rich .get_console ()
20+ console = rich .console .Console (file = io .StringIO (), color_system = terminal .color_system )
1921 console .print (self .tree )
2022 return str (console .file .getvalue ())
2123
24+ def _repr_mimebundle_ (self , ** kwargs : dict [str , Any ]) -> dict [str , str ]:
25+ # For jupyter support.
26+ # We don't depend on jupyter, so we can't do the static types appropriately here.
27+ return self .tree ._repr_mimebundle_ (** kwargs ) # type: ignore[no-any-return]
28+
2229
2330async def group_tree_async (group : AsyncGroup , max_depth : int | None = None ) -> TreeRepr :
24- tree = rich .tree .Tree (label = f"[b ]{ group .name } [/b ]" )
31+ tree = rich .tree .Tree (label = f"[bold ]{ group .name } [/bold ]" )
2532 nodes = {"" : tree }
2633 members = sorted ([x async for x in group .members (max_depth = max_depth )])
2734
@@ -36,9 +43,9 @@ async def group_tree_async(group: AsyncGroup, max_depth: int | None = None) -> T
3643 # /'s and path segments. But node.name includes all that, so we build it here.
3744 name = key .rsplit ("/" )[- 1 ]
3845 if isinstance (node , AsyncGroup ):
39- label = f"[b ]{ name } [/b ]"
46+ label = f"[bold ]{ name } [/bold ]"
4047 else :
41- label = f"[b ]{ name } [/b ] { node .shape } { node .dtype } "
48+ label = f"[bold ]{ name } [/bold ] { node .shape } { node .dtype } "
4249 nodes [key ] = parent .add (label )
4350
4451 return TreeRepr (tree )
0 commit comments