1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

pkg/term: deprecate package in favor of moby/term

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
This commit is contained in:
Sebastiaan van Stijn 2020-04-16 10:17:46 +02:00
parent ba8129b28a
commit 701b39f5f0
No known key found for this signature in database
GPG key ID: 76698F39D527CE8C
11 changed files with 43 additions and 3 deletions

View file

@ -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:

View file

@ -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,

View file

@ -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
}

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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)

View file

@ -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)

View file

@ -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

View file

@ -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 (

View file

@ -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)