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

pkg/term: vendor moby/term and make pkg/term an alias

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

View file

@ -1,25 +0,0 @@
package term // import "github.com/docker/docker/pkg/term"
import (
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestToBytes(t *testing.T) {
codes, err := ToBytes("ctrl-a,a")
assert.NilError(t, err)
assert.Check(t, is.DeepEqual([]byte{1, 97}, codes))
_, err = ToBytes("shift-z")
assert.Check(t, is.ErrorContains(err, ""))
codes, err = ToBytes("ctrl-@,ctrl-[,~,ctrl-o")
assert.NilError(t, err)
assert.Check(t, is.DeepEqual([]byte{0, 27, 126, 15}, codes))
codes, err = ToBytes("DEL,+")
assert.NilError(t, err)
assert.Check(t, is.DeepEqual([]byte{127, 43}, codes))
}

84
pkg/term/deprecated.go Normal file
View file

@ -0,0 +1,84 @@
// 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 (
"github.com/moby/term"
)
// 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 = term.EscapeError
// State represents the state of the terminal.
// Deprecated: use github.com/moby/term.State
type State = term.State
// Winsize represents the size of the terminal window.
// Deprecated: use github.com/moby/term.Winsize
type Winsize = term.Winsize
var (
// ASCII list the possible supported ASCII key sequence
ASCII = term.ASCII
// ToBytes converts a string representing a suite of key-sequence to the corresponding ASCII code.
// Deprecated: use github.com/moby/term.ToBytes
ToBytes = term.ToBytes
// StdStreams returns the standard streams (stdin, stdout, stderr).
// Deprecated: use github.com/moby/term.StdStreams
StdStreams = term.StdStreams
// GetFdInfo returns the file descriptor for an os.File and indicates whether the file represents a terminal.
// Deprecated: use github.com/moby/term.GetFdInfo
GetFdInfo = term.GetFdInfo
// GetWinsize returns the window size based on the specified file descriptor.
// Deprecated: use github.com/moby/term.GetWinsize
GetWinsize = term.GetWinsize
// IsTerminal returns true if the given file descriptor is a terminal.
// Deprecated: use github.com/moby/term.IsTerminal
IsTerminal = term.IsTerminal
// RestoreTerminal restores the terminal connected to the given file descriptor
// to a previous state.
// Deprecated: use github.com/moby/term.RestoreTerminal
RestoreTerminal = term.RestoreTerminal
// SaveState saves the state of the terminal connected to the given file descriptor.
// Deprecated: use github.com/moby/term.SaveState
SaveState = term.SaveState
// DisableEcho applies the specified state to the terminal connected to the file
// descriptor, with echo disabled.
// Deprecated: use github.com/moby/term.DisableEcho
DisableEcho = term.DisableEcho
// 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
SetRawTerminal = term.SetRawTerminal
// 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
SetRawTerminalOutput = term.SetRawTerminalOutput
// MakeRaw puts 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
MakeRaw = term.MakeRaw
// 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
NewEscapeProxy = term.NewEscapeProxy
)

View file

@ -0,0 +1,20 @@
// +build !windows
package term // import "github.com/docker/docker/pkg/term"
import (
"github.com/moby/term"
)
// Termios is the Unix API for terminal I/O.
// Deprecated: use github.com/moby/term.Termios
type Termios = term.Termios
var (
// ErrInvalidState is returned if the state of the terminal is invalid.
ErrInvalidState = term.ErrInvalidState
// SetWinsize tries to set the specified window size for the specified file descriptor.
// Deprecated: use github.com/moby/term.GetWinsize
SetWinsize = term.SetWinsize
)

View file

