-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
pty.go
76 lines (58 loc) · 1.87 KB
/
pty.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package pty
import (
"context"
"errors"
"io"
"os"
)
var (
// ErrInvalidCommand is returned when the command is invalid.
ErrInvalidCommand = errors.New("pty: invalid command")
// ErrUnsupported is returned when the platform is unsupported.
ErrUnsupported = errors.New("pty: unsupported platform")
)
// New returns a new pseudo-terminal.
func New() (Pty, error) {
return newPty()
}
// Pty is a pseudo-terminal interface.
type Pty interface {
io.ReadWriteCloser
// Name returns the name of the pseudo-terminal.
// On Windows, this will always be "windows-pty".
// On Unix, this will return the name of the slave end of the
// pseudo-terminal TTY.
Name() string
// Command returns a command that can be used to start a process
// attached to the pseudo-terminal.
Command(name string, args ...string) *Cmd
// CommandContext returns a command that can be used to start a process
// attached to the pseudo-terminal.
CommandContext(ctx context.Context, name string, args ...string) *Cmd
// Resize resizes the pseudo-terminal.
Resize(width int, height int) error
// Fd returns the file descriptor of the pseudo-terminal.
// On Unix, this will return the file descriptor of the master end.
// On Windows, this will return the handle of the console.
Fd() uintptr
}
// UnixPty is a Unix pseudo-terminal interface.
type UnixPty interface {
Pty
// Master returns the pseudo-terminal master end (pty).
Master() *os.File
// Slave returns the pseudo-terminal slave end (tty).
Slave() *os.File
// Control calls f on the pseudo-terminal master end (pty).
Control(f func(fd uintptr)) error
// SetWinsize sets the pseudo-terminal window size.
SetWinsize(ws *Winsize) error
}
// ConPty is a Windows ConPTY interface.
type ConPty interface {
Pty
// InputPipe returns the ConPty input pipe.
InputPipe() *os.File
// OutputPipe returns the ConPty output pipe.
OutputPipe() *os.File
}