diff --git a/lib/layout.go b/lib/layout.go index 0443da8..f30bfab 100644 --- a/lib/layout.go +++ b/lib/layout.go @@ -105,7 +105,7 @@ func (self *Layout) Quotes(quotes *Quotes) string { {{.Header}} -{{range.Stocks}}{{.Color}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}} +{{range.Stocks}}{{.Color}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}}{{.ResetColor}} {{end}}` //markup += fmt.Sprintf("[%v]", quotes.profile.Grouped) template, err := template.New(`quotes`).Parse(markup) diff --git a/lib/screen.go b/lib/screen.go index 49ddc0f..a372ee2 100644 --- a/lib/screen.go +++ b/lib/screen.go @@ -12,14 +12,15 @@ type Screen struct { width int height int cleared bool + markup *Markup } //----------------------------------------------------------------------------- func (self *Screen) Initialize() *Screen { - err := termbox.Init() - if err != nil { + if err := termbox.Init(); err != nil { panic(err) } + self.markup = new(Markup).Initialize() return self.Resize() } @@ -80,17 +81,16 @@ func (self *Screen) ClearLine(x int, y int) { func (self *Screen) DrawLine(x int, y int, str string) { start, column := 0, 0 - markup := new(Markup).Initialize() - for _, token := range markup.Tokenize(str) { - if !markup.IsTag(token) { + for _, token := range self.markup.Tokenize(str) { + if !self.markup.IsTag(token) { for i, char := range token { - if !markup.RightAligned { + if !self.markup.RightAligned { start = x + column column++ } else { start = self.width - len(token) + i } - termbox.SetCell(start, y, char, markup.Foreground, markup.Background) + termbox.SetCell(start, y, char, self.markup.Foreground, self.markup.Background) } } } diff --git a/lib/yahoo_quotes.go b/lib/yahoo_quotes.go index 64453dc..be7db5f 100644 --- a/lib/yahoo_quotes.go +++ b/lib/yahoo_quotes.go @@ -151,8 +151,17 @@ func (self *Quotes) sanitize(body []byte) []byte { //----------------------------------------------------------------------------- func (stock *Stock) Color() string { if strings.Index(stock.Change, "-") == -1 { - return `` + return `` } else { - return `` // `` + return `` } } + +func (stock *Stock) ResetColor() string { + if strings.Index(stock.Change, "-") == -1 { + return `` + } else { + return `` + } +} +