Skip to content

Commit

Permalink
client: use golang/x/term instead of u-root termios
Browse files Browse the repository at this point in the history
u-root termios has much more capability than we need, and
does not work on windows yet.

Signed-off-by: Ron Minnich <[email protected]>
  • Loading branch information
rminnich committed Nov 27, 2023
1 parent 10e9cb0 commit 83e883d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 15 deletions.
21 changes: 6 additions & 15 deletions client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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{
Expand Down Expand Up @@ -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
})

Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 83e883d

Please sign in to comment.