From e1f4cdd06dfcb892096e90d6e94ac0129a3aee69 Mon Sep 17 00:00:00 2001 From: Vasile Popescu Date: Mon, 19 Oct 2020 19:22:12 +0200 Subject: [PATCH] Improve the terminal restoring from RAW format Use a defer mechanism to restore the terminal from its RAW state. This way it's resilient to panic calls --- main.go | 2 ++ pty_master.go | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/main.go b/main.go index 932d347..9874217 100644 --- a/main.go +++ b/main.go @@ -146,6 +146,8 @@ Flags: bufio.NewReader(os.Stdin).ReadString('\n') ptyMaster := ptyMasterNew() + defer ptyMaster.Restore() + ptyMaster.Start(*commandName, strings.Fields(*commandArgs)) var pty server.PTYHandler = ptyMaster diff --git a/pty_master.go b/pty_master.go index b39366b..8a26a09 100644 --- a/pty_master.go +++ b/pty_master.go @@ -101,7 +101,10 @@ func (pty *ptyMaster) Refresh() { func (pty *ptyMaster) Wait() (err error) { err = pty.command.Wait() - // The terminal has to be restored from the RAW state, to its initial state + return +} + +func (pty *ptyMaster) Restore() { terminal.Restore(0, pty.terminalInitState) return }