@ 261105.1

260402.12 · bea6721549ceb25695fc81f375aae2368517c38f

fix(tty): flush input before start (fixes #1045)

reading declarations

tty/nonblock_bsd.go

@@ -41,3 +41,10 @@ func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { 	} 	return nil }++// tcFlushInput discards any queued input before the caller starts reading from+// the tty. This avoids stale bytes, such as delayed mouse reports, from being+// delivered to the next foreground application.+func tcFlushInput(fd int) error {+	return unix.IoctlSetPointerInt(fd, unix.TIOCFLUSH, unix.TCIFLUSH)+}

tty/nonblock_unix.go

@@ -39,3 +39,10 @@ func tcSetBufParams(fd int, vMin uint8, vTime uint8) error { 	} 	return nil }++// tcFlushInput discards any queued input before the caller starts reading from+// the tty. This avoids stale bytes, such as delayed mouse reports, from being+// delivered to the next foreground application.+func tcFlushInput(fd int) error {+	return unix.IoctlSetInt(fd, unix.TCFLSH, unix.TCIFLUSH)+}

tty/stdin_unix.go

@@ -71,6 +71,10 @@ func (tty *stdIoTty) Start() error { 	if err != nil { 		return err 	}+	if err = tcFlushInput(tty.fd); err != nil {+		_ = term.Restore(tty.fd, saved)+		return err+	} 	tty.saved = saved 	tty.started = true 

tty/tty_unix.go

@@ -85,6 +85,11 @@ func (tty *devTty) Start() error { 		tty.f.Close() 		return err 	}+	if err = tcFlushInput(tty.fd); err != nil {+		_ = term.Restore(tty.fd, saved)+		tty.f.Close()+		return err+	} 	tty.saved = saved 	tty.started = true