From 701b39f5f064e54080a74d37d8444cf9ee183f5c Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Thu, 16 Apr 2020 10:17:46 +0200 Subject: [PATCH] pkg/term: deprecate package in favor of moby/term Signed-off-by: Sebastiaan van Stijn --- pkg/term/ascii.go | 1 + pkg/term/proxy.go | 2 ++ pkg/term/term.go | 12 ++++++++++++ pkg/term/term_windows.go | 12 ++++++++++++ pkg/term/termios_bsd.go | 2 ++ pkg/term/termios_linux.go | 2 ++ pkg/term/windows/ansi_reader.go | 1 + pkg/term/windows/ansi_writer.go | 1 + pkg/term/windows/console.go | 2 ++ pkg/term/windows/windows.go | 9 ++++++--- pkg/term/winsize.go | 2 ++ 11 files changed, 43 insertions(+), 3 deletions(-) diff --git a/pkg/term/ascii.go b/pkg/term/ascii.go index 87bca8d4ac..93961016ec 100644 --- a/pkg/term/ascii.go +++ b/pkg/term/ascii.go @@ -42,6 +42,7 @@ var ASCII = []string{ } // ToBytes converts a string representing a suite of key-sequence to the corresponding ASCII code. +// Deprecated: use github.com/moby/term.ToBytes func ToBytes(keys string) ([]byte, error) { codes := []byte{} next: diff --git a/pkg/term/proxy.go b/pkg/term/proxy.go index 42158bd6c7..41a5631cd3 100644 --- a/pkg/term/proxy.go +++ b/pkg/term/proxy.go @@ -6,6 +6,7 @@ import ( // EscapeError is special error which returned by a TTY proxy reader's Read() // method in case its detach escape sequence is read. +// Deprecated: use github.com/moby/term.EscapeError type EscapeError struct{} func (EscapeError) Error() string { @@ -25,6 +26,7 @@ type escapeProxy struct { // NewEscapeProxy returns a new TTY proxy reader which wraps the given reader // and detects when the specified escape keys are read, in which case the Read // method will return an error of type EscapeError. +// Deprecated: use github.com/moby/term.NewEscapeProxy func NewEscapeProxy(r io.Reader, escapeKeys []byte) io.Reader { return &escapeProxy{ escapeKeys: escapeKeys, diff --git a/pkg/term/term.go b/pkg/term/term.go index 0589a95519..f86612a2d7 100644 --- a/pkg/term/term.go +++ b/pkg/term/term.go @@ -2,6 +2,8 @@ // Package term provides structures and helper functions to work with // terminal (state, sizes). +// +// Deprecated: use github.com/moby/term instead package term // import "github.com/docker/docker/pkg/term" import ( @@ -20,11 +22,13 @@ var ( ) // State represents the state of the terminal. +// Deprecated: use github.com/moby/term.State type State struct { termios Termios } // Winsize represents the size of the terminal window. +// Deprecated: use github.com/moby/term.Winsize type Winsize struct { Height uint16 Width uint16 @@ -33,11 +37,13 @@ type Winsize struct { } // StdStreams returns the standard streams (stdin, stdout, stderr). +// Deprecated: use github.com/moby/term.StdStreams func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) { return os.Stdin, os.Stdout, os.Stderr } // GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal. +// Deprecated: use github.com/moby/term.GetFdInfo func GetFdInfo(in interface{}) (uintptr, bool) { var inFd uintptr var isTerminalIn bool @@ -49,6 +55,7 @@ func GetFdInfo(in interface{}) (uintptr, bool) { } // IsTerminal returns true if the given file descriptor is a terminal. +// Deprecated: use github.com/moby/term.IsTerminal func IsTerminal(fd uintptr) bool { var termios Termios return tcget(fd, &termios) == 0 @@ -56,6 +63,7 @@ func IsTerminal(fd uintptr) bool { // RestoreTerminal restores the terminal connected to the given file descriptor // to a previous state. +// Deprecated: use github.com/moby/term.RestoreTerminal func RestoreTerminal(fd uintptr, state *State) error { if state == nil { return ErrInvalidState @@ -67,6 +75,7 @@ func RestoreTerminal(fd uintptr, state *State) error { } // SaveState saves the state of the terminal connected to the given file descriptor. +// Deprecated: use github.com/moby/term.SaveState func SaveState(fd uintptr) (*State, error) { var oldState State if err := tcget(fd, &oldState.termios); err != 0 { @@ -78,6 +87,7 @@ func SaveState(fd uintptr) (*State, error) { // DisableEcho applies the specified state to the terminal connected to the file // descriptor, with echo disabled. +// Deprecated: use github.com/moby/term.DisableEcho func DisableEcho(fd uintptr, state *State) error { newState := state.termios newState.Lflag &^= unix.ECHO @@ -92,6 +102,7 @@ func DisableEcho(fd uintptr, state *State) error { // SetRawTerminal puts the terminal connected to the given file descriptor into // raw mode and returns the previous state. On UNIX, this puts both the input // and output into raw mode. On Windows, it only puts the input into raw mode. +// Deprecated: use github.com/moby/term.SetRawTerminal func SetRawTerminal(fd uintptr) (*State, error) { oldState, err := MakeRaw(fd) if err != nil { @@ -104,6 +115,7 @@ func SetRawTerminal(fd uintptr) (*State, error) { // SetRawTerminalOutput puts the output of terminal connected to the given file // descriptor into raw mode. On UNIX, this does nothing and returns nil for the // state. On Windows, it disables LF -> CRLF translation. +// Deprecated: use github.com/moby/term.SetRawTerminalOutput func SetRawTerminalOutput(fd uintptr) (*State, error) { return nil, nil } diff --git a/pkg/term/term_windows.go b/pkg/term/term_windows.go index 6e83b59e90..79f829838f 100644 --- a/pkg/term/term_windows.go +++ b/pkg/term/term_windows.go @@ -11,11 +11,13 @@ import ( ) // State holds the console mode for the terminal. +// Deprecated: use github.com/moby/term.State type State struct { mode uint32 } // Winsize is used for window size. +// Deprecated: use github.com/moby/term.Winsize type Winsize struct { Height uint16 Width uint16 @@ -25,6 +27,7 @@ type Winsize struct { var vtInputSupported bool // StdStreams returns the standard streams (stdin, stdout, stderr). +// Deprecated: use github.com/moby/term.StdStreams func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) { // Turn on VT handling on all std handles, if possible. This might // fail, in which case we will fall back to terminal emulation. @@ -88,11 +91,13 @@ func StdStreams() (stdIn io.ReadCloser, stdOut, stdErr io.Writer) { } // GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal. +// Deprecated: use github.com/moby/term.GetFdInfo func GetFdInfo(in interface{}) (uintptr, bool) { return windowsconsole.GetHandleInfo(in) } // GetWinsize returns the window size based on the specified file descriptor. +// Deprecated: use github.com/moby/term.GetWinsize func GetWinsize(fd uintptr) (*Winsize, error) { info, err := winterm.GetConsoleScreenBufferInfo(fd) if err != nil { @@ -108,17 +113,20 @@ func GetWinsize(fd uintptr) (*Winsize, error) { } // IsTerminal returns true if the given file descriptor is a terminal. +// Deprecated: use github.com/moby/term.IsTerminal func IsTerminal(fd uintptr) bool { return windowsconsole.IsConsole(fd) } // RestoreTerminal restores the terminal connected to the given file descriptor // to a previous state. +// Deprecated: use github.com/moby/term.RestoreTerminal func RestoreTerminal(fd uintptr, state *State) error { return winterm.SetConsoleMode(fd, state.mode) } // SaveState saves the state of the terminal connected to the given file descriptor. +// Deprecated: use github.com/moby/term.SaveState func SaveState(fd uintptr) (*State, error) { mode, e := winterm.GetConsoleMode(fd) if e != nil { @@ -130,6 +138,7 @@ func SaveState(fd uintptr) (*State, error) { // DisableEcho disables echo for the terminal connected to the given file descriptor. // -- See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683462(v=vs.85).aspx +// Deprecated: use github.com/moby/term.DisableEcho func DisableEcho(fd uintptr, state *State) error { mode := state.mode mode &^= winterm.ENABLE_ECHO_INPUT @@ -147,6 +156,7 @@ func DisableEcho(fd uintptr, state *State) error { // SetRawTerminal puts the terminal connected to the given file descriptor into // raw mode and returns the previous state. On UNIX, this puts both the input // and output into raw mode. On Windows, it only puts the input into raw mode. +// Deprecated: use github.com/moby/term.SetRawTerminal func SetRawTerminal(fd uintptr) (*State, error) { state, err := MakeRaw(fd) if err != nil { @@ -161,6 +171,7 @@ func SetRawTerminal(fd uintptr) (*State, error) { // SetRawTerminalOutput puts the output of terminal connected to the given file // descriptor into raw mode. On UNIX, this does nothing and returns nil for the // state. On Windows, it disables LF -> CRLF translation. +// Deprecated: use github.com/moby/term.SetRawTerminalOutput func SetRawTerminalOutput(fd uintptr) (*State, error) { state, err := SaveState(fd) if err != nil { @@ -175,6 +186,7 @@ func SetRawTerminalOutput(fd uintptr) (*State, error) { // MakeRaw puts the terminal (Windows Console) connected to the given file descriptor into raw // mode and returns the previous state of the terminal so that it can be restored. +// Deprecated: use github.com/moby/term.MakeRaw func MakeRaw(fd uintptr) (*State, error) { state, err := SaveState(fd) if err != nil { diff --git a/pkg/term/termios_bsd.go b/pkg/term/termios_bsd.go index 48b16f5203..ce79c4ed1b 100644 --- a/pkg/term/termios_bsd.go +++ b/pkg/term/termios_bsd.go @@ -14,11 +14,13 @@ const ( ) // Termios is the Unix API for terminal I/O. +// Deprecated: use github.com/moby/term.Termios type Termios unix.Termios // MakeRaw put the terminal connected to the given file descriptor into raw // mode and returns the previous state of the terminal so that it can be // restored. +// Deprecated: use github.com/moby/term.MakeRaw func MakeRaw(fd uintptr) (*State, error) { var oldState State if _, _, err := unix.Syscall(unix.SYS_IOCTL, fd, getTermios, uintptr(unsafe.Pointer(&oldState.termios))); err != 0 { diff --git a/pkg/term/termios_linux.go b/pkg/term/termios_linux.go index 6d4c63fdb7..ae48a3b218 100644 --- a/pkg/term/termios_linux.go +++ b/pkg/term/termios_linux.go @@ -10,11 +10,13 @@ const ( ) // Termios is the Unix API for terminal I/O. +// Deprecated: use github.com/moby/term.Termios type Termios unix.Termios // MakeRaw put the terminal connected to the given file descriptor into raw // mode and returns the previous state of the terminal so that it can be // restored. +// Deprecated: use github.com/moby/term.MakeRaw func MakeRaw(fd uintptr) (*State, error) { termios, err := unix.IoctlGetTermios(int(fd), getTermios) if err != nil { diff --git a/pkg/term/windows/ansi_reader.go b/pkg/term/windows/ansi_reader.go index 1d7c452cc8..67d45a107c 100644 --- a/pkg/term/windows/ansi_reader.go +++ b/pkg/term/windows/ansi_reader.go @@ -30,6 +30,7 @@ type ansiReader struct { // NewAnsiReader returns an io.ReadCloser that provides VT100 terminal emulation on top of a // Windows console input handle. +// Deprecated: use github.com/moby/term/windows.NewAnsiReader func NewAnsiReader(nFile int) io.ReadCloser { initLogger() file, fd := winterm.GetStdFile(nFile) diff --git a/pkg/term/windows/ansi_writer.go b/pkg/term/windows/ansi_writer.go index 7799a03fc5..a53bc30047 100644 --- a/pkg/term/windows/ansi_writer.go +++ b/pkg/term/windows/ansi_writer.go @@ -23,6 +23,7 @@ type ansiWriter struct { // NewAnsiWriter returns an io.Writer that provides VT100 terminal emulation on top of a // Windows console output handle. +// Deprecated: use github.com/moby/term/windows.NewAnsiWriter func NewAnsiWriter(nFile int) io.Writer { initLogger() file, fd := winterm.GetStdFile(nFile) diff --git a/pkg/term/windows/console.go b/pkg/term/windows/console.go index 5274019758..575e3b655a 100644 --- a/pkg/term/windows/console.go +++ b/pkg/term/windows/console.go @@ -9,6 +9,7 @@ import ( ) // GetHandleInfo returns file descriptor and bool indicating whether the file is a console. +// Deprecated: use github.com/moby/term/windows.GetHandleInfo func GetHandleInfo(in interface{}) (uintptr, bool) { switch t := in.(type) { case *ansiReader: @@ -29,6 +30,7 @@ func GetHandleInfo(in interface{}) (uintptr, bool) { // IsConsole returns true if the given file descriptor is a Windows Console. // The code assumes that GetConsoleMode will return an error for file descriptors that are not a console. +// Deprecated: use github.com/moby/term/windows.IsConsole func IsConsole(fd uintptr) bool { _, e := winterm.GetConsoleMode(fd) return e == nil diff --git a/pkg/term/windows/windows.go b/pkg/term/windows/windows.go index 7e8f265d47..b5453e7a80 100644 --- a/pkg/term/windows/windows.go +++ b/pkg/term/windows/windows.go @@ -1,8 +1,11 @@ // +build windows -// These files implement ANSI-aware input and output streams for use by the Docker Windows client. -// When asked for the set of standard streams (e.g., stdin, stdout, stderr), the code will create -// and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls. +// Package windowsconsole implements ANSI-aware input and output streams for use +// by the Docker Windows client. When asked for the set of standard streams (e.g., +// stdin, stdout, stderr), the code will create and return pseudo-streams that +// convert ANSI sequences to / from Windows Console API calls. +// +// Deprecated: use github.com/moby/term/windows instead package windowsconsole // import "github.com/docker/docker/pkg/term/windows" import ( diff --git a/pkg/term/winsize.go b/pkg/term/winsize.go index a19663ad83..7c56a2d734 100644 --- a/pkg/term/winsize.go +++ b/pkg/term/winsize.go @@ -7,6 +7,7 @@ import ( ) // GetWinsize returns the window size based on the specified file descriptor. +// Deprecated: use github.com/moby/term.GetWinsize func GetWinsize(fd uintptr) (*Winsize, error) { uws, err := unix.IoctlGetWinsize(int(fd), unix.TIOCGWINSZ) ws := &Winsize{Height: uws.Row, Width: uws.Col, x: uws.Xpixel, y: uws.Ypixel} @@ -14,6 +15,7 @@ func GetWinsize(fd uintptr) (*Winsize, error) { } // SetWinsize tries to set the specified window size for the specified file descriptor. +// Deprecated: use github.com/moby/term.GetWinsize func SetWinsize(fd uintptr, ws *Winsize) error { uws := &unix.Winsize{Row: ws.Height, Col: ws.Width, Xpixel: ws.x, Ypixel: ws.y} return unix.IoctlSetWinsize(int(fd), unix.TIOCSWINSZ, uws)