mirror of
https://github.com/yusing/godoxy.git
synced 2026-04-24 09:48:49 +02: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
|
// Create a pipe to stream the websocket messages
|
||||||
pr, pw := io.Pipe()
|
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
|
// Start a goroutine to read from websocket and write to pipe
|
||||||
go func() {
|
go func() {
|
||||||
defer close()
|
defer close()
|
||||||
defer pw.Close()
|
defer pw.Close()
|
||||||
|
|
||||||
|
seenCommand := false
|
||||||
|
shouldSkip := true
|
||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case <-ctx.Done():
|
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
|
// send begins after the line above
|
||||||
if shouldSkip {
|
if shouldSkip {
|
||||||
if bytes.Contains(msg, cmd[:len(cmd)-2]) { // without the \n
|
// First, check if this message contains our command echo
|
||||||
shouldSkip = false
|
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
|
continue
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user