Closed grst closed 5 years ago
I'll look at your script when I have a moment, but the icat kitten is itself a simple script. it should be trivial to modify it, replace the little bits of kitty functionality it uses with stdlib quivalents and use it.
See icat/main.py in the kitty source code.
Thanks @kovidgoyal,
I indeed had a look there to come up with the minimal working example... however it did not work out. While I agree that I probably should refactor the icat
code for my purposes I really want to understand the underlying basics.
From what I understand from the docs this should be the minimal code to make it work, yet it does not.
with open('file.png', 'rb') as f:
png = base64.standard_b64encode(f.read())
protocol_start = b'\033_Gf=100;'
protocol_end = b'\033\\'
sys.stdout.buffer.write(protocol_start + png + protocol_end)
sys.stdout.buffer.flush()
well ok I'll see if I can cook up a minimal example when I have a moment.
looking at your example, you need a=T which means transmit and display the default is a=t which is only transmit. This patch will show you the command icat uses:
diff --git a/kittens/icat/main.py b/kittens/icat/main.py
index 5f2f9815..ef2da784 100755
--- a/kittens/icat/main.py
+++ b/kittens/icat/main.py
@@ -93,6 +93,7 @@ def options_spec():
def write_gr_cmd(cmd, payload=None):
+ print(11111, cmd)
sys.stdout.buffer.write(serialize_gr_command(cmd, payload))
sys.stdout.flush()
@@ -204,6 +205,8 @@ def scan(d):
def detect_support(wait_for=10, silent=False):
+ detect_support.has_files = False
+ return True
if not silent:
print('Checking for graphics ({}s max. wait)...'.format(wait_for), end='\r')
sys.stdout.flush()
for direct transmission. Probably it has some redundant keys, you can experiment with removing some to reach a minimal example. If you do feel free to update this bug report and I will add it to the docs.
@grst Replacing protocol_start = b'\033_Gf=100;'
with protocol_start = b'\033_Gf=100,a=T;'
in your minimal example prints the image for me.
I have added a minimal example to the docs, that works with arbitrary sized PNG files.
Awesome! Works like a charm now.
Thanks a lot!
I want to send a png image using direct transmission (
d
) transfer mode from a python script to kitty. It does not work. Maybe you can help me to figure out what I am doing wrong.kitty icat
works. However that's not an option as later, I want to execute the script via ssh on a remote server that does not have kitty installed:Therefore, I read the png image, encode it as base64 and send it to stdout enclosed in the escape characters. While kitty seems to recognize the escape sequence (no output text is shown) the image does not appear. The output text does appear on a terminal that does not recognize the escape sequence.
Here's the
/tmp/test.png
image. It only has 124 bytes, so the chunk size limit of 4096 should not be an issue here? https://user-images.githubusercontent.com/7051479/47207461-92b43a80-d38b-11e8-82fb-d9c2abb6461f.pngThis is the output of
kitty --dump-commands