Skip to content

Commit

Permalink
fix: improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Nov 16, 2023
1 parent 9583789 commit 2dc652d
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 12 deletions.
16 changes: 4 additions & 12 deletions client_local.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (
"os/signal"
"os/user"
"path/filepath"
"runtime"

tea "github.com/charmbracelet/bubbletea"
"github.com/charmbracelet/log"
Expand Down Expand Up @@ -118,18 +117,11 @@ func (s *localSession) Run() error {
}

log.Info("requesting tty")
if runtime.GOOS != "windows" {
originalState, err := term.MakeRaw(fd)
if err != nil {
return fmt.Errorf("failed get terminal state: %w", err)
}

defer func() {
if err := term.Restore(fd, originalState); err != nil {
log.Warn("couldn't restore terminal state", "err", err)
}
}()
restore, err := makeRaw(fd)
if err != nil {
return 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 2dc652d

Please sign in to comment.