Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion termenv_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,23 @@ func (o Output) termStatusReport(sequence int) (string, error) {
return "", fmt.Errorf("%s: %s", ErrStatusReport, err)
}

// if this is not OSC response, then the terminal does not support it
// if this is not OSC response, then the cursor position response arrived first.
// The terminal may still send the OSC response; drain it so it doesn't leak
// into the TTY buffer and appear as garbage output or a phantom shell command.
if !isOSC {
if tty := o.TTY(); tty != nil {
fd := int(tty.Fd())
tv := unix.NsecToTimeval(int64(100 * time.Millisecond))
var rfds unix.FdSet
rfds.Set(fd)
if n, _ := unix.Select(fd+1, &rfds, nil, nil, &tv); n > 0 {
drained, _, _ := o.readNextResponse()
// readNextResponse stops at ESC (first byte of ST = ESC+\); consume the trailing \.
if strings.HasSuffix(drained, string(ESC)) {
_, _ = o.readNextByte()
}
}
}
return "", ErrStatusReport
}

Expand Down