From 2f68c7c3860a79c0aaee9adf43d504ae3690f15e Mon Sep 17 00:00:00 2001 From: yusing Date: Sat, 24 Jan 2026 23:38:29 +0800 Subject: [PATCH] fix(proxmox): enhance LXCCommand skip logic Updated the LXCCommand function to skip until`\x1b[H` and `\x1b[?2004`, ensuring no garbage output. --- internal/proxmox/lxc_command.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/internal/proxmox/lxc_command.go b/internal/proxmox/lxc_command.go index 902e5a66..f9981dcf 100644 --- a/internal/proxmox/lxc_command.go +++ b/internal/proxmox/lxc_command.go @@ -53,13 +53,17 @@ func (n *Node) LXCCommand(ctx context.Context, vmid int, command string) (io.Rea // Create a pipe to stream the websocket messages pr, pw := io.Pipe() - shouldSkip := true + // Command line without trailing newline for matching in output + cmdLine := cmd[:len(cmd)-1] // Start a goroutine to read from websocket and write to pipe go func() { defer close() defer pw.Close() + seenCommand := false + shouldSkip := true + for { select { case <-ctx.Done(): @@ -80,8 +84,16 @@ func (n *Node) LXCCommand(ctx context.Context, vmid int, command string) (io.Rea // // send begins after the line above if shouldSkip { - if bytes.Contains(msg, cmd[:len(cmd)-2]) { // without the \n - shouldSkip = false + // First, check if this message contains our command echo + if !seenCommand && bytes.Contains(msg, cmdLine) { + seenCommand = true + } + // Only stop skipping after we've seen the command AND output markers + if seenCommand { + if bytes.Contains(msg, []byte("\x1b[H")) || // watch cursor home + bytes.Contains(msg, []byte("\x1b[?2004l")) { // bracket paste OFF (command ended) + shouldSkip = false + } } continue }