Use theme styles

pull/38/head
Miguel Mota 5 years ago
parent 81af942dbf
commit 12d56decc3
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9

@ -7,7 +7,6 @@ import (
"time"
"github.com/gizak/termui"
"github.com/miguelmota/cointop/cointop/common/color"
"github.com/miguelmota/cointop/cointop/common/filecache"
"github.com/miguelmota/cointop/cointop/common/timeutil"
)
@ -47,7 +46,7 @@ func (ct *Cointop) updateChart() error {
}
}
ct.update(func() {
fmt.Fprint(ct.chartview, color.White(body))
fmt.Fprint(ct.chartview, ct.colorscheme.Chart(body))
})
return nil
@ -62,12 +61,10 @@ func (ct *Cointop) chartPoints(symbol string, name string) error {
chart := termui.NewLineChart()
chart.Height = 10
chart.AxesColor = termui.ColorWhite
chart.LineColor = termui.ColorCyan
chart.Border = false
// NOTE: empty list means don't show x-axis labels
chart.DataLabels = []string{""}
chart.DataLabels = []string{""}
rangeseconds := ct.chartrangesmap[ct.selectedchartrange]
if ct.selectedchartrange == "YTD" {
@ -161,10 +158,11 @@ func (ct *Cointop) portfolioChart() error {
chart := termui.NewLineChart()
chart.Height = 10
chart.AxesColor = termui.ColorWhite
chart.LineColor = termui.ColorCyan
chart.Border = false
// NOTE: empty list means don't show x-axis labels
chart.DataLabels = []string{""}
rangeseconds := ct.chartrangesmap[ct.selectedchartrange]
if ct.selectedchartrange == "YTD" {
ytd := time.Now().Unix() - int64(timeutil.BeginningOfYear().Unix())

@ -315,16 +315,16 @@ func NewCointop(config *Config) *Cointop {
// Run runs cointop
func (ct *Cointop) Run() {
g, err := gocui.NewGui(gocui.Output256)
g.BgColor = gocui.ColorDefault
if err != nil {
log.Fatalf("new gocui: %v", err)
}
g.FgColor = ct.colorscheme.BaseFg()
g.BgColor = ct.colorscheme.BaseBg()
ct.g = g
defer g.Close()
g.InputEsc = true
//g.BgColor = gocui.ColorBlack
g.FgColor = gocui.ColorWhite
g.Mouse = true
g.Highlight = true
g.SetManagerFunc(ct.layout)

@ -2,108 +2,314 @@ package cointop
import (
"github.com/fatih/color"
"github.com/jroimartin/gocui"
)
// Colors ..
type Colors map[string]interface{}
// colorschemeColors ..
type colorschemeColors map[string]interface{}
// Cache ..
type Cache map[string]func(...interface{}) string
// ISprintf ...
type ISprintf func(...interface{}) string
// colorCache ..
type colorCache map[string]ISprintf
// ColorScheme ...
type ColorScheme struct {
colors Colors
cache Cache
colors colorschemeColors
cache colorCache
}
var fgcolorschemeColorsMap = map[string]color.Attribute{
"black": color.FgBlack,
"blue": color.FgBlue,
"cyan": color.FgCyan,
"green": color.FgGreen,
"magenta": color.FgMagenta,
"red": color.FgRed,
"white": color.FgWhite,
"yellow": color.FgYellow,
}
var bgcolorschemeColorsMap = map[string]color.Attribute{
"black": color.BgBlack,
"blue": color.BgBlue,
"cyan": color.BgCyan,
"green": color.BgGreen,
"magenta": color.BgMagenta,
"red": color.BgRed,
"white": color.BgWhite,
"yellow": color.BgYellow,
}
var gocuicolorschemeColorsMap = map[string]gocui.Attribute{
"black": gocui.ColorBlack,
"blue": gocui.ColorBlue,
"cyan": gocui.ColorCyan,
"green": gocui.ColorGreen,
"magenta": gocui.ColorMagenta,
"red": gocui.ColorRed,
"white": gocui.ColorWhite,
"yellow": gocui.ColorYellow,
}
// NewColorScheme ...
func NewColorScheme(colors Colors) *ColorScheme {
func NewColorScheme(colors colorschemeColors) *ColorScheme {
return &ColorScheme{
colors: colors,
cache: make(Cache),
cache: make(colorCache),
}
}
// RowText ...
func (c *ColorScheme) RowText(a ...interface{}) string {
name := "row_text"
return c.color(name, a...)
// BaseFg ...
func (c *ColorScheme) BaseFg() gocui.Attribute {
return c.gocuiFgColor("base")
}
func (c *ColorScheme) color(name string, a ...interface{}) string {
// BaseBg ...
func (c *ColorScheme) BaseBg() gocui.Attribute {
return c.gocuiBgColor("base")
}
// Chart ...
func (c *ColorScheme) Chart(a ...interface{}) string {
return c.color("chart", a...)
}
// Marketbar ...
func (c *ColorScheme) Marketbar(a ...interface{}) string {
return c.color("marketbar", a...)
}
// MarketbarSprintf ...
func (c *ColorScheme) MarketbarSprintf() ISprintf {
return c.toSprintf("marketbar")
}
// MarketbarChangeSprintf ...
func (c *ColorScheme) MarketbarChangeSprintf() ISprintf {
// NOTE: reusing table styles
return c.toSprintf("table_column_change")
}
// MarketbarChangeDownSprintf ...
func (c *ColorScheme) MarketbarChangeDownSprintf() ISprintf {
// NOTE: reusing table styles
return c.toSprintf("table_column_change_down")
}
// MarketbarChangeUpSprintf ...
func (c *ColorScheme) MarketbarChangeUpSprintf() ISprintf {
// NOTE: reusing table styles
return c.toSprintf("table_column_change_up")
}
// MarketBarLabelActive ...
func (c *ColorScheme) MarketBarLabelActive(a ...interface{}) string {
return c.color("marketbar_label_active", a...)
}
// Menu ...
func (c *ColorScheme) Menu(a ...interface{}) string {
return c.color("menu", a...)
}
// MenuHeader ...
func (c *ColorScheme) MenuHeader(a ...interface{}) string {
return c.color("menu_header", a...)
}
// MenuLabel ...
func (c *ColorScheme) MenuLabel(a ...interface{}) string {
return c.color("menu_label", a...)
}
// MenuLabelActive ...
func (c *ColorScheme) MenuLabelActive(a ...interface{}) string {
return c.color("menu_label_active", a...)
}
// Searchbar ...
func (c *ColorScheme) Searchbar(a ...interface{}) string {
return c.color("searchbar", a...)
}
// Statusbar ...
func (c *ColorScheme) Statusbar(a ...interface{}) string {
return c.color("statusbar", a...)
}
// TableColumnPrice ...
func (c *ColorScheme) TableColumnPrice(a ...interface{}) string {
return c.color("table_column_price", a...)
}
// TableColumnPriceSprintf ...
func (c *ColorScheme) TableColumnPriceSprintf() ISprintf {
return c.toSprintf("table_column_price")
}
// TableColumnChange ...
func (c *ColorScheme) TableColumnChange(a ...interface{}) string {
return c.color("table_column_change", a...)
}
// TableColumnChangeSprintf ...
func (c *ColorScheme) TableColumnChangeSprintf() ISprintf {
return c.toSprintf("table_column_change")
}
// TableColumnChangeDown ...
func (c *ColorScheme) TableColumnChangeDown(a ...interface{}) string {
return c.color("table_column_change_down", a...)
}
// TableColumnChangeDownSprintf ...
func (c *ColorScheme) TableColumnChangeDownSprintf() ISprintf {
return c.toSprintf("table_column_change_down")
}
// TableColumnChangeUp ...
func (c *ColorScheme) TableColumnChangeUp(a ...interface{}) string {
return c.color("table_column_change_up", a...)
}
// TableColumnChangeUpSprintf ...
func (c *ColorScheme) TableColumnChangeUpSprintf() ISprintf {
return c.toSprintf("table_column_change_up")
}
// TableHeader ...
func (c *ColorScheme) TableHeader(a ...interface{}) string {
return c.color("table_header", a...)
}
// TableHeaderSprintf ...
func (c *ColorScheme) TableHeaderSprintf() ISprintf {
return c.toSprintf("table_header")
}
// TableHeaderColumnActive ...
func (c *ColorScheme) TableHeaderColumnActive(a ...interface{}) string {
return c.color("table_header_column_active", a...)
}
// TableHeaderColumnActiveSprintf ...
func (c *ColorScheme) TableHeaderColumnActiveSprintf() ISprintf {
return c.toSprintf("table_header_column_active")
}
// TableRow ...
func (c *ColorScheme) TableRow(a ...interface{}) string {
return c.color("table_row", a...)
}
// TableRowSprintf ...
func (c *ColorScheme) TableRowSprintf() ISprintf {
return c.toSprintf("table_row")
}
// TableRowActive ...
func (c *ColorScheme) TableRowActive(a ...interface{}) string {
return c.color("table_row_active", a...)
}
// TableRowFavorite ...
func (c *ColorScheme) TableRowFavorite(a ...interface{}) string {
return c.color("table_row_favorite", a...)
}
// TableRowFavoriteSprintf ...
func (c *ColorScheme) TableRowFavoriteSprintf() ISprintf {
return c.toSprintf("table_row_favorite")
}
// SetViewColor ...
func (c *ColorScheme) SetViewColor(view *gocui.View, name string) {
view.FgColor = c.gocuiFgColor(name)
view.BgColor = c.gocuiBgColor(name)
}
// SetViewActiveColor ...
func (c *ColorScheme) SetViewActiveColor(view *gocui.View, name string) {
view.SelFgColor = c.gocuiFgColor(name)
view.SelBgColor = c.gocuiBgColor(name)
}
func (c *ColorScheme) toSprintf(name string) ISprintf {
if cached, ok := c.cache[name]; ok {
return cached(a...)
return cached
}
var colors []color.Attribute
if v, ok := c.colors[name+"_fg"].(string); ok {
if fg, ok := toFgAttr(v); ok {
if fg, ok := c.toFgAttr(v); ok {
colors = append(colors, fg)
}
}
if v, ok := c.colors[name+"_bg"].(string); ok {
if bg, ok := toBgAttr(v); ok {
if bg, ok := c.toBgAttr(v); ok {
colors = append(colors, bg)
}
}
if v, ok := c.colors[name+"_bold"].(bool); ok {
if bold, ok := toBoldAttr(v); ok {
if bold, ok := c.toBoldAttr(v); ok {
colors = append(colors, bold)
}
}
if v, ok := c.colors[name+"_underline"].(bool); ok {
if underline, ok := toUnderlineAttr(v); ok {
if underline, ok := c.toUnderlineAttr(v); ok {
colors = append(colors, underline)
}
}
c.cache[name] = color.New(colors...).SprintFunc()
return c.cache[name](a...)
return c.cache[name]
}
var fgColorsMap = map[string]color.Attribute{
"black": color.FgBlack,
"blue": color.FgBlue,
"cyan": color.FgCyan,
"green": color.FgGreen,
"magenta": color.FgMagenta,
"red": color.FgRed,
"white": color.FgWhite,
"yellow": color.FgYellow,
func (c *ColorScheme) color(name string, a ...interface{}) string {
return c.toSprintf(name)(a...)
}
var bgColorsMap = map[string]color.Attribute{
"black": color.BgBlack,
"blue": color.BgBlue,
"cyan": color.BgCyan,
"green": color.BgGreen,
"magenta": color.BgMagenta,
"red": color.BgRed,
"white": color.BgWhite,
"yellow": color.BgYellow,
func (c *ColorScheme) gocuiFgColor(name string) gocui.Attribute {
if v, ok := c.colors[name+"_fg"].(string); ok {
if fg, ok := c.toGocuiAttr(v); ok {
return fg
}
}
return gocui.ColorDefault
}
func (c *ColorScheme) gocuiBgColor(name string) gocui.Attribute {
if v, ok := c.colors[name+"_bg"].(string); ok {
if bg, ok := c.toGocuiAttr(v); ok {
return bg
}
}
return gocui.ColorDefault
}
func toFgAttr(c string) (color.Attribute, bool) {
attr, ok := fgColorsMap[c]
func (c *ColorScheme) toFgAttr(k string) (color.Attribute, bool) {
attr, ok := fgcolorschemeColorsMap[k]
return attr, ok
}
func toBgAttr(c string) (color.Attribute, bool) {
attr, ok := bgColorsMap[c]
func (c *ColorScheme) toBgAttr(k string) (color.Attribute, bool) {
attr, ok := bgcolorschemeColorsMap[k]
return attr, ok
}
func toBoldAttr(v bool) (color.Attribute, bool) {
func (c *ColorScheme) toBoldAttr(v bool) (color.Attribute, bool) {
return color.Bold, v
}
func toUnderlineAttr(v bool) (color.Attribute, bool) {
func (c *ColorScheme) toUnderlineAttr(v bool) (color.Attribute, bool) {
return color.Underline, v
}
// CointopColorscheme ...
var CointopColorscheme = `
row_text_fg = "white"
row_text_bg = ""
row_text_bold = false
`
func (c *ColorScheme) toGocuiAttr(k string) (gocui.Attribute, bool) {
attr, ok := gocuicolorschemeColorsMap[k]
return attr, ok
}

@ -6,6 +6,8 @@ import "github.com/fatih/color"
type Color color.Color
var (
// Bold color
Bold = color.New(color.Bold).SprintFunc()
// Black color
Black = color.New(color.FgBlack).SprintFunc()
// BlackBg color

@ -63,10 +63,21 @@ func (ct *Cointop) createConfigIfNotExists() error {
if err != nil {
return err
}
// NOTE: legacy support for default path
path := ct.configPath()
oldConfigPath := strings.Replace(path, "cointop/config.toml", "cointop/config", 1)
if _, err := os.Stat(oldConfigPath); err == nil {
path = oldConfigPath
ct.configFilepath = oldConfigPath
return nil
}
err = ct.makeConfigFile()
if err != nil {
return err
}
return nil
}
@ -92,14 +103,6 @@ func (ct *Cointop) makeConfigDir() error {
func (ct *Cointop) makeConfigFile() error {
path := ct.configPath()
if _, err := os.Stat(path); os.IsNotExist(err) {
// NOTE: legacy support for default path
oldConfigPath := strings.Replace(path, "cointop/config.toml", "cointop/config", 1)
if _, err := os.Stat(oldConfigPath); err == nil {
path = oldConfigPath
ct.configFilepath = oldConfigPath
return nil
}
fo, err := os.Create(path)
if err != nil {
return err
@ -177,19 +180,22 @@ func (ct *Cointop) configToToml() ([]byte, error) {
var currencyIfc interface{} = ct.currencyconversion
var defaultViewIfc interface{} = ct.defaultView
var colorschemeIfc interface{} = ct.colorschemename
cmcIfc := map[string]interface{}{
"pro_api_key": ct.apiKeys.cmc,
}
var apiChoiceIfc interface{} = ct.apiChoice
var inputs = &config{
Shortcuts: shortcutsIfcs,
Favorites: favoritesIfcs,
Portfolio: portfolioIfc,
API: apiChoiceIfc,
ColorScheme: colorschemeIfc,
CoinMarketCap: cmcIfc,
Currency: currencyIfc,
DefaultView: defaultViewIfc,
CoinMarketCap: cmcIfc,
API: apiChoiceIfc,
Favorites: favoritesIfcs,
Shortcuts: shortcutsIfcs,
Portfolio: portfolioIfc,
}
var b bytes.Buffer
@ -262,7 +268,7 @@ func (ct *Cointop) loadColorSchemeFromConfig() error {
var colors map[string]interface{}
if ct.colorschemename == "" {
ct.colorschemename = "cointop"
if _, err := toml.Decode(CointopColorscheme, &colors); err != nil {
if _, err := toml.Decode(DefaultColors, &colors); err != nil {
return err
}
} else {

@ -4,7 +4,7 @@ import (
"fmt"
"sort"
"github.com/miguelmota/cointop/cointop/common/color"
color "github.com/miguelmota/cointop/cointop/common/color"
"github.com/miguelmota/cointop/cointop/common/pad"
)
@ -128,7 +128,7 @@ func (ct *Cointop) toggleConvertMenu() error {
}
func (ct *Cointop) updateConvertMenu() {
header := color.GreenBg(fmt.Sprintf(" Currency Conversion %s\n\n", pad.Left("[q] close menu ", ct.maxtablewidth-20, " ")))
header := ct.colorscheme.MenuHeader(fmt.Sprintf(" Currency Conversion %s\n\n", pad.Left("[q] close menu ", ct.maxtablewidth-20, " ")))
helpline := " Press the corresponding key to select currency for conversion\n\n"
cnt := 0
h := ct.viewHeight(ct.convertmenuviewname)
@ -147,12 +147,12 @@ func (ct *Cointop) updateConvertMenu() {
}
shortcut := string(alphanumericcharacters[i])
if key == ct.currencyconversion {
shortcut = color.YellowBold("*")
key = color.WhiteBold(key)
currency = color.YellowBold(currency)
shortcut = ct.colorscheme.MenuLabelActive(color.Bold("*"))
key = ct.colorscheme.Menu(color.Bold(key))
currency = ct.colorscheme.MenuLabelActive(color.Bold(currency))
} else {
key = color.White(key)
currency = color.Yellow(currency)
key = ct.colorscheme.Menu(key)
currency = ct.colorscheme.MenuLabel(currency)
}
item := fmt.Sprintf(" [ %1s ] %4s %-34s", shortcut, key, currency)
cols[cnt] = append(cols[cnt], item)

@ -0,0 +1,81 @@
package cointop
// DefaultColors ...
var DefaultColors = `
colorscheme = "cointop"
base_fg = "white"
base_bg = "black"
chart_fg = "white"
chart_bg = "black"
chart_bold = false
marketbar_fg = "white"
marketbar_bg = "black"
marketbar_bold = false
marketbar_label_active_fg = "cyan"
marketbar_label_active_bg = "black"
marketbar_label_active_bold = false
menu_fg = "white"
menu_bg = "black"
menu_bold = false
menu_header_fg = "black"
menu_header_bg = "green"
menu_header_bold = false
menu_label_fg = "yellow"
menu_label_bg = "black"
menu_label_bold = false
menu_label_active_fg = "yellow"
menu_label_active_bg = "black"
menu_label_active_bold = true
searchbar_fg = "white"
searchbar_bg = "black"
searchbar_bold = false
statusbar_fg = "black"
statusbar_bg = "cyan"
statusbar_bold = false
table_column_price_fg = "cyan"
table_column_price_bg = "black"
table_column_price_bold = false
table_column_change_fg = "white"
table_column_change_bg = "black"
table_column_change_bold = false
table_column_change_down_fg = "red"
table_column_change_down_bg = "black"
table_column_change_down_bold = false
table_column_change_up_fg = "green"
table_column_change_up_bg = "black"
table_column_change_up_bold = false
table_header_fg = "black"
table_header_bg = "green"
table_header_bold = false
table_header_column_active_fg = "black"
table_header_column_active_bg = "cyan"
table_header_column_active_bold = false
table_row_fg = "white"
table_row_bg = "black"
table_row_bold = false
table_row_active_fg = "black"
table_row_active_bg = "cyan"
table_row_active_bold = false
table_row_favorite_fg = "yellow"
table_row_favorite_bg = "black"
table_row_favorite_bold = false
`

@ -3,8 +3,6 @@ package cointop
import (
"fmt"
"strings"
"github.com/miguelmota/cointop/cointop/common/color"
)
func (ct *Cointop) updateHeaders() {
@ -18,28 +16,29 @@ func (ct *Cointop) updateHeaders() {
arrow string
}
baseColor := ct.colorscheme.TableHeaderSprintf()
cm := map[string]*t{
"rank": &t{color.Black, "[r]ank", 0, 1, " "},
"name": &t{color.Black, "[n]ame", 0, 11, " "},
"symbol": &t{color.Black, "[s]ymbol", 4, 0, " "},
"price": &t{color.Black, "[p]rice", 2, 0, " "},
"holdings": &t{color.Black, "[h]oldings", 5, 0, " "},
"balance": &t{color.Black, "[b]alance", 5, 0, " "},
"marketcap": &t{color.Black, "[m]arket cap", 5, 0, " "},
"24hvolume": &t{color.Black, "24H [v]olume", 3, 0, " "},
"1hchange": &t{color.Black, "[1]H%", 5, 0, " "},
"24hchange": &t{color.Black, "[2]4H%", 3, 0, " "},
"7dchange": &t{color.Black, "[7]D%", 4, 0, " "},
"totalsupply": &t{color.Black, "[t]otal supply", 7, 0, " "},
"availablesupply": &t{color.Black, "[a]vailable supply", 0, 0, " "},
"percentholdings": &t{color.Black, "%holdings", 2, 0, " "},
"lastupdated": &t{color.Black, "last [u]pdated", 3, 0, " "},
"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, " "},
}
for k := range cm {
cm[k].arrow = " "
if ct.sortby == k {
cm[k].colorfn = color.CyanBg
cm[k].colorfn = ct.colorscheme.TableHeaderColumnActiveSprintf()
if ct.sortdesc {
cm[k].arrow = "▼"
} else {

@ -4,7 +4,6 @@ import (
"fmt"
"sort"
"github.com/miguelmota/cointop/cointop/common/color"
"github.com/miguelmota/cointop/cointop/common/pad"
)
@ -23,7 +22,7 @@ func (ct *Cointop) updateHelp() {
}
sort.Strings(keys)
header := color.GreenBg(fmt.Sprintf(" Help %s\n\n", pad.Left("[q] close ", ct.maxtablewidth-10, " ")))
header := ct.colorscheme.MenuHeader(fmt.Sprintf(" Help %s\n\n", pad.Left("[q] close ", ct.maxtablewidth-10, " ")))
cnt := 0
h := ct.viewHeight(ct.helpviewname)
percol := h - 6
@ -36,7 +35,7 @@ func (ct *Cointop) updateHelp() {
if cnt%percol == 0 {
cnt = 0
}
item := fmt.Sprintf("%10s %-40s", k, color.Yellow(v))
item := fmt.Sprintf("%10s %-40s", k, ct.colorscheme.MenuLabel(v))
cols[cnt] = append(cols[cnt], item)
cnt = cnt + 1
}

@ -19,8 +19,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
}
ct.marketbarview = v
ct.marketbarview.Frame = false
ct.marketbarview.BgColor = gocui.ColorDefault
ct.marketbarview.FgColor = gocui.ColorDefault
ct.colorscheme.SetViewColor(ct.marketbarview, "marketbar")
go func() {
ct.updateMarketbar()
_, found := ct.cache.Get(ct.marketbarviewname)
@ -38,7 +37,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
}
ct.chartview = v
ct.chartview.Frame = false
ct.chartview.BgColor = gocui.ColorDefault
ct.colorscheme.SetViewColor(ct.chartview, "chart")
go func() {
ct.updateChart()
cachekey := strings.ToLower(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.selectedchartrange, " ", "", -1)))
@ -57,8 +56,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
}
ct.headersview = v
ct.headersview.Frame = false
ct.headersview.FgColor = gocui.ColorBlack
ct.headersview.BgColor = gocui.ColorGreen
ct.colorscheme.SetViewColor(ct.headersview, "table_header")
go ct.updateHeaders()
}
@ -70,8 +68,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
ct.tableview = v
ct.tableview.Frame = false
ct.tableview.Highlight = true
ct.tableview.SelBgColor = gocui.ColorCyan
ct.tableview.SelFgColor = gocui.ColorBlack
ct.colorscheme.SetViewActiveColor(ct.tableview, "table_row_active")
_, found := ct.cache.Get("allcoinsslugmap")
if found {
ct.cache.Delete("allcoinsslugmap")
@ -88,8 +85,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
}
ct.statusbarview = v
ct.statusbarview.Frame = false
ct.statusbarview.BgColor = gocui.ColorCyan
ct.statusbarview.FgColor = gocui.ColorBlack
ct.colorscheme.SetViewColor(ct.statusbarview, "statusbar")
go ct.updateStatusbar("")
}
@ -101,7 +97,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
ct.searchfield.Editable = true
ct.searchfield.Wrap = true
ct.searchfield.Frame = false
ct.searchfield.FgColor = gocui.ColorWhite
ct.colorscheme.SetViewColor(ct.searchfield, "searchbar")
}
if v, err := g.SetView(ct.helpviewname, 1, 1, ct.maxtablewidth-2, maxY-1); err != nil {
@ -110,8 +106,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
}
ct.helpview = v
ct.helpview.Frame = false
ct.helpview.BgColor = gocui.ColorBlack
ct.helpview.FgColor = gocui.ColorWhite
ct.colorscheme.SetViewColor(ct.helpview, "menu")
}
if v, err := g.SetView(ct.portfolioupdatemenuviewname, 1, 1, ct.maxtablewidth-2, maxY-1); err != nil {
@ -120,8 +115,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
}
ct.portfolioupdatemenuview = v
ct.portfolioupdatemenuview.Frame = false
ct.portfolioupdatemenuview.BgColor = gocui.ColorBlack
ct.portfolioupdatemenuview.FgColor = gocui.ColorWhite
ct.colorscheme.SetViewColor(ct.portfolioupdatemenuview, "menu")
}
if v, err := g.SetView(ct.inputviewname, 3, 6, 30, 8); err != nil {
@ -132,8 +126,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
ct.inputview.Frame = true
ct.inputview.Editable = true
ct.inputview.Wrap = true
ct.inputview.BgColor = gocui.ColorBlack
ct.inputview.FgColor = gocui.ColorWhite
ct.colorscheme.SetViewColor(ct.inputview, "menu")
}
if v, err := g.SetView(ct.convertmenuviewname, 1, 1, ct.maxtablewidth-2, maxY-1); err != nil {
@ -142,8 +135,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
}
ct.convertmenuview = v
ct.convertmenuview.Frame = false
ct.convertmenuview.BgColor = gocui.ColorBlack
ct.convertmenuview.FgColor = gocui.ColorWhite
ct.colorscheme.SetViewColor(ct.convertmenuview, "menu")
// run only once on init.
// this bit of code should be at the bottom

@ -14,7 +14,10 @@ import (
func (ct *Cointop) updateMarketbar() error {
maxX := ct.width()
logo := fmt.Sprintf("%s%s%s%s", color.Green(""), color.Cyan(""), color.Green(""), color.Cyan("cointop"))
logo := "cointop"
if ct.colorschemename == "cointop" {
logo = fmt.Sprintf("%s%s%s%s", color.Green(""), color.Cyan(""), color.Green(""), color.Cyan("cointop"))
}
var content string
if ct.portfoliovisible {
@ -30,9 +33,9 @@ func (ct *Cointop) updateMarketbar() error {
var charttitle string
if chartname == "" {
chartname = "Portfolio"
charttitle = color.Cyan(chartname)
charttitle = ct.colorscheme.MarketBarLabelActive(chartname)
} else {
charttitle = fmt.Sprintf("Portfolio - %s", color.Cyan(chartname))
charttitle = fmt.Sprintf("Portfolio - %s", ct.colorscheme.MarketBarLabelActive(chartname))
}
var percentChange24H float64
@ -44,14 +47,14 @@ func (ct *Cointop) updateMarketbar() error {
percentChange24H += n
}
color24h := color.White
color24h := ct.colorscheme.MarketbarSprintf()
arrow := ""
if percentChange24H > 0 {
color24h = color.Green
color24h = ct.colorscheme.MarketbarChangeUpSprintf()
arrow = "▲"
}
if percentChange24H < 0 {
color24h = color.Red
color24h = ct.colorscheme.MarketbarChangeDownSprintf()
arrow = "▼"
}
@ -59,7 +62,7 @@ func (ct *Cointop) updateMarketbar() error {
"[ Chart: %s %s ] Total Portfolio Value: %s • 24H: %s",
charttitle,
timeframe,
color.Cyan(fmt.Sprintf("%s%s", ct.currencySymbol(), totalstr)),
ct.colorscheme.MarketBarLabelActive(fmt.Sprintf("%s%s", ct.currencySymbol(), totalstr)),
color24h(fmt.Sprintf("%.2f%%%s", percentChange24H, arrow)),
)
} else {
@ -97,7 +100,7 @@ func (ct *Cointop) updateMarketbar() error {
content = fmt.Sprintf(
"[ Chart: %s %s ] Global ▶ Market Cap: %s • 24H Volume: %s • BTC Dominance: %.2f%%",
color.Cyan(chartname),
ct.colorscheme.MarketBarLabelActive(chartname),
timeframe,
fmt.Sprintf("%s%s", ct.currencySymbol(), humanize.Commaf(market.TotalMarketCapUSD)),
fmt.Sprintf("%s%s", ct.currencySymbol(), humanize.Commaf(market.Total24HVolumeUSD)),
@ -107,6 +110,7 @@ func (ct *Cointop) updateMarketbar() error {
content = fmt.Sprintf("%s %s", logo, content)
content = pad.Right(content, maxX, " ")
content = ct.colorscheme.Marketbar(content)
ct.update(func() {
ct.marketbarview.Clear()

@ -7,7 +7,6 @@ import (
"strconv"
"strings"
"github.com/miguelmota/cointop/cointop/common/color"
"github.com/miguelmota/cointop/cointop/common/pad"
)
@ -48,8 +47,8 @@ func (ct *Cointop) updatePortfolioUpdateMenu() {
mode = "Add"
submitText = "Add"
}
header := color.GreenBg(fmt.Sprintf(" %s Portfolio Entry %s\n\n", mode, pad.Left("[q] close ", ct.maxtablewidth-26, " ")))
label := fmt.Sprintf(" Enter holdings for %s %s", color.Yellow(coin.Name), current)
header := ct.colorscheme.MenuHeader(fmt.Sprintf(" %s Portfolio Entry %s\n\n", mode, pad.Left("[q] close ", ct.maxtablewidth-26, " ")))
label := fmt.Sprintf(" Enter holdings for %s %s", ct.colorscheme.MenuLabel(coin.Name), current)
content := fmt.Sprintf("%s\n%s\n\n%s%s\n\n\n [Enter] %s [ESC] Cancel", header, label, strings.Repeat(" ", 29), coin.Symbol, submitText)
ct.update(func() {

@ -8,7 +8,6 @@ import (
"strings"
"time"
"github.com/miguelmota/cointop/cointop/common/color"
"github.com/miguelmota/cointop/cointop/common/humanize"
"github.com/miguelmota/cointop/cointop/common/pad"
"github.com/miguelmota/cointop/cointop/common/table"
@ -35,20 +34,18 @@ func (ct *Cointop) refreshTable() error {
for _, coin := range ct.coins {
unix, _ := strconv.ParseInt(coin.LastUpdated, 10, 64)
lastUpdated := time.Unix(unix, 0).Format("15:04:05 Jan 02")
namecolor := color.White
colorprice := color.White
colorbalance := color.Cyan
color24h := color.White
colorbalance := ct.colorscheme.TableColumnPrice
color24h := ct.colorscheme.TableColumnChange
if coin.PercentChange24H > 0 {
color24h = color.Green
color24h = ct.colorscheme.TableColumnChangeUp
}
if coin.PercentChange24H < 0 {
color24h = color.Red
color24h = ct.colorscheme.TableColumnChangeDown
}
name := coin.Name
dots := "..."
star := " "
rank := fmt.Sprintf("%s%v", color.Yellow(star), color.White(fmt.Sprintf("%6v ", coin.Rank)))
rank := fmt.Sprintf("%s%v", star, ct.colorscheme.TableRow(fmt.Sprintf("%6v ", coin.Rank)))
if len(name) > 20 {
name = fmt.Sprintf("%s%s", name[0:18], dots)
}
@ -60,14 +57,14 @@ func (ct *Cointop) refreshTable() error {
ct.table.AddRow(
rank,
namecolor(pad.Right(fmt.Sprintf("%.22s", name), 21, " ")),
ct.colorscheme.RowText(pad.Right(fmt.Sprintf("%.6s", coin.Symbol), 5, " ")),
colorprice(fmt.Sprintf("%13s", humanize.Commaf(coin.Price))),
color.White(fmt.Sprintf("%15s", strconv.FormatFloat(coin.Holdings, 'f', -1, 64))),
ct.colorscheme.TableRow(pad.Right(fmt.Sprintf("%.22s", name), 21, " ")),
ct.colorscheme.TableRow(pad.Right(fmt.Sprintf("%.6s", coin.Symbol), 5, " ")),
ct.colorscheme.TableRow(fmt.Sprintf("%13s", humanize.Commaf(coin.Price))),
ct.colorscheme.TableRow(fmt.Sprintf("%15s", strconv.FormatFloat(coin.Holdings, 'f', -1, 64))),
colorbalance(fmt.Sprintf("%15s", humanize.Commaf(coin.Balance))),
color24h(fmt.Sprintf("%8.2f%%", coin.PercentChange24H)),
color.White(fmt.Sprintf("%10.2f%%", percentHoldings)),
color.White(pad.Right(fmt.Sprintf("%17s", lastUpdated), 80, " ")),
ct.colorscheme.TableRow(fmt.Sprintf("%10.2f%%", percentHoldings)),
ct.colorscheme.TableRow(pad.Right(fmt.Sprintf("%17s", lastUpdated), 80, " ")),
)
}
} else {
@ -89,39 +86,38 @@ func (ct *Cointop) refreshTable() error {
}
unix, _ := strconv.ParseInt(coin.LastUpdated, 10, 64)
lastUpdated := time.Unix(unix, 0).Format("15:04:05 Jan 02")
namecolor := color.White
colorprice := color.Cyan
color1h := color.White
color24h := color.White
color7d := color.White
namecolor := ct.colorscheme.TableRow
color1h := ct.colorscheme.TableColumnChange
color24h := ct.colorscheme.TableColumnChange
color7d := ct.colorscheme.TableColumnChange
if coin.Favorite {
namecolor = color.Yellow
namecolor = ct.colorscheme.TableRowFavorite
}
if coin.PercentChange1H > 0 {
color1h = color.Green
color1h = ct.colorscheme.TableColumnChangeUp
}
if coin.PercentChange1H < 0 {
color1h = color.Red
color1h = ct.colorscheme.TableColumnChangeDown
}
if coin.PercentChange24H > 0 {
color24h = color.Green
color24h = ct.colorscheme.TableColumnChangeUp
}
if coin.PercentChange24H < 0 {
color24h = color.Red
color24h = ct.colorscheme.TableColumnChangeDown
}
if coin.PercentChange7D > 0 {
color7d = color.Green
color7d = ct.colorscheme.TableColumnChangeUp
}
if coin.PercentChange7D < 0 {
color7d = color.Red
color7d = ct.colorscheme.TableColumnChangeDown
}
name := coin.Name
dots := "..."
star := " "
star := ct.colorscheme.TableRow(" ")
if coin.Favorite {
star = "*"
star = ct.colorscheme.TableRowFavorite("*")
}
rank := fmt.Sprintf("%s%v", color.Yellow(star), color.White(fmt.Sprintf("%6v ", coin.Rank)))
rank := fmt.Sprintf("%s%v", star, ct.colorscheme.TableRow(fmt.Sprintf("%6v ", coin.Rank)))
if len(name) > 20 {
name = fmt.Sprintf("%s%s", name[0:18], dots)
}
@ -135,16 +131,16 @@ func (ct *Cointop) refreshTable() error {
ct.table.AddRow(
rank,
namecolor(pad.Right(fmt.Sprintf("%.22s", name), 21, " ")),
ct.colorscheme.RowText(pad.Right(fmt.Sprintf("%.6s", coin.Symbol), symbolpadding, " ")),
colorprice(fmt.Sprintf("%12s", humanize.Commaf(coin.Price))),
color.White(fmt.Sprintf("%18s", humanize.Commaf(coin.MarketCap))),
color.White(fmt.Sprintf("%15s", humanize.Commaf(coin.Volume24H))),
ct.colorscheme.TableRow(pad.Right(fmt.Sprintf("%.6s", coin.Symbol), symbolpadding, " ")),
ct.colorscheme.TableColumnPrice(fmt.Sprintf("%12s", humanize.Commaf(coin.Price))),
ct.colorscheme.TableRow(fmt.Sprintf("%18s", humanize.Commaf(coin.MarketCap))),
ct.colorscheme.TableRow(fmt.Sprintf("%15s", humanize.Commaf(coin.Volume24H))),
color1h(fmt.Sprintf("%8.2f%%", coin.PercentChange1H)),
color24h(fmt.Sprintf("%8.2f%%", coin.PercentChange24H)),
color7d(fmt.Sprintf("%8.2f%%", coin.PercentChange7D)),
color.White(fmt.Sprintf("%21s", humanize.Commaf(coin.TotalSupply))),
color.White(fmt.Sprintf("%18s", humanize.Commaf(coin.AvailableSupply))),
color.White(fmt.Sprintf("%18s", lastUpdated)),
ct.colorscheme.TableRow(fmt.Sprintf("%21s", humanize.Commaf(coin.TotalSupply))),
ct.colorscheme.TableRow(fmt.Sprintf("%18s", humanize.Commaf(coin.AvailableSupply))),
ct.colorscheme.TableRow(fmt.Sprintf("%18s", lastUpdated)),
// TODO: add %percent of cap
)
}

Loading…
Cancel
Save