Skip to content

Commit

Permalink
use read syscall directly to get character
Browse files Browse the repository at this point in the history
Due to go std lib uses poller for os.File introducing in this commit:
golang/go@c05b06a
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.

Signed-off-by: Tw <tw19881113@gmail.com>
  • Loading branch information
tw4452852 committed May 24, 2017
1 parent 3a50867 commit e8dd2b4
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/tui/light.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,8 +251,9 @@ func (r *LightRenderer) updateTerminalSize() {

func (r *LightRenderer) getch(nonblock bool) (int, bool) {
b := make([]byte, 1)
fd := r.fd()
util.SetNonblock(r.ttyin, nonblock)
_, err := r.ttyin.Read(b)
_, err := syscall.Read(fd, b)
if err != nil {
return 0, false
}
Expand Down

0 comments on commit e8dd2b4

Please sign in to comment.