diff --git a/escape.go b/escape.go index c3ea31a..54b99ed 100644 --- a/escape.go +++ b/escape.go @@ -76,14 +76,16 @@ func (ei *escapeInterpreter) reset() { // of an escape sequence, and as such should not be printed verbatim. Otherwise, // it's not an escape sequence. func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) { - // Sanity checks to make sure we're not parsing something totally bogus. + // Sanity checks if len(ei.csiParam) > 20 { return false, errCSITooLong } if len(ei.csiParam) > 0 && len(ei.csiParam[len(ei.csiParam)-1]) > 255 { return false, errCSITooLong } + ei.curch = ch + switch ei.state { case stateNone: if ch == 0x1b { @@ -117,16 +119,11 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) { ei.csiParam = append(ei.csiParam, "") return true, nil case ch == 'm': - if len(ei.csiParam) < 1 { - return false, errCSIParseError - } - var err error - switch ei.mode { - case OutputMode(OutputNormal): + case OutputNormal: err = ei.outputNormal() - case OutputMode(Output256): + case Output256: err = ei.output256() } if err != nil {