Documentation
¶
Overview ¶
Package terminal attaches a local terminal to a hijacked container stream.
A Session puts stdin into raw mode when it is a terminal, copies bytes in both directions, and restores the terminal when the remote side finishes, the context is canceled, or Close is called. Window changes are reported through a callback so the caller can invoke the engine resize API.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrClosed = errors.New("terminal: session closed")
ErrClosed is returned when Close is called, including when Close stops a running Start.
Functions ¶
This section is empty.
Types ¶
type Session ¶
type Session struct {
// contains filtered or unexported fields
}
Session is an interactive terminal bound to a hijacked connection.
Close is idempotent. It is safe to call if Start never runs, and it is safe to call again after Start returns. Close during Start stops the copies and makes Start return ErrClosed.
func NewSession ¶
func NewSession(in *os.File, out io.Writer, conn io.WriteCloser, reader io.Reader) (*Session, error)
NewSession binds in and out to a hijacked stream.
conn is the write side of the stream. reader is the read side. For a Docker hijack those are the connection and its buffered reader, which must be drained separately. NewSession does not change terminal settings; Start does that when in is a terminal.
func (*Session) Close ¶
Close restores the terminal state and closes the hijacked connection. A second call is a no-op. Close during Start makes Start return ErrClosed.
func (*Session) Start ¶
Start copies in to conn and reader to out.
When in reaches EOF, Start half-closes conn so the remote sees EOF and keeps copying output. When reader returns, Start closes conn and returns. Canceling ctx closes conn and stops both copies.
resize is called with the current size before copying starts, then again when the window changes. A nil resize skips watching. resize runs synchronously for the initial size and again from a goroutine afterward; it should return when ctx is canceled.
Start is called once. It enters raw mode when in is a terminal and restores the previous state before returning.