diff --git a/client_local.go b/client_local.go index db4d3b0..5bc8a7e 100644 --- a/client_local.go +++ b/client_local.go @@ -117,16 +117,11 @@ func (s *localSession) Run() error { } log.Info("requesting tty") - originalState, err := term.MakeRaw(fd) + restore, err := makeRaw(fd) if err != nil { - return fmt.Errorf("failed get terminal state: %w", err) + return err } - - defer func() { - if err := term.Restore(fd, originalState); err != nil { - log.Warn("couldn't restore terminal state", "err", err) - } - }() + defer restore() w, h, err := term.GetSize(fd) if err != nil { diff --git a/client_signals_unix.go b/client_unix.go similarity index 69% rename from client_signals_unix.go rename to client_unix.go index abc5535..6c46bef 100644 --- a/client_signals_unix.go +++ b/client_unix.go @@ -5,6 +5,7 @@ package wishlist import ( "context" + "fmt" "os" "os/signal" "syscall" @@ -36,3 +37,17 @@ func (s *localSession) notifyWindowChanges(ctx context.Context, session *ssh.Ses } } } + +func makeRaw(fd int) (func(), error) { + log.Info("putting term in raw mode") + originalState, err := term.MakeRaw(fd) + if err != nil { + return func() {}, fmt.Errorf("failed get terminal state: %w", err) + } + + return func() { + if err := term.Restore(fd, originalState); err != nil { + log.Warn("couldn't restore terminal state", "err", err) + } + }, nil +} diff --git a/client_signals_windows.go b/client_windows.go similarity index 80% rename from client_signals_windows.go rename to client_windows.go index b062498..b91b8b7 100644 --- a/client_signals_windows.go +++ b/client_windows.go @@ -11,3 +11,7 @@ import ( // not available because windows does not implement siscall.SIGWINCH. func (c *localSession) notifyWindowChanges(ctx context.Context, session *ssh.Session) {} + +func makeRaw(fd int) (func(), error) { + return func() {}, nil +}