mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-20 02:57:19 +03:00
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']
|
||||
for ln in tb.splitlines():
|
||||
print('\r\n', ln, sep='', end='')
|
||||
print(flush=True)
|
||||
print(end='\r\n', flush=True)
|
||||
hold_till_enter()
|
||||
|
||||
|
||||
|
@ -1,12 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
import imghdr
|
||||
import os
|
||||
from base64 import standard_b64decode, standard_b64encode
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from kitty.types import AsyncResponse
|
||||
from kitty.utils import is_png
|
||||
|
||||
from .base import (
|
||||
MATCH_WINDOW_OPTION,
|
||||
@ -89,7 +89,7 @@ def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: Arg
|
||||
if path.lower() == 'none':
|
||||
ret['data'] = '-'
|
||||
return ret
|
||||
if imghdr.what(path) != 'png':
|
||||
if not is_png(path):
|
||||
self.fatal(f'{path} is not a PNG image')
|
||||
|
||||
def file_pipe(path: str) -> CmdGenerator:
|
||||
|
@ -1,13 +1,12 @@
|
||||
#!/usr/bin/env python
|
||||
# License: GPLv3 Copyright: 2020, Kovid Goyal <kovid at kovidgoyal.net>
|
||||
|
||||
|
||||
import imghdr
|
||||
import os
|
||||
from base64 import standard_b64decode, standard_b64encode
|
||||
from typing import TYPE_CHECKING, Optional
|
||||
|
||||
from kitty.types import AsyncResponse
|
||||
from kitty.utils import is_png
|
||||
|
||||
from .base import (
|
||||
MATCH_WINDOW_OPTION,
|
||||
@ -85,7 +84,7 @@ def message_to_kitty(self, global_opts: RCOptions, opts: 'CLIOptions', args: Arg
|
||||
if path.lower() == 'none':
|
||||
ret['data'] = '-'
|
||||
return ret
|
||||
if imghdr.what(path) != 'png':
|
||||
if not is_png(path):
|
||||
self.fatal(f'{path} is not a PNG image')
|
||||
|
||||
def file_pipe(path: str) -> CmdGenerator:
|
||||
|
@ -1137,3 +1137,11 @@ def safe_extract(tar: 'tarfile.TarFile', path: str = ".", numeric_owner: bool =
|
||||
tar.extractall(path, tar.getmembers(), numeric_owner=numeric_owner)
|
||||
|
||||
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…
Reference in New Issue
Block a user