mirror of
https://github.com/docker/cli.git
synced 2026-11-06 13:10:41 -04:00
full diff: https://github.com/Azure/go-ansiterm/compare/faa5f7b0171c...e937bb47801ae0fd8fb8ff02743f6a93e2b51982 Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
96 lines
1.7 KiB
Go
96 lines
1.7 KiB
Go
package ansiterm
|
|
|
|
import (
|
|
"strconv"
|
|
)
|
|
|
|
func parseParams(bytes []byte) []string {
|
|
var paramBuff []byte
|
|
var 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 = paramBuff[: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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
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
|
|
}
|
|
|
|
func (ap *AnsiParser) hDispatch(params []string) error {
|
|
if len(params) == 1 {
|
|
return ap.modeDispatch(params[0], true)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func (ap *AnsiParser) lDispatch(params []string) error {
|
|
if len(params) == 1 {
|
|
return ap.modeDispatch(params[0], false)
|
|
}
|
|
|
|
return nil
|
|
}
|
|
|
|
func getEraseParam(params []string) int {
|
|
param := getInt(params, 0)
|
|
if param < 0 || 3 < param {
|
|
param = 0
|
|
}
|
|
|
|
return param
|
|
}
|