Make icat a kitten
The kittens framework did not exist when icat was first written.
This commit is contained in:
parent
6d038f5cdf
commit
2be2f6aa0c
@ -6,7 +6,7 @@ import sys
|
|||||||
|
|
||||||
|
|
||||||
def icat(args):
|
def icat(args):
|
||||||
from kitty.icat import main
|
from kittens.icat.main import main
|
||||||
main(args)
|
main(args)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
0
kittens/icat/__init__.py
Normal file
0
kittens/icat/__init__.py
Normal file
@ -2,7 +2,6 @@
|
|||||||
# vim:fileencoding=utf-8
|
# vim:fileencoding=utf-8
|
||||||
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
# License: GPL v3 Copyright: 2017, Kovid Goyal <kovid at kovidgoyal.net>
|
||||||
|
|
||||||
import codecs
|
|
||||||
import mimetypes
|
import mimetypes
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
@ -17,24 +16,10 @@ from tempfile import NamedTemporaryFile
|
|||||||
|
|
||||||
from kitty.cli import parse_args
|
from kitty.cli import parse_args
|
||||||
from kitty.constants import appname
|
from kitty.constants import appname
|
||||||
from kitty.utils import fit_image, read_with_timeout, screen_size_function
|
from kitty.utils import fit_image, read_with_timeout
|
||||||
|
|
||||||
screen_size = screen_size_function()
|
|
||||||
try:
|
|
||||||
fsenc = sys.getfilesystemencoding() or 'utf-8'
|
|
||||||
codecs.lookup(fsenc)
|
|
||||||
except Exception:
|
|
||||||
fsenc = 'utf-8'
|
|
||||||
|
|
||||||
|
|
||||||
class OpenFailed(ValueError):
|
|
||||||
|
|
||||||
def __init__(self, path, message):
|
|
||||||
ValueError.__init__(
|
|
||||||
self, 'Failed to open: {} with error: {}'.format(path, message)
|
|
||||||
)
|
|
||||||
self.path = path
|
|
||||||
|
|
||||||
|
from ..tui.images import ImageData, OpenFailed, fsenc, screen_size
|
||||||
|
from ..tui.operations import clear_images_on_screen, serialize_gr_command
|
||||||
|
|
||||||
OPTIONS = '''\
|
OPTIONS = '''\
|
||||||
--align
|
--align
|
||||||
@ -99,13 +84,7 @@ def options_spec():
|
|||||||
|
|
||||||
|
|
||||||
def write_gr_cmd(cmd, payload=None):
|
def write_gr_cmd(cmd, payload=None):
|
||||||
cmd = ','.join('{}={}'.format(k, v) for k, v in cmd.items())
|
sys.stdout.buffer.write(serialize_gr_command(cmd, payload))
|
||||||
w = sys.stdout.buffer.write
|
|
||||||
w(b'\033_G'), w(cmd.encode('ascii'))
|
|
||||||
if payload:
|
|
||||||
w(b';')
|
|
||||||
w(payload)
|
|
||||||
w(b'\033\\')
|
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
@ -186,9 +165,6 @@ def show(outfile, width, height, fmt, transmit_mode='t', align='center', place=N
|
|||||||
write_chunked(cmd, data)
|
write_chunked(cmd, data)
|
||||||
|
|
||||||
|
|
||||||
ImageData = namedtuple('ImageData', 'fmt width height mode')
|
|
||||||
|
|
||||||
|
|
||||||
def run_imagemagick(path, cmd, keep_stdout=True):
|
def run_imagemagick(path, cmd, keep_stdout=True):
|
||||||
try:
|
try:
|
||||||
p = subprocess.run(cmd, stdout=subprocess.PIPE if keep_stdout else subprocess.DEVNULL, stderr=subprocess.PIPE)
|
p = subprocess.run(cmd, stdout=subprocess.PIPE if keep_stdout else subprocess.DEVNULL, stderr=subprocess.PIPE)
|
||||||
@ -338,7 +314,7 @@ def main(args=sys.argv):
|
|||||||
detect_support.has_files = args.transfer_mode == 'file'
|
detect_support.has_files = args.transfer_mode == 'file'
|
||||||
errors = []
|
errors = []
|
||||||
if args.clear:
|
if args.clear:
|
||||||
write_gr_cmd({'a': 'd'})
|
sys.stdout.buffer.write(clear_images_on_screen(delete_data=True))
|
||||||
if not items:
|
if not items:
|
||||||
return
|
return
|
||||||
if not items:
|
if not items:
|
||||||
@ -365,5 +341,9 @@ def main(args=sys.argv):
|
|||||||
raise SystemExit(1)
|
raise SystemExit(1)
|
||||||
|
|
||||||
|
|
||||||
|
def handle_result(args, current_char, target_window_id, boss):
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
@ -33,7 +33,7 @@ class OpenFailed(ValueError):
|
|||||||
|
|
||||||
def __init__(self, path, message):
|
def __init__(self, path, message):
|
||||||
ValueError.__init__(
|
ValueError.__init__(
|
||||||
self, 'Failed to open: {} with error: {}'.format(path, message)
|
self, 'Failed to open image: {} with error: {}'.format(path, message)
|
||||||
)
|
)
|
||||||
self.path = path
|
self.path = path
|
||||||
|
|
||||||
|
|||||||
@ -162,7 +162,7 @@ def serialize_gr_command(cmd, payload=None):
|
|||||||
|
|
||||||
|
|
||||||
def clear_images_on_screen(delete_data=False) -> str:
|
def clear_images_on_screen(delete_data=False) -> str:
|
||||||
return serialize_gr_command({'a': 'D' if delete_data else 'd'})
|
return serialize_gr_command({'a': 'd', 'd': 'A' if delete_data else 'a'})
|
||||||
|
|
||||||
|
|
||||||
def init_state(alternate_screen=True):
|
def init_state(alternate_screen=True):
|
||||||
|
|||||||
@ -220,7 +220,7 @@ def shape_string(text="abcd", family='monospace', size=11.0, dpi=96.0, path=None
|
|||||||
|
|
||||||
def display_bitmap(rgb_data, width, height):
|
def display_bitmap(rgb_data, width, height):
|
||||||
from tempfile import NamedTemporaryFile
|
from tempfile import NamedTemporaryFile
|
||||||
from kitty.icat import detect_support, show
|
from kittens.icat.main import detect_support, show
|
||||||
if not hasattr(display_bitmap, 'detected') and not detect_support():
|
if not hasattr(display_bitmap, 'detected') and not detect_support():
|
||||||
raise SystemExit('Your terminal does not support the graphics protocol')
|
raise SystemExit('Your terminal does not support the graphics protocol')
|
||||||
display_bitmap.detected = True
|
display_bitmap.detected = True
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user