mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-27 10:41:58 +02:00
pep8-ify sample code
This commit is contained in:
@@ -97,32 +97,36 @@ features of the graphics protocol:
|
|||||||
|
|
||||||
.. code-block:: python
|
.. code-block:: python
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
from base64 import standard_b64encode
|
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):
|
def serialize_gr_command(**cmd):
|
||||||
data = standard_b64encode(cmd.pop('data'))
|
payload = cmd.pop('payload', None)
|
||||||
while data:
|
cmd = ','.join('{}={}'.format(k, v) for k, v in cmd.items())
|
||||||
chunk, data = data[:4096], data[4096:]
|
ans = []
|
||||||
m = 1 if data else 0
|
w = ans.append
|
||||||
sys.stdout.buffer.write(serialize_gr_command(payload=chunk, m=m, **cmd))
|
w(b'\033_G'), w(cmd.encode('ascii'))
|
||||||
sys.stdout.flush()
|
if payload:
|
||||||
cmd.clear()
|
w(b';')
|
||||||
|
w(payload)
|
||||||
|
w(b'\033\\')
|
||||||
|
return b''.join(ans)
|
||||||
|
|
||||||
with open(sys.argv[-1], 'rb') as f:
|
|
||||||
write_chunked(a='T', f=100, data=f.read())
|
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())
|
||||||
|
|
||||||
|
|
||||||
Save this script as :file:`png.py`, then you can use it to display any PNG
|
Save this script as :file:`png.py`, then you can use it to display any PNG
|
||||||
|
|||||||
Reference in New Issue
Block a user