2015-04-16 17:01:37 -04:00
|
|
|
package ansiterm
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strconv"
|
|
|
|
)
|
|
|
|
|
|
|
|
func parseParams(bytes []byte) ([]string, error) {
|
|
|
|
paramBuff := make([]byte, 0, 0)
|
|
|
|
params := []string{}
|
|
|
|
|
|
|
|
for _, v := range bytes {
|
|
|
|
if v == ';' {
|
|
|
|
if len(paramBuff) > 0 {
|
|
|
|
// Completed parameter, append it to the list
|
|
|
|
s := string(paramBuff)
|
|
|
|
params = append(params, s)
|
|
|
|
paramBuff = make([]byte, 0, 0)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
paramBuff = append(paramBuff, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Last parameter may not be terminated with ';'
|
|
|
|
if len(paramBuff) > 0 {
|
|
|
|
s := string(paramBuff)
|
|
|
|
params = append(params, s)
|
|
|
|
}
|
|
|
|
|
|
|
|
return params, nil
|
|
|
|
}
|
|
|
|
|
2016-04-25 18:55:12 -04:00
|
|
|
func parseCmd(context ansiContext) (string, error) {
|
2015-04-16 17:01:37 -04:00
|
|
|
return string(context.currentChar), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getInt(params []string, dflt int) int {
|
|
|
|
i := getInts(params, 1, dflt)[0]
|
|
|
|
return i
|
|
|
|
}
|
|
|
|
|
|
|
|
func getInts(params []string, minCount int, dflt int) []int {
|
|
|
|
ints := []int{}
|
|
|
|
|
|
|
|
for _, v := range params {
|
|
|
|
i, _ := strconv.Atoi(v)
|
|
|
|
// Zero is mapped to the default value in VT100.
|
|
|
|
if i == 0 {
|
|
|
|
i = dflt
|
|
|
|
}
|
|
|
|
ints = append(ints, i)
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(ints) < minCount {
|
|
|
|
remaining := minCount - len(ints)
|
|
|
|
for i := 0; i < remaining; i++ {
|
|
|
|
ints = append(ints, dflt)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ints
|
|
|
|
}
|
|
|
|
|
2015-08-06 23:38:56 -04:00
|
|
|
func (ap *AnsiParser) modeDispatch(param string, set bool) error {
|
|
|
|
switch param {
|
|
|
|
case "?3":
|
|
|
|
return ap.eventHandler.DECCOLM(set)
|
|
|
|
case "?6":
|
|
|
|
return ap.eventHandler.DECOM(set)
|
|
|
|
case "?25":
|
|
|
|
return ap.eventHandler.DECTCEM(set)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2015-04-16 17:01:37 -04:00
|
|
|
func (ap *AnsiParser) hDispatch(params []string) error {
|
2015-08-06 23:38:56 -04:00
|
|
|
if len(params) == 1 {
|
|
|
|
return ap.modeDispatch(params[0], true)
|
2015-04-16 17:01:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (ap *AnsiParser) lDispatch(params []string) error {
|
2015-08-06 23:38:56 -04:00
|
|
|
if len(params) == 1 {
|
|
|
|
return ap.modeDispatch(params[0], false)
|
2015-04-16 17:01:37 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func getEraseParam(params []string) int {
|
|
|
|
param := getInt(params, 0)
|
|
|
|
if param < 0 || 3 < param {
|
|
|
|
param = 0
|
|
|
|
}
|
|
|
|
|
|
|
|
return param
|
|
|
|
}
|