diff --git a/cmd/mop/main.go b/cmd/mop/main.go index 00eb8bf..5b7cc4a 100644 --- a/cmd/mop/main.go +++ b/cmd/mop/main.go @@ -138,10 +138,10 @@ func main() { profileName := flag.String("profile", path.Join(usr.HomeDir, defaultProfile), "path to profile") flag.Parse() - screen := mop.NewScreen() + profile := mop.NewProfile(*profileName) + screen := mop.NewScreen(profile) defer screen.Close() - profile := mop.NewProfile(*profileName) mainLoop(screen, profile) profile.Save() } diff --git a/layout.go b/layout.go index 7f57ae4..5478981 100644 --- a/layout.go +++ b/layout.go @@ -209,9 +209,9 @@ func (layout *Layout) pad(str string, width int) string { //----------------------------------------------------------------------------- func buildMarketTemplate() *template.Template { - markup := `Dow {{.Dow.change}} ({{.Dow.percent}}) at {{.Dow.latest}} S&P 500 {{.Sp500.change}} ({{.Sp500.percent}}) at {{.Sp500.latest}} NASDAQ {{.Nasdaq.change}} ({{.Nasdaq.percent}}) at {{.Nasdaq.latest}} -Tokyo {{.Tokyo.change}} ({{.Tokyo.percent}}) at {{.Tokyo.latest}} HK {{.HongKong.change}} ({{.HongKong.percent}}) at {{.HongKong.latest}} London {{.London.change}} ({{.London.percent}}) at {{.London.latest}} Frankfurt {{.Frankfurt.change}} ({{.Frankfurt.percent}}) at {{.Frankfurt.latest}} {{if .IsClosed}}U.S. markets closed{{end}} -10-Year Yield {{.Yield.latest}} ({{.Yield.change}}) Euro ${{.Euro.latest}} ({{.Euro.change}}) Yen ¥{{.Yen.latest}} ({{.Yen.change}}) Oil ${{.Oil.latest}} ({{.Oil.change}}) Gold ${{.Gold.latest}} ({{.Gold.change}})` + markup := `Dow {{.Dow.change}} ({{.Dow.percent}}) at {{.Dow.latest}} S&P 500 {{.Sp500.change}} ({{.Sp500.percent}}) at {{.Sp500.latest}} NASDAQ {{.Nasdaq.change}} ({{.Nasdaq.percent}}) at {{.Nasdaq.latest}} +Tokyo {{.Tokyo.change}} ({{.Tokyo.percent}}) at {{.Tokyo.latest}} HK {{.HongKong.change}} ({{.HongKong.percent}}) at {{.HongKong.latest}} London {{.London.change}} ({{.London.percent}}) at {{.London.latest}} Frankfurt {{.Frankfurt.change}} ({{.Frankfurt.percent}}) at {{.Frankfurt.latest}} {{if .IsClosed}}U.S. markets closed{{end}} +10-Year Yield {{.Yield.latest}} ({{.Yield.change}}) Euro ${{.Euro.latest}} ({{.Euro.change}}) Yen ¥{{.Yen.latest}} ({{.Yen.change}}) Oil ${{.Oil.latest}} ({{.Oil.change}}) Gold ${{.Gold.latest}} ({{.Gold.change}})` return template.Must(template.New(`market`).Parse(markup)) } @@ -223,7 +223,7 @@ func buildQuotesTemplate() *template.Template { {{.Header}} -{{range.Stocks}}{{if eq .Direction 1}}{{else if eq .Direction -1}}{{end}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}}{{.PreOpen}}{{.AfterHours}} +{{range.Stocks}}{{if eq .Direction 1}}{{else if eq .Direction -1}}{{end}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}}{{.PreOpen}}{{.AfterHours}} {{end}}` return template.Must(template.New(`quotes`).Parse(markup)) @@ -239,9 +239,9 @@ func highlight(collections ...map[string]string) { adv, err := strconv.ParseFloat(change, 64) if err == nil { if adv < 0.0 { - collection[`change`] = `` + collection[`change`] + `` + collection[`change`] = `` + collection[`change`] + `` } else if adv > 0.0 { - collection[`change`] = `` + collection[`change`] + `` + collection[`change`] = `` + collection[`change`] + `` } } } diff --git a/markup.go b/markup.go index 4bf5e64..461cdb3 100644 --- a/markup.go +++ b/markup.go @@ -33,7 +33,7 @@ type Markup struct { // Creates markup to define tag to Termbox translation rules and store default // colors and column alignments. -func NewMarkup() *Markup { +func NewMarkup(profile *Profile) *Markup { markup := &Markup{} markup.Foreground = termbox.ColorDefault markup.Background = termbox.ColorDefault @@ -53,6 +53,12 @@ func NewMarkup() *Markup { markup.tags[`b`] = termbox.AttrBold // Attribute = 1 << (iota + 4) markup.tags[`u`] = termbox.AttrUnderline markup.tags[`r`] = termbox.AttrReverse + + // Semantic markups + markup.tags[`gain`] = markup.tags[profile.TickerColors.Gain] + markup.tags[`loss`] = markup.tags[profile.TickerColors.Loss] + markup.tags[`tag`] = markup.tags[profile.TickerColors.Tag] + markup.regex = markup.supportedTags() // Once we have the hash we could build the regex. return markup diff --git a/screen.go b/screen.go index 2c92614..91a2932 100644 --- a/screen.go +++ b/screen.go @@ -26,13 +26,13 @@ type Screen struct { // Initializes Termbox, creates screen along with layout and markup, and // calculates current screen dimensions. Once initialized the screen is // ready for display. -func NewScreen() *Screen { +func NewScreen(profile *Profile) *Screen { if err := termbox.Init(); err != nil { panic(err) } screen := &Screen{} screen.layout = NewLayout() - screen.markup = NewMarkup() + screen.markup = NewMarkup(profile) return screen.Resize() }