From d1a7b7d6a1280c8c2f763691222803944a719fd5 Mon Sep 17 00:00:00 2001 From: Liam Galvin Date: Sat, 31 Jul 2021 13:40:52 +0100 Subject: [PATCH] Don't save terminal state if the process was launched from a non-tty, e.g. WM --- internal/app/darktile/termutil/terminal.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/internal/app/darktile/termutil/terminal.go b/internal/app/darktile/termutil/terminal.go index 0b89b04..eacacfb 100644 --- a/internal/app/darktile/termutil/terminal.go +++ b/internal/app/darktile/termutil/terminal.go @@ -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 err != nil { - t.windowManipulator.ReportError(err) + + 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(fd, oldState) }() // Best effort. } - defer func() { _ = term.Restore(int(os.Stdin.Fd()), oldState) }() // Best effort. go t.process()