Skip to content
Myr

Use read syscall directly to get character (#931)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Due to go std lib uses poller for os.File introducing in this commit: https://github.com/golang/go/commit/c05b06a12d005f50e4776095a60d6bd9c2c91fac There are two changes to watch out: 1. os.File.Fd will always return a blocking fd except on bsd. 2. os.File.Read won't return EAGAIN error for nonblocking fd. So For 1, we just get tty's fd in advance and then set its block mode. For 2, we use read syscall directly to get what we wanted error(EAGAIN). Fix issue #910.

authored by Tw · committed by Junegunn Choi · parent 96a3250 · Browse files · 3 files+12 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Signed-off-by: Tw <tw19881113@gmail.com>

Diff stats

3 files+12 added−1 removed

  • other:+12 added−1 removed

3 files+12 added−1 removed

modified:src/tui/light.go+2 added-1 removed
249 unmodified lines
250}251252func (r *LightRenderer) getch(nonblock bool) (int, bool) {253 b := make([]byte, 1)254 fd := r.fd()255 util.SetNonblock(r.ttyin, nonblock)255 _, err := r.ttyin.Read(b)256 _, err := util.Read(fd, b)257 if err != nil {258 return 0, false259 }260 return int(b[0]), true
626 unmodified lines
modified:src/util/util_unix.go+5 added
24 unmodified lines
25// SetNonBlock executes syscall.SetNonblock on file descriptor26func SetNonblock(file *os.File, nonblock bool) {27 syscall.SetNonblock(int(file.Fd()), nonblock)28}2930// Read executes syscall.Read on file descriptor31func Read(fd int, b []byte) (int, error) {32 return syscall.Read(int(fd), b)33}
modified:src/util/util_windows.go+5 added
30 unmodified lines
31// SetNonBlock executes syscall.SetNonblock on file descriptor32func SetNonblock(file *os.File, nonblock bool) {33 syscall.SetNonblock(syscall.Handle(file.Fd()), nonblock)34}3536// Read executes syscall.Read on file descriptor37func Read(fd int, b []byte) (int, error) {38 return syscall.Read(syscall.Handle(fd), b)39}