diff --git a/src/core/ssh.ts b/src/core/ssh.ts index 9a46c65..502b67e 100644 --- a/src/core/ssh.ts +++ b/src/core/ssh.ts @@ -139,7 +139,7 @@ export class SSHRunner { // Exit alternate screen buffer before attaching process.stdout.write("\x1b[?1049l") - process.stdout.write("\x1b[2J\x1b[H") + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") process.stdout.write("\x1b[?25h") const sshArgs = [ @@ -159,7 +159,7 @@ export class SSHRunner { child.on("exit", () => { // Clear screen and re-enter alternate buffer for TUI - process.stdout.write("\x1b[2J\x1b[H") + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") process.stdout.write("\x1b[?1049h") process.stdout.write("\x1b]0;Agent View\x07") }) @@ -175,7 +175,7 @@ export class SSHRunner { // Exit alternate screen buffer process.stdout.write("\x1b[?1049l") - process.stdout.write("\x1b[2J\x1b[H") + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") process.stdout.write("\x1b[?25h") const sshArgs = [ @@ -207,7 +207,7 @@ export class SSHRunner { } // Clear screen and re-enter alternate buffer for TUI - process.stdout.write("\x1b[2J\x1b[H") + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") process.stdout.write("\x1b[?1049h") process.stdout.write("\x1b]0;Agent View\x07") diff --git a/src/core/tmux.conf b/src/core/tmux.conf index 6bf96bd..d9d8277 100644 --- a/src/core/tmux.conf +++ b/src/core/tmux.conf @@ -18,8 +18,10 @@ bind-key -n C-t if-shell "[ $(tmux display -p '#{window_panes}') -eq 1 ]" "split bind-key -n C-o select-pane -t :.+ # Session switching (no prefix needed) -bind-key -n C-] switch-client -n -bind-key -n 'C-\' switch-client -p +# refresh-client after switch forces a full terminal redraw to prevent +# screen artifacts from the previous session. +bind-key -n C-] switch-client -n \; refresh-client +bind-key -n 'C-\' switch-client -p \; refresh-client bind-key -n C-l run-shell "touch /tmp/agent-view-session-list" \; detach-client # --- Status bar --- diff --git a/src/core/tmux.ts b/src/core/tmux.ts index 7271b41..2c17b19 100644 --- a/src/core/tmux.ts +++ b/src/core/tmux.ts @@ -577,8 +577,8 @@ export async function attachWithPty(sessionName: string): Promise { // PTY may already be closed } - // Clear screen before returning to TUI - process.stdout.write("\x1b[2J\x1b[H") + // Clear screen + scrollback before returning to TUI + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") } }) } @@ -698,7 +698,7 @@ export function attachSessionSync(sessionName: string): void { // Exit alternate screen buffer (TUI uses this) process.stdout.write("\x1b[?1049l") - process.stdout.write("\x1b[2J\x1b[H") + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") // Clear screen + scrollback process.stdout.write("\x1b[?25h") // Attach to tmux - this blocks until user detaches (Ctrl+Q or Ctrl+B d) @@ -707,8 +707,8 @@ export function attachSessionSync(sessionName: string): void { env: process.env }) - // Clear screen and re-enter alternate buffer for TUI - process.stdout.write("\x1b[2J\x1b[H") + // Clear screen + scrollback and re-enter alternate buffer for TUI + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") process.stdout.write("\x1b[?1049h") // Restore terminal title to "Agent View" diff --git a/src/core/updater.ts b/src/core/updater.ts index 3663b19..ff72e56 100644 --- a/src/core/updater.ts +++ b/src/core/updater.ts @@ -52,7 +52,7 @@ export function performUpdateSync(): void { // Exit alternate screen buffer process.stdout.write("\x1b[?1049l") - process.stdout.write("\x1b[2J\x1b[H") + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") process.stdout.write("\x1b[?25h") spawnSync("bash", ["-c", "curl -fsSL https://raw.githubusercontent.com/frayo44/agent-view/main/install.sh | bash"], { @@ -61,7 +61,7 @@ export function performUpdateSync(): void { }) // Clear screen and re-enter alternate buffer for TUI - process.stdout.write("\x1b[2J\x1b[H") + process.stdout.write("\x1b[2J\x1b[3J\x1b[H") process.stdout.write("\x1b[?1049h") // Restore terminal title