Signed-off-by: mqliang <mqliang.zju@gmail.com>
| ... | ... |
@@ -14,6 +14,10 @@ import ( |
| 14 | 14 |
"github.com/Azure/go-ansiterm/winterm" |
| 15 | 15 |
) |
| 16 | 16 |
|
| 17 |
+const ( |
|
| 18 |
+ escapeSequence = ansiterm.KEY_ESC_CSI |
|
| 19 |
+) |
|
| 20 |
+ |
|
| 17 | 21 |
// ansiReader wraps a standard input file (e.g., os.Stdin) providing ANSI sequence translation. |
| 18 | 22 |
type ansiReader struct {
|
| 19 | 23 |
file *os.File |
| ... | ... |
@@ -21,18 +25,15 @@ type ansiReader struct {
|
| 21 | 21 |
buffer []byte |
| 22 | 22 |
cbBuffer int |
| 23 | 23 |
command []byte |
| 24 |
- // TODO(azlinux): Remove this and hard-code the string -- it is not going to change |
|
| 25 |
- escapeSequence []byte |
|
| 26 | 24 |
} |
| 27 | 25 |
|
| 28 | 26 |
func newAnsiReader(nFile int) *ansiReader {
|
| 29 | 27 |
file, fd := winterm.GetStdFile(nFile) |
| 30 | 28 |
return &ansiReader{
|
| 31 |
- file: file, |
|
| 32 |
- fd: fd, |
|
| 33 |
- command: make([]byte, 0, ansiterm.ANSI_MAX_CMD_LENGTH), |
|
| 34 |
- escapeSequence: []byte(ansiterm.KEY_ESC_CSI), |
|
| 35 |
- buffer: make([]byte, 0), |
|
| 29 |
+ file: file, |
|
| 30 |
+ fd: fd, |
|
| 31 |
+ command: make([]byte, 0, ansiterm.ANSI_MAX_CMD_LENGTH), |
|
| 32 |
+ buffer: make([]byte, 0), |
|
| 36 | 33 |
} |
| 37 | 34 |
} |
| 38 | 35 |
|
| ... | ... |
@@ -78,7 +79,7 @@ func (ar *ansiReader) Read(p []byte) (int, error) {
|
| 78 | 78 |
return 0, nil |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
- keyBytes := translateKeyEvents(events, ar.escapeSequence) |
|
| 81 |
+ keyBytes := translateKeyEvents(events, []byte(escapeSequence)) |
|
| 82 | 82 |
|
| 83 | 83 |
// Save excess bytes and right-size keyBytes |
| 84 | 84 |
if len(keyBytes) > len(p) {
|