Skip to content

Commit

Permalink
rename tui functions
Browse files Browse the repository at this point in the history
  • Loading branch information
murilo-cunha committed Nov 11, 2022
1 parent 88b81e8 commit 39badd2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
6 changes: 3 additions & 3 deletions databooks/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from databooks.logging import get_logger
from databooks.metadata import clear_all
from databooks.recipes import Recipe
from databooks.tui import ImgFmt, print_diffs, print_nbs
from databooks.tui import ImgFmt, diffs2rich, nbs2rich
from databooks.version import __version__

logger = get_logger(__file__)
Expand Down Expand Up @@ -420,7 +420,7 @@ def show(
if not Confirm.ask(f"Show {len(nb_paths)} notebooks?"):
raise Exit()
echo(
print_nbs(
nbs2rich(
nb_paths,
context=export or pager,
)
Expand Down Expand Up @@ -490,4 +490,4 @@ def diff(
if len(diffs) > 1 and not multiple:
if not Confirm.ask(f"Show {len(diffs)} notebook diffs?"):
raise Exit()
echo(print_diffs(diffs=diffs, context=export or pager))
echo(diffs2rich(diffs=diffs, context=export or pager))
20 changes: 10 additions & 10 deletions databooks/tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
ImgFmt = Enum("ImgFmt", {"html": "HTML", "svg": "SVG", "text": "TXT"})


def print_nb(
def nb2rich(
path: Path,
console: Console = Console(),
) -> None:
Expand All @@ -28,7 +28,7 @@ def print_nb(


@overload
def print_nbs(
def nbs2rich(
paths: List[Path],
*,
context: ImgFmt,
Expand All @@ -38,7 +38,7 @@ def print_nbs(


@overload
def print_nbs(
def nbs2rich(
paths: List[Path],
*,
context: bool,
Expand All @@ -47,7 +47,7 @@ def print_nbs(
...


def print_nbs(
def nbs2rich(
paths: List[Path],
*,
context: Union[ImgFmt, bool] = False,
Expand Down Expand Up @@ -75,12 +75,12 @@ def print_nbs(
}
with ctx_map.get(context, console.capture()):
for path in paths:
print_nb(path, console=console)
nb2rich(path, console=console)
if isinstance(context, ImgFmt):
return getattr(console, f"export_{context.name}")(**(export_kwargs or {}))


def print_diff(
def diff2rich(
diff: DiffContents,
*,
console: Console = Console(),
Expand Down Expand Up @@ -109,7 +109,7 @@ def print_diff(


@overload
def print_diffs(
def diffs2rich(
diffs: List[DiffContents],
*,
context: ImgFmt,
Expand All @@ -119,7 +119,7 @@ def print_diffs(


@overload
def print_diffs(
def diffs2rich(
diffs: List[DiffContents],
*,
context: bool,
Expand All @@ -128,7 +128,7 @@ def print_diffs(
...


def print_diffs(
def diffs2rich(
diffs: List[DiffContents],
*,
context: Union[ImgFmt, bool] = False,
Expand All @@ -152,6 +152,6 @@ def print_diffs(
}
with ctx_map.get(context, console.capture()):
for diff in diffs:
print_diff(diff, console=console)
diff2rich(diff, console=console)
if isinstance(context, ImgFmt):
return getattr(console, f"export_{context.name}")(**(export_kwargs or {}))
4 changes: 2 additions & 2 deletions tests/test_tui.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

from databooks.data_models.cell import CellMetadata, RawCell
from databooks.data_models.notebook import JupyterNotebook, NotebookMetadata
from databooks.tui import print_nb
from databooks.tui import nb2rich
from tests.test_data_models.test_notebook import TestJupyterNotebook

with resources.path("tests.files", "tui-demo.ipynb") as nb_path:
Expand Down Expand Up @@ -193,7 +193,7 @@ def test_print_nb() -> None:
"""Print notebook from path and add rules with file name."""
console = Console(file=io.StringIO(), width=50, legacy_windows=False)
with resources.path("tests.files", "tui-demo.ipynb") as path:
print_nb(path, console=console)
nb2rich(path, console=console)
assert console.file.getvalue() == "\n".join(
("───────────────── tui-demo.ipynb ─────────────────", rich_nb)
)
Expand Down

0 comments on commit 39badd2

Please sign in to comment.