Merge branch 'png' of https://github.com/page-down/kitty
This commit is contained in:
commit
cbf3b5860b
@ -55,7 +55,7 @@ def real_main(args: List[str]) -> None:
|
|||||||
tb = data['tb']
|
tb = data['tb']
|
||||||
for ln in tb.splitlines():
|
for ln in tb.splitlines():
|
||||||
print('\r\n', ln, sep='', end='')
|
print('\r\n', ln, sep='', end='')
|
||||||
print(flush=True)
|
print(end='\r\n', flush=True)
|
||||||
hold_till_enter()
|
hold_till_enter()
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import imghdr
|
|
||||||
import os
|
import os
|
||||||
from base64 import standard_b64decode, standard_b64encode
|
from base64 import standard_b64decode, standard_b64encode
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from kitty.types import AsyncResponse
|
from kitty.types import AsyncResponse
|
||||||
|
from kitty.utils import is_png
|
||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
MATCH_WINDOW_OPTION,
|
MATCH_WINDOW_OPTION,
|
||||||
@ -89,7 +89,7 @@ failed, the command will exit with a success code.
|
|||||||
if path.lower() == 'none':
|
if path.lower() == 'none':
|
||||||
ret['data'] = '-'
|
ret['data'] = '-'
|
||||||
return ret
|
return ret
|
||||||
if imghdr.what(path) != 'png':
|
if not is_png(path):
|
||||||
self.fatal(f'{path} is not a PNG image')
|
self.fatal(f'{path} is not a PNG image')
|
||||||
|
|
||||||
def file_pipe(path: str) -> CmdGenerator:
|
def file_pipe(path: str) -> CmdGenerator:
|
||||||
|
|||||||
@ -1,13 +1,12 @@
|
|||||||
#!/usr/bin/env python
|
#!/usr/bin/env python
|
||||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
|
|
||||||
import imghdr
|
|
||||||
import os
|
import os
|
||||||
from base64 import standard_b64decode, standard_b64encode
|
from base64 import standard_b64decode, standard_b64encode
|
||||||
from typing import TYPE_CHECKING, Optional
|
from typing import TYPE_CHECKING, Optional
|
||||||
|
|
||||||
from kitty.types import AsyncResponse
|
from kitty.types import AsyncResponse
|
||||||
|
from kitty.utils import is_png
|
||||||
|
|
||||||
from .base import (
|
from .base import (
|
||||||
MATCH_WINDOW_OPTION,
|
MATCH_WINDOW_OPTION,
|
||||||
@ -85,7 +84,7 @@ failed, the command will exit with a success code.
|
|||||||
if path.lower() == 'none':
|
if path.lower() == 'none':
|
||||||
ret['data'] = '-'
|
ret['data'] = '-'
|
||||||
return ret
|
return ret
|
||||||
if imghdr.what(path) != 'png':
|
if not is_png(path):
|
||||||
self.fatal(f'{path} is not a PNG image')
|
self.fatal(f'{path} is not a PNG image')
|
||||||
|
|
||||||
def file_pipe(path: str) -> CmdGenerator:
|
def file_pipe(path: str) -> CmdGenerator:
|
||||||
|
|||||||
@ -1137,3 +1137,11 @@ def extract_all_from_tarfile_safely(tf: 'tarfile.TarFile', dest: str) -> None:
|
|||||||
tar.extractall(path, tar.getmembers(), numeric_owner=numeric_owner)
|
tar.extractall(path, tar.getmembers(), numeric_owner=numeric_owner)
|
||||||
|
|
||||||
safe_extract(tf, dest)
|
safe_extract(tf, dest)
|
||||||
|
|
||||||
|
|
||||||
|
def is_png(path: str) -> bool:
|
||||||
|
if path:
|
||||||
|
with suppress(Exception), open(path, 'rb') as f:
|
||||||
|
header = f.read(8)
|
||||||
|
return header.startswith(b'\211PNG\r\n\032\n')
|
||||||
|
return False
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user