Skip to content

Commit

Permalink
Send a dummy input to clear the read block
Browse files Browse the repository at this point in the history
fixed gdamore#452.
When switching nonBlocking, a dummy input is sent to process read
and clear the read block.
  • Loading branch information
noborus committed Apr 25, 2021
1 parent 299cb41 commit 88d9bf7
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion nonblock_bsd.go
Expand Up @@ -30,7 +30,7 @@ import (
// that loop. Normally we use VMIN 1 and VTIME 0, which ensures we pick up bytes when
// they come but don't spin burning cycles.
func (t *tScreen) nonBlocking(on bool) {
fd := int(os.Stdin.Fd())
fd := int(t.in.Fd())
tio, err := unix.IoctlGetTermios(fd, unix.TIOCGETA)
if err != nil {
return
Expand All @@ -47,4 +47,6 @@ func (t *tScreen) nonBlocking(on bool) {
_ = syscall.SetNonblock(fd, on)
// We want to set this *right now*.
_ = unix.IoctlSetTermios(fd, unix.TIOCSETA, tio)
// dummy input to clear the read block.
_ = unix.IoctlSetPointerInt(fd, unix.TIOCSTI, int(0))
}
5 changes: 3 additions & 2 deletions nonblock_unix.go
Expand Up @@ -17,7 +17,6 @@
package tcell

import (
"os"
"syscall"

"golang.org/x/sys/unix"
Expand All @@ -32,7 +31,7 @@ import (
// that loop. Normally we use VMIN 1 and VTIME 0, which ensures we pick up bytes when
// they come but don't spin burning cycles.
func (t *tScreen) nonBlocking(on bool) {
fd := int(os.Stdin.Fd())
fd := int(t.in.Fd())
tio, err := unix.IoctlGetTermios(fd, unix.TCGETS)
if err != nil {
return
Expand All @@ -49,4 +48,6 @@ func (t *tScreen) nonBlocking(on bool) {
_ = syscall.SetNonblock(fd, on)
// We want to set this *right now*.
_ = unix.IoctlSetTermios(fd, unix.TCSETS, tio)
// dummy input to clear the read block.
_ = unix.IoctlSetPointerInt(fd, unix.TIOCSTI, int(0))
}

0 comments on commit 88d9bf7

Please sign in to comment.