Skip to content

Qwen3-0.6B inference (12 KB), bare-metal bootable OS (22 KB), and from-scratch Mini-GPT trainer with live Braille TUI (32 KB) in 100% pure x86-64 NASM assembly. Zero C, zero libc, zero dependencies.

1.6 KB
Raw Blame
#!/usr/bin/env python3
"""Relay the right tmux pane to the guest's second serial terminal."""
import os
import select
import signal
import socket
import subprocess
import sys
import termios
import time
import tty
from pathlib import Path

run = Path(sys.argv[1])

def dimensions(*_):
    width, height = os.get_terminal_size(1)
    left = subprocess.check_output(["tmux", "display-message", "-p", "-t", "jev:0.0",
                                    "#{pane_width} #{pane_height}"], text=True).strip()
    path = run / "geometry.tmp"
    path.write_text(f"{height} {width} {left}\n")
    path.replace(run / "geometry")

with socket.socket(socket.AF_UNIX) as serial:
    for _ in range(150):
        try:
            serial.connect(str(run / "hud.sock"))
            break
        except (FileNotFoundError, ConnectionRefusedError):
            time.sleep(.05)
    else:
        raise SystemExit("Guest HUD serial socket unavailable")
    dimensions()
    signal.signal(signal.SIGWINCH, dimensions)
    original = termios.tcgetattr(0)
    try:
        tty.setraw(0)
        while True:
            ready, _, _ = select.select([0, serial], [], [])
            if serial in ready:
                data = serial.recv(65536)
                if not data:
                    break
                view = memoryview(data)
                while view:
                    view = view[os.write(1, view):]
            if 0 in ready:
                data = os.read(0, 4096)
                if not data:
                    break
                serial.sendall(data)
    finally:
        termios.tcsetattr(0, termios.TCSANOW, original)