mirror of
https://github.com/kovidgoyal/kitty.git
synced 2024-09-20 11:07:38 +03:00
icat kitten: Add support for displaying images at http(s) URLs
Fixes #1340
This commit is contained in:
parent
af9e633d56
commit
a09fb7b20d
@ -6,6 +6,8 @@ Changelog
|
||||
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
|
||||
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])):
|
||||
raise SystemExit(f'The --place option can only be used with a single image, not {items}')
|
||||
sys.stdout.buffer.write(b'\0337') # save cursor
|
||||
url_pat = re.compile(r'https?://', flags=re.I)
|
||||
for item in items:
|
||||
is_tempfile = False
|
||||
try:
|
||||
@ -326,11 +327,22 @@ def main(args=sys.argv):
|
||||
tf.write(item), tf.close()
|
||||
item = tf.name
|
||||
is_tempfile = True
|
||||
if os.path.isdir(item):
|
||||
for x in scan(item):
|
||||
process(item, args)
|
||||
else:
|
||||
if url_pat.match(item) is not None:
|
||||
from urllib.request import urlretrieve
|
||||
with NamedTemporaryFile(prefix='url-image-data-', delete=False) as tf:
|
||||
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)
|
||||
else:
|
||||
if os.path.isdir(item):
|
||||
for x in scan(item):
|
||||
process(item, args)
|
||||
else:
|
||||
process(item, args, is_tempfile)
|
||||
except NoImageMagick as e:
|
||||
raise SystemExit(str(e))
|
||||
except ConvertFailed as e:
|
||||
|
Loading…
Reference in New Issue
Block a user