@ -1,208 +0,0 @@
package term // import "github.com/docker/docker/pkg/term"
import (
"bytes"
"testing"
"gotest.tools/v3/assert"
is "gotest.tools/v3/assert/cmp"
)
func TestEscapeProxyRead(t *testing.T) {
t.Run("no escape keys, keys [a]", func(t *testing.T) {
escapeKeys, _ := ToBytes("")
keys, _ := ToBytes("a")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, len(keys))
assert.DeepEqual(t, keys, buf)
})
t.Run("no escape keys, keys [a,b,c]", func(t *testing.T) {
escapeKeys, _ := ToBytes("")
keys, _ := ToBytes("a,b,c")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, len(keys))
assert.DeepEqual(t, keys, buf)
})
t.Run("no escape keys, no keys", func(t *testing.T) {
escapeKeys, _ := ToBytes("")
keys, _ := ToBytes("")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
assert.Assert(t, is.ErrorContains(err, ""), "Should throw error when no keys are to read")
assert.Equal(t, nr, 0)
assert.Check(t, is.Len(keys, 0))
assert.Check(t, is.Len(buf, 0))
})
t.Run("DEL escape key, keys [a,b,c,+]", func(t *testing.T) {
escapeKeys, _ := ToBytes("DEL")
keys, _ := ToBytes("a,b,c,+")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, len(keys))
assert.DeepEqual(t, keys, buf)
})
t.Run("DEL escape key, no keys", func(t *testing.T) {
escapeKeys, _ := ToBytes("DEL")
keys, _ := ToBytes("")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
assert.Assert(t, is.ErrorContains(err, ""), "Should throw error when no keys are to read")
assert.Equal(t, nr, 0)
assert.Check(t, is.Len(keys, 0))
assert.Check(t, is.Len(buf, 0))
})
t.Run("ctrl-x,ctrl-@ escape key, keys [DEL]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-x,ctrl-@")
keys, _ := ToBytes("DEL")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, 1)
assert.DeepEqual(t, keys, buf)
})
t.Run("ctrl-c escape key, keys [ctrl-c]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c")
keys, _ := ToBytes("ctrl-c")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, len(keys))
nr, err := reader.Read(buf)
assert.Error(t, err, "read escape sequence")
assert.Equal(t, nr, 0)
assert.DeepEqual(t, keys, buf)
})
t.Run("ctrl-c,ctrl-z escape key, keys [ctrl-c],[ctrl-z]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c,ctrl-z")
keys, _ := ToBytes("ctrl-c,ctrl-z")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, 1)
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, 0)
assert.DeepEqual(t, keys[0:1], buf)
nr, err = reader.Read(buf)
assert.Error(t, err, "read escape sequence")
assert.Equal(t, nr, 0)
assert.DeepEqual(t, keys[1:], buf)
})
t.Run("ctrl-c,ctrl-z escape key, keys [ctrl-c,ctrl-z]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c,ctrl-z")
keys, _ := ToBytes("ctrl-c,ctrl-z")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, 2)
nr, err := reader.Read(buf)
assert.Error(t, err, "read escape sequence")
assert.Equal(t, nr, 0, "nr should be equal to 0")
assert.DeepEqual(t, keys, buf)
})
t.Run("ctrl-c,ctrl-z escape key, keys [ctrl-c],[DEL,+]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c,ctrl-z")
keys, _ := ToBytes("ctrl-c,DEL,+")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, 1)
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, 0)
assert.DeepEqual(t, keys[0:1], buf)
buf = make([]byte, len(keys))
nr, err = reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, len(keys))
assert.DeepEqual(t, keys, buf)
})
t.Run("ctrl-c,ctrl-z escape key, keys [ctrl-c],[DEL]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-c,ctrl-z")
keys, _ := ToBytes("ctrl-c,DEL")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, 1)
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, 0)
assert.DeepEqual(t, keys[0:1], buf)
buf = make([]byte, len(keys))
nr, err = reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, nr, len(keys))
assert.DeepEqual(t, keys, buf)
})
t.Run("a,b,c,d escape key, keys [a,b],[c,d]", func(t *testing.T) {
escapeKeys, _ := ToBytes("a,b,c,d")
keys, _ := ToBytes("a,b,c,d")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, 2)
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, 0, nr)
assert.DeepEqual(t, keys[0:2], buf)
buf = make([]byte, 2)
nr, err = reader.Read(buf)
assert.Error(t, err, "read escape sequence")
assert.Equal(t, 0, nr)
assert.DeepEqual(t, keys[2:4], buf)
})
t.Run("ctrl-p,ctrl-q escape key, keys [ctrl-p],[a],[ctrl-p,ctrl-q]", func(t *testing.T) {
escapeKeys, _ := ToBytes("ctrl-p,ctrl-q")
keys, _ := ToBytes("ctrl-p,a,ctrl-p,ctrl-q")
reader := NewEscapeProxy(bytes.NewReader(keys), escapeKeys)
buf := make([]byte, 1)
nr, err := reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, 0, nr)
buf = make([]byte, 1)
nr, err = reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, 1, nr)
assert.DeepEqual(t, keys[:1], buf)
buf = make([]byte, 2)
nr, err = reader.Read(buf)
assert.NilError(t, err)
assert.Equal(t, 1, nr)
assert.DeepEqual(t, keys[1:3], buf)
buf = make([]byte, 2)
nr, err = reader.Read(buf)
assert.Error(t, err, "read escape sequence")
assert.Equal(t, 0, nr)
})
}

