From 56a1633c766144bb586233232d26d65252df2b83 Mon Sep 17 00:00:00 2001 From: Roi Martin Date: Sun, 13 Nov 2016 20:45:04 +0100 Subject: [PATCH] Minor style changes --- escape.go | 31 +++++++++++-------------------- gui.go | 4 ++-- 2 files changed, 13 insertions(+), 22 deletions(-) diff --git a/escape.go b/escape.go index 86aa7a4..ec80899 100644 --- a/escape.go +++ b/escape.go @@ -126,7 +126,6 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) { case OutputMode(Output256): err = ei.output256() } - if err != nil { return false, errCSIParseError } @@ -139,13 +138,11 @@ func (ei *escapeInterpreter) parseOne(ch rune) (isEscape bool, err error) { return false, nil } -// outputNormal provides 8 different colors: -// black, red, green, yellow, blue, magenta, cyan, white +// outputNormal provides 8 different colors: +// black, red, green, yellow, blue, magenta, cyan, white func (ei *escapeInterpreter) outputNormal() error { - for _, param := range ei.csiParam { p, err := strconv.Atoi(param) - if err != nil { return errCSIParseError } @@ -170,45 +167,40 @@ func (ei *escapeInterpreter) outputNormal() error { return nil } -// output256 allows you to leverage the 256 terminal mode -// 0x01 - 0x08: the 8 colors as in OutputNormal -// 0x09 - 0x10: Color* | AttrBold -// 0x11 - 0xe8: 216 different colors -// 0xe9 - 0x1ff: 24 different shades of grey +// output256 allows you to leverage the 256-colors terminal mode: +// 0x01 - 0x08: the 8 colors as in OutputNormal +// 0x09 - 0x10: Color* | AttrBold +// 0x11 - 0xe8: 216 different colors +// 0xe9 - 0x1ff: 24 different shades of grey func (ei *escapeInterpreter) output256() error { - if len(ei.csiParam) < 3 { return ei.outputNormal() } fgbgParam, err := strconv.Atoi(ei.csiParam[0]) - if err != nil { return errCSIParseError } fgbgType, err := strconv.Atoi(ei.csiParam[1]) - if err != nil { return errCSIParseError } - if fgbgType != 5 { return ei.outputNormal() } fgbgColor, err := strconv.Atoi(ei.csiParam[2]) - if err != nil { return errCSIParseError } - if fgbgParam == 38 { + switch fgbgParam { + case 38: ei.curFgColor = Attribute(fgbgColor + 1) for _, param := range ei.csiParam[3:] { p, err := strconv.Atoi(param) - if err != nil { return errCSIParseError } @@ -222,10 +214,9 @@ func (ei *escapeInterpreter) output256() error { ei.curFgColor |= AttrReverse } } - - } else if fgbgParam == 48 { + case 48: ei.curBgColor = Attribute(fgbgColor + 1) - } else { + default: return errCSIParseError } diff --git a/gui.go b/gui.go index c42adbd..826f2c0 100644 --- a/gui.go +++ b/gui.go @@ -22,10 +22,10 @@ var ( type OutputMode termbox.OutputMode const ( - // OutputNormal provides 8-colors terminal mode + // OutputNormal provides 8-colors terminal mode. OutputNormal = OutputMode(termbox.OutputNormal) - // Output256 provides 256-colors terminal mode + // Output256 provides 256-colors terminal mode. Output256 = OutputMode(termbox.Output256) )