Some more markup tweaks

master
Michael Dvorkin 11 years ago
parent 86037e627d
commit 00a7ee406d
  1. 2
      lib/layout.go
  2. 14
      lib/screen.go
  3. 13
      lib/yahoo_quotes.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)

@ -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)
}
}
}

@ -151,8 +151,17 @@ func (self *Quotes) sanitize(body []byte) []byte {
//-----------------------------------------------------------------------------
func (stock *Stock) Color() string {
if strings.Index(stock.Change, "-") == -1 {
return `</><green>`
return `<green>`
} else {
return `` // `</red><red>`
return ``
}
}
func (stock *Stock) ResetColor() string {
if strings.Index(stock.Change, "-") == -1 {
return `</>`
} else {
return ``
}
}

Loading…
Cancel
Save