Minor style changes

This commit is contained in:
Roi Martin 2016-11-13 20:45:04 +01:00
parent ff841413b6
commit 56a1633c76
2 changed files with 13 additions and 22 deletions

View File

@ -126,7 +126,6 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) {
case OutputMode(Output256): case OutputMode(Output256):
err = ei.output256() err = ei.output256()
} }
if err != nil { if err != nil {
return false, errCSIParseError return false, errCSIParseError
} }
@ -139,13 +138,11 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) {
return false, nil return false, nil
} }
// outputNormal provides 8 different colors: // outputNormal provides 8 different colors:
// black, red, green, yellow, blue, magenta, cyan, white // black, red, green, yellow, blue, magenta, cyan, white
func (ei *escapeInterpreter) outputNormal() error { func (ei *escapeInterpreter) outputNormal() error {
for _, param := range ei.csiParam { for _, param := range ei.csiParam {
p, err := strconv.Atoi(param) p, err := strconv.Atoi(param)
if err != nil { if err != nil {
return errCSIParseError return errCSIParseError
} }
@ -170,45 +167,40 @@ func (ei *escapeInterpreter) outputNormal() error {
return nil return nil
} }
// output256 allows you to leverage the 256 terminal mode // output256 allows you to leverage the 256-colors terminal mode:
// 0x01 - 0x08: the 8 colors as in OutputNormal // 0x01 - 0x08: the 8 colors as in OutputNormal
// 0x09 - 0x10: Color* | AttrBold // 0x09 - 0x10: Color* | AttrBold
// 0x11 - 0xe8: 216 different colors // 0x11 - 0xe8: 216 different colors
// 0xe9 - 0x1ff: 24 different shades of grey // 0xe9 - 0x1ff: 24 different shades of grey
func (ei *escapeInterpreter) output256() error { func (ei *escapeInterpreter) output256() error {
if len(ei.csiParam) < 3 { if len(ei.csiParam) < 3 {
return ei.outputNormal() return ei.outputNormal()
} }
fgbgParam, err := strconv.Atoi(ei.csiParam[0]) fgbgParam, err := strconv.Atoi(ei.csiParam[0])
if err != nil { if err != nil {
return errCSIParseError return errCSIParseError
} }
fgbgType, err := strconv.Atoi(ei.csiParam[1]) fgbgType, err := strconv.Atoi(ei.csiParam[1])
if err != nil { if err != nil {
return errCSIParseError return errCSIParseError
} }
if fgbgType != 5 { if fgbgType != 5 {
return ei.outputNormal() return ei.outputNormal()
} }
fgbgColor, err := strconv.Atoi(ei.csiParam[2]) fgbgColor, err := strconv.Atoi(ei.csiParam[2])
if err != nil { if err != nil {
return errCSIParseError return errCSIParseError
} }
if fgbgParam == 38 { switch fgbgParam {
case 38:
ei.curFgColor = Attribute(fgbgColor + 1) ei.curFgColor = Attribute(fgbgColor + 1)
for _, param := range ei.csiParam[3:] { for _, param := range ei.csiParam[3:] {
p, err := strconv.Atoi(param) p, err := strconv.Atoi(param)
if err != nil { if err != nil {
return errCSIParseError return errCSIParseError
} }
@ -222,10 +214,9 @@ func (ei *escapeInterpreter) output256() error {
ei.curFgColor |= AttrReverse ei.curFgColor |= AttrReverse
} }
} }
case 48:
} else if fgbgParam == 48 {
ei.curBgColor = Attribute(fgbgColor + 1) ei.curBgColor = Attribute(fgbgColor + 1)
} else { default:
return errCSIParseError return errCSIParseError
} }

4
gui.go
View File

@ -22,10 +22,10 @@ var (
type OutputMode termbox.OutputMode type OutputMode termbox.OutputMode
const ( const (
// OutputNormal provides 8-colors terminal mode // OutputNormal provides 8-colors terminal mode.
OutputNormal = OutputMode(termbox.OutputNormal) OutputNormal = OutputMode(termbox.OutputNormal)
// Output256 provides 256-colors terminal mode // Output256 provides 256-colors terminal mode.
Output256 = OutputMode(termbox.Output256) Output256 = OutputMode(termbox.Output256)
) )