diff --git a/layout.go b/layout.go index 358175f..1dd80fe 100644 --- a/layout.go +++ b/layout.go @@ -12,6 +12,7 @@ import ( "strings" "text/template" "time" + "unicode" ) var currencies = map[string]string{ @@ -54,8 +55,8 @@ func NewLayout() *Layout { {10, `High`, `High`, currency}, {10, `Low52`, `52w Low`, currency}, {10, `High52`, `52w High`, currency}, - {11, `Volume`, `Volume`, nil}, - {11, `AvgVolume`, `AvgVolume`, nil}, + {11, `Volume`, `Volume`, integer}, + {11, `AvgVolume`, `AvgVolume`, integer}, {9, `PeRatio`, `P/E`, blank}, {9, `Dividend`, `Dividend`, zero}, {9, `Yield`, `Yield`, percent}, @@ -63,7 +64,7 @@ func NewLayout() *Layout { {13, `PreOpen`, `PreMktChg%`, percent}, {13, `AfterHours`, `AfterMktChg%`, percent}, } - layout.regex = regexp.MustCompile(`(\.\d+)[BMK]?$`) + layout.regex = regexp.MustCompile(`(\.\d+)[TBMK]?$`) layout.marketTemplate = buildMarketTemplate() layout.quotesTemplate = buildQuotesTemplate() @@ -269,7 +270,7 @@ func blank(str ...string) string { if len(str) < 1 { return "ERR" } - if len(str[0]) == 3 && str[0][0:3] == `N/A` { + if (len(str[0]) == 3 && str[0][0:3] == `N/A`) || len(str[0]) == 0 { return `-` } @@ -344,3 +345,23 @@ func percent(str ...string) string { } return str[0] } + +// Returns value as integer (no trailing digits after a '.'). +//----------------------------------------------------------------------------- +func integer(str ...string) string { + if len(str) < 1 { + return "ERR" + } + if str[0] == `N/A` || len(str[0]) == 0 { + return `-` + } + + // Don't strip after the '.' if we have a value such as 123.45M + if unicode.IsDigit(rune(str[0][len(str[0])-1])) { + split := strings.Split(str[0], ".") + if len(split) == 2 { + return split[0] + } + } + return str[0] +} diff --git a/line_editor.go b/line_editor.go index 35e803d..b83439a 100644 --- a/line_editor.go +++ b/line_editor.go @@ -5,10 +5,10 @@ package mop import ( - `regexp` - `strings` + "regexp" + "strings" - `github.com/nsf/termbox-go` + "github.com/nsf/termbox-go" ) // LineEditor kicks in when user presses '+' or '-' to add or delete stock @@ -189,7 +189,7 @@ func (editor *LineEditor) execute() *LineEditor { // Clear the lines at the bottom of the list, if any. after := before - removed - for i := before; i > after; i-- { + for i := before + 1; i > after; i-- { editor.screen.ClearLine(0, i+4) } } diff --git a/sorter.go b/sorter.go index ba6f181..7389c8a 100644 --- a/sorter.go +++ b/sorter.go @@ -86,10 +86,10 @@ func (list byHigh52Asc) Less(i, j int) bool { return list.sortable[i].High52 < list.sortable[j].High52 } func (list byVolumeAsc) Less(i, j int) bool { - return list.sortable[i].Volume < list.sortable[j].Volume + return m(list.sortable[i].Volume) < m(list.sortable[j].Volume) } func (list byAvgVolumeAsc) Less(i, j int) bool { - return list.sortable[i].AvgVolume < list.sortable[j].AvgVolume + return m(list.sortable[i].AvgVolume) < m(list.sortable[j].AvgVolume) } func (list byPeRatioAsc) Less(i, j int) bool { return list.sortable[i].PeRatio < list.sortable[j].PeRatio @@ -139,10 +139,10 @@ func (list byHigh52Desc) Less(i, j int) bool { return list.sortable[j].High52 < list.sortable[i].High52 } func (list byVolumeDesc) Less(i, j int) bool { - return list.sortable[j].Volume < list.sortable[i].Volume + return m(list.sortable[j].Volume) < m(list.sortable[i].Volume) } func (list byAvgVolumeDesc) Less(i, j int) bool { - return list.sortable[j].AvgVolume < list.sortable[i].AvgVolume + return m(list.sortable[j].AvgVolume) < m(list.sortable[i].AvgVolume) } func (list byPeRatioDesc) Less(i, j int) bool { return list.sortable[j].PeRatio < list.sortable[i].PeRatio @@ -246,6 +246,8 @@ func m(str string) float32 { multiplier := 1.0 switch str[len(str)-1 : len(str)] { // Check the last character. + case `T`: + multiplier = 1000000000000.0 case `B`: multiplier = 1000000000.0 case `M`: @@ -254,7 +256,7 @@ func m(str string) float32 { multiplier = 1000.0 } - trimmed := strings.Trim(str, ` $BMK`) // Get rid of non-numeric characters. + trimmed := strings.Trim(str, ` $TBMK`) // Get rid of non-numeric characters. value, _ := strconv.ParseFloat(trimmed, 32) return float32(value * multiplier)