View file

@ -1,117 +0,0 @@
//+build linux
package term // import "github.com/docker/docker/pkg/term"
import (
"io/ioutil"
"os"
"testing"
"github.com/google/go-cmp/cmp"
"gotest.tools/v3/assert"
)
// RequiresRoot skips tests that require root, unless the test.root flag has
// been set
func RequiresRoot(t *testing.T) {
if os.Getuid() != 0 {
t.Skip("skipping test that requires root")
return
}
}
func newTtyForTest(t *testing.T) (*os.File, error) {
RequiresRoot(t)
return os.OpenFile("/dev/tty", os.O_RDWR, os.ModeDevice)
}
func newTempFile() (*os.File, error) {
return ioutil.TempFile(os.TempDir(), "temp")
}
func TestGetWinsize(t *testing.T) {
tty, err := newTtyForTest(t)
assert.NilError(t, err)
defer tty.Close()
winSize, err := GetWinsize(tty.Fd())
assert.NilError(t, err)
assert.Assert(t, winSize != nil)
newSize := Winsize{Width: 200, Height: 200, x: winSize.x, y: winSize.y}
err = SetWinsize(tty.Fd(), &newSize)
assert.NilError(t, err)
winSize, err = GetWinsize(tty.Fd())
assert.NilError(t, err)
assert.DeepEqual(t, *winSize, newSize, cmpWinsize)
}
var cmpWinsize = cmp.AllowUnexported(Winsize{})
func TestSetWinsize(t *testing.T) {
tty, err := newTtyForTest(t)
assert.NilError(t, err)
defer tty.Close()
winSize, err := GetWinsize(tty.Fd())
assert.NilError(t, err)
assert.Assert(t, winSize != nil)
newSize := Winsize{Width: 200, Height: 200, x: winSize.x, y: winSize.y}
err = SetWinsize(tty.Fd(), &newSize)
assert.NilError(t, err)
winSize, err = GetWinsize(tty.Fd())
assert.NilError(t, err)
assert.DeepEqual(t, *winSize, newSize, cmpWinsize)
}
func TestGetFdInfo(t *testing.T) {
tty, err := newTtyForTest(t)
assert.NilError(t, err)
defer tty.Close()
inFd, isTerminal := GetFdInfo(tty)
assert.Equal(t, inFd, tty.Fd())
assert.Equal(t, isTerminal, true)
tmpFile, err := newTempFile()
assert.NilError(t, err)
defer tmpFile.Close()
inFd, isTerminal = GetFdInfo(tmpFile)
assert.Equal(t, inFd, tmpFile.Fd())
assert.Equal(t, isTerminal, false)
}
func TestIsTerminal(t *testing.T) {
tty, err := newTtyForTest(t)
assert.NilError(t, err)
defer tty.Close()
isTerminal := IsTerminal(tty.Fd())
assert.Equal(t, isTerminal, true)
tmpFile, err := newTempFile()
assert.NilError(t, err)
defer tmpFile.Close()
isTerminal = IsTerminal(tmpFile.Fd())
assert.Equal(t, isTerminal, false)
}
func TestSaveState(t *testing.T) {
tty, err := newTtyForTest(t)
assert.NilError(t, err)
defer tty.Close()
state, err := SaveState(tty.Fd())
assert.NilError(t, err)
assert.Assert(t, state != nil)
tty, err = newTtyForTest(t)
assert.NilError(t, err)
defer tty.Close()
err = RestoreTerminal(tty.Fd(), state)
assert.NilError(t, err)
}
func TestDisableEcho(t *testing.T) {
tty, err := newTtyForTest(t)
assert.NilError(t, err)
defer tty.Close()
state, err := SetRawTerminal(tty.Fd())
defer RestoreTerminal(tty.Fd(), state)
assert.NilError(t, err)
assert.Assert(t, state != nil)
err = DisableEcho(tty.Fd(), state)
assert.NilError(t, err)
}

View file

@ -0,0 +1,34 @@
// +build windows
// 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 (
windowsconsole "github.com/moby/term/windows"
)
var (
// GetHandleInfo returns file descriptor and bool indicating whether the file is a console.
// Deprecated: use github.com/moby/term/windows.GetHandleInfo
GetHandleInfo = windowsconsole.GetHandleInfo
// 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
IsConsole = windowsconsole.IsConsole
// 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
NewAnsiReader = windowsconsole.NewAnsiReader
// 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
NewAnsiWriter = windowsconsole.NewAnsiWriter
)

View file

@ -6,6 +6,7 @@ github.com/golang/gddo 72a348e765d293ed6d1ded7b6995
github.com/google/uuid 0cd6bf5da1e1c83f8b45653022c74f71af0538a4 # v1.1.1
github.com/gorilla/mux 00bdffe0f3c77e27d2cf6f5c70232a2d3e4d9c15 # v1.7.3
github.com/Microsoft/opengcs a10967154e143a36014584a6f664344e3bb0aa64
github.com/moby/term 063f2cd0b49dbb0752774d1cb649998d91424fea
github.com/creack/pty 3a6a957789163cacdfe0e291617a1c8e80612c11 # v1.1.9
github.com/konsorten/go-windows-terminal-sequences f55edac94c9bbba5d6182a4be46d86a2c9b5b50e # v1.0.2

191
vendor/github.com/moby/term/LICENSE generated vendored Normal file
View file

@ -0,0 +1,191 @@
Apache License
Version 2.0, January 2004
https://www.apache.org/licenses/
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
1. Definitions.
"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.
"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.
"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.
"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.
"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.
"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.
"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).
"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.
"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."
"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.
2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.
3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.
4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:
(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and
(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and
(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and
(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.
You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.
5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.
6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.
7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.
8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.
9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.
END OF TERMS AND CONDITIONS
Copyright 2013-2018 Docker, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

36
vendor/github.com/moby/term/README.md generated vendored Normal file
View file

@ -0,0 +1,36 @@
# term - utilities for dealing with terminals
![](https://github.com/moby/term/workflows/.github/workflows/test.yml/badge.svg) [![GoDoc](https://godoc.org/github.com/moby/term?status.svg)](https://godoc.org/github.com/moby/term) [![Go Report Card](https://goreportcard.com/badge/github.com/moby/term)](https://goreportcard.com/report/github.com/moby/term)
term provides structures and helper functions to work with terminal (state, sizes).
#### Using term
```go
package main
import (
"log"
"os"
"github.com/moby/term"
)
func main() {
fd := os.Stdin.Fd()
if term.IsTerminal(fd) {
ws, err := term.GetWinsize(fd)
if err != nil {
log.Fatalf("term.GetWinsize: %s", err)
}
log.Printf("%d:%d\n", ws.Height, ws.Width)
}
}
```
## Contributing
Want to hack on term? [Docker's contributions guidelines](https://github.com/docker/docker/blob/master/CONTRIBUTING.md) apply.
## Copyright and license
Code and documentation copyright 2015 Docker, inc. Code released under the Apache 2.0 license. Docs released under Creative commons.

View file

@ -1,4 +1,4 @@
package term // import "github.com/docker/docker/pkg/term"
package term
import (
"fmt"
@ -42,7 +42,6 @@ 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:

13
vendor/github.com/moby/term/go.mod generated vendored Normal file
View file

@ -0,0 +1,13 @@
module github.com/moby/term
go 1.13
require (
github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78
github.com/google/go-cmp v0.3.1
github.com/pkg/errors v0.9.1 // indirect
github.com/sirupsen/logrus v1.4.2
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527
gotest.tools v2.2.0+incompatible
gotest.tools/v3 v3.0.2 // indirect
)

View file

@ -1,4 +1,4 @@
package term // import "github.com/docker/docker/pkg/term"
package term
import (
"io"
@ -6,7 +6,6 @@ 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 {
@ -26,7 +25,6 @@ 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

@ -1,6 +1,6 @@
// +build !windows
package term // import "github.com/docker/docker/pkg/term"
package term
import (
"syscall"

View file

@ -2,9 +2,7 @@
// 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"
package term
import (
"errors"
@ -22,13 +20,11 @@ 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
@ -37,13 +33,11 @@ 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
@ -55,7 +49,6 @@ 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
@ -63,7 +56,6 @@ 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
@ -75,7 +67,6 @@ 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 {
@ -87,7 +78,6 @@ 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
@ -102,7 +92,6 @@ 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 {
@ -115,7 +104,6 @@ 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

@ -1,4 +1,4 @@
package term // import "github.com/docker/docker/pkg/term"
package term
import (
"io"
@ -7,17 +7,15 @@ import (
"syscall" // used for STD_INPUT_HANDLE, STD_OUTPUT_HANDLE and STD_ERROR_HANDLE
"github.com/Azure/go-ansiterm/winterm"
windowsconsole "github.com/docker/docker/pkg/term/windows"
windowsconsole "github.com/moby/term/windows"
)
// 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
@ -27,7 +25,6 @@ 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.
@ -91,13 +88,11 @@ 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 {
@ -113,20 +108,17 @@ 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 {
@ -138,7 +130,6 @@ 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
@ -156,7 +147,6 @@ 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 {
@ -171,7 +161,6 @@ 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 {
@ -186,7 +175,6 @@ 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

@ -1,6 +1,6 @@
// +build darwin freebsd openbsd netbsd
package term // import "github.com/docker/docker/pkg/term"
package term
import (
"unsafe"
@ -14,13 +14,11 @@ 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

@ -1,4 +1,4 @@
package term // import "github.com/docker/docker/pkg/term"
package term
import (
"golang.org/x/sys/unix"
@ -10,13 +10,11 @@ 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

@ -1,6 +1,6 @@
// +build windows
package windowsconsole // import "github.com/docker/docker/pkg/term/windows"
package windowsconsole // import "github.com/moby/term/windows"
import (
"bytes"
@ -30,7 +30,6 @@ 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

@ -1,6 +1,6 @@
// +build windows
package windowsconsole // import "github.com/docker/docker/pkg/term/windows"
package windowsconsole // import "github.com/moby/term/windows"
import (
"io"
@ -23,7 +23,6 @@ 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

@ -1,6 +1,6 @@
// +build windows
package windowsconsole // import "github.com/docker/docker/pkg/term/windows"
package windowsconsole // import "github.com/moby/term/windows"
import (
"os"
@ -9,7 +9,6 @@ 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:
@ -30,7 +29,6 @@ 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,12 +1,9 @@
// +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"
package windowsconsole // import "github.com/moby/term/windows"
import (
"io/ioutil"

View file

@ -1,13 +1,12 @@
// +build !windows
package term // import "github.com/docker/docker/pkg/term"
package term
import (
"golang.org/x/sys/unix"
)
// 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}
@ -15,7 +14,6 @@ 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)