(data []byte)
| 87 | } |
| 88 | |
| 89 | func (b *PtyBuffer) processData(data []byte) { |
| 90 | outputBuf := make([]byte, 0, len(data)) |
| 91 | for _, ch := range data { |
| 92 | if b.EscMode == Mode_WaveEsc { |
| 93 | if ch == ESC { |
| 94 | // terminates the escape sequence (and the rest was invalid) |
| 95 | b.EscMode = Mode_Normal |
| 96 | outputBuf = append(outputBuf, b.EscSeqBuf...) |
| 97 | outputBuf = append(outputBuf, ch) |
| 98 | b.EscSeqBuf = nil |
| 99 | } else if ch == BEL || ch == ST { |
| 100 | // terminates the escpae sequence (is a valid Wave OSC command) |
| 101 | b.EscMode = Mode_Normal |
| 102 | waveEscSeq := b.EscSeqBuf[WaveOSCPrefixLen:] |
| 103 | b.EscSeqBuf = nil |
| 104 | b.processWaveEscSeq(waveEscSeq) |
| 105 | } else { |
| 106 | b.EscSeqBuf = append(b.EscSeqBuf, ch) |
| 107 | } |
| 108 | continue |
| 109 | } |
| 110 | if b.EscMode == Mode_Esc { |
| 111 | if ch == ESC || ch == BEL || ch == ST { |
| 112 | // these all terminate the escape sequence (invalid, not a Wave OSC) |
| 113 | b.EscMode = Mode_Normal |
| 114 | outputBuf = append(outputBuf, b.EscSeqBuf...) |
| 115 | outputBuf = append(outputBuf, ch) |
| 116 | b.EscSeqBuf = nil |
| 117 | continue |
| 118 | } |
| 119 | if ch != b.OSCPrefix[len(b.EscSeqBuf)] { |
| 120 | // this is not a Wave OSC sequence, just an escape sequence |
| 121 | b.EscMode = Mode_Normal |
| 122 | outputBuf = append(outputBuf, b.EscSeqBuf...) |
| 123 | outputBuf = append(outputBuf, ch) |
| 124 | b.EscSeqBuf = nil |
| 125 | continue |
| 126 | } |
| 127 | // we're still building what could be a Wave OSC sequence |
| 128 | b.EscSeqBuf = append(b.EscSeqBuf, ch) |
| 129 | // check to see if we have a full Wave OSC prefix |
| 130 | if len(b.EscSeqBuf) == len(b.OSCPrefix) { |
| 131 | b.EscMode = Mode_WaveEsc |
| 132 | } |
| 133 | continue |
| 134 | } |
| 135 | // Mode_Normal |
| 136 | if ch == ESC { |
| 137 | b.EscMode = Mode_Esc |
| 138 | b.EscSeqBuf = []byte{ch} |
| 139 | continue |
| 140 | } |
| 141 | outputBuf = append(outputBuf, ch) |
| 142 | } |
| 143 | if len(outputBuf) > 0 { |
| 144 | b.writeData(outputBuf) |
| 145 | } |
| 146 | } |
no test coverage detected