Don't save terminal state if the process was launched from a non-tty, e.g. WM

This commit is contained in:
Liam Galvin 2021-07-31 13:40:52 +01:00
parent d99bdd3bb2
commit d1a7b7d6a1
1 changed files with 7 additions and 4 deletions

View File

@ -157,11 +157,14 @@ func (t *Terminal) Run(updateChan chan struct{}, rows uint16, cols uint16) error
}
// Set stdin in raw mode.
oldState, err := term.MakeRaw(int(os.Stdin.Fd()))
if fd := int(os.Stdin.Fd()); term.IsTerminal(fd) {
oldState, err := term.MakeRaw(fd)
if err != nil {
t.windowManipulator.ReportError(err)
}
defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort.
defer func() { _ = term.Restore(fd, oldState) }() // Best effort.
}
go t.process()