package sshimport ()// ErrUnsupported is returned when the platform does not support PTY.varErrUnsupported = errors.New("pty unsupported")// NewPtyWriter creates a writer that handles when the session has a active// PTY, replacing the \n with \r\n.func ( io.Writer) io.Writer {returnptyWriter{w: , }}var _ io.Writer = ptyWriter{}type ptyWriter struct { w io.Writer}func ( ptyWriter) ( []byte) (int, error) { := len()// normalize \n to \r\n when pty is accepted. // this is a hardcoded shortcut since we don't support terminal modes. = bytes.Replace(, []byte{'\n'}, []byte{'\r', '\n'}, -1) = bytes.Replace(, []byte{'\r', '\r', '\n'}, []byte{'\r', '\n'}, -1) , := .w.Write()if > { = }return , }// NewPtyReadWriter return an io.ReadWriter that delegates the read to the// given io.ReadWriter, and the writes to a ptyWriter.func ( io.ReadWriter) io.ReadWriter {returnreadWriterDelegate{w: NewPtyWriter(),r: , }}var _ io.ReadWriter = readWriterDelegate{}type readWriterDelegate struct { w io.Writer r io.Reader}func ( readWriterDelegate) ( []byte) ( int, error) {return .r.Read()}func ( readWriterDelegate) ( []byte) ( int, error) {return .w.Write()}// Start starts a *exec.Cmd attached to the Session. If a PTY is allocated,// it will use that for I/O.// On Windows, the process execution lifecycle is not managed by Go and has to// be managed manually. This means that c.Wait() won't work.// See https://github.com/charmbracelet/x/blob/main/exp/term/conpty/conpty_windows.gofunc ( *Pty) ( *exec.Cmd) error {return .start()}
The pages are generated with Goldsv0.8.2. (GOOS=linux GOARCH=amd64)
Golds is a Go 101 project developed by Tapir Liu.
PR and bug reports are welcome and can be submitted to the issue list.
Please follow @zigo_101 (reachable from the left QR code) to get the latest news of Golds.