Skip to content

Commit

Permalink
fix: do not make raw terminal on windows (#241)
Browse files Browse the repository at this point in the history
* fix: do not make raw terminal on windows

apparently windows does not handle it very well... and it seems to not
be needed for windows either way.

closes #102

Signed-off-by: Carlos Alexandro Becker <[email protected]>

* fix: improvements

---------

Signed-off-by: Carlos Alexandro Becker <[email protected]>
  • Loading branch information
caarlos0 authored Nov 16, 2023
1 parent 995aff2 commit 1fdfd4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
11 changes: 3 additions & 8 deletions client_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
15 changes: 15 additions & 0 deletions client_signals_unix.go → client_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package wishlist

import (
"context"
"fmt"
"os"
"os/signal"
"syscall"
Expand Down Expand Up @@ -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
}
4 changes: 4 additions & 0 deletions client_signals_windows.go → client_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 1fdfd4f

Please sign in to comment.