xpty

package module
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 21, 2024 License: MIT Imports: 11 Imported by: 4

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrUnsupported = pty.ErrUnsupported

ErrUnsupported is returned when a feature is not supported.

Functions

func WaitProcess

func WaitProcess(ctx context.Context, cmd *exec.Cmd) (err error)

WaitProcess waits for the process to exit. This exists because on Windows, cmd.Wait() doesn't work with ConPty. When the OS is not windows, it'll simply fall back to cmd.Wait().

Types

type ConPty

type ConPty struct {
	*conpty.ConPty
}

ConPty is a Windows console pty.

func NewConPty

func NewConPty(width, height int, opts ...PtyOption) (*ConPty, error)

NewConPty creates a new ConPty.

func (*ConPty) Name

func (c *ConPty) Name() string

Name returns the name of the ConPty.

func (*ConPty) Start

func (c *ConPty) Start(cmd *exec.Cmd) error

Start starts a command on the ConPty. This is a wrapper around conpty.Spawn.

type Options

type Options struct {
	Flags int
}

Options represents PTY options.

type Pty

type Pty interface {
	term.File
	io.ReadWriteCloser

	// Resize resizes the PTY.
	Resize(width, height int) error

	// Size returns the size of the PTY.
	Size() (width, height int, err error)

	// Name returns the name of the PTY.
	Name() string

	// Start starts a command on the PTY.
	// The command started will have its standard input, output, and error
	// connected to the PTY.
	// On Windows, calling Wait won't work since the Go runtime doesn't handle
	// ConPTY processes correctly. See https://github.com/golang/go/pull/62710.
	Start(cmd *exec.Cmd) error
}

Pty represents a PTY (pseudo-terminal) interface.

func NewPty

func NewPty(width, height int, opts ...PtyOption) (Pty, error)

NewPty creates a new PTY.

The returned PTY will be a Unix PTY on Unix systems and a ConPTY on Windows. The width and height parameters specify the initial size of the PTY. You can pass additional options to the PTY by passing PtyOptions.

pty, err := xpty.NewPty(80, 24)
if err != nil {
   // handle error
}

defer pty.Close() // Make sure to close the PTY when done.
switch pty := pty.(type) {
case xpty.UnixPty:
    // Unix PTY
case xpty.ConPty:
    // ConPTY
}

type PtyOption

type PtyOption func(o Options)

PtyOption is a PTY option.

type UnixPty

type UnixPty struct {
	// contains filtered or unexported fields
}

UnixPty represents a classic Unix PTY (pseudo-terminal).

func NewUnixPty

func NewUnixPty(width, height int, _ ...PtyOption) (*UnixPty, error)

NewUnixPty creates a new Unix PTY.

func (*UnixPty) Close

func (p *UnixPty) Close() (err error)

Close implements XPTY.

func (*UnixPty) Control

func (p *UnixPty) Control(fn func(fd uintptr)) error

Control runs the given function with the file descriptor of the master PTY.

func (*UnixPty) Fd

func (p *UnixPty) Fd() uintptr

Fd implements XPTY.

func (*UnixPty) Master

func (p *UnixPty) Master() *os.File

Master returns the master end of the PTY.

func (*UnixPty) Name

func (p *UnixPty) Name() string

Name implements XPTY.

func (*UnixPty) Read

func (p *UnixPty) Read(b []byte) (n int, err error)

Read implements XPTY.

func (*UnixPty) Resize

func (p *UnixPty) Resize(width int, height int) (err error)

Resize implements XPTY.

func (*UnixPty) SetWinsize

func (p *UnixPty) SetWinsize(width, height, x, y int) error

SetWinsize sets window size for the PTY.

func (*UnixPty) Size

func (p *UnixPty) Size() (width, height int, err error)

Size returns the size of the PTY.

func (*UnixPty) Slave

func (p *UnixPty) Slave() *os.File

Slave returns the slave end of the PTY.

func (*UnixPty) SlaveName

func (p *UnixPty) SlaveName() string

SlaveName returns the name of the slave PTY. This is usually used for remote sessions to identify the running TTY. You can find this in SSH sessions defined as $SSH_TTY.

func (*UnixPty) Start

func (p *UnixPty) Start(c *exec.Cmd) error

Start implements XPTY.

func (*UnixPty) Write

func (p *UnixPty) Write(b []byte) (n int, err error)

Write implements XPTY.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL