Codebase list golang-github-moby-term / 7a7248e
Remove debug logs and logrus dependency, and go mod tidy Logrus was only used for debug logging, which should not be needed. Signed-off-by: Sebastiaan van Stijn <github@gone.nl> Sebastiaan van Stijn 4 years ago
7 changed file(s) with 10 addition(s) and 86 deletion(s). Raw diff Collapse all Expand all
55 github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78
66 github.com/google/go-cmp v0.3.1
77 github.com/pkg/errors v0.9.1 // indirect
8 github.com/sirupsen/logrus v1.4.2
98 golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527
109 gotest.tools v2.2.0+incompatible
11 gotest.tools/v3 v3.0.2 // indirect
1210 )
00 github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8=
11 github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8=
2 github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
3 github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
4 github.com/google/go-cmp v0.3.0 h1:crn/baboCvb5fXaQ0IJ1SGTsTVrWpDsCWC8EGETZijY=
5 github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
62 github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg=
73 github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU=
8 github.com/konsorten/go-windows-terminal-sequences v1.0.1 h1:mweAR1A6xJ3oS2pRaGiHgQ4OO8tzTaLawm8vnODuwDk=
9 github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
10 github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
114 github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
125 github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
13 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
14 github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
15 github.com/sirupsen/logrus v1.4.2 h1:SPIRibHv4MatM3XXNO2BJeFLZwZ2LvZgfQ5+UNI2im4=
16 github.com/sirupsen/logrus v1.4.2/go.mod h1:tLMulIdttU9McNUspp0xgXVQah82FyeX6MwdIuYE2rE=
17 github.com/spf13/pflag v1.0.3/go.mod h1:DYY7MBk1bdzusC3SYhjObp+wFpr4gzcvqqNjLnInEg4=
18 github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
19 github.com/stretchr/testify v1.2.2 h1:bSDNvY7ZPG5RlJ8otE/7V6gMiyenm9RtJ7IUVIAoJ1w=
20 github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
21 golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
22 golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
23 golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
24 golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
25 golang.org/x/sys v0.0.0-20190422165155-953cdadca894/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
266 golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So=
277 golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
28 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
29 golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
308 gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
319 gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
32 gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
3030 // NewAnsiReader returns an io.ReadCloser that provides VT100 terminal emulation on top of a
3131 // Windows console input handle.
3232 func NewAnsiReader(nFile int) io.ReadCloser {
33 initLogger()
3433 file, fd := winterm.GetStdFile(nFile)
3534 return &ansiReader{
3635 file: file,
5857
5958 // Previously read bytes exist, read as much as we can and return
6059 if len(ar.buffer) > 0 {
61 logger.Debugf("Reading previously cached bytes")
62
6360 originalLength := len(ar.buffer)
6461 copiedLength := copy(p, ar.buffer)
6562
6966 ar.buffer = ar.buffer[copiedLength:]
7067 }
7168
72 logger.Debugf("Read from cache p[%d]: % x", copiedLength, p)
7369 return copiedLength, nil
7470 }
7571
7672 // Read and translate key events
77 events, err := readInputEvents(ar.fd, len(p))
73 events, err := readInputEvents(ar, len(p))
7874 if err != nil {
7975 return 0, err
8076 } else if len(events) == 0 {
81 logger.Debug("No input events detected")
8277 return 0, nil
8378 }
8479
8681
8782 // Save excess bytes and right-size keyBytes
8883 if len(keyBytes) > len(p) {
89 logger.Debugf("Received %d keyBytes, only room for %d bytes", len(keyBytes), len(p))
9084 ar.buffer = keyBytes[len(p):]
9185 keyBytes = keyBytes[:len(p)]
9286 } else if len(keyBytes) == 0 {
93 logger.Debug("No key bytes returned from the translator")
9487 return 0, nil
9588 }
9689
9992 return 0, errors.New("unexpected copy length encountered")
10093 }
10194
102 logger.Debugf("Read p[%d]: % x", copiedLength, p)
103 logger.Debugf("Read keyBytes[%d]: % x", copiedLength, keyBytes)
10495 return copiedLength, nil
10596 }
10697
10798 // readInputEvents polls until at least one event is available.
108 func readInputEvents(fd uintptr, maxBytes int) ([]winterm.INPUT_RECORD, error) {
99 func readInputEvents(ar *ansiReader, maxBytes int) ([]winterm.INPUT_RECORD, error) {
109100 // Determine the maximum number of records to retrieve
110101 // -- Cast around the type system to obtain the size of a single INPUT_RECORD.
111102 // unsafe.Sizeof requires an expression vs. a type-reference; the casting
117108 } else if countRecords == 0 {
118109 countRecords = 1
119110 }
120 logger.Debugf("[windows] readInputEvents: Reading %v records (buffer size %v, record size %v)", countRecords, maxBytes, recordSize)
121111
122112 // Wait for and read input events
123113 events := make([]winterm.INPUT_RECORD, countRecords)
124114 nEvents := uint32(0)
125 eventsExist, err := winterm.WaitForSingleObject(fd, winterm.WAIT_INFINITE)
115 eventsExist, err := winterm.WaitForSingleObject(ar.fd, winterm.WAIT_INFINITE)
126116 if err != nil {
127117 return nil, err
128118 }
129119
130120 if eventsExist {
131 err = winterm.ReadConsoleInput(fd, events, &nEvents)
121 err = winterm.ReadConsoleInput(ar.fd, events, &nEvents)
132122 if err != nil {
133123 return nil, err
134124 }
135125 }
136126
137127 // Return a slice restricted to the number of returned records
138 logger.Debugf("[windows] readInputEvents: Read %v events", nEvents)
139128 return events[:nEvents], nil
140129 }
141130
2323 // NewAnsiWriter returns an io.Writer that provides VT100 terminal emulation on top of a
2424 // Windows console output handle.
2525 func NewAnsiWriter(nFile int) io.Writer {
26 initLogger()
2726 file, fd := winterm.GetStdFile(nFile)
2827 info, err := winterm.GetConsoleScreenBufferInfo(fd)
2928 if err != nil {
3130 }
3231
3332 parser := ansiterm.CreateParser("Ground", winterm.CreateWinEventHandler(fd, file))
34 logger.Infof("newAnsiWriter: parser %p", parser)
3533
36 aw := &ansiWriter{
34 return &ansiWriter{
3735 file: file,
3836 fd: fd,
3937 infoReset: info,
4139 escapeSequence: []byte(ansiterm.KEY_ESC_CSI),
4240 parser: parser,
4341 }
44
45 logger.Infof("newAnsiWriter: aw.parser %p", aw.parser)
46 logger.Infof("newAnsiWriter: %v", aw)
47 return aw
4842 }
4943
5044 func (aw *ansiWriter) Fd() uintptr {
5751 return 0, nil
5852 }
5953
60 logger.Infof("Write: % x", p)
61 logger.Infof("Write: %s", string(p))
6254 return aw.parser.Parse(p)
6355 }
0 // These files implement ANSI-aware input and output streams for use by the Docker Windows client.
1 // When asked for the set of standard streams (e.g., stdin, stdout, stderr), the code will create
2 // and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls.
3
4 package windowsconsole // import "github.com/moby/term/windows"
+0
-34
windows/windows.go less more
0 // +build windows
1 // These files implement ANSI-aware input and output streams for use by the Docker Windows client.
2 // When asked for the set of standard streams (e.g., stdin, stdout, stderr), the code will create
3 // and return pseudo-streams that convert ANSI sequences to / from Windows Console API calls.
4
5 package windowsconsole // import "github.com/moby/term/windows"
6
7 import (
8 "io/ioutil"
9 "os"
10 "sync"
11
12 ansiterm "github.com/Azure/go-ansiterm"
13 "github.com/sirupsen/logrus"
14 )
15
16 var logger *logrus.Logger
17 var initOnce sync.Once
18
19 func initLogger() {
20 initOnce.Do(func() {
21 logFile := ioutil.Discard
22
23 if isDebugEnv := os.Getenv(ansiterm.LogEnv); isDebugEnv == "1" {
24 logFile, _ = os.Create("ansiReaderWriter.log")
25 }
26
27 logger = &logrus.Logger{
28 Out: logFile,
29 Formatter: new(logrus.TextFormatter),
30 Level: logrus.DebugLevel,
31 }
32 })
33 }
+0
-3
windows/windows_test.go less more
0 // This file is necessary to pass the Docker tests.
1
2 package windowsconsole // import "github.com/moby/term/windows"