|
|
|
@ -5,13 +5,13 @@ |
|
|
|
|
package mop |
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
|
`bytes` |
|
|
|
|
`fmt` |
|
|
|
|
`reflect` |
|
|
|
|
`regexp` |
|
|
|
|
`strings` |
|
|
|
|
`text/template` |
|
|
|
|
`time` |
|
|
|
|
"bytes" |
|
|
|
|
"fmt" |
|
|
|
|
"reflect" |
|
|
|
|
"regexp" |
|
|
|
|
"strings" |
|
|
|
|
"text/template" |
|
|
|
|
"time" |
|
|
|
|
) |
|
|
|
|
|
|
|
|
|
// Column describes formatting rules for individual column within the list
|
|
|
|
@ -20,7 +20,7 @@ type Column struct { |
|
|
|
|
width int // Column width.
|
|
|
|
|
name string // The name of the field in the Stock struct.
|
|
|
|
|
title string // Column title to display in the header.
|
|
|
|
|
formatter func(... string) string // Optional function to format the contents of the column.
|
|
|
|
|
formatter func(...string) string // Optional function to format the contents of the column.
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Layout is used to format and display all the collected data, i.e. market
|
|
|
|
@ -53,6 +53,8 @@ func NewLayout() *Layout { |
|
|
|
|
{9, `Dividend`, `Dividend`, zero}, |
|
|
|
|
{9, `Yield`, `Yield`, percent}, |
|
|
|
|
{11, `MarketCap`, `MktCap`, currency}, |
|
|
|
|
{13, `PreOpen`, `PreMktChg%`, last}, |
|
|
|
|
{13, `AfterHours`, `AfterMktChg%`, last}, |
|
|
|
|
} |
|
|
|
|
layout.regex = regexp.MustCompile(`(\.\d+)[BMK]?$`) |
|
|
|
|
layout.marketTemplate = buildMarketTemplate() |
|
|
|
@ -208,7 +210,7 @@ func buildQuotesTemplate() *template.Template { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{{.Header}} |
|
|
|
|
{{range.Stocks}}{{if .Advancing}}<green>{{end}}{{.Ticker}}{{.LastTrade}}{{.Change}}{{.ChangePct}}{{.Open}}{{.Low}}{{.High}}{{.Low52}}{{.High52}}{{.Volume}}{{.AvgVolume}}{{.PeRatio}}{{.Dividend}}{{.Yield}}{{.MarketCap}}</> |
|
|
|
|
{{range.Stocks}}{{if .Advancing}}<green>{{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)) |
|
|
|
@ -256,7 +258,7 @@ func arrowFor(column int, profile *Profile) string { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
func blank(str... string) string { |
|
|
|
|
func blank(str ...string) string { |
|
|
|
|
if len(str) < 1 { |
|
|
|
|
return "ERR" |
|
|
|
|
} |
|
|
|
@ -268,8 +270,8 @@ func blank(str... string) string { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
func zero(str... string) string { |
|
|
|
|
if len(str) < 2{ |
|
|
|
|
func zero(str ...string) string { |
|
|
|
|
if len(str) < 2 { |
|
|
|
|
return "ERR" |
|
|
|
|
} |
|
|
|
|
if str[0] == `0.00` { |
|
|
|
@ -280,7 +282,7 @@ func zero(str... string) string { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
func last(str... string) string { |
|
|
|
|
func last(str ...string) string { |
|
|
|
|
if len(str) < 1 { |
|
|
|
|
return "ERR" |
|
|
|
|
} |
|
|
|
@ -292,13 +294,13 @@ func last(str... string) string { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
func currency(str... string) string { |
|
|
|
|
func currency(str ...string) string { |
|
|
|
|
if len(str) < 2 { |
|
|
|
|
return "ERR" |
|
|
|
|
} |
|
|
|
|
//default to $
|
|
|
|
|
symbol := "$" |
|
|
|
|
switch (str[1]){ |
|
|
|
|
switch str[1] { |
|
|
|
|
case "JPY": |
|
|
|
|
symbol = "¥" |
|
|
|
|
break |
|
|
|
@ -321,7 +323,7 @@ func currency(str... string) string { |
|
|
|
|
|
|
|
|
|
// Returns percent value truncated at 2 decimal points.
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
func percent(str... string) string { |
|
|
|
|
func percent(str ...string) string { |
|
|
|
|
if len(str) < 1 { |
|
|
|
|
return "ERR" |
|
|
|
|
} |
|
|
|
|