nbcat 0.9.6__py3-none-any.whl → 0.10.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nbcat/__init__.py +1 -1
- nbcat/image.py +28 -0
- nbcat/main.py +2 -1
- nbcat/schemas.py +1 -1
- {nbcat-0.9.6.dist-info → nbcat-0.10.0.dist-info}/METADATA +2 -1
- nbcat-0.10.0.dist-info/RECORD +13 -0
- nbcat-0.9.6.dist-info/RECORD +0 -12
- {nbcat-0.9.6.dist-info → nbcat-0.10.0.dist-info}/WHEEL +0 -0
- {nbcat-0.9.6.dist-info → nbcat-0.10.0.dist-info}/entry_points.txt +0 -0
- {nbcat-0.9.6.dist-info → nbcat-0.10.0.dist-info}/licenses/LICENSE +0 -0
nbcat/__init__.py
CHANGED
@@ -1 +1 @@
|
|
1
|
-
__version__ = "0.
|
1
|
+
__version__ = "0.10.0"
|
nbcat/image.py
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
import base64
|
2
|
+
import shutil
|
3
|
+
from io import BytesIO
|
4
|
+
from platform import system
|
5
|
+
|
6
|
+
from PIL import Image as PilImage
|
7
|
+
from rich.console import Console, ConsoleOptions, RenderResult
|
8
|
+
from rich.text import Text
|
9
|
+
from timg import METHODS, Renderer
|
10
|
+
|
11
|
+
|
12
|
+
class Image:
|
13
|
+
def __init__(self, image: str):
|
14
|
+
img = BytesIO(base64.b64decode(image.replace("\n", "")))
|
15
|
+
self.image = PilImage.open(img)
|
16
|
+
|
17
|
+
@property
|
18
|
+
def method_class(self):
|
19
|
+
# TODO: auto detect terminal to benefit from sixel protocol support
|
20
|
+
method = "a24h" if system() != "Windows" else "ascii"
|
21
|
+
return METHODS[method]["class"]
|
22
|
+
|
23
|
+
def __rich_console__(self, console: Console, options: ConsoleOptions) -> RenderResult:
|
24
|
+
img = Renderer()
|
25
|
+
img.load_image(self.image)
|
26
|
+
img.resize(shutil.get_terminal_size()[0] - 1)
|
27
|
+
output = img.to_string(self.method_class)
|
28
|
+
yield Text.from_ansi(output)
|
nbcat/main.py
CHANGED
@@ -22,6 +22,7 @@ from .exceptions import (
|
|
22
22
|
NotebookNotFoundError,
|
23
23
|
UnsupportedNotebookTypeError,
|
24
24
|
)
|
25
|
+
from .image import Image
|
25
26
|
from .markdown import Markdown
|
26
27
|
from .schemas import Cell, Notebook
|
27
28
|
|
@@ -94,7 +95,7 @@ def render_cell(cell: Cell) -> list[tuple[Union[str, None], RenderableType]]:
|
|
94
95
|
return Text(input)
|
95
96
|
|
96
97
|
def _render_image(input: str) -> None:
|
97
|
-
return
|
98
|
+
return Image(input)
|
98
99
|
|
99
100
|
def _render_json(input: str) -> Pretty:
|
100
101
|
return Pretty(input)
|
nbcat/schemas.py
CHANGED
@@ -34,7 +34,7 @@ class DisplayDataOutput(BaseOutput):
|
|
34
34
|
def output(self) -> Union[CellOutput, None]:
|
35
35
|
data_type_map = {
|
36
36
|
"text/html": OutputCellType.HTML,
|
37
|
-
"
|
37
|
+
"image/png": OutputCellType.IMAGE,
|
38
38
|
"text/plain": OutputCellType.PLAIN,
|
39
39
|
"application/vnd.raw.v1+json": OutputCellType.JSON,
|
40
40
|
}
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: nbcat
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.10.0
|
4
4
|
Summary: cat for jupyter notebooks
|
5
5
|
Project-URL: Homepage, https://github.com/akopdev/nbcat
|
6
6
|
Project-URL: Repository, https://github.com/akopdev/nbcat
|
@@ -33,6 +33,7 @@ Requires-Dist: argcomplete
|
|
33
33
|
Requires-Dist: pydantic
|
34
34
|
Requires-Dist: requests
|
35
35
|
Requires-Dist: rich
|
36
|
+
Requires-Dist: timg
|
36
37
|
Provides-Extra: dev
|
37
38
|
Requires-Dist: pytest; extra == 'dev'
|
38
39
|
Requires-Dist: pytest-cov; extra == 'dev'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
nbcat/__init__.py,sha256=v4zmKjsKOPZbp6BrWoz7iK4ST0sdZdUh9bQSJmluZ5o,23
|
2
|
+
nbcat/enums.py,sha256=Fn8PIcLl_uY4nQIs1EUvmKTwfhNUIZgmhRFiCSJk9wk,411
|
3
|
+
nbcat/exceptions.py,sha256=Ho7LQz9K70VtIMDNtAwuAtGmb-lFKxGxSj7MN3-EpDA,321
|
4
|
+
nbcat/image.py,sha256=xv_IH2JMyzelUvLjVUbubfc8blmRuxqa-FcKXn25LSk,909
|
5
|
+
nbcat/main.py,sha256=89qxlA6viuRP6_ugbf7zRE4clH4oX67-1t1EbpABUfA,5838
|
6
|
+
nbcat/markdown.py,sha256=K6yL9rY3uTxMPsRIJnxqNHmCX2Qc-f3my8eiHxTLfic,1835
|
7
|
+
nbcat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
8
|
+
nbcat/schemas.py,sha256=a7GoKgPTHgun199-J-sZq-ahkdQwvyRaCdQVg1gC798,3135
|
9
|
+
nbcat-0.10.0.dist-info/METADATA,sha256=jAKupKwXwBtwqMmTT96IE1LihLl3GUhrfLBd0dfTAxw,4103
|
10
|
+
nbcat-0.10.0.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
11
|
+
nbcat-0.10.0.dist-info/entry_points.txt,sha256=io_GRDsecAkYuCZALsjyea3VBq91VCoSznqlZEAJshY,42
|
12
|
+
nbcat-0.10.0.dist-info/licenses/LICENSE,sha256=7GjUnahXdd5opdvlpJdb1BisLbiXt2iOFhzIUduhdkE,1072
|
13
|
+
nbcat-0.10.0.dist-info/RECORD,,
|
nbcat-0.9.6.dist-info/RECORD
DELETED
@@ -1,12 +0,0 @@
|
|
1
|
-
nbcat/__init__.py,sha256=IgVHjr-TeioZYLJSkvpT80LLGi6U3ONzR1cfYfd5XNQ,22
|
2
|
-
nbcat/enums.py,sha256=Fn8PIcLl_uY4nQIs1EUvmKTwfhNUIZgmhRFiCSJk9wk,411
|
3
|
-
nbcat/exceptions.py,sha256=Ho7LQz9K70VtIMDNtAwuAtGmb-lFKxGxSj7MN3-EpDA,321
|
4
|
-
nbcat/main.py,sha256=7RYjHvWmKWoD9LFI1dopKvp_wvqWa2Rk9AYZ_RsrIaw,5805
|
5
|
-
nbcat/markdown.py,sha256=K6yL9rY3uTxMPsRIJnxqNHmCX2Qc-f3my8eiHxTLfic,1835
|
6
|
-
nbcat/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
7
|
-
nbcat/schemas.py,sha256=fjSbdXa4pHKRV1Z-vUESkYZywkojanCvSu8s7rc9Xkw,3134
|
8
|
-
nbcat-0.9.6.dist-info/METADATA,sha256=v-8f9HAlHG2t-Mw36CZAIGcMRTeCWiyt0BzZMlS164w,4082
|
9
|
-
nbcat-0.9.6.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
10
|
-
nbcat-0.9.6.dist-info/entry_points.txt,sha256=io_GRDsecAkYuCZALsjyea3VBq91VCoSznqlZEAJshY,42
|
11
|
-
nbcat-0.9.6.dist-info/licenses/LICENSE,sha256=7GjUnahXdd5opdvlpJdb1BisLbiXt2iOFhzIUduhdkE,1072
|
12
|
-
nbcat-0.9.6.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|