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}} {{.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}}` {{end}}`
//markup += fmt.Sprintf("[%v]", quotes.profile.Grouped) //markup += fmt.Sprintf("[%v]", quotes.profile.Grouped)
template, err := template.New(`quotes`).Parse(markup) template, err := template.New(`quotes`).Parse(markup)

@ -12,14 +12,15 @@ type Screen struct {
width int width int
height int height int
cleared bool cleared bool
markup *Markup
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
func (self *Screen) Initialize() *Screen { func (self *Screen) Initialize() *Screen {
err := termbox.Init() if err := termbox.Init(); err != nil {
if err != nil {
panic(err) panic(err)
} }
self.markup = new(Markup).Initialize()
return self.Resize() 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) { func (self *Screen) DrawLine(x int, y int, str string) {
start, column := 0, 0 start, column := 0, 0
markup := new(Markup).Initialize() for _, token := range self.markup.Tokenize(str) {
for _, token := range markup.Tokenize(str) { if !self.markup.IsTag(token) {
if !markup.IsTag(token) {
for i, char := range token { for i, char := range token {
if !markup.RightAligned { if !self.markup.RightAligned {
start = x + column start = x + column
column++ column++
} else { } else {
start = self.width - len(token) + i 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 { func (stock *Stock) Color() string {
if strings.Index(stock.Change, "-") == -1 { if strings.Index(stock.Change, "-") == -1 {
return `</><green>` return `<green>`
} else { } else {
return `` // `</red><red>` return ``
} }
} }
func (stock *Stock) ResetColor() string {
if strings.Index(stock.Change, "-") == -1 {
return `</>`
} else {
return ``
}
}

Loading…
Cancel
Save