New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open /dev/tty in non-blocking mode #454
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,10 +34,10 @@ func (t *tScreen) engage() error { | |
if t.stopQ != nil { | ||
return errors.New("already engaged") | ||
} | ||
if _, err := term.MakeRaw(int(t.in.Fd())); err != nil { | ||
if _, err := term.MakeRaw(t.inFd); err != nil { | ||
return err | ||
} | ||
if w, h, err := term.GetSize(int(t.in.Fd())); err == nil && w != 0 && h != 0 { | ||
if w, h, err := term.GetSize(t.inFd); err == nil && w != 0 && h != 0 { | ||
t.cells.Resize(w, h) | ||
} | ||
stopQ := make(chan struct{}) | ||
|
@@ -93,7 +93,7 @@ func (t *tScreen) disengage() { | |
t.enablePasting(false) | ||
|
||
// restore the termios that we were started with | ||
_ = term.Restore(int(t.in.Fd()), t.saved) | ||
_ = term.Restore(t.inFd, t.saved) | ||
|
||
} | ||
|
||
|
@@ -102,15 +102,19 @@ func (t *tScreen) disengage() { | |
// so that it can be restored when the application terminates. | ||
func (t *tScreen) initialize() error { | ||
var err error | ||
t.out = os.Stdout | ||
if t.in, err = os.Open("/dev/tty"); err != nil { | ||
t.inFd, err = syscall.Open("/dev/tty", syscall.O_RDONLY|syscall.O_NONBLOCK, 0644) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should not be necessary -- I believe os.Open() will do what you need, and you can call SetNonBlocking() if need be. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I already tried this (on Linux) to no effect. |
||
if err != nil { | ||
return err | ||
} | ||
t.in = os.NewFile(uintptr(t.inFd), "/dev/tty") | ||
|
||
t.out = os.Stdout | ||
|
||
t.saved, err = term.GetState(int(t.in.Fd())) | ||
if err == nil { | ||
return nil | ||
t.saved, err = term.GetState(t.inFd) | ||
if err != nil { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was a bug in the old code ... thanks for noticing it. :-) |
||
return err | ||
} | ||
|
||
return nil | ||
} | ||
|
||
|
@@ -123,7 +127,7 @@ func (t *tScreen) finalize() { | |
|
||
// getWinSize is called to obtain the terminal dimensions. | ||
func (t *tScreen) getWinSize() (int, int, error) { | ||
return term.GetSize(int(t.in.Fd())) | ||
return term.GetSize(t.inFd) | ||
} | ||
|
||
// Beep emits a beep to the terminal. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, 250ms feels like the delay I had.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This causes us to wake up every 250ms. Which is vile on some platforms. I was hoping to avoid period polling.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...Okay? What do you propose instead, considering the issues regarding suspend and resume (#452)?