mirror of
https://github.com/wez/wezterm.git
synced 2024-12-01 00:35:46 +03:00
62cc64f293
This isn't complete; many of the placement options are not supported, and the status reporting is missing in a number of cases, including querying/probing, and shared memory objects are not supported yet. However, this commit is sufficient to allow the kitty-png.py script (that was copied from https://sw.kovidgoyal.net/kitty/graphics-protocol/#a-minimal-example) to render a PNG in the terminal. This implementation routes the basic image display via the same code that we use for iterm2 and sixel protocols, but it isn't sufficient to support the rest of the placement options allowed by the spec. Notably, we'll need to add the concept of image placements to the data model maintained by the terminal state and find a way to efficiently manage placements both by id and by a viewport range. The renderer will need to manage separate quads for placements and order them by z-index, and adjust the render phases so that images can appear in the correct plane. refs: #986
29 lines
780 B
Python
Executable File
29 lines
780 B
Python
Executable File
#!python3
|
|
# This script encodes a PNG file using the kitty image protocol
|
|
import sys
|
|
from base64 import standard_b64encode
|
|
|
|
def serialize_gr_command(**cmd):
|
|
payload = cmd.pop('payload', None)
|
|
cmd = ','.join('{}={}'.format(k, v) for k, v in cmd.items())
|
|
ans = []
|
|
w = ans.append
|
|
w(b'\033_G'), w(cmd.encode('ascii'))
|
|
if payload:
|
|
w(b';')
|
|
w(payload)
|
|
w(b'\033\\')
|
|
return b''.join(ans)
|
|
|
|
def write_chunked(**cmd):
|
|
data = standard_b64encode(cmd.pop('data'))
|
|
while data:
|
|
chunk, data = data[:4096], data[4096:]
|
|
m = 1 if data else 0
|
|
sys.stdout.buffer.write(serialize_gr_command(payload=chunk, m=m, **cmd))
|
|
sys.stdout.flush()
|
|
cmd.clear()
|
|
|
|
with open(sys.argv[-1], 'rb') as f:
|
|
write_chunked(a='T', f=100, data=f.read())
|