Movatterモバイル変換


[0]ホーム

URL:


pty

package
v2.23.0Latest Latest
Warning

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

Go to latest
Published: Jun 3, 2025 License:AGPL-3.0Imports:18Imported by:1

Details

Repository

github.com/coder/coder

Links

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrClosed =xerrors.New("pty: closed")

ErrClosed is returned when a PTY is used after it has been closed.

Functions

funcRestoreTerminaladded inv2.9.3

func RestoreTerminal(fduintptr, state *TerminalState)error

RestoreTerminal restores the terminal back to its original state.

funcStart

func Start(cmd *Cmd, opt ...StartOption) (PTYCmd,Process,error)

Start the command in a TTY. The calling code must not use cmd after passing it to the PTY, andinstead rely on the returned Process to manage the command/process.

Types

typeCmd

type Cmd struct {Contextcontext.ContextPathstringArgs    []stringEnv     []stringDirstring}

Cmd is a drop-in replacement for exec.Cmd with most of the same API, butit exposes the context.Context to our PTY code so that we can still kill theprocess when the Context expires. This is required because on Windows, we don'tstart the command using the `exec` library, so we have to manage the contextourselves.

funcCommand

func Command(namestring, arg ...string) *Cmd

funcCommandContext

func CommandContext(ctxcontext.Context, namestring, arg ...string) *Cmd

func (*Cmd)AsExec

func (c *Cmd) AsExec() *exec.Cmd

typeOption

type Option func(*ptyOptions)

Options represents a an option for a PTY.

funcWithGPGTTY

func WithGPGTTY()Option

WithGPGTTY sets the GPG_TTY environment variable to the PTY name. This onlyapplies to non-Windows platforms.

funcWithLogger

func WithLogger(logger *log.Logger)Option

WithLogger sets a logger for logging errors.

funcWithSSHRequest

func WithSSHRequest(reqssh.Pty)Option

WithSSHRequest applies the ssh.Pty request to the PTY.

Only partially supported on Windows (e.g. window size).

typePTY

type PTY interface {io.Closer// Resize sets the size of the PTY.Resize(heightuint16, widthuint16)error// Name of the TTY. Example on Linux would be "/dev/pts/1".Name()string// Output handles TTY output.//// cmd.SetOutput(pty.Output()) would be used to specify a command// uses the output stream for writing.//// The same stream could be read to validate output.Output()ReadWriter// Input handles TTY input.//// cmd.SetInput(pty.Input()) would be used to specify a command// uses the PTY input for reading.//// The same stream would be used to provide user input: pty.Input().Write(...)Input()ReadWriter}

PTY is a minimal interface for interacting with pseudo-TTY where thisprocess retains access to _both_ ends of the pseudo-TTY (i.e. `ptm` & `pts`on Linux).

funcNew

func New(opts ...Option) (PTY,error)

New constructs a new Pty.

typePTYCmd

type PTYCmd interface {io.Closer// Resize sets the size of the PTY.Resize(heightuint16, widthuint16)error// OutputReader returns an io.Reader for reading the output from the process// controlled by the pseudo-TTYOutputReader()io.Reader// InputWriter returns an io.Writer for writing into to the process// controlled by the pseudo-TTYInputWriter()io.Writer}

PTYCmd is an interface for interacting with a pseudo-TTY where we controlonly one end, and the other end has been passed to a running os.Process.nolint:revive

typeProcess

type Process interface {// Wait for the command to complete.  Returned error is as for exec.Cmd.Wait()Wait()error// Kill the command process.  Returned error is as for os.Process.Kill()Kill()error// Signal sends a signal to the command process. On non-windows systems, the// returned error is as for os.Process.Signal(), on Windows it's// as for os.Process.Kill().Signal(sigos.Signal)error}

Process represents a process running in a PTY. We need to trigger special processing on the PTYon process completion, meaning that we will have goroutines calling Wait() on the process. Sincethe caller will also typically wait for the process, and it is not safe for multiple goroutinesto Wait() on a process, this abstraction provides a goroutine-safe interface for interacting withthe process.

typeReadWriter

type ReadWriter struct {Readerio.ReaderWriterio.Writer}

ReadWriter is an implementation of io.ReadWriter that wraps two separateunderlying file descriptors, one for reading and one for writing, and allowsthem to be accessed separately.

func (ReadWriter)Read

func (rwReadWriter) Read(p []byte) (int,error)

func (ReadWriter)Write

func (rwReadWriter) Write(p []byte) (int,error)

typeStartOption

type StartOption func(*startOptions)

StartOption represents a configuration option passed to Start.

funcWithPTYOption

func WithPTYOption(opts ...Option)StartOption

WithPTYOption applies the given options to the underlying PTY.

typeTerminalStateadded inv2.9.3

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

TerminalState differs per-platform.

funcMakeInputRawadded inv2.9.3

func MakeInputRaw(fduintptr) (*TerminalState,error)

MakeInputRaw calls term.MakeRaw on non-Windows platforms. On Windows it setsspecial terminal modes that enable VT100 emulation as well as setting thesame modes that term.MakeRaw sets.

funcMakeOutputRawadded inv2.9.3

func MakeOutputRaw(fduintptr) (*TerminalState,error)

MakeOutputRaw does nothing on non-Windows platforms. On Windows it setsspecial terminal modes that enable VT100 emulation as well as setting thesame modes that term.MakeRaw sets.

typeWithFlags

type WithFlags interface {PTY// EchoEnabled determines whether local echo is currently enabled for this terminal.EchoEnabled() (bool,error)}

WithFlags represents a PTY whose flags can be inspected, in particularto determine whether local echo is enabled.

Source Files

View all Source files

Directories

PathSynopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp