diff --git a/client/client.go b/client/client.go index 703fb691..37221885 100644 --- a/client/client.go +++ b/client/client.go @@ -17,8 +17,8 @@ import ( "github.com/hugelgupf/p9/p9" "github.com/mdlayher/vsock" - "github.com/u-root/u-root/pkg/termios" "golang.org/x/crypto/ssh" + "golang.org/x/term" ) const ( @@ -111,11 +111,11 @@ func Command(host string, args ...string) *Cmd { } col, row := 80, 40 - if w, err := termios.GetWinSize(0); err != nil { + if c, r, err := term.GetSize(int(os.Stdin.Fd())); err != nil { verbose("Can not get winsize: %v; assuming %dx%d and non-interactive", err, col, row) } else { hasTTY = true - col, row = int(w.Col), int(w.Row) + col, row = c, r } return &Cmd{ @@ -588,23 +588,14 @@ func (c *Cmd) TTYIn(s *ssh.Session, w io.WriteCloser, r io.Reader) { } // SetupInteractive sets up a cpu client for interactive access. -// It returns a function to be run when the session ends. +// It adds a function to c.Closers to clean up the terminal. func (c *Cmd) SetupInteractive() error { - t, err := termios.New() + oldState, err := term.MakeRaw(int(os.Stdin.Fd())) if err != nil { return err } - r, err := t.Get() - if err != nil { - return err - } - if _, err = t.Raw(); err != nil { - return err - } c.closers = append(c.closers, func() error { - if err := t.Set(r); err != nil { - return err - } + term.Restore(int(os.Stdin.Fd()), oldState) return nil }) diff --git a/go.mod b/go.mod index 5c36d31a..189fdf0c 100644 --- a/go.mod +++ b/go.mod @@ -17,6 +17,7 @@ require ( github.com/mdlayher/vsock v1.2.1 github.com/shirou/gopsutil v3.21.11+incompatible golang.org/x/exp v0.0.0-20230810033253-352e893a4cad + golang.org/x/term v0.13.0 ) require ( diff --git a/go.sum b/go.sum index c8f0c91b..f8ba1c7c 100644 --- a/go.sum +++ b/go.sum @@ -96,6 +96,7 @@ golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9sn golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.0.0-20220722155259-a9ba230a4035/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/term v0.13.0 h1:bb+I9cTfFazGW51MZqBVmZy7+JEJMouUHTUSKVQLBek= +golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=