Skip to content

Commit

Permalink
chore: update
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Feb 1, 2024
1 parent a66bf33 commit d6f8574
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 71 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ go 1.17

require (
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be
github.com/charmbracelet/x/exp/term v0.0.0-20240201140106-7029f92eb43a
github.com/charmbracelet/x/exp/term v0.0.0-20240201181342-a29809e6b18c
github.com/creack/pty v1.1.21
golang.org/x/crypto v0.17.0
golang.org/x/sys v0.16.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFI
github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4=
github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651 h1:3RXpZWGWTOeVXCTv0Dnzxdv/MhNUkBfEcbaTY0zrTQI=
github.com/charmbracelet/x/errors v0.0.0-20240117030013-d31dba354651/go.mod h1:2P0UgXMEa6TsToMSuFqKFQR+fZTO9CNGUNokkPatT/0=
github.com/charmbracelet/x/exp/term v0.0.0-20240201140106-7029f92eb43a h1:AFUHgnJWSI+0UHDUoRZjb/D1iDava8HAlR+KYPjkBH8=
github.com/charmbracelet/x/exp/term v0.0.0-20240201140106-7029f92eb43a/go.mod h1:8NVO/XlUZbcJU5g0gVE7K1YiNnRFqYA3nZzGS/0lBRk=
github.com/charmbracelet/x/exp/term v0.0.0-20240201181342-a29809e6b18c h1:SFBGmYc3b7jUgVl3FQWs7EmHyuITDjep8QwCnotsEh4=
github.com/charmbracelet/x/exp/term v0.0.0-20240201181342-a29809e6b18c/go.mod h1:8NVO/XlUZbcJU5g0gVE7K1YiNnRFqYA3nZzGS/0lBRk=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
Expand Down
170 changes: 102 additions & 68 deletions pty_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func (i *impl) Resize(w int, h int) (rErr error) {
}

return conn.Control(func(fd uintptr) {
rErr = termios.SetWinSize(fd, &unix.Winsize{
rErr = termios.SetWinSize(int(fd), &unix.Winsize{
Row: uint16(h),
Col: uint16(w),

Check warning on line 59 in pty_unix.go

View check run for this annotation

Codecov / codecov/patch

pty_unix.go#L57-L59

Added lines #L57 - L59 were not covered by tests
})
Expand Down Expand Up @@ -88,96 +88,130 @@ func newPty(_ Context, _ string, win Window, modes ssh.TerminalModes) (_ impl, r

func applyTerminalModesToFd(fd uintptr, width int, height int, modes ssh.TerminalModes) error {
var ispeed, ospeed uint32
ccs := map[string]uint8{}
bools := map[string]bool{}
ccs := map[termios.CC]uint8{}
iflag := map[termios.I]bool{}
oflag := map[termios.O]bool{}
cflag := map[termios.C]bool{}
lflag := map[termios.L]bool{}

for op, value := range modes {
switch op {
case ssh.TTY_OP_ISPEED:
ispeed = value
case ssh.TTY_OP_OSPEED:
ospeed = value
default:
name, ok := sshToCc[op]
cc, ok := sshToCc[op]
if ok {
ccs[cc] = uint8(value)
continue

Check warning on line 107 in pty_unix.go

View check run for this annotation

Codecov / codecov/patch

pty_unix.go#L90-L107

Added lines #L90 - L107 were not covered by tests
}
i, ok := sshToIflag[op]
if ok {
ccs[name] = uint8(value)
iflag[i] = value > 0
continue

Check warning on line 112 in pty_unix.go

View check run for this annotation

Codecov / codecov/patch

pty_unix.go#L109-L112

Added lines #L109 - L112 were not covered by tests
}
name, ok = sshToBools[op]
o, ok := sshToOflag[op]
if ok {
bools[name] = value > 0
oflag[o] = value > 0
continue

Check warning on line 117 in pty_unix.go

View check run for this annotation

Codecov / codecov/patch

pty_unix.go#L114-L117

Added lines #L114 - L117 were not covered by tests
}

c, ok := sshToCflag[op]
if ok {
cflag[c] = value > 0
continue

Check warning on line 123 in pty_unix.go

View check run for this annotation

Codecov / codecov/patch

pty_unix.go#L120-L123

Added lines #L120 - L123 were not covered by tests
}
l, ok := sshToLflag[op]
if ok {
lflag[l] = value > 0
continue

Check warning on line 128 in pty_unix.go

View check run for this annotation

Codecov / codecov/patch

pty_unix.go#L125-L128

Added lines #L125 - L128 were not covered by tests
}
}
}
if err := termios.SetTermios(int(fd), ispeed, ospeed, ccs, bools); err != nil {
if err := termios.SetTermios(
int(fd),
ispeed,
ospeed,
ccs,
iflag,
oflag,
cflag,
lflag,
); err != nil {
return err

Check warning on line 142 in pty_unix.go

View check run for this annotation

Codecov / codecov/patch

pty_unix.go#L132-L142

Added lines #L132 - L142 were not covered by tests
}
return termios.SetWinSize(fd, &unix.Winsize{
return termios.SetWinSize(int(fd), &unix.Winsize{
Row: uint16(height),
Col: uint16(width),
})

Check warning on line 147 in pty_unix.go

View check run for this annotation

Codecov / codecov/patch

pty_unix.go#L144-L147

Added lines #L144 - L147 were not covered by tests
}

var sshToCc = map[uint8]string{
ssh.VINTR: "intr",
ssh.VQUIT: "quit",
ssh.VERASE: "erase",
ssh.VKILL: "kill",
ssh.VEOF: "eof",
ssh.VEOL: "eol",
ssh.VEOL2: "eol2",
ssh.VSTART: "start",
ssh.VSTOP: "stop",
ssh.VSUSP: "susp",
ssh.VWERASE: "werase",
ssh.VREPRINT: "rprnt",
ssh.VLNEXT: "lnext",
ssh.VDISCARD: "discard",
ssh.VSTATUS: "status",
ssh.VSWTCH: "swtch",
ssh.VFLUSH: "flush",
ssh.VDSUSP: "dsusp",
var sshToCc = map[uint8]termios.CC{
ssh.VINTR: termios.INTR,
ssh.VQUIT: termios.QUIT,
ssh.VERASE: termios.ERASE,
ssh.VKILL: termios.KILL,
ssh.VEOF: termios.EOF,
ssh.VEOL: termios.EOL,
ssh.VEOL2: termios.EOL2,
ssh.VSTART: termios.START,
ssh.VSTOP: termios.STOP,
ssh.VSUSP: termios.SUSP,
ssh.VWERASE: termios.WERASE,
ssh.VREPRINT: termios.RPRNT,
ssh.VLNEXT: termios.LNEXT,
ssh.VDISCARD: termios.DISCARD,
ssh.VSTATUS: termios.STATUS,
ssh.VSWTCH: termios.SWTCH,
ssh.VFLUSH: termios.FLUSH,
ssh.VDSUSP: termios.DSUSP,
}

var sshToIflag = map[uint8]termios.I{
ssh.IGNPAR: termios.IGNPAR,
ssh.PARMRK: termios.PARMRK,
ssh.INPCK: termios.INPCK,
ssh.ISTRIP: termios.ISTRIP,
ssh.INLCR: termios.INLCR,
ssh.IGNCR: termios.IGNCR,
ssh.ICRNL: termios.ICRNL,
ssh.IUCLC: termios.IUCLC,
ssh.IXON: termios.IXON,
ssh.IXANY: termios.IXANY,
ssh.IXOFF: termios.IXOFF,
ssh.IMAXBEL: termios.IMAXBEL,
}

var sshToOflag = map[uint8]termios.O{
ssh.OPOST: termios.OPOST,
ssh.OLCUC: termios.OLCUC,
ssh.ONLCR: termios.ONLCR,
ssh.OCRNL: termios.OCRNL,
ssh.ONOCR: termios.ONOCR,
ssh.ONLRET: termios.ONLRET,
}

var sshToCflag = map[uint8]termios.C{
ssh.CS7: termios.CS7,
ssh.CS8: termios.CS8,
ssh.PARENB: termios.PARENB,
ssh.PARODD: termios.PARODD,
}

var sshToBools = map[uint8]string{
ssh.IGNPAR: "ignpar",
ssh.PARMRK: "parmrk",
ssh.INPCK: "inpck",
ssh.ISTRIP: "istrip",
ssh.INLCR: "inlcr",
ssh.IGNCR: "igncr",
ssh.ICRNL: "icrnl",
ssh.IUCLC: "iuclc",
ssh.IXON: "ixon",
ssh.IXANY: "ixany",
ssh.IXOFF: "ixoff",
ssh.IMAXBEL: "imaxbel",

ssh.IUTF8: "iutf8",
ssh.ISIG: "isig",
ssh.ICANON: "icanon",
ssh.ECHO: "echo",
ssh.ECHOE: "echoe",
ssh.ECHOK: "echok",
ssh.ECHONL: "echonl",
ssh.NOFLSH: "noflsh",
ssh.TOSTOP: "tostop",
ssh.IEXTEN: "iexten",
ssh.ECHOCTL: "echoctl",
ssh.ECHOKE: "echoke",
ssh.PENDIN: "pendin",
ssh.XCASE: "xcase",

ssh.OPOST: "opost",
ssh.OLCUC: "olcuc",
ssh.ONLCR: "onlcr",
ssh.OCRNL: "ocrnl",
ssh.ONOCR: "onocr",
ssh.ONLRET: "onlret",

ssh.CS7: "cs7",
ssh.CS8: "cs8",
ssh.PARENB: "parenb",
ssh.PARODD: "parodd",
var sshToLflag = map[uint8]termios.L{
ssh.IUTF8: termios.IUTF8,
ssh.ISIG: termios.ISIG,
ssh.ICANON: termios.ICANON,
ssh.ECHO: termios.ECHO,
ssh.ECHOE: termios.ECHOE,
ssh.ECHOK: termios.ECHOK,
ssh.ECHONL: termios.ECHONL,
ssh.NOFLSH: termios.NOFLSH,
ssh.TOSTOP: termios.TOSTOP,
ssh.IEXTEN: termios.IEXTEN,
ssh.ECHOCTL: termios.ECHOCTL,
ssh.ECHOKE: termios.ECHOKE,
ssh.PENDIN: termios.PENDIN,
ssh.XCASE: termios.XCASE,
}

0 comments on commit d6f8574

Please sign in to comment.