Coverage for databooks/tui.py: 100%

16 statements  

« 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 

5 

6from rich.console import Console 

7from rich.theme import Theme 

8 

9from databooks import JupyterNotebook 

10 

11DATABOOKS_TUI = Theme({"in_count": "blue", "out_count": "orange3", "kernel": "bold"}) 

12 

13databooks_console = Console(theme=DATABOOKS_TUI) 

14 

15 

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) 

21 

22 

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)