mirror of https://github.com/jroimartin/gocui.git
Support zero parameteter 'CSI n m' in parseOne
According to https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_codes, a zero-parameter 'CSI n m' code (for setting SGR parameters) should be treated as the same as 'CSI 0 m'. This PR changes escapeInterpreter.parseOne to support this shorthand.
This commit is contained in:
parent
88d2b471d4
commit
e27f247a3e
15
escape.go
15
escape.go
|
@ -28,7 +28,6 @@ const (
|
||||||
|
|
||||||
var (
|
var (
|
||||||
errNotCSI = errors.New("Not a CSI escape sequence")
|
errNotCSI = errors.New("Not a CSI escape sequence")
|
||||||
errCSINotANumber = errors.New("CSI escape sequence was expecting a number or a ;")
|
|
||||||
errCSIParseError = errors.New("CSI escape sequence parsing error")
|
errCSIParseError = errors.New("CSI escape sequence parsing error")
|
||||||
errCSITooLong = errors.New("CSI escape sequence is too long")
|
errCSITooLong = errors.New("CSI escape sequence is too long")
|
||||||
)
|
)
|
||||||
|
@ -99,12 +98,16 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) {
|
||||||
}
|
}
|
||||||
return false, errNotCSI
|
return false, errNotCSI
|
||||||
case stateCSI:
|
case stateCSI:
|
||||||
if ch >= '0' && ch <= '9' {
|
switch {
|
||||||
ei.state = stateParams
|
case ch >= '0' && ch <= '9':
|
||||||
ei.csiParam = append(ei.csiParam, string(ch))
|
ei.csiParam = append(ei.csiParam, "")
|
||||||
return true, nil
|
case ch == 'm':
|
||||||
|
ei.csiParam = append(ei.csiParam, "0")
|
||||||
|
default:
|
||||||
|
return false, errCSIParseError
|
||||||
}
|
}
|
||||||
return false, errCSINotANumber
|
ei.state = stateParams
|
||||||
|
fallthrough
|
||||||
case stateParams:
|
case stateParams:
|
||||||
switch {
|
switch {
|
||||||
case ch >= '0' && ch <= '9':
|
case ch >= '0' && ch <= '9':
|
||||||
|
|
Loading…
Reference in New Issue