go-ansiterm was previously pulling the testing package into the docker
binaries.
Signed-off-by: John Starks <jostarks@microsoft.com>
| ... | ... |
@@ -6,7 +6,7 @@ rm -rf vendor/ |
| 6 | 6 |
source 'hack/.vendor-helpers.sh' |
| 7 | 7 |
|
| 8 | 8 |
# the following lines are in sorted order, FYI |
| 9 |
-clone git github.com/Azure/go-ansiterm 70b2c90b260171e829f1ebd7c17f600c11858dbe |
|
| 9 |
+clone git github.com/Azure/go-ansiterm 388960b655244e76e24c75f48631564eaefade62 |
|
| 10 | 10 |
clone git github.com/Microsoft/hcsshim v0.2.2 |
| 11 | 11 |
clone git github.com/Microsoft/go-winio v0.3.0 |
| 12 | 12 |
clone git github.com/Sirupsen/logrus v0.9.0 # logrus is a common dependency among multiple deps |
| ... | ... |
@@ -136,14 +136,14 @@ func readInputEvents(fd uintptr, maxBytes int) ([]winterm.INPUT_RECORD, error) {
|
| 136 | 136 |
|
| 137 | 137 |
// KeyEvent Translation Helpers |
| 138 | 138 |
|
| 139 |
-var arrowKeyMapPrefix = map[winterm.WORD]string{
|
|
| 139 |
+var arrowKeyMapPrefix = map[uint16]string{
|
|
| 140 | 140 |
winterm.VK_UP: "%s%sA", |
| 141 | 141 |
winterm.VK_DOWN: "%s%sB", |
| 142 | 142 |
winterm.VK_RIGHT: "%s%sC", |
| 143 | 143 |
winterm.VK_LEFT: "%s%sD", |
| 144 | 144 |
} |
| 145 | 145 |
|
| 146 |
-var keyMapPrefix = map[winterm.WORD]string{
|
|
| 146 |
+var keyMapPrefix = map[uint16]string{
|
|
| 147 | 147 |
winterm.VK_UP: "\x1B[%sA", |
| 148 | 148 |
winterm.VK_DOWN: "\x1B[%sB", |
| 149 | 149 |
winterm.VK_RIGHT: "\x1B[%sC", |
| ... | ... |
@@ -207,7 +207,7 @@ func keyToString(keyEvent *winterm.KEY_EVENT_RECORD, escapeSequence []byte) stri |
| 207 | 207 |
} |
| 208 | 208 |
|
| 209 | 209 |
// formatVirtualKey converts a virtual key (e.g., up arrow) into the appropriate ANSI string. |
| 210 |
-func formatVirtualKey(key winterm.WORD, controlState winterm.DWORD, escapeSequence []byte) string {
|
|
| 210 |
+func formatVirtualKey(key uint16, controlState uint32, escapeSequence []byte) string {
|
|
| 211 | 211 |
shift, alt, control := getControlKeys(controlState) |
| 212 | 212 |
modifier := getControlKeysModifier(shift, alt, control) |
| 213 | 213 |
|
| ... | ... |
@@ -223,7 +223,7 @@ func formatVirtualKey(key winterm.WORD, controlState winterm.DWORD, escapeSequen |
| 223 | 223 |
} |
| 224 | 224 |
|
| 225 | 225 |
// getControlKeys extracts the shift, alt, and ctrl key states. |
| 226 |
-func getControlKeys(controlState winterm.DWORD) (shift, alt, control bool) {
|
|
| 226 |
+func getControlKeys(controlState uint32) (shift, alt, control bool) {
|
|
| 227 | 227 |
shift = 0 != (controlState & winterm.SHIFT_PRESSED) |
| 228 | 228 |
alt = 0 != (controlState & (winterm.LEFT_ALT_PRESSED | winterm.RIGHT_ALT_PRESSED)) |
| 229 | 229 |
control = 0 != (controlState & (winterm.LEFT_CTRL_PRESSED | winterm.RIGHT_CTRL_PRESSED)) |
| ... | ... |
@@ -124,32 +124,32 @@ func getByteRange(start byte, end byte) []byte {
|
| 124 | 124 |
return bytes |
| 125 | 125 |
} |
| 126 | 126 |
|
| 127 |
-var ToGroundBytes = getToGroundBytes() |
|
| 128 |
-var Executors = getExecuteBytes() |
|
| 127 |
+var toGroundBytes = getToGroundBytes() |
|
| 128 |
+var executors = getExecuteBytes() |
|
| 129 | 129 |
|
| 130 | 130 |
// SPACE 20+A0 hex Always and everywhere a blank space |
| 131 | 131 |
// Intermediate 20-2F hex !"#$%&'()*+,-./ |
| 132 |
-var Intermeds = getByteRange(0x20, 0x2F) |
|
| 132 |
+var intermeds = getByteRange(0x20, 0x2F) |
|
| 133 | 133 |
|
| 134 | 134 |
// Parameters 30-3F hex 0123456789:;<=>? |
| 135 | 135 |
// CSI Parameters 30-39, 3B hex 0123456789; |
| 136 |
-var CsiParams = getByteRange(0x30, 0x3F) |
|
| 136 |
+var csiParams = getByteRange(0x30, 0x3F) |
|
| 137 | 137 |
|
| 138 |
-var CsiCollectables = append(getByteRange(0x30, 0x39), getByteRange(0x3B, 0x3F)...) |
|
| 138 |
+var csiCollectables = append(getByteRange(0x30, 0x39), getByteRange(0x3B, 0x3F)...) |
|
| 139 | 139 |
|
| 140 | 140 |
// Uppercase 40-5F hex @ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_ |
| 141 |
-var UpperCase = getByteRange(0x40, 0x5F) |
|
| 141 |
+var upperCase = getByteRange(0x40, 0x5F) |
|
| 142 | 142 |
|
| 143 | 143 |
// Lowercase 60-7E hex `abcdefghijlkmnopqrstuvwxyz{|}~
|
| 144 |
-var LowerCase = getByteRange(0x60, 0x7E) |
|
| 144 |
+var lowerCase = getByteRange(0x60, 0x7E) |
|
| 145 | 145 |
|
| 146 | 146 |
// Alphabetics 40-7E hex (all of upper and lower case) |
| 147 |
-var Alphabetics = append(UpperCase, LowerCase...) |
|
| 147 |
+var alphabetics = append(upperCase, lowerCase...) |
|
| 148 | 148 |
|
| 149 |
-var Printables = getByteRange(0x20, 0x7F) |
|
| 149 |
+var printables = getByteRange(0x20, 0x7F) |
|
| 150 | 150 |
|
| 151 |
-var EscapeIntermediateToGroundBytes = getByteRange(0x30, 0x7E) |
|
| 152 |
-var EscapeToGroundBytes = getEscapeToGroundBytes() |
|
| 151 |
+var escapeIntermediateToGroundBytes = getByteRange(0x30, 0x7E) |
|
| 152 |
+var escapeToGroundBytes = getEscapeToGroundBytes() |
|
| 153 | 153 |
|
| 154 | 154 |
// See http://www.vt100.net/emu/vt500_parser.png for description of the complex |
| 155 | 155 |
// byte ranges below |
| ... | ... |
@@ -1,41 +1,41 @@ |
| 1 | 1 |
package ansiterm |
| 2 | 2 |
|
| 3 |
-type CsiEntryState struct {
|
|
| 4 |
- BaseState |
|
| 3 |
+type csiEntryState struct {
|
|
| 4 |
+ baseState |
|
| 5 | 5 |
} |
| 6 | 6 |
|
| 7 |
-func (csiState CsiEntryState) Handle(b byte) (s State, e error) {
|
|
| 7 |
+func (csiState csiEntryState) Handle(b byte) (s state, e error) {
|
|
| 8 | 8 |
logger.Infof("CsiEntry::Handle %#x", b)
|
| 9 | 9 |
|
| 10 |
- nextState, err := csiState.BaseState.Handle(b) |
|
| 10 |
+ nextState, err := csiState.baseState.Handle(b) |
|
| 11 | 11 |
if nextState != nil || err != nil {
|
| 12 | 12 |
return nextState, err |
| 13 | 13 |
} |
| 14 | 14 |
|
| 15 | 15 |
switch {
|
| 16 |
- case sliceContains(Alphabetics, b): |
|
| 17 |
- return csiState.parser.Ground, nil |
|
| 18 |
- case sliceContains(CsiCollectables, b): |
|
| 19 |
- return csiState.parser.CsiParam, nil |
|
| 20 |
- case sliceContains(Executors, b): |
|
| 16 |
+ case sliceContains(alphabetics, b): |
|
| 17 |
+ return csiState.parser.ground, nil |
|
| 18 |
+ case sliceContains(csiCollectables, b): |
|
| 19 |
+ return csiState.parser.csiParam, nil |
|
| 20 |
+ case sliceContains(executors, b): |
|
| 21 | 21 |
return csiState, csiState.parser.execute() |
| 22 | 22 |
} |
| 23 | 23 |
|
| 24 | 24 |
return csiState, nil |
| 25 | 25 |
} |
| 26 | 26 |
|
| 27 |
-func (csiState CsiEntryState) Transition(s State) error {
|
|
| 27 |
+func (csiState csiEntryState) Transition(s state) error {
|
|
| 28 | 28 |
logger.Infof("CsiEntry::Transition %s --> %s", csiState.Name(), s.Name())
|
| 29 |
- csiState.BaseState.Transition(s) |
|
| 29 |
+ csiState.baseState.Transition(s) |
|
| 30 | 30 |
|
| 31 | 31 |
switch s {
|
| 32 |
- case csiState.parser.Ground: |
|
| 32 |
+ case csiState.parser.ground: |
|
| 33 | 33 |
return csiState.parser.csiDispatch() |
| 34 |
- case csiState.parser.CsiParam: |
|
| 34 |
+ case csiState.parser.csiParam: |
|
| 35 | 35 |
switch {
|
| 36 |
- case sliceContains(CsiParams, csiState.parser.context.currentChar): |
|
| 36 |
+ case sliceContains(csiParams, csiState.parser.context.currentChar): |
|
| 37 | 37 |
csiState.parser.collectParam() |
| 38 |
- case sliceContains(Intermeds, csiState.parser.context.currentChar): |
|
| 38 |
+ case sliceContains(intermeds, csiState.parser.context.currentChar): |
|
| 39 | 39 |
csiState.parser.collectInter() |
| 40 | 40 |
} |
| 41 | 41 |
} |
| ... | ... |
@@ -43,7 +43,7 @@ func (csiState CsiEntryState) Transition(s State) error {
|
| 43 | 43 |
return nil |
| 44 | 44 |
} |
| 45 | 45 |
|
| 46 |
-func (csiState CsiEntryState) Enter() error {
|
|
| 46 |
+func (csiState csiEntryState) Enter() error {
|
|
| 47 | 47 |
csiState.parser.clear() |
| 48 | 48 |
return nil |
| 49 | 49 |
} |
| ... | ... |
@@ -1,36 +1,36 @@ |
| 1 | 1 |
package ansiterm |
| 2 | 2 |
|
| 3 |
-type CsiParamState struct {
|
|
| 4 |
- BaseState |
|
| 3 |
+type csiParamState struct {
|
|
| 4 |
+ baseState |
|
| 5 | 5 |
} |
| 6 | 6 |
|
| 7 |
-func (csiState CsiParamState) Handle(b byte) (s State, e error) {
|
|
| 7 |
+func (csiState csiParamState) Handle(b byte) (s state, e error) {
|
|
| 8 | 8 |
logger.Infof("CsiParam::Handle %#x", b)
|
| 9 | 9 |
|
| 10 |
- nextState, err := csiState.BaseState.Handle(b) |
|
| 10 |
+ nextState, err := csiState.baseState.Handle(b) |
|
| 11 | 11 |
if nextState != nil || err != nil {
|
| 12 | 12 |
return nextState, err |
| 13 | 13 |
} |
| 14 | 14 |
|
| 15 | 15 |
switch {
|
| 16 |
- case sliceContains(Alphabetics, b): |
|
| 17 |
- return csiState.parser.Ground, nil |
|
| 18 |
- case sliceContains(CsiCollectables, b): |
|
| 16 |
+ case sliceContains(alphabetics, b): |
|
| 17 |
+ return csiState.parser.ground, nil |
|
| 18 |
+ case sliceContains(csiCollectables, b): |
|
| 19 | 19 |
csiState.parser.collectParam() |
| 20 | 20 |
return csiState, nil |
| 21 |
- case sliceContains(Executors, b): |
|
| 21 |
+ case sliceContains(executors, b): |
|
| 22 | 22 |
return csiState, csiState.parser.execute() |
| 23 | 23 |
} |
| 24 | 24 |
|
| 25 | 25 |
return csiState, nil |
| 26 | 26 |
} |
| 27 | 27 |
|
| 28 |
-func (csiState CsiParamState) Transition(s State) error {
|
|
| 28 |
+func (csiState csiParamState) Transition(s state) error {
|
|
| 29 | 29 |
logger.Infof("CsiParam::Transition %s --> %s", csiState.Name(), s.Name())
|
| 30 |
- csiState.BaseState.Transition(s) |
|
| 30 |
+ csiState.baseState.Transition(s) |
|
| 31 | 31 |
|
| 32 | 32 |
switch s {
|
| 33 |
- case csiState.parser.Ground: |
|
| 33 |
+ case csiState.parser.ground: |
|
| 34 | 34 |
return csiState.parser.csiDispatch() |
| 35 | 35 |
} |
| 36 | 36 |
|
| ... | ... |
@@ -1,34 +1,34 @@ |
| 1 | 1 |
package ansiterm |
| 2 | 2 |
|
| 3 |
-type EscapeIntermediateState struct {
|
|
| 4 |
- BaseState |
|
| 3 |
+type escapeIntermediateState struct {
|
|
| 4 |
+ baseState |
|
| 5 | 5 |
} |
| 6 | 6 |
|
| 7 |
-func (escState EscapeIntermediateState) Handle(b byte) (s State, e error) {
|
|
| 8 |
- logger.Infof("EscapeIntermediateState::Handle %#x", b)
|
|
| 9 |
- nextState, err := escState.BaseState.Handle(b) |
|
| 7 |
+func (escState escapeIntermediateState) Handle(b byte) (s state, e error) {
|
|
| 8 |
+ logger.Infof("escapeIntermediateState::Handle %#x", b)
|
|
| 9 |
+ nextState, err := escState.baseState.Handle(b) |
|
| 10 | 10 |
if nextState != nil || err != nil {
|
| 11 | 11 |
return nextState, err |
| 12 | 12 |
} |
| 13 | 13 |
|
| 14 | 14 |
switch {
|
| 15 |
- case sliceContains(Intermeds, b): |
|
| 15 |
+ case sliceContains(intermeds, b): |
|
| 16 | 16 |
return escState, escState.parser.collectInter() |
| 17 |
- case sliceContains(Executors, b): |
|
| 17 |
+ case sliceContains(executors, b): |
|
| 18 | 18 |
return escState, escState.parser.execute() |
| 19 |
- case sliceContains(EscapeIntermediateToGroundBytes, b): |
|
| 20 |
- return escState.parser.Ground, nil |
|
| 19 |
+ case sliceContains(escapeIntermediateToGroundBytes, b): |
|
| 20 |
+ return escState.parser.ground, nil |
|
| 21 | 21 |
} |
| 22 | 22 |
|
| 23 | 23 |
return escState, nil |
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 |
-func (escState EscapeIntermediateState) Transition(s State) error {
|
|
| 27 |
- logger.Infof("EscapeIntermediateState::Transition %s --> %s", escState.Name(), s.Name())
|
|
| 28 |
- escState.BaseState.Transition(s) |
|
| 26 |
+func (escState escapeIntermediateState) Transition(s state) error {
|
|
| 27 |
+ logger.Infof("escapeIntermediateState::Transition %s --> %s", escState.Name(), s.Name())
|
|
| 28 |
+ escState.baseState.Transition(s) |
|
| 29 | 29 |
|
| 30 | 30 |
switch s {
|
| 31 |
- case escState.parser.Ground: |
|
| 31 |
+ case escState.parser.ground: |
|
| 32 | 32 |
return escState.parser.escDispatch() |
| 33 | 33 |
} |
| 34 | 34 |
|
| ... | ... |
@@ -1,47 +1,47 @@ |
| 1 | 1 |
package ansiterm |
| 2 | 2 |
|
| 3 |
-type EscapeState struct {
|
|
| 4 |
- BaseState |
|
| 3 |
+type escapeState struct {
|
|
| 4 |
+ baseState |
|
| 5 | 5 |
} |
| 6 | 6 |
|
| 7 |
-func (escState EscapeState) Handle(b byte) (s State, e error) {
|
|
| 8 |
- logger.Infof("EscapeState::Handle %#x", b)
|
|
| 9 |
- nextState, err := escState.BaseState.Handle(b) |
|
| 7 |
+func (escState escapeState) Handle(b byte) (s state, e error) {
|
|
| 8 |
+ logger.Infof("escapeState::Handle %#x", b)
|
|
| 9 |
+ nextState, err := escState.baseState.Handle(b) |
|
| 10 | 10 |
if nextState != nil || err != nil {
|
| 11 | 11 |
return nextState, err |
| 12 | 12 |
} |
| 13 | 13 |
|
| 14 | 14 |
switch {
|
| 15 | 15 |
case b == ANSI_ESCAPE_SECONDARY: |
| 16 |
- return escState.parser.CsiEntry, nil |
|
| 16 |
+ return escState.parser.csiEntry, nil |
|
| 17 | 17 |
case b == ANSI_OSC_STRING_ENTRY: |
| 18 |
- return escState.parser.OscString, nil |
|
| 19 |
- case sliceContains(Executors, b): |
|
| 18 |
+ return escState.parser.oscString, nil |
|
| 19 |
+ case sliceContains(executors, b): |
|
| 20 | 20 |
return escState, escState.parser.execute() |
| 21 |
- case sliceContains(EscapeToGroundBytes, b): |
|
| 22 |
- return escState.parser.Ground, nil |
|
| 23 |
- case sliceContains(Intermeds, b): |
|
| 24 |
- return escState.parser.EscapeIntermediate, nil |
|
| 21 |
+ case sliceContains(escapeToGroundBytes, b): |
|
| 22 |
+ return escState.parser.ground, nil |
|
| 23 |
+ case sliceContains(intermeds, b): |
|
| 24 |
+ return escState.parser.escapeIntermediate, nil |
|
| 25 | 25 |
} |
| 26 | 26 |
|
| 27 | 27 |
return escState, nil |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 |
-func (escState EscapeState) Transition(s State) error {
|
|
| 30 |
+func (escState escapeState) Transition(s state) error {
|
|
| 31 | 31 |
logger.Infof("Escape::Transition %s --> %s", escState.Name(), s.Name())
|
| 32 |
- escState.BaseState.Transition(s) |
|
| 32 |
+ escState.baseState.Transition(s) |
|
| 33 | 33 |
|
| 34 | 34 |
switch s {
|
| 35 |
- case escState.parser.Ground: |
|
| 35 |
+ case escState.parser.ground: |
|
| 36 | 36 |
return escState.parser.escDispatch() |
| 37 |
- case escState.parser.EscapeIntermediate: |
|
| 37 |
+ case escState.parser.escapeIntermediate: |
|
| 38 | 38 |
return escState.parser.collectInter() |
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
return nil |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
-func (escState EscapeState) Enter() error {
|
|
| 44 |
+func (escState escapeState) Enter() error {
|
|
| 45 | 45 |
escState.parser.clear() |
| 46 | 46 |
return nil |
| 47 | 47 |
} |
| ... | ... |
@@ -1,22 +1,22 @@ |
| 1 | 1 |
package ansiterm |
| 2 | 2 |
|
| 3 |
-type GroundState struct {
|
|
| 4 |
- BaseState |
|
| 3 |
+type groundState struct {
|
|
| 4 |
+ baseState |
|
| 5 | 5 |
} |
| 6 | 6 |
|
| 7 |
-func (gs GroundState) Handle(b byte) (s State, e error) {
|
|
| 7 |
+func (gs groundState) Handle(b byte) (s state, e error) {
|
|
| 8 | 8 |
gs.parser.context.currentChar = b |
| 9 | 9 |
|
| 10 |
- nextState, err := gs.BaseState.Handle(b) |
|
| 10 |
+ nextState, err := gs.baseState.Handle(b) |
|
| 11 | 11 |
if nextState != nil || err != nil {
|
| 12 | 12 |
return nextState, err |
| 13 | 13 |
} |
| 14 | 14 |
|
| 15 | 15 |
switch {
|
| 16 |
- case sliceContains(Printables, b): |
|
| 16 |
+ case sliceContains(printables, b): |
|
| 17 | 17 |
return gs, gs.parser.print() |
| 18 | 18 |
|
| 19 |
- case sliceContains(Executors, b): |
|
| 19 |
+ case sliceContains(executors, b): |
|
| 20 | 20 |
return gs, gs.parser.execute() |
| 21 | 21 |
} |
| 22 | 22 |
|
| ... | ... |
@@ -1,19 +1,19 @@ |
| 1 | 1 |
package ansiterm |
| 2 | 2 |
|
| 3 |
-type OscStringState struct {
|
|
| 4 |
- BaseState |
|
| 3 |
+type oscStringState struct {
|
|
| 4 |
+ baseState |
|
| 5 | 5 |
} |
| 6 | 6 |
|
| 7 |
-func (oscState OscStringState) Handle(b byte) (s State, e error) {
|
|
| 7 |
+func (oscState oscStringState) Handle(b byte) (s state, e error) {
|
|
| 8 | 8 |
logger.Infof("OscString::Handle %#x", b)
|
| 9 |
- nextState, err := oscState.BaseState.Handle(b) |
|
| 9 |
+ nextState, err := oscState.baseState.Handle(b) |
|
| 10 | 10 |
if nextState != nil || err != nil {
|
| 11 | 11 |
return nextState, err |
| 12 | 12 |
} |
| 13 | 13 |
|
| 14 | 14 |
switch {
|
| 15 | 15 |
case isOscStringTerminator(b): |
| 16 |
- return oscState.parser.Ground, nil |
|
| 16 |
+ return oscState.parser.ground, nil |
|
| 17 | 17 |
} |
| 18 | 18 |
|
| 19 | 19 |
return oscState, nil |
| ... | ... |
@@ -2,7 +2,6 @@ package ansiterm |
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"errors" |
| 5 |
- "fmt" |
|
| 6 | 5 |
"io/ioutil" |
| 7 | 6 |
"os" |
| 8 | 7 |
|
| ... | ... |
@@ -12,18 +11,18 @@ import ( |
| 12 | 12 |
var logger *logrus.Logger |
| 13 | 13 |
|
| 14 | 14 |
type AnsiParser struct {
|
| 15 |
- currState State |
|
| 15 |
+ currState state |
|
| 16 | 16 |
eventHandler AnsiEventHandler |
| 17 |
- context *AnsiContext |
|
| 18 |
- CsiEntry State |
|
| 19 |
- CsiParam State |
|
| 20 |
- DcsEntry State |
|
| 21 |
- Escape State |
|
| 22 |
- EscapeIntermediate State |
|
| 23 |
- Error State |
|
| 24 |
- Ground State |
|
| 25 |
- OscString State |
|
| 26 |
- stateMap []State |
|
| 17 |
+ context *ansiContext |
|
| 18 |
+ csiEntry state |
|
| 19 |
+ csiParam state |
|
| 20 |
+ dcsEntry state |
|
| 21 |
+ escape state |
|
| 22 |
+ escapeIntermediate state |
|
| 23 |
+ error state |
|
| 24 |
+ ground state |
|
| 25 |
+ oscString state |
|
| 26 |
+ stateMap []state |
|
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 | 29 |
func CreateParser(initialState string, evtHandler AnsiEventHandler) *AnsiParser {
|
| ... | ... |
@@ -41,27 +40,27 @@ func CreateParser(initialState string, evtHandler AnsiEventHandler) *AnsiParser |
| 41 | 41 |
|
| 42 | 42 |
parser := &AnsiParser{
|
| 43 | 43 |
eventHandler: evtHandler, |
| 44 |
- context: &AnsiContext{},
|
|
| 44 |
+ context: &ansiContext{},
|
|
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 |
- parser.CsiEntry = CsiEntryState{BaseState{name: "CsiEntry", parser: parser}}
|
|
| 48 |
- parser.CsiParam = CsiParamState{BaseState{name: "CsiParam", parser: parser}}
|
|
| 49 |
- parser.DcsEntry = DcsEntryState{BaseState{name: "DcsEntry", parser: parser}}
|
|
| 50 |
- parser.Escape = EscapeState{BaseState{name: "Escape", parser: parser}}
|
|
| 51 |
- parser.EscapeIntermediate = EscapeIntermediateState{BaseState{name: "EscapeIntermediate", parser: parser}}
|
|
| 52 |
- parser.Error = ErrorState{BaseState{name: "Error", parser: parser}}
|
|
| 53 |
- parser.Ground = GroundState{BaseState{name: "Ground", parser: parser}}
|
|
| 54 |
- parser.OscString = OscStringState{BaseState{name: "OscString", parser: parser}}
|
|
| 55 |
- |
|
| 56 |
- parser.stateMap = []State{
|
|
| 57 |
- parser.CsiEntry, |
|
| 58 |
- parser.CsiParam, |
|
| 59 |
- parser.DcsEntry, |
|
| 60 |
- parser.Escape, |
|
| 61 |
- parser.EscapeIntermediate, |
|
| 62 |
- parser.Error, |
|
| 63 |
- parser.Ground, |
|
| 64 |
- parser.OscString, |
|
| 47 |
+ parser.csiEntry = csiEntryState{baseState{name: "CsiEntry", parser: parser}}
|
|
| 48 |
+ parser.csiParam = csiParamState{baseState{name: "CsiParam", parser: parser}}
|
|
| 49 |
+ parser.dcsEntry = dcsEntryState{baseState{name: "DcsEntry", parser: parser}}
|
|
| 50 |
+ parser.escape = escapeState{baseState{name: "Escape", parser: parser}}
|
|
| 51 |
+ parser.escapeIntermediate = escapeIntermediateState{baseState{name: "EscapeIntermediate", parser: parser}}
|
|
| 52 |
+ parser.error = errorState{baseState{name: "Error", parser: parser}}
|
|
| 53 |
+ parser.ground = groundState{baseState{name: "Ground", parser: parser}}
|
|
| 54 |
+ parser.oscString = oscStringState{baseState{name: "OscString", parser: parser}}
|
|
| 55 |
+ |
|
| 56 |
+ parser.stateMap = []state{
|
|
| 57 |
+ parser.csiEntry, |
|
| 58 |
+ parser.csiParam, |
|
| 59 |
+ parser.dcsEntry, |
|
| 60 |
+ parser.escape, |
|
| 61 |
+ parser.escapeIntermediate, |
|
| 62 |
+ parser.error, |
|
| 63 |
+ parser.ground, |
|
| 64 |
+ parser.oscString, |
|
| 65 | 65 |
} |
| 66 | 66 |
|
| 67 | 67 |
parser.currState = getState(initialState, parser.stateMap) |
| ... | ... |
@@ -70,7 +69,7 @@ func CreateParser(initialState string, evtHandler AnsiEventHandler) *AnsiParser |
| 70 | 70 |
return parser |
| 71 | 71 |
} |
| 72 | 72 |
|
| 73 |
-func getState(name string, states []State) State {
|
|
| 73 |
+func getState(name string, states []state) state {
|
|
| 74 | 74 |
for _, el := range states {
|
| 75 | 75 |
if el.Name() == name {
|
| 76 | 76 |
return el |
| ... | ... |
@@ -99,7 +98,7 @@ func (ap *AnsiParser) handle(b byte) error {
|
| 99 | 99 |
|
| 100 | 100 |
if newState == nil {
|
| 101 | 101 |
logger.Warning("newState is nil")
|
| 102 |
- return errors.New(fmt.Sprintf("New state of 'nil' is invalid."))
|
|
| 102 |
+ return errors.New("New state of 'nil' is invalid.")
|
|
| 103 | 103 |
} |
| 104 | 104 |
|
| 105 | 105 |
if newState != ap.currState {
|
| ... | ... |
@@ -111,7 +110,7 @@ func (ap *AnsiParser) handle(b byte) error {
|
| 111 | 111 |
return nil |
| 112 | 112 |
} |
| 113 | 113 |
|
| 114 |
-func (ap *AnsiParser) changeState(newState State) error {
|
|
| 114 |
+func (ap *AnsiParser) changeState(newState state) error {
|
|
| 115 | 115 |
logger.Infof("ChangeState %s --> %s", ap.currState.Name(), newState.Name())
|
| 116 | 116 |
|
| 117 | 117 |
// Exit old state |
| 120 | 120 |
deleted file mode 100644 |
| ... | ... |
@@ -1,114 +0,0 @@ |
| 1 |
-package ansiterm |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 5 |
- "testing" |
|
| 6 |
-) |
|
| 7 |
- |
|
| 8 |
-func getStateNames() []string {
|
|
| 9 |
- parser, _ := createTestParser("Ground")
|
|
| 10 |
- |
|
| 11 |
- stateNames := []string{}
|
|
| 12 |
- for _, state := range parser.stateMap {
|
|
| 13 |
- stateNames = append(stateNames, state.Name()) |
|
| 14 |
- } |
|
| 15 |
- |
|
| 16 |
- return stateNames |
|
| 17 |
-} |
|
| 18 |
- |
|
| 19 |
-func stateTransitionHelper(t *testing.T, start string, end string, bytes []byte) {
|
|
| 20 |
- for _, b := range bytes {
|
|
| 21 |
- bytes := []byte{byte(b)}
|
|
| 22 |
- parser, _ := createTestParser(start) |
|
| 23 |
- parser.Parse(bytes) |
|
| 24 |
- validateState(t, parser.currState, end) |
|
| 25 |
- } |
|
| 26 |
-} |
|
| 27 |
- |
|
| 28 |
-func anyToXHelper(t *testing.T, bytes []byte, expectedState string) {
|
|
| 29 |
- for _, s := range getStateNames() {
|
|
| 30 |
- stateTransitionHelper(t, s, expectedState, bytes) |
|
| 31 |
- } |
|
| 32 |
-} |
|
| 33 |
- |
|
| 34 |
-func funcCallParamHelper(t *testing.T, bytes []byte, start string, expected string, expectedCalls []string) {
|
|
| 35 |
- parser, evtHandler := createTestParser(start) |
|
| 36 |
- parser.Parse(bytes) |
|
| 37 |
- validateState(t, parser.currState, expected) |
|
| 38 |
- validateFuncCalls(t, evtHandler.FunctionCalls, expectedCalls) |
|
| 39 |
-} |
|
| 40 |
- |
|
| 41 |
-func parseParamsHelper(t *testing.T, bytes []byte, expectedParams []string) {
|
|
| 42 |
- params, err := parseParams(bytes) |
|
| 43 |
- |
|
| 44 |
- if err != nil {
|
|
| 45 |
- t.Errorf("Parameter parse error: %v", err)
|
|
| 46 |
- return |
|
| 47 |
- } |
|
| 48 |
- |
|
| 49 |
- if len(params) != len(expectedParams) {
|
|
| 50 |
- t.Errorf("Parsed parameters: %v", params)
|
|
| 51 |
- t.Errorf("Expected parameters: %v", expectedParams)
|
|
| 52 |
- t.Errorf("Parameter length failure: %d != %d", len(params), len(expectedParams))
|
|
| 53 |
- return |
|
| 54 |
- } |
|
| 55 |
- |
|
| 56 |
- for i, v := range expectedParams {
|
|
| 57 |
- if v != params[i] {
|
|
| 58 |
- t.Errorf("Parsed parameters: %v", params)
|
|
| 59 |
- t.Errorf("Expected parameters: %v", expectedParams)
|
|
| 60 |
- t.Errorf("Parameter parse failure: %s != %s at position %d", v, params[i], i)
|
|
| 61 |
- } |
|
| 62 |
- } |
|
| 63 |
-} |
|
| 64 |
- |
|
| 65 |
-func cursorSingleParamHelper(t *testing.T, command byte, funcName string) {
|
|
| 66 |
- funcCallParamHelper(t, []byte{command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)})
|
|
| 67 |
- funcCallParamHelper(t, []byte{'0', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)})
|
|
| 68 |
- funcCallParamHelper(t, []byte{'2', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2])", funcName)})
|
|
| 69 |
- funcCallParamHelper(t, []byte{'2', '3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([23])", funcName)})
|
|
| 70 |
- funcCallParamHelper(t, []byte{'2', ';', '3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2])", funcName)})
|
|
| 71 |
- funcCallParamHelper(t, []byte{'2', ';', '3', ';', '4', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2])", funcName)})
|
|
| 72 |
-} |
|
| 73 |
- |
|
| 74 |
-func cursorTwoParamHelper(t *testing.T, command byte, funcName string) {
|
|
| 75 |
- funcCallParamHelper(t, []byte{command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1 1])", funcName)})
|
|
| 76 |
- funcCallParamHelper(t, []byte{'0', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1 1])", funcName)})
|
|
| 77 |
- funcCallParamHelper(t, []byte{'2', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2 1])", funcName)})
|
|
| 78 |
- funcCallParamHelper(t, []byte{'2', '3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([23 1])", funcName)})
|
|
| 79 |
- funcCallParamHelper(t, []byte{'2', ';', '3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2 3])", funcName)})
|
|
| 80 |
- funcCallParamHelper(t, []byte{'2', ';', '3', ';', '4', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2 3])", funcName)})
|
|
| 81 |
-} |
|
| 82 |
- |
|
| 83 |
-func eraseHelper(t *testing.T, command byte, funcName string) {
|
|
| 84 |
- funcCallParamHelper(t, []byte{command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([0])", funcName)})
|
|
| 85 |
- funcCallParamHelper(t, []byte{'0', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([0])", funcName)})
|
|
| 86 |
- funcCallParamHelper(t, []byte{'1', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)})
|
|
| 87 |
- funcCallParamHelper(t, []byte{'2', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([2])", funcName)})
|
|
| 88 |
- funcCallParamHelper(t, []byte{'3', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([3])", funcName)})
|
|
| 89 |
- funcCallParamHelper(t, []byte{'4', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([0])", funcName)})
|
|
| 90 |
- funcCallParamHelper(t, []byte{'1', ';', '2', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)})
|
|
| 91 |
-} |
|
| 92 |
- |
|
| 93 |
-func scrollHelper(t *testing.T, command byte, funcName string) {
|
|
| 94 |
- funcCallParamHelper(t, []byte{command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)})
|
|
| 95 |
- funcCallParamHelper(t, []byte{'0', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)})
|
|
| 96 |
- funcCallParamHelper(t, []byte{'1', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([1])", funcName)})
|
|
| 97 |
- funcCallParamHelper(t, []byte{'5', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([5])", funcName)})
|
|
| 98 |
- funcCallParamHelper(t, []byte{'4', ';', '6', command}, "CsiEntry", "Ground", []string{fmt.Sprintf("%s([4])", funcName)})
|
|
| 99 |
-} |
|
| 100 |
- |
|
| 101 |
-func clearOnStateChangeHelper(t *testing.T, start string, end string, bytes []byte) {
|
|
| 102 |
- p, _ := createTestParser(start) |
|
| 103 |
- fillContext(p.context) |
|
| 104 |
- p.Parse(bytes) |
|
| 105 |
- validateState(t, p.currState, end) |
|
| 106 |
- validateEmptyContext(t, p.context) |
|
| 107 |
-} |
|
| 108 |
- |
|
| 109 |
-func c0Helper(t *testing.T, bytes []byte, expectedState string, expectedCalls []string) {
|
|
| 110 |
- parser, evtHandler := createTestParser("Ground")
|
|
| 111 |
- parser.Parse(bytes) |
|
| 112 |
- validateState(t, parser.currState, expectedState) |
|
| 113 |
- validateFuncCalls(t, evtHandler.FunctionCalls, expectedCalls) |
|
| 114 |
-} |
| 115 | 1 |
deleted file mode 100644 |
| ... | ... |
@@ -1,66 +0,0 @@ |
| 1 |
-package ansiterm |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "testing" |
|
| 5 |
-) |
|
| 6 |
- |
|
| 7 |
-func createTestParser(s string) (*AnsiParser, *TestAnsiEventHandler) {
|
|
| 8 |
- evtHandler := CreateTestAnsiEventHandler() |
|
| 9 |
- parser := CreateParser(s, evtHandler) |
|
| 10 |
- |
|
| 11 |
- return parser, evtHandler |
|
| 12 |
-} |
|
| 13 |
- |
|
| 14 |
-func validateState(t *testing.T, actualState State, expectedStateName string) {
|
|
| 15 |
- actualName := "Nil" |
|
| 16 |
- |
|
| 17 |
- if actualState != nil {
|
|
| 18 |
- actualName = actualState.Name() |
|
| 19 |
- } |
|
| 20 |
- |
|
| 21 |
- if actualName != expectedStateName {
|
|
| 22 |
- t.Errorf("Invalid State: '%s' != '%s'", actualName, expectedStateName)
|
|
| 23 |
- } |
|
| 24 |
-} |
|
| 25 |
- |
|
| 26 |
-func validateFuncCalls(t *testing.T, actualCalls []string, expectedCalls []string) {
|
|
| 27 |
- actualCount := len(actualCalls) |
|
| 28 |
- expectedCount := len(expectedCalls) |
|
| 29 |
- |
|
| 30 |
- if actualCount != expectedCount {
|
|
| 31 |
- t.Errorf("Actual calls: %v", actualCalls)
|
|
| 32 |
- t.Errorf("Expected calls: %v", expectedCalls)
|
|
| 33 |
- t.Errorf("Call count error: %d != %d", actualCount, expectedCount)
|
|
| 34 |
- return |
|
| 35 |
- } |
|
| 36 |
- |
|
| 37 |
- for i, v := range actualCalls {
|
|
| 38 |
- if v != expectedCalls[i] {
|
|
| 39 |
- t.Errorf("Actual calls: %v", actualCalls)
|
|
| 40 |
- t.Errorf("Expected calls: %v", expectedCalls)
|
|
| 41 |
- t.Errorf("Mismatched calls: %s != %s with lengths %d and %d", v, expectedCalls[i], len(v), len(expectedCalls[i]))
|
|
| 42 |
- } |
|
| 43 |
- } |
|
| 44 |
-} |
|
| 45 |
- |
|
| 46 |
-func fillContext(context *AnsiContext) {
|
|
| 47 |
- context.currentChar = 'A' |
|
| 48 |
- context.paramBuffer = []byte{'C', 'D', 'E'}
|
|
| 49 |
- context.interBuffer = []byte{'F', 'G', 'H'}
|
|
| 50 |
-} |
|
| 51 |
- |
|
| 52 |
-func validateEmptyContext(t *testing.T, context *AnsiContext) {
|
|
| 53 |
- var expectedCurrChar byte = 0x0 |
|
| 54 |
- if context.currentChar != expectedCurrChar {
|
|
| 55 |
- t.Errorf("Currentchar mismatch '%#x' != '%#x'", context.currentChar, expectedCurrChar)
|
|
| 56 |
- } |
|
| 57 |
- |
|
| 58 |
- if len(context.paramBuffer) != 0 {
|
|
| 59 |
- t.Errorf("Non-empty parameter buffer: %v", context.paramBuffer)
|
|
| 60 |
- } |
|
| 61 |
- |
|
| 62 |
- if len(context.paramBuffer) != 0 {
|
|
| 63 |
- t.Errorf("Non-empty intermediate buffer: %v", context.interBuffer)
|
|
| 64 |
- } |
|
| 65 |
- |
|
| 66 |
-} |
| ... | ... |
@@ -1,52 +1,52 @@ |
| 1 | 1 |
package ansiterm |
| 2 | 2 |
|
| 3 |
-type StateId int |
|
| 3 |
+type stateID int |
|
| 4 | 4 |
|
| 5 |
-type State interface {
|
|
| 5 |
+type state interface {
|
|
| 6 | 6 |
Enter() error |
| 7 | 7 |
Exit() error |
| 8 |
- Handle(byte) (State, error) |
|
| 8 |
+ Handle(byte) (state, error) |
|
| 9 | 9 |
Name() string |
| 10 |
- Transition(State) error |
|
| 10 |
+ Transition(state) error |
|
| 11 | 11 |
} |
| 12 | 12 |
|
| 13 |
-type BaseState struct {
|
|
| 13 |
+type baseState struct {
|
|
| 14 | 14 |
name string |
| 15 | 15 |
parser *AnsiParser |
| 16 | 16 |
} |
| 17 | 17 |
|
| 18 |
-func (base BaseState) Enter() error {
|
|
| 18 |
+func (base baseState) Enter() error {
|
|
| 19 | 19 |
return nil |
| 20 | 20 |
} |
| 21 | 21 |
|
| 22 |
-func (base BaseState) Exit() error {
|
|
| 22 |
+func (base baseState) Exit() error {
|
|
| 23 | 23 |
return nil |
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 |
-func (base BaseState) Handle(b byte) (s State, e error) {
|
|
| 26 |
+func (base baseState) Handle(b byte) (s state, e error) {
|
|
| 27 | 27 |
|
| 28 | 28 |
switch {
|
| 29 | 29 |
case b == CSI_ENTRY: |
| 30 |
- return base.parser.CsiEntry, nil |
|
| 30 |
+ return base.parser.csiEntry, nil |
|
| 31 | 31 |
case b == DCS_ENTRY: |
| 32 |
- return base.parser.DcsEntry, nil |
|
| 32 |
+ return base.parser.dcsEntry, nil |
|
| 33 | 33 |
case b == ANSI_ESCAPE_PRIMARY: |
| 34 |
- return base.parser.Escape, nil |
|
| 34 |
+ return base.parser.escape, nil |
|
| 35 | 35 |
case b == OSC_STRING: |
| 36 |
- return base.parser.OscString, nil |
|
| 37 |
- case sliceContains(ToGroundBytes, b): |
|
| 38 |
- return base.parser.Ground, nil |
|
| 36 |
+ return base.parser.oscString, nil |
|
| 37 |
+ case sliceContains(toGroundBytes, b): |
|
| 38 |
+ return base.parser.ground, nil |
|
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 | 41 |
return nil, nil |
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 |
-func (base BaseState) Name() string {
|
|
| 44 |
+func (base baseState) Name() string {
|
|
| 45 | 45 |
return base.name |
| 46 | 46 |
} |
| 47 | 47 |
|
| 48 |
-func (base BaseState) Transition(s State) error {
|
|
| 49 |
- if s == base.parser.Ground {
|
|
| 48 |
+func (base baseState) Transition(s state) error {
|
|
| 49 |
+ if s == base.parser.ground {
|
|
| 50 | 50 |
execBytes := []byte{0x18}
|
| 51 | 51 |
execBytes = append(execBytes, 0x1A) |
| 52 | 52 |
execBytes = append(execBytes, getByteRange(0x80, 0x8F)...) |
| ... | ... |
@@ -62,10 +62,10 @@ func (base BaseState) Transition(s State) error {
|
| 62 | 62 |
return nil |
| 63 | 63 |
} |
| 64 | 64 |
|
| 65 |
-type DcsEntryState struct {
|
|
| 66 |
- BaseState |
|
| 65 |
+type dcsEntryState struct {
|
|
| 66 |
+ baseState |
|
| 67 | 67 |
} |
| 68 | 68 |
|
| 69 |
-type ErrorState struct {
|
|
| 70 |
- BaseState |
|
| 69 |
+type errorState struct {
|
|
| 70 |
+ baseState |
|
| 71 | 71 |
} |
| 72 | 72 |
deleted file mode 100644 |
| ... | ... |
@@ -1,173 +0,0 @@ |
| 1 |
-package ansiterm |
|
| 2 |
- |
|
| 3 |
-import ( |
|
| 4 |
- "fmt" |
|
| 5 |
- "strconv" |
|
| 6 |
-) |
|
| 7 |
- |
|
| 8 |
-type TestAnsiEventHandler struct {
|
|
| 9 |
- FunctionCalls []string |
|
| 10 |
-} |
|
| 11 |
- |
|
| 12 |
-func CreateTestAnsiEventHandler() *TestAnsiEventHandler {
|
|
| 13 |
- evtHandler := TestAnsiEventHandler{}
|
|
| 14 |
- evtHandler.FunctionCalls = make([]string, 0) |
|
| 15 |
- return &evtHandler |
|
| 16 |
-} |
|
| 17 |
- |
|
| 18 |
-func (h *TestAnsiEventHandler) recordCall(call string, params []string) {
|
|
| 19 |
- s := fmt.Sprintf("%s(%v)", call, params)
|
|
| 20 |
- h.FunctionCalls = append(h.FunctionCalls, s) |
|
| 21 |
-} |
|
| 22 |
- |
|
| 23 |
-func (h *TestAnsiEventHandler) Print(b byte) error {
|
|
| 24 |
- h.recordCall("Print", []string{string(b)})
|
|
| 25 |
- return nil |
|
| 26 |
-} |
|
| 27 |
- |
|
| 28 |
-func (h *TestAnsiEventHandler) Execute(b byte) error {
|
|
| 29 |
- h.recordCall("Execute", []string{string(b)})
|
|
| 30 |
- return nil |
|
| 31 |
-} |
|
| 32 |
- |
|
| 33 |
-func (h *TestAnsiEventHandler) CUU(param int) error {
|
|
| 34 |
- h.recordCall("CUU", []string{strconv.Itoa(param)})
|
|
| 35 |
- return nil |
|
| 36 |
-} |
|
| 37 |
- |
|
| 38 |
-func (h *TestAnsiEventHandler) CUD(param int) error {
|
|
| 39 |
- h.recordCall("CUD", []string{strconv.Itoa(param)})
|
|
| 40 |
- return nil |
|
| 41 |
-} |
|
| 42 |
- |
|
| 43 |
-func (h *TestAnsiEventHandler) CUF(param int) error {
|
|
| 44 |
- h.recordCall("CUF", []string{strconv.Itoa(param)})
|
|
| 45 |
- return nil |
|
| 46 |
-} |
|
| 47 |
- |
|
| 48 |
-func (h *TestAnsiEventHandler) CUB(param int) error {
|
|
| 49 |
- h.recordCall("CUB", []string{strconv.Itoa(param)})
|
|
| 50 |
- return nil |
|
| 51 |
-} |
|
| 52 |
- |
|
| 53 |
-func (h *TestAnsiEventHandler) CNL(param int) error {
|
|
| 54 |
- h.recordCall("CNL", []string{strconv.Itoa(param)})
|
|
| 55 |
- return nil |
|
| 56 |
-} |
|
| 57 |
- |
|
| 58 |
-func (h *TestAnsiEventHandler) CPL(param int) error {
|
|
| 59 |
- h.recordCall("CPL", []string{strconv.Itoa(param)})
|
|
| 60 |
- return nil |
|
| 61 |
-} |
|
| 62 |
- |
|
| 63 |
-func (h *TestAnsiEventHandler) CHA(param int) error {
|
|
| 64 |
- h.recordCall("CHA", []string{strconv.Itoa(param)})
|
|
| 65 |
- return nil |
|
| 66 |
-} |
|
| 67 |
- |
|
| 68 |
-func (h *TestAnsiEventHandler) VPA(param int) error {
|
|
| 69 |
- h.recordCall("VPA", []string{strconv.Itoa(param)})
|
|
| 70 |
- return nil |
|
| 71 |
-} |
|
| 72 |
- |
|
| 73 |
-func (h *TestAnsiEventHandler) CUP(x int, y int) error {
|
|
| 74 |
- xS, yS := strconv.Itoa(x), strconv.Itoa(y) |
|
| 75 |
- h.recordCall("CUP", []string{xS, yS})
|
|
| 76 |
- return nil |
|
| 77 |
-} |
|
| 78 |
- |
|
| 79 |
-func (h *TestAnsiEventHandler) HVP(x int, y int) error {
|
|
| 80 |
- xS, yS := strconv.Itoa(x), strconv.Itoa(y) |
|
| 81 |
- h.recordCall("HVP", []string{xS, yS})
|
|
| 82 |
- return nil |
|
| 83 |
-} |
|
| 84 |
- |
|
| 85 |
-func (h *TestAnsiEventHandler) DECTCEM(visible bool) error {
|
|
| 86 |
- h.recordCall("DECTCEM", []string{strconv.FormatBool(visible)})
|
|
| 87 |
- return nil |
|
| 88 |
-} |
|
| 89 |
- |
|
| 90 |
-func (h *TestAnsiEventHandler) DECOM(visible bool) error {
|
|
| 91 |
- h.recordCall("DECOM", []string{strconv.FormatBool(visible)})
|
|
| 92 |
- return nil |
|
| 93 |
-} |
|
| 94 |
- |
|
| 95 |
-func (h *TestAnsiEventHandler) DECCOLM(use132 bool) error {
|
|
| 96 |
- h.recordCall("DECOLM", []string{strconv.FormatBool(use132)})
|
|
| 97 |
- return nil |
|
| 98 |
-} |
|
| 99 |
- |
|
| 100 |
-func (h *TestAnsiEventHandler) ED(param int) error {
|
|
| 101 |
- h.recordCall("ED", []string{strconv.Itoa(param)})
|
|
| 102 |
- return nil |
|
| 103 |
-} |
|
| 104 |
- |
|
| 105 |
-func (h *TestAnsiEventHandler) EL(param int) error {
|
|
| 106 |
- h.recordCall("EL", []string{strconv.Itoa(param)})
|
|
| 107 |
- return nil |
|
| 108 |
-} |
|
| 109 |
- |
|
| 110 |
-func (h *TestAnsiEventHandler) IL(param int) error {
|
|
| 111 |
- h.recordCall("IL", []string{strconv.Itoa(param)})
|
|
| 112 |
- return nil |
|
| 113 |
-} |
|
| 114 |
- |
|
| 115 |
-func (h *TestAnsiEventHandler) DL(param int) error {
|
|
| 116 |
- h.recordCall("DL", []string{strconv.Itoa(param)})
|
|
| 117 |
- return nil |
|
| 118 |
-} |
|
| 119 |
- |
|
| 120 |
-func (h *TestAnsiEventHandler) ICH(param int) error {
|
|
| 121 |
- h.recordCall("ICH", []string{strconv.Itoa(param)})
|
|
| 122 |
- return nil |
|
| 123 |
-} |
|
| 124 |
- |
|
| 125 |
-func (h *TestAnsiEventHandler) DCH(param int) error {
|
|
| 126 |
- h.recordCall("DCH", []string{strconv.Itoa(param)})
|
|
| 127 |
- return nil |
|
| 128 |
-} |
|
| 129 |
- |
|
| 130 |
-func (h *TestAnsiEventHandler) SGR(params []int) error {
|
|
| 131 |
- strings := []string{}
|
|
| 132 |
- for _, v := range params {
|
|
| 133 |
- strings = append(strings, strconv.Itoa(v)) |
|
| 134 |
- } |
|
| 135 |
- |
|
| 136 |
- h.recordCall("SGR", strings)
|
|
| 137 |
- return nil |
|
| 138 |
-} |
|
| 139 |
- |
|
| 140 |
-func (h *TestAnsiEventHandler) SU(param int) error {
|
|
| 141 |
- h.recordCall("SU", []string{strconv.Itoa(param)})
|
|
| 142 |
- return nil |
|
| 143 |
-} |
|
| 144 |
- |
|
| 145 |
-func (h *TestAnsiEventHandler) SD(param int) error {
|
|
| 146 |
- h.recordCall("SD", []string{strconv.Itoa(param)})
|
|
| 147 |
- return nil |
|
| 148 |
-} |
|
| 149 |
- |
|
| 150 |
-func (h *TestAnsiEventHandler) DA(params []string) error {
|
|
| 151 |
- h.recordCall("DA", params)
|
|
| 152 |
- return nil |
|
| 153 |
-} |
|
| 154 |
- |
|
| 155 |
-func (h *TestAnsiEventHandler) DECSTBM(top int, bottom int) error {
|
|
| 156 |
- topS, bottomS := strconv.Itoa(top), strconv.Itoa(bottom) |
|
| 157 |
- h.recordCall("DECSTBM", []string{topS, bottomS})
|
|
| 158 |
- return nil |
|
| 159 |
-} |
|
| 160 |
- |
|
| 161 |
-func (h *TestAnsiEventHandler) RI() error {
|
|
| 162 |
- h.recordCall("RI", nil)
|
|
| 163 |
- return nil |
|
| 164 |
-} |
|
| 165 |
- |
|
| 166 |
-func (h *TestAnsiEventHandler) IND() error {
|
|
| 167 |
- h.recordCall("IND", nil)
|
|
| 168 |
- return nil |
|
| 169 |
-} |
|
| 170 |
- |
|
| 171 |
-func (h *TestAnsiEventHandler) Flush() error {
|
|
| 172 |
- return nil |
|
| 173 |
-} |
| ... | ... |
@@ -9,7 +9,7 @@ import ( |
| 9 | 9 |
"strings" |
| 10 | 10 |
"syscall" |
| 11 | 11 |
|
| 12 |
- . "github.com/Azure/go-ansiterm" |
|
| 12 |
+ "github.com/Azure/go-ansiterm" |
|
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
// Windows keyboard constants |
| ... | ... |
@@ -85,17 +85,17 @@ func newAnsiCommand(command []byte) *ansiCommand {
|
| 85 | 85 |
if lastCharIndex != 0 {
|
| 86 | 86 |
start := 1 |
| 87 | 87 |
// skip if double char escape sequence |
| 88 |
- if command[0] == ANSI_ESCAPE_PRIMARY && command[1] == ANSI_ESCAPE_SECONDARY {
|
|
| 88 |
+ if command[0] == ansiterm.ANSI_ESCAPE_PRIMARY && command[1] == ansiterm.ANSI_ESCAPE_SECONDARY {
|
|
| 89 | 89 |
start++ |
| 90 | 90 |
} |
| 91 | 91 |
// convert this to GetNextParam method |
| 92 |
- ac.Parameters = strings.Split(string(command[start:lastCharIndex]), ANSI_PARAMETER_SEP) |
|
| 92 |
+ ac.Parameters = strings.Split(string(command[start:lastCharIndex]), ansiterm.ANSI_PARAMETER_SEP) |
|
| 93 | 93 |
} |
| 94 | 94 |
|
| 95 | 95 |
return ac |
| 96 | 96 |
} |
| 97 | 97 |
|
| 98 |
-func (ac *ansiCommand) paramAsSHORT(index int, defaultValue SHORT) SHORT {
|
|
| 98 |
+func (ac *ansiCommand) paramAsSHORT(index int, defaultValue int16) int16 {
|
|
| 99 | 99 |
if index < 0 || index >= len(ac.Parameters) {
|
| 100 | 100 |
return defaultValue |
| 101 | 101 |
} |
| ... | ... |
@@ -105,7 +105,7 @@ func (ac *ansiCommand) paramAsSHORT(index int, defaultValue SHORT) SHORT {
|
| 105 | 105 |
return defaultValue |
| 106 | 106 |
} |
| 107 | 107 |
|
| 108 |
- return SHORT(param) |
|
| 108 |
+ return int16(param) |
|
| 109 | 109 |
} |
| 110 | 110 |
|
| 111 | 111 |
func (ac *ansiCommand) String() string {
|
| ... | ... |
@@ -119,12 +119,12 @@ func (ac *ansiCommand) String() string {
|
| 119 | 119 |
// See http://manpages.ubuntu.com/manpages/intrepid/man4/console_codes.4.html. |
| 120 | 120 |
func isAnsiCommandChar(b byte) bool {
|
| 121 | 121 |
switch {
|
| 122 |
- case ANSI_COMMAND_FIRST <= b && b <= ANSI_COMMAND_LAST && b != ANSI_ESCAPE_SECONDARY: |
|
| 122 |
+ case ansiterm.ANSI_COMMAND_FIRST <= b && b <= ansiterm.ANSI_COMMAND_LAST && b != ansiterm.ANSI_ESCAPE_SECONDARY: |
|
| 123 | 123 |
return true |
| 124 |
- case b == ANSI_CMD_G1 || b == ANSI_CMD_OSC || b == ANSI_CMD_DECPAM || b == ANSI_CMD_DECPNM: |
|
| 124 |
+ case b == ansiterm.ANSI_CMD_G1 || b == ansiterm.ANSI_CMD_OSC || b == ansiterm.ANSI_CMD_DECPAM || b == ansiterm.ANSI_CMD_DECPNM: |
|
| 125 | 125 |
// non-CSI escape sequence terminator |
| 126 | 126 |
return true |
| 127 |
- case b == ANSI_CMD_STR_TERM || b == ANSI_BEL: |
|
| 127 |
+ case b == ansiterm.ANSI_CMD_STR_TERM || b == ansiterm.ANSI_BEL: |
|
| 128 | 128 |
// String escape sequence terminator |
| 129 | 129 |
return true |
| 130 | 130 |
} |
| ... | ... |
@@ -132,11 +132,11 @@ func isAnsiCommandChar(b byte) bool {
|
| 132 | 132 |
} |
| 133 | 133 |
|
| 134 | 134 |
func isXtermOscSequence(command []byte, current byte) bool {
|
| 135 |
- return (len(command) >= 2 && command[0] == ANSI_ESCAPE_PRIMARY && command[1] == ANSI_CMD_OSC && current != ANSI_BEL) |
|
| 135 |
+ return (len(command) >= 2 && command[0] == ansiterm.ANSI_ESCAPE_PRIMARY && command[1] == ansiterm.ANSI_CMD_OSC && current != ansiterm.ANSI_BEL) |
|
| 136 | 136 |
} |
| 137 | 137 |
|
| 138 | 138 |
func isCharacterSelectionCmdChar(b byte) bool {
|
| 139 |
- return (b == ANSI_CMD_G0 || b == ANSI_CMD_G1 || b == ANSI_CMD_G2 || b == ANSI_CMD_G3) |
|
| 139 |
+ return (b == ansiterm.ANSI_CMD_G0 || b == ansiterm.ANSI_CMD_G1 || b == ansiterm.ANSI_CMD_G2 || b == ansiterm.ANSI_CMD_G3) |
|
| 140 | 140 |
} |
| 141 | 141 |
|
| 142 | 142 |
// bytesToHex converts a slice of bytes to a human-readable string. |
| ... | ... |
@@ -150,7 +150,7 @@ func bytesToHex(b []byte) string {
|
| 150 | 150 |
|
| 151 | 151 |
// ensureInRange adjusts the passed value, if necessary, to ensure it is within |
| 152 | 152 |
// the passed min / max range. |
| 153 |
-func ensureInRange(n SHORT, min SHORT, max SHORT) SHORT {
|
|
| 153 |
+func ensureInRange(n int16, min int16, max int16) int16 {
|
|
| 154 | 154 |
if n < min {
|
| 155 | 155 |
return min |
| 156 | 156 |
} else if n > max {
|
| ... | ... |
@@ -66,21 +66,21 @@ const ( |
| 66 | 66 |
// -- The attributes are combined to produce various colors (e.g., Blue + Green will create Cyan). |
| 67 | 67 |
// Clearing all foreground or background colors results in black; setting all creates white. |
| 68 | 68 |
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682088(v=vs.85).aspx#_win32_character_attributes. |
| 69 |
- FOREGROUND_BLUE WORD = 0x0001 |
|
| 70 |
- FOREGROUND_GREEN WORD = 0x0002 |
|
| 71 |
- FOREGROUND_RED WORD = 0x0004 |
|
| 72 |
- FOREGROUND_INTENSITY WORD = 0x0008 |
|
| 73 |
- FOREGROUND_MASK WORD = 0x000F |
|
| 74 |
- |
|
| 75 |
- BACKGROUND_BLUE WORD = 0x0010 |
|
| 76 |
- BACKGROUND_GREEN WORD = 0x0020 |
|
| 77 |
- BACKGROUND_RED WORD = 0x0040 |
|
| 78 |
- BACKGROUND_INTENSITY WORD = 0x0080 |
|
| 79 |
- BACKGROUND_MASK WORD = 0x00F0 |
|
| 80 |
- |
|
| 81 |
- COMMON_LVB_MASK WORD = 0xFF00 |
|
| 82 |
- COMMON_LVB_REVERSE_VIDEO WORD = 0x4000 |
|
| 83 |
- COMMON_LVB_UNDERSCORE WORD = 0x8000 |
|
| 69 |
+ FOREGROUND_BLUE uint16 = 0x0001 |
|
| 70 |
+ FOREGROUND_GREEN uint16 = 0x0002 |
|
| 71 |
+ FOREGROUND_RED uint16 = 0x0004 |
|
| 72 |
+ FOREGROUND_INTENSITY uint16 = 0x0008 |
|
| 73 |
+ FOREGROUND_MASK uint16 = 0x000F |
|
| 74 |
+ |
|
| 75 |
+ BACKGROUND_BLUE uint16 = 0x0010 |
|
| 76 |
+ BACKGROUND_GREEN uint16 = 0x0020 |
|
| 77 |
+ BACKGROUND_RED uint16 = 0x0040 |
|
| 78 |
+ BACKGROUND_INTENSITY uint16 = 0x0080 |
|
| 79 |
+ BACKGROUND_MASK uint16 = 0x00F0 |
|
| 80 |
+ |
|
| 81 |
+ COMMON_LVB_MASK uint16 = 0xFF00 |
|
| 82 |
+ COMMON_LVB_REVERSE_VIDEO uint16 = 0x4000 |
|
| 83 |
+ COMMON_LVB_UNDERSCORE uint16 = 0x8000 |
|
| 84 | 84 |
|
| 85 | 85 |
// Input event types |
| 86 | 86 |
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683499(v=vs.85).aspx. |
| ... | ... |
@@ -104,60 +104,53 @@ const ( |
| 104 | 104 |
) |
| 105 | 105 |
|
| 106 | 106 |
// Windows API Console types |
| 107 |
-// -- See https://msdn.microsoft.com/en-us/library/windows/desktop/aa383751(v=vs.85).aspx for core types (e.g., SHORT) |
|
| 108 | 107 |
// -- See https://msdn.microsoft.com/en-us/library/windows/desktop/ms682101(v=vs.85).aspx for Console specific types (e.g., COORD) |
| 109 | 108 |
// -- See https://msdn.microsoft.com/en-us/library/aa296569(v=vs.60).aspx for comments on alignment |
| 110 | 109 |
type ( |
| 111 |
- SHORT int16 |
|
| 112 |
- BOOL int32 |
|
| 113 |
- WORD uint16 |
|
| 114 |
- WCHAR uint16 |
|
| 115 |
- DWORD uint32 |
|
| 116 |
- |
|
| 117 | 110 |
CHAR_INFO struct {
|
| 118 |
- UnicodeChar WCHAR |
|
| 119 |
- Attributes WORD |
|
| 111 |
+ UnicodeChar uint16 |
|
| 112 |
+ Attributes uint16 |
|
| 120 | 113 |
} |
| 121 | 114 |
|
| 122 | 115 |
CONSOLE_CURSOR_INFO struct {
|
| 123 |
- Size DWORD |
|
| 124 |
- Visible BOOL |
|
| 116 |
+ Size uint32 |
|
| 117 |
+ Visible int32 |
|
| 125 | 118 |
} |
| 126 | 119 |
|
| 127 | 120 |
CONSOLE_SCREEN_BUFFER_INFO struct {
|
| 128 | 121 |
Size COORD |
| 129 | 122 |
CursorPosition COORD |
| 130 |
- Attributes WORD |
|
| 123 |
+ Attributes uint16 |
|
| 131 | 124 |
Window SMALL_RECT |
| 132 | 125 |
MaximumWindowSize COORD |
| 133 | 126 |
} |
| 134 | 127 |
|
| 135 | 128 |
COORD struct {
|
| 136 |
- X SHORT |
|
| 137 |
- Y SHORT |
|
| 129 |
+ X int16 |
|
| 130 |
+ Y int16 |
|
| 138 | 131 |
} |
| 139 | 132 |
|
| 140 | 133 |
SMALL_RECT struct {
|
| 141 |
- Left SHORT |
|
| 142 |
- Top SHORT |
|
| 143 |
- Right SHORT |
|
| 144 |
- Bottom SHORT |
|
| 134 |
+ Left int16 |
|
| 135 |
+ Top int16 |
|
| 136 |
+ Right int16 |
|
| 137 |
+ Bottom int16 |
|
| 145 | 138 |
} |
| 146 | 139 |
|
| 147 | 140 |
// INPUT_RECORD is a C/C++ union of which KEY_EVENT_RECORD is one case, it is also the largest |
| 148 | 141 |
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms683499(v=vs.85).aspx. |
| 149 | 142 |
INPUT_RECORD struct {
|
| 150 |
- EventType WORD |
|
| 143 |
+ EventType uint16 |
|
| 151 | 144 |
KeyEvent KEY_EVENT_RECORD |
| 152 | 145 |
} |
| 153 | 146 |
|
| 154 | 147 |
KEY_EVENT_RECORD struct {
|
| 155 |
- KeyDown BOOL |
|
| 156 |
- RepeatCount WORD |
|
| 157 |
- VirtualKeyCode WORD |
|
| 158 |
- VirtualScanCode WORD |
|
| 159 |
- UnicodeChar WCHAR |
|
| 160 |
- ControlKeyState DWORD |
|
| 148 |
+ KeyDown int32 |
|
| 149 |
+ RepeatCount uint16 |
|
| 150 |
+ VirtualKeyCode uint16 |
|
| 151 |
+ VirtualScanCode uint16 |
|
| 152 |
+ UnicodeChar uint16 |
|
| 153 |
+ ControlKeyState uint32 |
|
| 161 | 154 |
} |
| 162 | 155 |
|
| 163 | 156 |
WINDOW_BUFFER_SIZE struct {
|
| ... | ... |
@@ -165,12 +158,12 @@ type ( |
| 165 | 165 |
} |
| 166 | 166 |
) |
| 167 | 167 |
|
| 168 |
-// boolToBOOL converts a Go bool into a Windows BOOL. |
|
| 169 |
-func boolToBOOL(f bool) BOOL {
|
|
| 168 |
+// boolToBOOL converts a Go bool into a Windows int32. |
|
| 169 |
+func boolToBOOL(f bool) int32 {
|
|
| 170 | 170 |
if f {
|
| 171 |
- return BOOL(1) |
|
| 171 |
+ return int32(1) |
|
| 172 | 172 |
} else {
|
| 173 |
- return BOOL(0) |
|
| 173 |
+ return int32(0) |
|
| 174 | 174 |
} |
| 175 | 175 |
} |
| 176 | 176 |
|
| ... | ... |
@@ -242,7 +235,7 @@ func SetConsoleScreenBufferSize(handle uintptr, coord COORD) error {
|
| 242 | 242 |
// SetConsoleTextAttribute sets the attributes of characters written to the |
| 243 | 243 |
// console screen buffer by the WriteFile or WriteConsole function. |
| 244 | 244 |
// See http://msdn.microsoft.com/en-us/library/windows/desktop/ms686047(v=vs.85).aspx. |
| 245 |
-func SetConsoleTextAttribute(handle uintptr, attribute WORD) error {
|
|
| 245 |
+func SetConsoleTextAttribute(handle uintptr, attribute uint16) error {
|
|
| 246 | 246 |
r1, r2, err := setConsoleTextAttributeProc.Call(handle, uintptr(attribute), 0) |
| 247 | 247 |
use(attribute) |
| 248 | 248 |
return checkError(r1, r2, err) |
| ... | ... |
@@ -280,7 +273,7 @@ func ReadConsoleInput(handle uintptr, buffer []INPUT_RECORD, count *uint32) erro |
| 280 | 280 |
// It returns true if the handle was signaled; false otherwise. |
| 281 | 281 |
// See https://msdn.microsoft.com/en-us/library/windows/desktop/ms687032(v=vs.85).aspx. |
| 282 | 282 |
func WaitForSingleObject(handle uintptr, msWait uint32) (bool, error) {
|
| 283 |
- r1, _, err := waitForSingleObjectProc.Call(handle, uintptr(DWORD(msWait))) |
|
| 283 |
+ r1, _, err := waitForSingleObjectProc.Call(handle, uintptr(uint32(msWait))) |
|
| 284 | 284 |
switch r1 {
|
| 285 | 285 |
case WAIT_ABANDONED, WAIT_TIMEOUT: |
| 286 | 286 |
return false, nil |
| ... | ... |
@@ -320,8 +313,8 @@ func checkError(r1, r2 uintptr, err error) error {
|
| 320 | 320 |
|
| 321 | 321 |
// coordToPointer converts a COORD into a uintptr (by fooling the type system). |
| 322 | 322 |
func coordToPointer(c COORD) uintptr {
|
| 323 |
- // Note: This code assumes the two SHORTs are correctly laid out; the "cast" to DWORD is just to get a pointer to pass. |
|
| 324 |
- return uintptr(*((*DWORD)(unsafe.Pointer(&c)))) |
|
| 323 |
+ // Note: This code assumes the two SHORTs are correctly laid out; the "cast" to uint32 is just to get a pointer to pass. |
|
| 324 |
+ return uintptr(*((*uint32)(unsafe.Pointer(&c)))) |
|
| 325 | 325 |
} |
| 326 | 326 |
|
| 327 | 327 |
// use is a no-op, but the compiler cannot see that it is. |
| ... | ... |
@@ -2,9 +2,7 @@ |
| 2 | 2 |
|
| 3 | 3 |
package winterm |
| 4 | 4 |
|
| 5 |
-import ( |
|
| 6 |
- . "github.com/Azure/go-ansiterm" |
|
| 7 |
-) |
|
| 5 |
+import "github.com/Azure/go-ansiterm" |
|
| 8 | 6 |
|
| 9 | 7 |
const ( |
| 10 | 8 |
FOREGROUND_COLOR_MASK = FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |
| ... | ... |
@@ -13,83 +11,83 @@ const ( |
| 13 | 13 |
|
| 14 | 14 |
// collectAnsiIntoWindowsAttributes modifies the passed Windows text mode flags to reflect the |
| 15 | 15 |
// request represented by the passed ANSI mode. |
| 16 |
-func collectAnsiIntoWindowsAttributes(windowsMode WORD, inverted bool, baseMode WORD, ansiMode SHORT) (WORD, bool) {
|
|
| 16 |
+func collectAnsiIntoWindowsAttributes(windowsMode uint16, inverted bool, baseMode uint16, ansiMode int16) (uint16, bool) {
|
|
| 17 | 17 |
switch ansiMode {
|
| 18 | 18 |
|
| 19 | 19 |
// Mode styles |
| 20 |
- case ANSI_SGR_BOLD: |
|
| 20 |
+ case ansiterm.ANSI_SGR_BOLD: |
|
| 21 | 21 |
windowsMode = windowsMode | FOREGROUND_INTENSITY |
| 22 | 22 |
|
| 23 |
- case ANSI_SGR_DIM, ANSI_SGR_BOLD_DIM_OFF: |
|
| 23 |
+ case ansiterm.ANSI_SGR_DIM, ansiterm.ANSI_SGR_BOLD_DIM_OFF: |
|
| 24 | 24 |
windowsMode &^= FOREGROUND_INTENSITY |
| 25 | 25 |
|
| 26 |
- case ANSI_SGR_UNDERLINE: |
|
| 26 |
+ case ansiterm.ANSI_SGR_UNDERLINE: |
|
| 27 | 27 |
windowsMode = windowsMode | COMMON_LVB_UNDERSCORE |
| 28 | 28 |
|
| 29 |
- case ANSI_SGR_REVERSE: |
|
| 29 |
+ case ansiterm.ANSI_SGR_REVERSE: |
|
| 30 | 30 |
inverted = true |
| 31 | 31 |
|
| 32 |
- case ANSI_SGR_REVERSE_OFF: |
|
| 32 |
+ case ansiterm.ANSI_SGR_REVERSE_OFF: |
|
| 33 | 33 |
inverted = false |
| 34 | 34 |
|
| 35 |
- case ANSI_SGR_UNDERLINE_OFF: |
|
| 35 |
+ case ansiterm.ANSI_SGR_UNDERLINE_OFF: |
|
| 36 | 36 |
windowsMode &^= COMMON_LVB_UNDERSCORE |
| 37 | 37 |
|
| 38 | 38 |
// Foreground colors |
| 39 |
- case ANSI_SGR_FOREGROUND_DEFAULT: |
|
| 39 |
+ case ansiterm.ANSI_SGR_FOREGROUND_DEFAULT: |
|
| 40 | 40 |
windowsMode = (windowsMode &^ FOREGROUND_MASK) | (baseMode & FOREGROUND_MASK) |
| 41 | 41 |
|
| 42 |
- case ANSI_SGR_FOREGROUND_BLACK: |
|
| 42 |
+ case ansiterm.ANSI_SGR_FOREGROUND_BLACK: |
|
| 43 | 43 |
windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) |
| 44 | 44 |
|
| 45 |
- case ANSI_SGR_FOREGROUND_RED: |
|
| 45 |
+ case ansiterm.ANSI_SGR_FOREGROUND_RED: |
|
| 46 | 46 |
windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_RED |
| 47 | 47 |
|
| 48 |
- case ANSI_SGR_FOREGROUND_GREEN: |
|
| 48 |
+ case ansiterm.ANSI_SGR_FOREGROUND_GREEN: |
|
| 49 | 49 |
windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_GREEN |
| 50 | 50 |
|
| 51 |
- case ANSI_SGR_FOREGROUND_YELLOW: |
|
| 51 |
+ case ansiterm.ANSI_SGR_FOREGROUND_YELLOW: |
|
| 52 | 52 |
windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_RED | FOREGROUND_GREEN |
| 53 | 53 |
|
| 54 |
- case ANSI_SGR_FOREGROUND_BLUE: |
|
| 54 |
+ case ansiterm.ANSI_SGR_FOREGROUND_BLUE: |
|
| 55 | 55 |
windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_BLUE |
| 56 | 56 |
|
| 57 |
- case ANSI_SGR_FOREGROUND_MAGENTA: |
|
| 57 |
+ case ansiterm.ANSI_SGR_FOREGROUND_MAGENTA: |
|
| 58 | 58 |
windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_RED | FOREGROUND_BLUE |
| 59 | 59 |
|
| 60 |
- case ANSI_SGR_FOREGROUND_CYAN: |
|
| 60 |
+ case ansiterm.ANSI_SGR_FOREGROUND_CYAN: |
|
| 61 | 61 |
windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_GREEN | FOREGROUND_BLUE |
| 62 | 62 |
|
| 63 |
- case ANSI_SGR_FOREGROUND_WHITE: |
|
| 63 |
+ case ansiterm.ANSI_SGR_FOREGROUND_WHITE: |
|
| 64 | 64 |
windowsMode = (windowsMode &^ FOREGROUND_COLOR_MASK) | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_BLUE |
| 65 | 65 |
|
| 66 | 66 |
// Background colors |
| 67 |
- case ANSI_SGR_BACKGROUND_DEFAULT: |
|
| 67 |
+ case ansiterm.ANSI_SGR_BACKGROUND_DEFAULT: |
|
| 68 | 68 |
// Black with no intensity |
| 69 | 69 |
windowsMode = (windowsMode &^ BACKGROUND_MASK) | (baseMode & BACKGROUND_MASK) |
| 70 | 70 |
|
| 71 |
- case ANSI_SGR_BACKGROUND_BLACK: |
|
| 71 |
+ case ansiterm.ANSI_SGR_BACKGROUND_BLACK: |
|
| 72 | 72 |
windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) |
| 73 | 73 |
|
| 74 |
- case ANSI_SGR_BACKGROUND_RED: |
|
| 74 |
+ case ansiterm.ANSI_SGR_BACKGROUND_RED: |
|
| 75 | 75 |
windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_RED |
| 76 | 76 |
|
| 77 |
- case ANSI_SGR_BACKGROUND_GREEN: |
|
| 77 |
+ case ansiterm.ANSI_SGR_BACKGROUND_GREEN: |
|
| 78 | 78 |
windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_GREEN |
| 79 | 79 |
|
| 80 |
- case ANSI_SGR_BACKGROUND_YELLOW: |
|
| 80 |
+ case ansiterm.ANSI_SGR_BACKGROUND_YELLOW: |
|
| 81 | 81 |
windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_RED | BACKGROUND_GREEN |
| 82 | 82 |
|
| 83 |
- case ANSI_SGR_BACKGROUND_BLUE: |
|
| 83 |
+ case ansiterm.ANSI_SGR_BACKGROUND_BLUE: |
|
| 84 | 84 |
windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_BLUE |
| 85 | 85 |
|
| 86 |
- case ANSI_SGR_BACKGROUND_MAGENTA: |
|
| 86 |
+ case ansiterm.ANSI_SGR_BACKGROUND_MAGENTA: |
|
| 87 | 87 |
windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_RED | BACKGROUND_BLUE |
| 88 | 88 |
|
| 89 |
- case ANSI_SGR_BACKGROUND_CYAN: |
|
| 89 |
+ case ansiterm.ANSI_SGR_BACKGROUND_CYAN: |
|
| 90 | 90 |
windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_GREEN | BACKGROUND_BLUE |
| 91 | 91 |
|
| 92 |
- case ANSI_SGR_BACKGROUND_WHITE: |
|
| 92 |
+ case ansiterm.ANSI_SGR_BACKGROUND_WHITE: |
|
| 93 | 93 |
windowsMode = (windowsMode &^ BACKGROUND_COLOR_MASK) | BACKGROUND_RED | BACKGROUND_GREEN | BACKGROUND_BLUE |
| 94 | 94 |
} |
| 95 | 95 |
|
| ... | ... |
@@ -97,6 +95,6 @@ func collectAnsiIntoWindowsAttributes(windowsMode WORD, inverted bool, baseMode |
| 97 | 97 |
} |
| 98 | 98 |
|
| 99 | 99 |
// invertAttributes inverts the foreground and background colors of a Windows attributes value |
| 100 |
-func invertAttributes(windowsMode WORD) WORD {
|
|
| 100 |
+func invertAttributes(windowsMode uint16) uint16 {
|
|
| 101 | 101 |
return (COMMON_LVB_MASK & windowsMode) | ((FOREGROUND_MASK & windowsMode) << 4) | ((BACKGROUND_MASK & windowsMode) >> 4) |
| 102 | 102 |
} |
| ... | ... |
@@ -3,11 +3,11 @@ |
| 3 | 3 |
package winterm |
| 4 | 4 |
|
| 5 | 5 |
const ( |
| 6 |
- Horizontal = iota |
|
| 7 |
- Vertical |
|
| 6 |
+ horizontal = iota |
|
| 7 |
+ vertical |
|
| 8 | 8 |
) |
| 9 | 9 |
|
| 10 |
-func (h *WindowsAnsiEventHandler) getCursorWindow(info *CONSOLE_SCREEN_BUFFER_INFO) SMALL_RECT {
|
|
| 10 |
+func (h *windowsAnsiEventHandler) getCursorWindow(info *CONSOLE_SCREEN_BUFFER_INFO) SMALL_RECT {
|
|
| 11 | 11 |
if h.originMode {
|
| 12 | 12 |
sr := h.effectiveSr(info.Window) |
| 13 | 13 |
return SMALL_RECT{
|
| ... | ... |
@@ -27,7 +27,7 @@ func (h *WindowsAnsiEventHandler) getCursorWindow(info *CONSOLE_SCREEN_BUFFER_IN |
| 27 | 27 |
} |
| 28 | 28 |
|
| 29 | 29 |
// setCursorPosition sets the cursor to the specified position, bounded to the screen size |
| 30 |
-func (h *WindowsAnsiEventHandler) setCursorPosition(position COORD, window SMALL_RECT) error {
|
|
| 30 |
+func (h *windowsAnsiEventHandler) setCursorPosition(position COORD, window SMALL_RECT) error {
|
|
| 31 | 31 |
position.X = ensureInRange(position.X, window.Left, window.Right) |
| 32 | 32 |
position.Y = ensureInRange(position.Y, window.Top, window.Bottom) |
| 33 | 33 |
err := SetConsoleCursorPosition(h.fd, position) |
| ... | ... |
@@ -38,15 +38,15 @@ func (h *WindowsAnsiEventHandler) setCursorPosition(position COORD, window SMALL |
| 38 | 38 |
return err |
| 39 | 39 |
} |
| 40 | 40 |
|
| 41 |
-func (h *WindowsAnsiEventHandler) moveCursorVertical(param int) error {
|
|
| 42 |
- return h.moveCursor(Vertical, param) |
|
| 41 |
+func (h *windowsAnsiEventHandler) moveCursorVertical(param int) error {
|
|
| 42 |
+ return h.moveCursor(vertical, param) |
|
| 43 | 43 |
} |
| 44 | 44 |
|
| 45 |
-func (h *WindowsAnsiEventHandler) moveCursorHorizontal(param int) error {
|
|
| 46 |
- return h.moveCursor(Horizontal, param) |
|
| 45 |
+func (h *windowsAnsiEventHandler) moveCursorHorizontal(param int) error {
|
|
| 46 |
+ return h.moveCursor(horizontal, param) |
|
| 47 | 47 |
} |
| 48 | 48 |
|
| 49 |
-func (h *WindowsAnsiEventHandler) moveCursor(moveMode int, param int) error {
|
|
| 49 |
+func (h *windowsAnsiEventHandler) moveCursor(moveMode int, param int) error {
|
|
| 50 | 50 |
info, err := GetConsoleScreenBufferInfo(h.fd) |
| 51 | 51 |
if err != nil {
|
| 52 | 52 |
return err |
| ... | ... |
@@ -54,10 +54,10 @@ func (h *WindowsAnsiEventHandler) moveCursor(moveMode int, param int) error {
|
| 54 | 54 |
|
| 55 | 55 |
position := info.CursorPosition |
| 56 | 56 |
switch moveMode {
|
| 57 |
- case Horizontal: |
|
| 58 |
- position.X += SHORT(param) |
|
| 59 |
- case Vertical: |
|
| 60 |
- position.Y += SHORT(param) |
|
| 57 |
+ case horizontal: |
|
| 58 |
+ position.X += int16(param) |
|
| 59 |
+ case vertical: |
|
| 60 |
+ position.Y += int16(param) |
|
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 | 63 |
if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil {
|
| ... | ... |
@@ -67,7 +67,7 @@ func (h *WindowsAnsiEventHandler) moveCursor(moveMode int, param int) error {
|
| 67 | 67 |
return nil |
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 |
-func (h *WindowsAnsiEventHandler) moveCursorLine(param int) error {
|
|
| 70 |
+func (h *windowsAnsiEventHandler) moveCursorLine(param int) error {
|
|
| 71 | 71 |
info, err := GetConsoleScreenBufferInfo(h.fd) |
| 72 | 72 |
if err != nil {
|
| 73 | 73 |
return err |
| ... | ... |
@@ -75,7 +75,7 @@ func (h *WindowsAnsiEventHandler) moveCursorLine(param int) error {
|
| 75 | 75 |
|
| 76 | 76 |
position := info.CursorPosition |
| 77 | 77 |
position.X = 0 |
| 78 |
- position.Y += SHORT(param) |
|
| 78 |
+ position.Y += int16(param) |
|
| 79 | 79 |
|
| 80 | 80 |
if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil {
|
| 81 | 81 |
return err |
| ... | ... |
@@ -84,14 +84,14 @@ func (h *WindowsAnsiEventHandler) moveCursorLine(param int) error {
|
| 84 | 84 |
return nil |
| 85 | 85 |
} |
| 86 | 86 |
|
| 87 |
-func (h *WindowsAnsiEventHandler) moveCursorColumn(param int) error {
|
|
| 87 |
+func (h *windowsAnsiEventHandler) moveCursorColumn(param int) error {
|
|
| 88 | 88 |
info, err := GetConsoleScreenBufferInfo(h.fd) |
| 89 | 89 |
if err != nil {
|
| 90 | 90 |
return err |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
position := info.CursorPosition |
| 94 |
- position.X = SHORT(param) - 1 |
|
| 94 |
+ position.X = int16(param) - 1 |
|
| 95 | 95 |
|
| 96 | 96 |
if err = h.setCursorPosition(position, h.getCursorWindow(info)); err != nil {
|
| 97 | 97 |
return err |
| ... | ... |
@@ -2,11 +2,9 @@ |
| 2 | 2 |
|
| 3 | 3 |
package winterm |
| 4 | 4 |
|
| 5 |
-import ( |
|
| 6 |
- . "github.com/Azure/go-ansiterm" |
|
| 7 |
-) |
|
| 5 |
+import "github.com/Azure/go-ansiterm" |
|
| 8 | 6 |
|
| 9 |
-func (h *WindowsAnsiEventHandler) clearRange(attributes WORD, fromCoord COORD, toCoord COORD) error {
|
|
| 7 |
+func (h *windowsAnsiEventHandler) clearRange(attributes uint16, fromCoord COORD, toCoord COORD) error {
|
|
| 10 | 8 |
// Ignore an invalid (negative area) request |
| 11 | 9 |
if toCoord.Y < fromCoord.Y {
|
| 12 | 10 |
return nil |
| ... | ... |
@@ -60,7 +58,7 @@ func (h *WindowsAnsiEventHandler) clearRange(attributes WORD, fromCoord COORD, t |
| 60 | 60 |
return nil |
| 61 | 61 |
} |
| 62 | 62 |
|
| 63 |
-func (h *WindowsAnsiEventHandler) clearRect(attributes WORD, fromCoord COORD, toCoord COORD) error {
|
|
| 63 |
+func (h *windowsAnsiEventHandler) clearRect(attributes uint16, fromCoord COORD, toCoord COORD) error {
|
|
| 64 | 64 |
region := SMALL_RECT{Top: fromCoord.Y, Left: fromCoord.X, Bottom: toCoord.Y, Right: toCoord.X}
|
| 65 | 65 |
width := toCoord.X - fromCoord.X + 1 |
| 66 | 66 |
height := toCoord.Y - fromCoord.Y + 1 |
| ... | ... |
@@ -72,7 +70,7 @@ func (h *WindowsAnsiEventHandler) clearRect(attributes WORD, fromCoord COORD, to |
| 72 | 72 |
|
| 73 | 73 |
buffer := make([]CHAR_INFO, size) |
| 74 | 74 |
|
| 75 |
- char := CHAR_INFO{WCHAR(FILL_CHARACTER), attributes}
|
|
| 75 |
+ char := CHAR_INFO{ansiterm.FILL_CHARACTER, attributes}
|
|
| 76 | 76 |
for i := 0; i < int(size); i++ {
|
| 77 | 77 |
buffer[i] = char |
| 78 | 78 |
} |
| ... | ... |
@@ -3,9 +3,9 @@ |
| 3 | 3 |
package winterm |
| 4 | 4 |
|
| 5 | 5 |
// effectiveSr gets the current effective scroll region in buffer coordinates |
| 6 |
-func (h *WindowsAnsiEventHandler) effectiveSr(window SMALL_RECT) scrollRegion {
|
|
| 7 |
- top := AddInRange(window.Top, h.sr.top, window.Top, window.Bottom) |
|
| 8 |
- bottom := AddInRange(window.Top, h.sr.bottom, window.Top, window.Bottom) |
|
| 6 |
+func (h *windowsAnsiEventHandler) effectiveSr(window SMALL_RECT) scrollRegion {
|
|
| 7 |
+ top := addInRange(window.Top, h.sr.top, window.Top, window.Bottom) |
|
| 8 |
+ bottom := addInRange(window.Top, h.sr.bottom, window.Top, window.Bottom) |
|
| 9 | 9 |
if top >= bottom {
|
| 10 | 10 |
top = window.Top |
| 11 | 11 |
bottom = window.Bottom |
| ... | ... |
@@ -13,7 +13,7 @@ func (h *WindowsAnsiEventHandler) effectiveSr(window SMALL_RECT) scrollRegion {
|
| 13 | 13 |
return scrollRegion{top: top, bottom: bottom}
|
| 14 | 14 |
} |
| 15 | 15 |
|
| 16 |
-func (h *WindowsAnsiEventHandler) scrollUp(param int) error {
|
|
| 16 |
+func (h *windowsAnsiEventHandler) scrollUp(param int) error {
|
|
| 17 | 17 |
info, err := GetConsoleScreenBufferInfo(h.fd) |
| 18 | 18 |
if err != nil {
|
| 19 | 19 |
return err |
| ... | ... |
@@ -23,11 +23,11 @@ func (h *WindowsAnsiEventHandler) scrollUp(param int) error {
|
| 23 | 23 |
return h.scroll(param, sr, info) |
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 |
-func (h *WindowsAnsiEventHandler) scrollDown(param int) error {
|
|
| 26 |
+func (h *windowsAnsiEventHandler) scrollDown(param int) error {
|
|
| 27 | 27 |
return h.scrollUp(-param) |
| 28 | 28 |
} |
| 29 | 29 |
|
| 30 |
-func (h *WindowsAnsiEventHandler) deleteLines(param int) error {
|
|
| 30 |
+func (h *windowsAnsiEventHandler) deleteLines(param int) error {
|
|
| 31 | 31 |
info, err := GetConsoleScreenBufferInfo(h.fd) |
| 32 | 32 |
if err != nil {
|
| 33 | 33 |
return err |
| ... | ... |
@@ -44,12 +44,12 @@ func (h *WindowsAnsiEventHandler) deleteLines(param int) error {
|
| 44 | 44 |
} |
| 45 | 45 |
} |
| 46 | 46 |
|
| 47 |
-func (h *WindowsAnsiEventHandler) insertLines(param int) error {
|
|
| 47 |
+func (h *windowsAnsiEventHandler) insertLines(param int) error {
|
|
| 48 | 48 |
return h.deleteLines(-param) |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 | 51 |
// scroll scrolls the provided scroll region by param lines. The scroll region is in buffer coordinates. |
| 52 |
-func (h *WindowsAnsiEventHandler) scroll(param int, sr scrollRegion, info *CONSOLE_SCREEN_BUFFER_INFO) error {
|
|
| 52 |
+func (h *windowsAnsiEventHandler) scroll(param int, sr scrollRegion, info *CONSOLE_SCREEN_BUFFER_INFO) error {
|
|
| 53 | 53 |
logger.Infof("scroll: scrollTop: %d, scrollBottom: %d", sr.top, sr.bottom)
|
| 54 | 54 |
logger.Infof("scroll: windowTop: %d, windowBottom: %d", info.Window.Top, info.Window.Bottom)
|
| 55 | 55 |
|
| ... | ... |
@@ -64,7 +64,7 @@ func (h *WindowsAnsiEventHandler) scroll(param int, sr scrollRegion, info *CONSO |
| 64 | 64 |
// Origin to which area should be copied |
| 65 | 65 |
destOrigin := COORD{
|
| 66 | 66 |
X: 0, |
| 67 |
- Y: sr.top - SHORT(param), |
|
| 67 |
+ Y: sr.top - int16(param), |
|
| 68 | 68 |
} |
| 69 | 69 |
|
| 70 | 70 |
char := CHAR_INFO{
|
| ... | ... |
@@ -78,7 +78,7 @@ func (h *WindowsAnsiEventHandler) scroll(param int, sr scrollRegion, info *CONSO |
| 78 | 78 |
return nil |
| 79 | 79 |
} |
| 80 | 80 |
|
| 81 |
-func (h *WindowsAnsiEventHandler) deleteCharacters(param int) error {
|
|
| 81 |
+func (h *windowsAnsiEventHandler) deleteCharacters(param int) error {
|
|
| 82 | 82 |
info, err := GetConsoleScreenBufferInfo(h.fd) |
| 83 | 83 |
if err != nil {
|
| 84 | 84 |
return err |
| ... | ... |
@@ -86,12 +86,12 @@ func (h *WindowsAnsiEventHandler) deleteCharacters(param int) error {
|
| 86 | 86 |
return h.scrollLine(param, info.CursorPosition, info) |
| 87 | 87 |
} |
| 88 | 88 |
|
| 89 |
-func (h *WindowsAnsiEventHandler) insertCharacters(param int) error {
|
|
| 89 |
+func (h *windowsAnsiEventHandler) insertCharacters(param int) error {
|
|
| 90 | 90 |
return h.deleteCharacters(-param) |
| 91 | 91 |
} |
| 92 | 92 |
|
| 93 | 93 |
// scrollLine scrolls a line horizontally starting at the provided position by a number of columns. |
| 94 |
-func (h *WindowsAnsiEventHandler) scrollLine(columns int, position COORD, info *CONSOLE_SCREEN_BUFFER_INFO) error {
|
|
| 94 |
+func (h *windowsAnsiEventHandler) scrollLine(columns int, position COORD, info *CONSOLE_SCREEN_BUFFER_INFO) error {
|
|
| 95 | 95 |
// Copy from and clip to the scroll region (full buffer width) |
| 96 | 96 |
scrollRect := SMALL_RECT{
|
| 97 | 97 |
Top: position.Y, |
| ... | ... |
@@ -102,7 +102,7 @@ func (h *WindowsAnsiEventHandler) scrollLine(columns int, position COORD, info * |
| 102 | 102 |
|
| 103 | 103 |
// Origin to which area should be copied |
| 104 | 104 |
destOrigin := COORD{
|
| 105 |
- X: position.X - SHORT(columns), |
|
| 105 |
+ X: position.X - int16(columns), |
|
| 106 | 106 |
Y: position.Y, |
| 107 | 107 |
} |
| 108 | 108 |
|
| ... | ... |
@@ -4,6 +4,6 @@ package winterm |
| 4 | 4 |
|
| 5 | 5 |
// AddInRange increments a value by the passed quantity while ensuring the values |
| 6 | 6 |
// always remain within the supplied min / max range. |
| 7 |
-func AddInRange(n SHORT, increment SHORT, min SHORT, max SHORT) SHORT {
|
|
| 7 |
+func addInRange(n int16, increment int16, min int16, max int16) int16 {
|
|
| 8 | 8 |
return ensureInRange(n+increment, min, max) |
| 9 | 9 |
} |
| ... | ... |
@@ -8,19 +8,19 @@ import ( |
| 8 | 8 |
"os" |
| 9 | 9 |
"strconv" |
| 10 | 10 |
|
| 11 |
- . "github.com/Azure/go-ansiterm" |
|
| 11 |
+ "github.com/Azure/go-ansiterm" |
|
| 12 | 12 |
"github.com/Sirupsen/logrus" |
| 13 | 13 |
) |
| 14 | 14 |
|
| 15 | 15 |
var logger *logrus.Logger |
| 16 | 16 |
|
| 17 |
-type WindowsAnsiEventHandler struct {
|
|
| 17 |
+type windowsAnsiEventHandler struct {
|
|
| 18 | 18 |
fd uintptr |
| 19 | 19 |
file *os.File |
| 20 | 20 |
infoReset *CONSOLE_SCREEN_BUFFER_INFO |
| 21 | 21 |
sr scrollRegion |
| 22 | 22 |
buffer bytes.Buffer |
| 23 |
- attributes WORD |
|
| 23 |
+ attributes uint16 |
|
| 24 | 24 |
inverted bool |
| 25 | 25 |
wrapNext bool |
| 26 | 26 |
drewMarginByte bool |
| ... | ... |
@@ -30,10 +30,10 @@ type WindowsAnsiEventHandler struct {
|
| 30 | 30 |
curPos COORD |
| 31 | 31 |
} |
| 32 | 32 |
|
| 33 |
-func CreateWinEventHandler(fd uintptr, file *os.File) AnsiEventHandler {
|
|
| 33 |
+func CreateWinEventHandler(fd uintptr, file *os.File) ansiterm.AnsiEventHandler {
|
|
| 34 | 34 |
logFile := ioutil.Discard |
| 35 | 35 |
|
| 36 |
- if isDebugEnv := os.Getenv(LogEnv); isDebugEnv == "1" {
|
|
| 36 |
+ if isDebugEnv := os.Getenv(ansiterm.LogEnv); isDebugEnv == "1" {
|
|
| 37 | 37 |
logFile, _ = os.Create("winEventHandler.log")
|
| 38 | 38 |
} |
| 39 | 39 |
|
| ... | ... |
@@ -48,7 +48,7 @@ func CreateWinEventHandler(fd uintptr, file *os.File) AnsiEventHandler {
|
| 48 | 48 |
return nil |
| 49 | 49 |
} |
| 50 | 50 |
|
| 51 |
- return &WindowsAnsiEventHandler{
|
|
| 51 |
+ return &windowsAnsiEventHandler{
|
|
| 52 | 52 |
fd: fd, |
| 53 | 53 |
file: file, |
| 54 | 54 |
infoReset: infoReset, |
| ... | ... |
@@ -57,8 +57,8 @@ func CreateWinEventHandler(fd uintptr, file *os.File) AnsiEventHandler {
|
| 57 | 57 |
} |
| 58 | 58 |
|
| 59 | 59 |
type scrollRegion struct {
|
| 60 |
- top SHORT |
|
| 61 |
- bottom SHORT |
|
| 60 |
+ top int16 |
|
| 61 |
+ bottom int16 |
|
| 62 | 62 |
} |
| 63 | 63 |
|
| 64 | 64 |
// simulateLF simulates a LF or CR+LF by scrolling if necessary to handle the |
| ... | ... |
@@ -68,7 +68,7 @@ type scrollRegion struct {
|
| 68 | 68 |
// |
| 69 | 69 |
// In the false case, the caller should ensure that a carriage return |
| 70 | 70 |
// and line feed are inserted or that the text is otherwise wrapped. |
| 71 |
-func (h *WindowsAnsiEventHandler) simulateLF(includeCR bool) (bool, error) {
|
|
| 71 |
+func (h *windowsAnsiEventHandler) simulateLF(includeCR bool) (bool, error) {
|
|
| 72 | 72 |
if h.wrapNext {
|
| 73 | 73 |
if err := h.Flush(); err != nil {
|
| 74 | 74 |
return false, err |
| ... | ... |
@@ -89,24 +89,25 @@ func (h *WindowsAnsiEventHandler) simulateLF(includeCR bool) (bool, error) {
|
| 89 | 89 |
h.updatePos(pos) |
| 90 | 90 |
} |
| 91 | 91 |
return false, nil |
| 92 |
- } else {
|
|
| 93 |
- // A custom scroll region is active. Scroll the window manually to simulate |
|
| 94 |
- // the LF. |
|
| 95 |
- if err := h.Flush(); err != nil {
|
|
| 96 |
- return false, err |
|
| 97 |
- } |
|
| 98 |
- logger.Info("Simulating LF inside scroll region")
|
|
| 99 |
- if err := h.scrollUp(1); err != nil {
|
|
| 92 |
+ } |
|
| 93 |
+ |
|
| 94 |
+ // A custom scroll region is active. Scroll the window manually to simulate |
|
| 95 |
+ // the LF. |
|
| 96 |
+ if err := h.Flush(); err != nil {
|
|
| 97 |
+ return false, err |
|
| 98 |
+ } |
|
| 99 |
+ logger.Info("Simulating LF inside scroll region")
|
|
| 100 |
+ if err := h.scrollUp(1); err != nil {
|
|
| 101 |
+ return false, err |
|
| 102 |
+ } |
|
| 103 |
+ if includeCR {
|
|
| 104 |
+ pos.X = 0 |
|
| 105 |
+ if err := SetConsoleCursorPosition(h.fd, pos); err != nil {
|
|
| 100 | 106 |
return false, err |
| 101 | 107 |
} |
| 102 |
- if includeCR {
|
|
| 103 |
- pos.X = 0 |
|
| 104 |
- if err := SetConsoleCursorPosition(h.fd, pos); err != nil {
|
|
| 105 |
- return false, err |
|
| 106 |
- } |
|
| 107 |
- } |
|
| 108 |
- return true, nil |
|
| 109 | 108 |
} |
| 109 |
+ return true, nil |
|
| 110 |
+ |
|
| 110 | 111 |
} else if pos.Y < info.Window.Bottom {
|
| 111 | 112 |
// Let Windows handle the LF. |
| 112 | 113 |
pos.Y++ |
| ... | ... |
@@ -133,7 +134,7 @@ func (h *WindowsAnsiEventHandler) simulateLF(includeCR bool) (bool, error) {
|
| 133 | 133 |
} |
| 134 | 134 |
|
| 135 | 135 |
// executeLF executes a LF without a CR. |
| 136 |
-func (h *WindowsAnsiEventHandler) executeLF() error {
|
|
| 136 |
+func (h *windowsAnsiEventHandler) executeLF() error {
|
|
| 137 | 137 |
handled, err := h.simulateLF(false) |
| 138 | 138 |
if err != nil {
|
| 139 | 139 |
return err |
| ... | ... |
@@ -145,7 +146,7 @@ func (h *WindowsAnsiEventHandler) executeLF() error {
|
| 145 | 145 |
if err != nil {
|
| 146 | 146 |
return err |
| 147 | 147 |
} |
| 148 |
- h.buffer.WriteByte(ANSI_LINE_FEED) |
|
| 148 |
+ h.buffer.WriteByte(ansiterm.ANSI_LINE_FEED) |
|
| 149 | 149 |
if pos.X != 0 {
|
| 150 | 150 |
if err := h.Flush(); err != nil {
|
| 151 | 151 |
return err |
| ... | ... |
@@ -159,7 +160,7 @@ func (h *WindowsAnsiEventHandler) executeLF() error {
|
| 159 | 159 |
return nil |
| 160 | 160 |
} |
| 161 | 161 |
|
| 162 |
-func (h *WindowsAnsiEventHandler) Print(b byte) error {
|
|
| 162 |
+func (h *windowsAnsiEventHandler) Print(b byte) error {
|
|
| 163 | 163 |
if h.wrapNext {
|
| 164 | 164 |
h.buffer.WriteByte(h.marginByte) |
| 165 | 165 |
h.clearWrap() |
| ... | ... |
@@ -182,9 +183,9 @@ func (h *WindowsAnsiEventHandler) Print(b byte) error {
|
| 182 | 182 |
return nil |
| 183 | 183 |
} |
| 184 | 184 |
|
| 185 |
-func (h *WindowsAnsiEventHandler) Execute(b byte) error {
|
|
| 185 |
+func (h *windowsAnsiEventHandler) Execute(b byte) error {
|
|
| 186 | 186 |
switch b {
|
| 187 |
- case ANSI_TAB: |
|
| 187 |
+ case ansiterm.ANSI_TAB: |
|
| 188 | 188 |
logger.Info("Execute(TAB)")
|
| 189 | 189 |
// Move to the next tab stop, but preserve auto-wrap if already set. |
| 190 | 190 |
if !h.wrapNext {
|
| ... | ... |
@@ -205,11 +206,11 @@ func (h *WindowsAnsiEventHandler) Execute(b byte) error {
|
| 205 | 205 |
} |
| 206 | 206 |
return nil |
| 207 | 207 |
|
| 208 |
- case ANSI_BEL: |
|
| 209 |
- h.buffer.WriteByte(ANSI_BEL) |
|
| 208 |
+ case ansiterm.ANSI_BEL: |
|
| 209 |
+ h.buffer.WriteByte(ansiterm.ANSI_BEL) |
|
| 210 | 210 |
return nil |
| 211 | 211 |
|
| 212 |
- case ANSI_BACKSPACE: |
|
| 212 |
+ case ansiterm.ANSI_BACKSPACE: |
|
| 213 | 213 |
if h.wrapNext {
|
| 214 | 214 |
if err := h.Flush(); err != nil {
|
| 215 | 215 |
return err |
| ... | ... |
@@ -223,15 +224,15 @@ func (h *WindowsAnsiEventHandler) Execute(b byte) error {
|
| 223 | 223 |
if pos.X > 0 {
|
| 224 | 224 |
pos.X-- |
| 225 | 225 |
h.updatePos(pos) |
| 226 |
- h.buffer.WriteByte(ANSI_BACKSPACE) |
|
| 226 |
+ h.buffer.WriteByte(ansiterm.ANSI_BACKSPACE) |
|
| 227 | 227 |
} |
| 228 | 228 |
return nil |
| 229 | 229 |
|
| 230 |
- case ANSI_VERTICAL_TAB, ANSI_FORM_FEED: |
|
| 230 |
+ case ansiterm.ANSI_VERTICAL_TAB, ansiterm.ANSI_FORM_FEED: |
|
| 231 | 231 |
// Treat as true LF. |
| 232 | 232 |
return h.executeLF() |
| 233 | 233 |
|
| 234 |
- case ANSI_LINE_FEED: |
|
| 234 |
+ case ansiterm.ANSI_LINE_FEED: |
|
| 235 | 235 |
// Simulate a CR and LF for now since there is no way in go-ansiterm |
| 236 | 236 |
// to tell if the LF should include CR (and more things break when it's |
| 237 | 237 |
// missing than when it's incorrectly added). |
| ... | ... |
@@ -239,9 +240,9 @@ func (h *WindowsAnsiEventHandler) Execute(b byte) error {
|
| 239 | 239 |
if handled || err != nil {
|
| 240 | 240 |
return err |
| 241 | 241 |
} |
| 242 |
- return h.buffer.WriteByte(ANSI_LINE_FEED) |
|
| 242 |
+ return h.buffer.WriteByte(ansiterm.ANSI_LINE_FEED) |
|
| 243 | 243 |
|
| 244 |
- case ANSI_CARRIAGE_RETURN: |
|
| 244 |
+ case ansiterm.ANSI_CARRIAGE_RETURN: |
|
| 245 | 245 |
if h.wrapNext {
|
| 246 | 246 |
if err := h.Flush(); err != nil {
|
| 247 | 247 |
return err |
| ... | ... |
@@ -255,7 +256,7 @@ func (h *WindowsAnsiEventHandler) Execute(b byte) error {
|
| 255 | 255 |
if pos.X != 0 {
|
| 256 | 256 |
pos.X = 0 |
| 257 | 257 |
h.updatePos(pos) |
| 258 |
- h.buffer.WriteByte(ANSI_CARRIAGE_RETURN) |
|
| 258 |
+ h.buffer.WriteByte(ansiterm.ANSI_CARRIAGE_RETURN) |
|
| 259 | 259 |
} |
| 260 | 260 |
return nil |
| 261 | 261 |
|
| ... | ... |
@@ -264,7 +265,7 @@ func (h *WindowsAnsiEventHandler) Execute(b byte) error {
|
| 264 | 264 |
} |
| 265 | 265 |
} |
| 266 | 266 |
|
| 267 |
-func (h *WindowsAnsiEventHandler) CUU(param int) error {
|
|
| 267 |
+func (h *windowsAnsiEventHandler) CUU(param int) error {
|
|
| 268 | 268 |
if err := h.Flush(); err != nil {
|
| 269 | 269 |
return err |
| 270 | 270 |
} |
| ... | ... |
@@ -273,7 +274,7 @@ func (h *WindowsAnsiEventHandler) CUU(param int) error {
|
| 273 | 273 |
return h.moveCursorVertical(-param) |
| 274 | 274 |
} |
| 275 | 275 |
|
| 276 |
-func (h *WindowsAnsiEventHandler) CUD(param int) error {
|
|
| 276 |
+func (h *windowsAnsiEventHandler) CUD(param int) error {
|
|
| 277 | 277 |
if err := h.Flush(); err != nil {
|
| 278 | 278 |
return err |
| 279 | 279 |
} |
| ... | ... |
@@ -282,7 +283,7 @@ func (h *WindowsAnsiEventHandler) CUD(param int) error {
|
| 282 | 282 |
return h.moveCursorVertical(param) |
| 283 | 283 |
} |
| 284 | 284 |
|
| 285 |
-func (h *WindowsAnsiEventHandler) CUF(param int) error {
|
|
| 285 |
+func (h *windowsAnsiEventHandler) CUF(param int) error {
|
|
| 286 | 286 |
if err := h.Flush(); err != nil {
|
| 287 | 287 |
return err |
| 288 | 288 |
} |
| ... | ... |
@@ -291,7 +292,7 @@ func (h *WindowsAnsiEventHandler) CUF(param int) error {
|
| 291 | 291 |
return h.moveCursorHorizontal(param) |
| 292 | 292 |
} |
| 293 | 293 |
|
| 294 |
-func (h *WindowsAnsiEventHandler) CUB(param int) error {
|
|
| 294 |
+func (h *windowsAnsiEventHandler) CUB(param int) error {
|
|
| 295 | 295 |
if err := h.Flush(); err != nil {
|
| 296 | 296 |
return err |
| 297 | 297 |
} |
| ... | ... |
@@ -300,7 +301,7 @@ func (h *WindowsAnsiEventHandler) CUB(param int) error {
|
| 300 | 300 |
return h.moveCursorHorizontal(-param) |
| 301 | 301 |
} |
| 302 | 302 |
|
| 303 |
-func (h *WindowsAnsiEventHandler) CNL(param int) error {
|
|
| 303 |
+func (h *windowsAnsiEventHandler) CNL(param int) error {
|
|
| 304 | 304 |
if err := h.Flush(); err != nil {
|
| 305 | 305 |
return err |
| 306 | 306 |
} |
| ... | ... |
@@ -309,7 +310,7 @@ func (h *WindowsAnsiEventHandler) CNL(param int) error {
|
| 309 | 309 |
return h.moveCursorLine(param) |
| 310 | 310 |
} |
| 311 | 311 |
|
| 312 |
-func (h *WindowsAnsiEventHandler) CPL(param int) error {
|
|
| 312 |
+func (h *windowsAnsiEventHandler) CPL(param int) error {
|
|
| 313 | 313 |
if err := h.Flush(); err != nil {
|
| 314 | 314 |
return err |
| 315 | 315 |
} |
| ... | ... |
@@ -318,7 +319,7 @@ func (h *WindowsAnsiEventHandler) CPL(param int) error {
|
| 318 | 318 |
return h.moveCursorLine(-param) |
| 319 | 319 |
} |
| 320 | 320 |
|
| 321 |
-func (h *WindowsAnsiEventHandler) CHA(param int) error {
|
|
| 321 |
+func (h *windowsAnsiEventHandler) CHA(param int) error {
|
|
| 322 | 322 |
if err := h.Flush(); err != nil {
|
| 323 | 323 |
return err |
| 324 | 324 |
} |
| ... | ... |
@@ -327,7 +328,7 @@ func (h *WindowsAnsiEventHandler) CHA(param int) error {
|
| 327 | 327 |
return h.moveCursorColumn(param) |
| 328 | 328 |
} |
| 329 | 329 |
|
| 330 |
-func (h *WindowsAnsiEventHandler) VPA(param int) error {
|
|
| 330 |
+func (h *windowsAnsiEventHandler) VPA(param int) error {
|
|
| 331 | 331 |
if err := h.Flush(); err != nil {
|
| 332 | 332 |
return err |
| 333 | 333 |
} |
| ... | ... |
@@ -339,11 +340,11 @@ func (h *WindowsAnsiEventHandler) VPA(param int) error {
|
| 339 | 339 |
} |
| 340 | 340 |
window := h.getCursorWindow(info) |
| 341 | 341 |
position := info.CursorPosition |
| 342 |
- position.Y = window.Top + SHORT(param) - 1 |
|
| 342 |
+ position.Y = window.Top + int16(param) - 1 |
|
| 343 | 343 |
return h.setCursorPosition(position, window) |
| 344 | 344 |
} |
| 345 | 345 |
|
| 346 |
-func (h *WindowsAnsiEventHandler) CUP(row int, col int) error {
|
|
| 346 |
+func (h *windowsAnsiEventHandler) CUP(row int, col int) error {
|
|
| 347 | 347 |
if err := h.Flush(); err != nil {
|
| 348 | 348 |
return err |
| 349 | 349 |
} |
| ... | ... |
@@ -355,11 +356,11 @@ func (h *WindowsAnsiEventHandler) CUP(row int, col int) error {
|
| 355 | 355 |
} |
| 356 | 356 |
|
| 357 | 357 |
window := h.getCursorWindow(info) |
| 358 |
- position := COORD{window.Left + SHORT(col) - 1, window.Top + SHORT(row) - 1}
|
|
| 358 |
+ position := COORD{window.Left + int16(col) - 1, window.Top + int16(row) - 1}
|
|
| 359 | 359 |
return h.setCursorPosition(position, window) |
| 360 | 360 |
} |
| 361 | 361 |
|
| 362 |
-func (h *WindowsAnsiEventHandler) HVP(row int, col int) error {
|
|
| 362 |
+func (h *windowsAnsiEventHandler) HVP(row int, col int) error {
|
|
| 363 | 363 |
if err := h.Flush(); err != nil {
|
| 364 | 364 |
return err |
| 365 | 365 |
} |
| ... | ... |
@@ -368,7 +369,7 @@ func (h *WindowsAnsiEventHandler) HVP(row int, col int) error {
|
| 368 | 368 |
return h.CUP(row, col) |
| 369 | 369 |
} |
| 370 | 370 |
|
| 371 |
-func (h *WindowsAnsiEventHandler) DECTCEM(visible bool) error {
|
|
| 371 |
+func (h *windowsAnsiEventHandler) DECTCEM(visible bool) error {
|
|
| 372 | 372 |
if err := h.Flush(); err != nil {
|
| 373 | 373 |
return err |
| 374 | 374 |
} |
| ... | ... |
@@ -377,7 +378,7 @@ func (h *WindowsAnsiEventHandler) DECTCEM(visible bool) error {
|
| 377 | 377 |
return nil |
| 378 | 378 |
} |
| 379 | 379 |
|
| 380 |
-func (h *WindowsAnsiEventHandler) DECOM(enable bool) error {
|
|
| 380 |
+func (h *windowsAnsiEventHandler) DECOM(enable bool) error {
|
|
| 381 | 381 |
if err := h.Flush(); err != nil {
|
| 382 | 382 |
return err |
| 383 | 383 |
} |
| ... | ... |
@@ -387,7 +388,7 @@ func (h *WindowsAnsiEventHandler) DECOM(enable bool) error {
|
| 387 | 387 |
return h.CUP(1, 1) |
| 388 | 388 |
} |
| 389 | 389 |
|
| 390 |
-func (h *WindowsAnsiEventHandler) DECCOLM(use132 bool) error {
|
|
| 390 |
+func (h *windowsAnsiEventHandler) DECCOLM(use132 bool) error {
|
|
| 391 | 391 |
if err := h.Flush(); err != nil {
|
| 392 | 392 |
return err |
| 393 | 393 |
} |
| ... | ... |
@@ -400,7 +401,7 @@ func (h *WindowsAnsiEventHandler) DECCOLM(use132 bool) error {
|
| 400 | 400 |
if err != nil {
|
| 401 | 401 |
return err |
| 402 | 402 |
} |
| 403 |
- targetWidth := SHORT(80) |
|
| 403 |
+ targetWidth := int16(80) |
|
| 404 | 404 |
if use132 {
|
| 405 | 405 |
targetWidth = 132 |
| 406 | 406 |
} |
| ... | ... |
@@ -426,7 +427,7 @@ func (h *WindowsAnsiEventHandler) DECCOLM(use132 bool) error {
|
| 426 | 426 |
return SetConsoleCursorPosition(h.fd, COORD{0, 0})
|
| 427 | 427 |
} |
| 428 | 428 |
|
| 429 |
-func (h *WindowsAnsiEventHandler) ED(param int) error {
|
|
| 429 |
+func (h *windowsAnsiEventHandler) ED(param int) error {
|
|
| 430 | 430 |
if err := h.Flush(); err != nil {
|
| 431 | 431 |
return err |
| 432 | 432 |
} |
| ... | ... |
@@ -485,7 +486,7 @@ func (h *WindowsAnsiEventHandler) ED(param int) error {
|
| 485 | 485 |
return nil |
| 486 | 486 |
} |
| 487 | 487 |
|
| 488 |
-func (h *WindowsAnsiEventHandler) EL(param int) error {
|
|
| 488 |
+func (h *windowsAnsiEventHandler) EL(param int) error {
|
|
| 489 | 489 |
if err := h.Flush(); err != nil {
|
| 490 | 490 |
return err |
| 491 | 491 |
} |
| ... | ... |
@@ -526,7 +527,7 @@ func (h *WindowsAnsiEventHandler) EL(param int) error {
|
| 526 | 526 |
return nil |
| 527 | 527 |
} |
| 528 | 528 |
|
| 529 |
-func (h *WindowsAnsiEventHandler) IL(param int) error {
|
|
| 529 |
+func (h *windowsAnsiEventHandler) IL(param int) error {
|
|
| 530 | 530 |
if err := h.Flush(); err != nil {
|
| 531 | 531 |
return err |
| 532 | 532 |
} |
| ... | ... |
@@ -535,7 +536,7 @@ func (h *WindowsAnsiEventHandler) IL(param int) error {
|
| 535 | 535 |
return h.insertLines(param) |
| 536 | 536 |
} |
| 537 | 537 |
|
| 538 |
-func (h *WindowsAnsiEventHandler) DL(param int) error {
|
|
| 538 |
+func (h *windowsAnsiEventHandler) DL(param int) error {
|
|
| 539 | 539 |
if err := h.Flush(); err != nil {
|
| 540 | 540 |
return err |
| 541 | 541 |
} |
| ... | ... |
@@ -544,7 +545,7 @@ func (h *WindowsAnsiEventHandler) DL(param int) error {
|
| 544 | 544 |
return h.deleteLines(param) |
| 545 | 545 |
} |
| 546 | 546 |
|
| 547 |
-func (h *WindowsAnsiEventHandler) ICH(param int) error {
|
|
| 547 |
+func (h *windowsAnsiEventHandler) ICH(param int) error {
|
|
| 548 | 548 |
if err := h.Flush(); err != nil {
|
| 549 | 549 |
return err |
| 550 | 550 |
} |
| ... | ... |
@@ -553,7 +554,7 @@ func (h *WindowsAnsiEventHandler) ICH(param int) error {
|
| 553 | 553 |
return h.insertCharacters(param) |
| 554 | 554 |
} |
| 555 | 555 |
|
| 556 |
-func (h *WindowsAnsiEventHandler) DCH(param int) error {
|
|
| 556 |
+func (h *windowsAnsiEventHandler) DCH(param int) error {
|
|
| 557 | 557 |
if err := h.Flush(); err != nil {
|
| 558 | 558 |
return err |
| 559 | 559 |
} |
| ... | ... |
@@ -562,7 +563,7 @@ func (h *WindowsAnsiEventHandler) DCH(param int) error {
|
| 562 | 562 |
return h.deleteCharacters(param) |
| 563 | 563 |
} |
| 564 | 564 |
|
| 565 |
-func (h *WindowsAnsiEventHandler) SGR(params []int) error {
|
|
| 565 |
+func (h *windowsAnsiEventHandler) SGR(params []int) error {
|
|
| 566 | 566 |
if err := h.Flush(); err != nil {
|
| 567 | 567 |
return err |
| 568 | 568 |
} |
| ... | ... |
@@ -579,13 +580,13 @@ func (h *WindowsAnsiEventHandler) SGR(params []int) error {
|
| 579 | 579 |
} else {
|
| 580 | 580 |
for _, attr := range params {
|
| 581 | 581 |
|
| 582 |
- if attr == ANSI_SGR_RESET {
|
|
| 582 |
+ if attr == ansiterm.ANSI_SGR_RESET {
|
|
| 583 | 583 |
h.attributes = h.infoReset.Attributes |
| 584 | 584 |
h.inverted = false |
| 585 | 585 |
continue |
| 586 | 586 |
} |
| 587 | 587 |
|
| 588 |
- h.attributes, h.inverted = collectAnsiIntoWindowsAttributes(h.attributes, h.inverted, h.infoReset.Attributes, SHORT(attr)) |
|
| 588 |
+ h.attributes, h.inverted = collectAnsiIntoWindowsAttributes(h.attributes, h.inverted, h.infoReset.Attributes, int16(attr)) |
|
| 589 | 589 |
} |
| 590 | 590 |
} |
| 591 | 591 |
|
| ... | ... |
@@ -601,7 +602,7 @@ func (h *WindowsAnsiEventHandler) SGR(params []int) error {
|
| 601 | 601 |
return nil |
| 602 | 602 |
} |
| 603 | 603 |
|
| 604 |
-func (h *WindowsAnsiEventHandler) SU(param int) error {
|
|
| 604 |
+func (h *windowsAnsiEventHandler) SU(param int) error {
|
|
| 605 | 605 |
if err := h.Flush(); err != nil {
|
| 606 | 606 |
return err |
| 607 | 607 |
} |
| ... | ... |
@@ -610,7 +611,7 @@ func (h *WindowsAnsiEventHandler) SU(param int) error {
|
| 610 | 610 |
return h.scrollUp(param) |
| 611 | 611 |
} |
| 612 | 612 |
|
| 613 |
-func (h *WindowsAnsiEventHandler) SD(param int) error {
|
|
| 613 |
+func (h *windowsAnsiEventHandler) SD(param int) error {
|
|
| 614 | 614 |
if err := h.Flush(); err != nil {
|
| 615 | 615 |
return err |
| 616 | 616 |
} |
| ... | ... |
@@ -619,29 +620,29 @@ func (h *WindowsAnsiEventHandler) SD(param int) error {
|
| 619 | 619 |
return h.scrollDown(param) |
| 620 | 620 |
} |
| 621 | 621 |
|
| 622 |
-func (h *WindowsAnsiEventHandler) DA(params []string) error {
|
|
| 622 |
+func (h *windowsAnsiEventHandler) DA(params []string) error {
|
|
| 623 | 623 |
logger.Infof("DA: [%v]", params)
|
| 624 | 624 |
// DA cannot be implemented because it must send data on the VT100 input stream, |
| 625 | 625 |
// which is not available to go-ansiterm. |
| 626 | 626 |
return nil |
| 627 | 627 |
} |
| 628 | 628 |
|
| 629 |
-func (h *WindowsAnsiEventHandler) DECSTBM(top int, bottom int) error {
|
|
| 629 |
+func (h *windowsAnsiEventHandler) DECSTBM(top int, bottom int) error {
|
|
| 630 | 630 |
if err := h.Flush(); err != nil {
|
| 631 | 631 |
return err |
| 632 | 632 |
} |
| 633 | 633 |
logger.Infof("DECSTBM: [%d, %d]", top, bottom)
|
| 634 | 634 |
|
| 635 | 635 |
// Windows is 0 indexed, Linux is 1 indexed |
| 636 |
- h.sr.top = SHORT(top - 1) |
|
| 637 |
- h.sr.bottom = SHORT(bottom - 1) |
|
| 636 |
+ h.sr.top = int16(top - 1) |
|
| 637 |
+ h.sr.bottom = int16(bottom - 1) |
|
| 638 | 638 |
|
| 639 | 639 |
// This command also moves the cursor to the origin. |
| 640 | 640 |
h.clearWrap() |
| 641 | 641 |
return h.CUP(1, 1) |
| 642 | 642 |
} |
| 643 | 643 |
|
| 644 |
-func (h *WindowsAnsiEventHandler) RI() error {
|
|
| 644 |
+func (h *windowsAnsiEventHandler) RI() error {
|
|
| 645 | 645 |
if err := h.Flush(); err != nil {
|
| 646 | 646 |
return err |
| 647 | 647 |
} |
| ... | ... |
@@ -656,17 +657,17 @@ func (h *WindowsAnsiEventHandler) RI() error {
|
| 656 | 656 |
sr := h.effectiveSr(info.Window) |
| 657 | 657 |
if info.CursorPosition.Y == sr.top {
|
| 658 | 658 |
return h.scrollDown(1) |
| 659 |
- } else {
|
|
| 660 |
- return h.moveCursorVertical(-1) |
|
| 661 | 659 |
} |
| 660 |
+ |
|
| 661 |
+ return h.moveCursorVertical(-1) |
|
| 662 | 662 |
} |
| 663 | 663 |
|
| 664 |
-func (h *WindowsAnsiEventHandler) IND() error {
|
|
| 664 |
+func (h *windowsAnsiEventHandler) IND() error {
|
|
| 665 | 665 |
logger.Info("IND: []")
|
| 666 | 666 |
return h.executeLF() |
| 667 | 667 |
} |
| 668 | 668 |
|
| 669 |
-func (h *WindowsAnsiEventHandler) Flush() error {
|
|
| 669 |
+func (h *windowsAnsiEventHandler) Flush() error {
|
|
| 670 | 670 |
h.curInfo = nil |
| 671 | 671 |
if h.buffer.Len() > 0 {
|
| 672 | 672 |
logger.Infof("Flush: [%s]", h.buffer.Bytes())
|
| ... | ... |
@@ -683,7 +684,7 @@ func (h *WindowsAnsiEventHandler) Flush() error {
|
| 683 | 683 |
return err |
| 684 | 684 |
} |
| 685 | 685 |
|
| 686 |
- charInfo := []CHAR_INFO{{UnicodeChar: WCHAR(h.marginByte), Attributes: info.Attributes}}
|
|
| 686 |
+ charInfo := []CHAR_INFO{{UnicodeChar: uint16(h.marginByte), Attributes: info.Attributes}}
|
|
| 687 | 687 |
size := COORD{1, 1}
|
| 688 | 688 |
position := COORD{0, 0}
|
| 689 | 689 |
region := SMALL_RECT{Left: info.CursorPosition.X, Top: info.CursorPosition.Y, Right: info.CursorPosition.X, Bottom: info.CursorPosition.Y}
|
| ... | ... |
@@ -697,7 +698,7 @@ func (h *WindowsAnsiEventHandler) Flush() error {
|
| 697 | 697 |
|
| 698 | 698 |
// cacheConsoleInfo ensures that the current console screen information has been queried |
| 699 | 699 |
// since the last call to Flush(). It must be called before accessing h.curInfo or h.curPos. |
| 700 |
-func (h *WindowsAnsiEventHandler) getCurrentInfo() (COORD, *CONSOLE_SCREEN_BUFFER_INFO, error) {
|
|
| 700 |
+func (h *windowsAnsiEventHandler) getCurrentInfo() (COORD, *CONSOLE_SCREEN_BUFFER_INFO, error) {
|
|
| 701 | 701 |
if h.curInfo == nil {
|
| 702 | 702 |
info, err := GetConsoleScreenBufferInfo(h.fd) |
| 703 | 703 |
if err != nil {
|
| ... | ... |
@@ -709,7 +710,7 @@ func (h *WindowsAnsiEventHandler) getCurrentInfo() (COORD, *CONSOLE_SCREEN_BUFFE |
| 709 | 709 |
return h.curPos, h.curInfo, nil |
| 710 | 710 |
} |
| 711 | 711 |
|
| 712 |
-func (h *WindowsAnsiEventHandler) updatePos(pos COORD) {
|
|
| 712 |
+func (h *windowsAnsiEventHandler) updatePos(pos COORD) {
|
|
| 713 | 713 |
if h.curInfo == nil {
|
| 714 | 714 |
panic("failed to call getCurrentInfo before calling updatePos")
|
| 715 | 715 |
} |
| ... | ... |
@@ -719,7 +720,7 @@ func (h *WindowsAnsiEventHandler) updatePos(pos COORD) {
|
| 719 | 719 |
// clearWrap clears the state where the cursor is in the margin |
| 720 | 720 |
// waiting for the next character before wrapping the line. This must |
| 721 | 721 |
// be done before most operations that act on the cursor. |
| 722 |
-func (h *WindowsAnsiEventHandler) clearWrap() {
|
|
| 722 |
+func (h *windowsAnsiEventHandler) clearWrap() {
|
|
| 723 | 723 |
h.wrapNext = false |
| 724 | 724 |
h.drewMarginByte = false |
| 725 | 725 |
} |