mirror of
https://github.com/yusing/godoxy.git
synced 2026-03-18 07:24:31 +01:00
fix(proxmox): enhance LXCCommand skip logic
Updated the LXCCommand function to skip until`\x1b[H` and `\x1b[?2004`, ensuring no garbage output.
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user