Coverage for databooks/tui.py: 100%
16 statements
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-04 16:41 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2022-11-04 16:41 +0000
1"""Terminal user interface (TUI) helper functions and components."""
2from contextlib import nullcontext
3from pathlib import Path
4from typing import Any, List
6from rich.console import Console
7from rich.theme import Theme
9from databooks import JupyterNotebook
11DATABOOKS_TUI = Theme({"in_count": "blue", "out_count": "orange3", "kernel": "bold"})
13databooks_console = Console(theme=DATABOOKS_TUI)
16def print_nb(path: Path, console: Console = databooks_console) -> None:
17 """Show rich representation of notebook in terminal."""
18 notebook = JupyterNotebook.parse_file(path)
19 console.rule(path.resolve().name)
20 console.print(notebook)
23def print_nbs(
24 paths: List[Path],
25 console: Console = databooks_console,
26 use_pager: bool = False,
27 **kwargs_print_nb: Any
28) -> None:
29 """Show rich representation of notebooks in terminal."""
30 with console.pager(styles=True) if use_pager else nullcontext(): # type: ignore
31 for path in paths:
32 print_nb(path, console=console, **kwargs_print_nb)