mirror of
https://github.com/Benexl/FastAnime.git
synced 2025-12-12 15:50:01 -08:00
feat: prefer to use direct implementation of graphics protocol over external tools
This commit is contained in:
@@ -163,6 +163,35 @@ def fzf_image_preview(file_path: str):
|
||||
)
|
||||
|
||||
|
||||
def fzf_text_preview(file_path: str):
|
||||
from base64 import standard_b64encode
|
||||
|
||||
def serialize_gr_command(**cmd):
|
||||
payload = cmd.pop("payload", None)
|
||||
cmd = ",".join(f"{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(file_path, "rb") as f:
|
||||
write_chunked(a="T", f=100, data=f.read())
|
||||
|
||||
|
||||
console = Console(force_terminal=True, color_system="truecolor")
|
||||
if PREVIEW_MODE == "image" or PREVIEW_MODE == "full":
|
||||
preview_image_path = IMAGE_CACHE_DIR / f"{hash}.png"
|
||||
|
||||
Reference in New Issue
Block a user