mirror of https://github.com/miguelmota/cointop
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
89 lines
2.3 KiB
Go
89 lines
2.3 KiB
Go
6 years ago
|
package cointop
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"strings"
|
||
|
)
|
||
|
|
||
|
func (ct *Cointop) updateHeaders() {
|
||
6 years ago
|
var cols []string
|
||
|
|
||
|
type t struct {
|
||
|
colorfn func(a ...interface{}) string
|
||
|
displaytext string
|
||
|
padleft int
|
||
|
padright int
|
||
|
arrow string
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
5 years ago
|
baseColor := ct.colorscheme.TableHeaderSprintf()
|
||
6 years ago
|
cm := map[string]*t{
|
||
5 years ago
|
"rank": &t{baseColor, "[r]ank", 0, 1, " "},
|
||
|
"name": &t{baseColor, "[n]ame", 0, 11, " "},
|
||
|
"symbol": &t{baseColor, "[s]ymbol", 4, 0, " "},
|
||
|
"price": &t{baseColor, "[p]rice", 2, 0, " "},
|
||
|
"holdings": &t{baseColor, "[h]oldings", 5, 0, " "},
|
||
|
"balance": &t{baseColor, "[b]alance", 5, 0, " "},
|
||
|
"marketcap": &t{baseColor, "[m]arket cap", 5, 0, " "},
|
||
|
"24hvolume": &t{baseColor, "24H [v]olume", 3, 0, " "},
|
||
|
"1hchange": &t{baseColor, "[1]H%", 5, 0, " "},
|
||
|
"24hchange": &t{baseColor, "[2]4H%", 3, 0, " "},
|
||
|
"7dchange": &t{baseColor, "[7]D%", 4, 0, " "},
|
||
|
"totalsupply": &t{baseColor, "[t]otal supply", 7, 0, " "},
|
||
|
"availablesupply": &t{baseColor, "[a]vailable supply", 0, 0, " "},
|
||
|
"percentholdings": &t{baseColor, "%holdings", 2, 0, " "},
|
||
|
"lastupdated": &t{baseColor, "last [u]pdated", 3, 0, " "},
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
6 years ago
|
for k := range cm {
|
||
6 years ago
|
cm[k].arrow = " "
|
||
5 years ago
|
if ct.State.sortBy == k {
|
||
5 years ago
|
cm[k].colorfn = ct.colorscheme.TableHeaderColumnActiveSprintf()
|
||
5 years ago
|
if ct.State.sortDesc {
|
||
6 years ago
|
cm[k].arrow = "▼"
|
||
6 years ago
|
} else {
|
||
6 years ago
|
cm[k].arrow = "▲"
|
||
6 years ago
|
}
|
||
|
}
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
5 years ago
|
if ct.State.portfolioVisible {
|
||
6 years ago
|
cols = []string{"rank", "name", "symbol", "price",
|
||
6 years ago
|
"holdings", "balance", "24hchange", "percentholdings", "lastupdated"}
|
||
6 years ago
|
} else {
|
||
|
cols = []string{"rank", "name", "symbol", "price",
|
||
|
"marketcap", "24hvolume", "1hchange", "24hchange",
|
||
|
"7dchange", "totalsupply", "availablesupply", "lastupdated"}
|
||
|
}
|
||
|
|
||
|
var headers []string
|
||
|
for _, v := range cols {
|
||
|
s, ok := cm[v]
|
||
|
if !ok {
|
||
|
continue
|
||
|
}
|
||
|
var str string
|
||
|
d := s.arrow + s.displaytext
|
||
|
if v == "price" || v == "balance" {
|
||
6 years ago
|
d = s.arrow + ct.currencySymbol() + s.displaytext
|
||
6 years ago
|
}
|
||
|
|
||
|
str = fmt.Sprintf(
|
||
|
"%s%s%s",
|
||
|
strings.Repeat(" ", s.padleft),
|
||
|
s.colorfn(d),
|
||
|
strings.Repeat(" ", s.padright),
|
||
|
)
|
||
|
headers = append(headers, str)
|
||
6 years ago
|
}
|
||
6 years ago
|
|
||
6 years ago
|
ct.update(func() {
|
||
5 years ago
|
if ct.Views.Header.Backing == nil {
|
||
5 years ago
|
return
|
||
|
}
|
||
|
|
||
5 years ago
|
ct.Views.Header.Backing.Clear()
|
||
|
fmt.Fprintln(ct.Views.Header.Backing, strings.Join(headers, ""))
|
||
6 years ago
|
})
|
||
|
}
|