From d52d92092d98ed2d6c48e6433cacb899582f617e Mon Sep 17 00:00:00 2001 From: gbc dev Date: Wed, 15 Jul 2026 10:10:16 +0200 Subject: gbctl: 'hud' kills any existing HUD pane before spawning (no double-HUD) gbctl hud now scans tmux for panes started with gbhud.py and kills them before spawning, so there's never more than one HUD (fixes the double-spawn flicker). Added 'gbctl hud --kill' to just tear the HUD down. --- gbctl | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'gbctl') diff --git a/gbctl b/gbctl index 4c3d4f9..287b16a 100755 --- a/gbctl +++ b/gbctl @@ -284,11 +284,35 @@ def cmd_screen(argv): r = subprocess.run(args, capture_output=True, text=True) sys.stdout.write(r.stdout) +def _kill_hud_panes(): + # kill any pane whose start command references the HUD, so there's never + # more than one HUD running (avoids the double-spawn tmux flicker). + n = 0 + try: + r = subprocess.run( + ["tmux", "list-panes", "-a", "-F", "#{pane_id}\t#{pane_start_command}"], + capture_output=True, text=True) + for line in r.stdout.splitlines(): + pid, _, startcmd = line.partition("\t") + if "gbhud.py" in startcmd: + subprocess.run(["tmux", "kill-pane", "-t", pid], capture_output=True) + n += 1 + except Exception: + pass + return n + def cmd_hud(argv): # spawn a tmux pane running the live debug HUD, bound to the resolved socket + killonly = "--kill" in argv + if killonly: + argv = [a for a in argv if a != "--kill"] + k = _kill_hud_panes() + print("killed %d hud pane(s)" % k) + return sock_path = _resolve_sock(argv) if "TMUX" not in os.environ: die("not inside tmux; gbctl hud needs a tmux session") + killed = _kill_hud_panes() # never leave a second HUD around hud = os.path.join(HERE, "tools", "gbhud.py") split = "-h" if "--split" in argv: @@ -298,7 +322,8 @@ def cmd_hud(argv): capture_output=True, text=True) if r.returncode != 0: die("tmux spawn failed: %s" % r.stderr.strip()) - print("hud pane=%s sock=%s" % (r.stdout.strip(), sock_path)) + note = (" (replaced %d)" % killed) if killed else "" + print("hud pane=%s sock=%s%s" % (r.stdout.strip(), sock_path, note)) def cmd_monitor(argv): secs = float(argv[0]) if argv and _isnum(argv[0]) else None -- cgit v1.3.1-sl0p