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
5 | 5 | github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 |
6 | 6 | github.com/google/go-cmp v0.3.1 |
7 | 7 | github.com/pkg/errors v0.9.1 // indirect |
8 | github.com/sirupsen/logrus v1.4.2 | |
9 | 8 | golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 |
10 | 9 | gotest.tools v2.2.0+incompatible |
11 | gotest.tools/v3 v3.0.2 // indirect | |
12 | 10 | ) |
0 | 0 | github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= |
1 | 1 | 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= | |
6 | 2 | github.com/google/go-cmp v0.3.1 h1:Xye71clBPdm5HgqGwUkwhbynsUJZhDbS20FvLhQ2izg= |
7 | 3 | 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= | |
11 | 4 | github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= |
12 | 5 | 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= | |
26 | 6 | golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527 h1:uYVVQ9WP/Ds2ROhcaGPeIdVq0RIXVLwsHlnvJ+cT1So= |
27 | 7 | 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= | |
30 | 8 | gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo= |
31 | 9 | gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= |
32 | gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk= |
30 | 30 | // NewAnsiReader returns an io.ReadCloser that provides VT100 terminal emulation on top of a |
31 | 31 | // Windows console input handle. |
32 | 32 | func NewAnsiReader(nFile int) io.ReadCloser { |
33 | initLogger() | |
34 | 33 | file, fd := winterm.GetStdFile(nFile) |
35 | 34 | return &ansiReader{ |
36 | 35 | file: file, |
58 | 57 | |
59 | 58 | // Previously read bytes exist, read as much as we can and return |
60 | 59 | if len(ar.buffer) > 0 { |
61 | logger.Debugf("Reading previously cached bytes") | |
62 | ||
63 | 60 | originalLength := len(ar.buffer) |
64 | 61 | copiedLength := copy(p, ar.buffer) |
65 | 62 | |
69 | 66 | ar.buffer = ar.buffer[copiedLength:] |
70 | 67 | } |
71 | 68 | |
72 | logger.Debugf("Read from cache p[%d]: % x", copiedLength, p) | |
73 | 69 | return copiedLength, nil |
74 | 70 | } |
75 | 71 | |
76 | 72 | // Read and translate key events |
77 | events, err := readInputEvents(ar.fd, len(p)) | |
73 | events, err := readInputEvents(ar, len(p)) | |
78 | 74 | if err != nil { |
79 | 75 | return 0, err |
80 | 76 | } else if len(events) == 0 { |
81 | logger.Debug("No input events detected") | |
82 | 77 | return 0, nil |
83 | 78 | } |
84 | 79 | |
86 | 81 | |
87 | 82 | // Save excess bytes and right-size keyBytes |
88 | 83 | if len(keyBytes) > len(p) { |
89 | logger.Debugf("Received %d keyBytes, only room for %d bytes", len(keyBytes), len(p)) | |
90 | 84 | ar.buffer = keyBytes[len(p):] |
91 | 85 | keyBytes = keyBytes[:len(p)] |
92 | 86 | } else if len(keyBytes) == 0 { |
93 | logger.Debug("No key bytes returned from the translator") | |
94 | 87 | return 0, nil |
95 | 88 | } |
96 | 89 | |
99 | 92 | return 0, errors.New("unexpected copy length encountered") |
100 | 93 | } |
101 | 94 | |
102 | logger.Debugf("Read p[%d]: % x", copiedLength, p) | |
103 | logger.Debugf("Read keyBytes[%d]: % x", copiedLength, keyBytes) | |
104 | 95 | return copiedLength, nil |
105 | 96 | } |
106 | 97 | |
107 | 98 | // 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) { | |
109 | 100 | // Determine the maximum number of records to retrieve |
110 | 101 | // -- Cast around the type system to obtain the size of a single INPUT_RECORD. |
111 | 102 | // unsafe.Sizeof requires an expression vs. a type-reference; the casting |
117 | 108 | } else if countRecords == 0 { |
118 | 109 | countRecords = 1 |
119 | 110 | } |
120 | logger.Debugf("[windows] readInputEvents: Reading %v records (buffer size %v, record size %v)", countRecords, maxBytes, recordSize) | |
121 | 111 | |
122 | 112 | // Wait for and read input events |
123 | 113 | events := make([]winterm.INPUT_RECORD, countRecords) |
124 | 114 | nEvents := uint32(0) |
125 | eventsExist, err := winterm.WaitForSingleObject(fd, winterm.WAIT_INFINITE) | |
115 | eventsExist, err := winterm.WaitForSingleObject(ar.fd, winterm.WAIT_INFINITE) | |
126 | 116 | if err != nil { |
127 | 117 | return nil, err |
128 | 118 | } |
129 | 119 | |
130 | 120 | if eventsExist { |
131 | err = winterm.ReadConsoleInput(fd, events, &nEvents) | |
121 | err = winterm.ReadConsoleInput(ar.fd, events, &nEvents) | |
132 | 122 | if err != nil { |
133 | 123 | return nil, err |
134 | 124 | } |
135 | 125 | } |
136 | 126 | |
137 | 127 | // Return a slice restricted to the number of returned records |
138 | logger.Debugf("[windows] readInputEvents: Read %v events", nEvents) | |
139 | 128 | return events[:nEvents], nil |
140 | 129 | } |
141 | 130 |
23 | 23 | // NewAnsiWriter returns an io.Writer that provides VT100 terminal emulation on top of a |
24 | 24 | // Windows console output handle. |
25 | 25 | func NewAnsiWriter(nFile int) io.Writer { |
26 | initLogger() | |
27 | 26 | file, fd := winterm.GetStdFile(nFile) |
28 | 27 | info, err := winterm.GetConsoleScreenBufferInfo(fd) |
29 | 28 | if err != nil { |
31 | 30 | } |
32 | 31 | |
33 | 32 | parser := ansiterm.CreateParser("Ground", winterm.CreateWinEventHandler(fd, file)) |
34 | logger.Infof("newAnsiWriter: parser %p", parser) | |
35 | 33 | |
36 | aw := &ansiWriter{ | |
34 | return &ansiWriter{ | |
37 | 35 | file: file, |
38 | 36 | fd: fd, |
39 | 37 | infoReset: info, |
41 | 39 | escapeSequence: []byte(ansiterm.KEY_ESC_CSI), |
42 | 40 | parser: parser, |
43 | 41 | } |
44 | ||
45 | logger.Infof("newAnsiWriter: aw.parser %p", aw.parser) | |
46 | logger.Infof("newAnsiWriter: %v", aw) | |
47 | return aw | |
48 | 42 | } |
49 | 43 | |
50 | 44 | func (aw *ansiWriter) Fd() uintptr { |
57 | 51 | return 0, nil |
58 | 52 | } |
59 | 53 | |
60 | logger.Infof("Write: % x", p) | |
61 | logger.Infof("Write: %s", string(p)) | |
62 | 54 | return aw.parser.Parse(p) |
63 | 55 | } |
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 | // +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 | } |