mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-28 11:11:47 +02:00
icat kitten: Add support for displaying images at http(s) URLs
Fixes #1340
This commit is contained in:
@@ -6,6 +6,8 @@ Changelog
|
|||||||
0.13.4 [future]
|
0.13.4 [future]
|
||||||
---------------------
|
---------------------
|
||||||
|
|
||||||
|
- icat kitten: Add support for displaying images at http(s) URLs (:iss:`1340`)
|
||||||
|
|
||||||
- A new option :opt:`strip_trailing_spaces` to optionally remove trailing
|
- A new option :opt:`strip_trailing_spaces` to optionally remove trailing
|
||||||
spaces from lines when copying to clipboard.
|
spaces from lines when copying to clipboard.
|
||||||
|
|
||||||
|
|||||||
@@ -318,6 +318,7 @@ def main(args=sys.argv):
|
|||||||
if len(items) > 1 or (isinstance(items[0], str) and os.path.isdir(items[0])):
|
if len(items) > 1 or (isinstance(items[0], str) and os.path.isdir(items[0])):
|
||||||
raise SystemExit(f'The --place option can only be used with a single image, not {items}')
|
raise SystemExit(f'The --place option can only be used with a single image, not {items}')
|
||||||
sys.stdout.buffer.write(b'\0337') # save cursor
|
sys.stdout.buffer.write(b'\0337') # save cursor
|
||||||
|
url_pat = re.compile(r'https?://', flags=re.I)
|
||||||
for item in items:
|
for item in items:
|
||||||
is_tempfile = False
|
is_tempfile = False
|
||||||
try:
|
try:
|
||||||
@@ -326,11 +327,22 @@ def main(args=sys.argv):
|
|||||||
tf.write(item), tf.close()
|
tf.write(item), tf.close()
|
||||||
item = tf.name
|
item = tf.name
|
||||||
is_tempfile = True
|
is_tempfile = True
|
||||||
if os.path.isdir(item):
|
if url_pat.match(item) is not None:
|
||||||
for x in scan(item):
|
from urllib.request import urlretrieve
|
||||||
process(item, args)
|
with NamedTemporaryFile(prefix='url-image-data-', delete=False) as tf:
|
||||||
else:
|
try:
|
||||||
|
urlretrieve(item, filename=tf.name)
|
||||||
|
except Exception as e:
|
||||||
|
raise SystemExit('Failed to download image at URL: {} with error: {}'.format(item, e))
|
||||||
|
item = tf.name
|
||||||
|
is_tempfile = True
|
||||||
process(item, args, is_tempfile)
|
process(item, args, is_tempfile)
|
||||||
|
else:
|
||||||
|
if os.path.isdir(item):
|
||||||
|
for x in scan(item):
|
||||||
|
process(item, args)
|
||||||
|
else:
|
||||||
|
process(item, args, is_tempfile)
|
||||||
except NoImageMagick as e:
|
except NoImageMagick as e:
|
||||||
raise SystemExit(str(e))
|
raise SystemExit(str(e))
|
||||||
except ConvertFailed as e:
|
except ConvertFailed as e:
|
||||||
|
|||||||
Reference in New Issue
Block a user