mirror of
https://github.com/miguelmota/cointop
synced 2024-11-10 13:10:26 +00:00
Use theme styles
This commit is contained in:
parent
81af942dbf
commit
12d56decc3
@ -7,7 +7,6 @@ import (
|
|||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/gizak/termui"
|
"github.com/gizak/termui"
|
||||||
"github.com/miguelmota/cointop/cointop/common/color"
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/filecache"
|
"github.com/miguelmota/cointop/cointop/common/filecache"
|
||||||
"github.com/miguelmota/cointop/cointop/common/timeutil"
|
"github.com/miguelmota/cointop/cointop/common/timeutil"
|
||||||
)
|
)
|
||||||
@ -47,7 +46,7 @@ func (ct *Cointop) updateChart() error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
ct.update(func() {
|
ct.update(func() {
|
||||||
fmt.Fprint(ct.chartview, color.White(body))
|
fmt.Fprint(ct.chartview, ct.colorscheme.Chart(body))
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
@ -62,8 +61,6 @@ func (ct *Cointop) chartPoints(symbol string, name string) error {
|
|||||||
|
|
||||||
chart := termui.NewLineChart()
|
chart := termui.NewLineChart()
|
||||||
chart.Height = 10
|
chart.Height = 10
|
||||||
chart.AxesColor = termui.ColorWhite
|
|
||||||
chart.LineColor = termui.ColorCyan
|
|
||||||
chart.Border = false
|
chart.Border = false
|
||||||
|
|
||||||
// NOTE: empty list means don't show x-axis labels
|
// NOTE: empty list means don't show x-axis labels
|
||||||
@ -161,10 +158,11 @@ func (ct *Cointop) portfolioChart() error {
|
|||||||
|
|
||||||
chart := termui.NewLineChart()
|
chart := termui.NewLineChart()
|
||||||
chart.Height = 10
|
chart.Height = 10
|
||||||
chart.AxesColor = termui.ColorWhite
|
|
||||||
chart.LineColor = termui.ColorCyan
|
|
||||||
chart.Border = false
|
chart.Border = false
|
||||||
|
|
||||||
|
// NOTE: empty list means don't show x-axis labels
|
||||||
|
chart.DataLabels = []string{""}
|
||||||
|
|
||||||
rangeseconds := ct.chartrangesmap[ct.selectedchartrange]
|
rangeseconds := ct.chartrangesmap[ct.selectedchartrange]
|
||||||
if ct.selectedchartrange == "YTD" {
|
if ct.selectedchartrange == "YTD" {
|
||||||
ytd := time.Now().Unix() - int64(timeutil.BeginningOfYear().Unix())
|
ytd := time.Now().Unix() - int64(timeutil.BeginningOfYear().Unix())
|
||||||
|
@ -315,16 +315,16 @@ func NewCointop(config *Config) *Cointop {
|
|||||||
// Run runs cointop
|
// Run runs cointop
|
||||||
func (ct *Cointop) Run() {
|
func (ct *Cointop) Run() {
|
||||||
g, err := gocui.NewGui(gocui.Output256)
|
g, err := gocui.NewGui(gocui.Output256)
|
||||||
g.BgColor = gocui.ColorDefault
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("new gocui: %v", err)
|
log.Fatalf("new gocui: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g.FgColor = ct.colorscheme.BaseFg()
|
||||||
|
g.BgColor = ct.colorscheme.BaseBg()
|
||||||
ct.g = g
|
ct.g = g
|
||||||
defer g.Close()
|
defer g.Close()
|
||||||
g.InputEsc = true
|
g.InputEsc = true
|
||||||
//g.BgColor = gocui.ColorBlack
|
|
||||||
g.FgColor = gocui.ColorWhite
|
|
||||||
g.Mouse = true
|
g.Mouse = true
|
||||||
g.Highlight = true
|
g.Highlight = true
|
||||||
g.SetManagerFunc(ct.layout)
|
g.SetManagerFunc(ct.layout)
|
||||||
|
@ -2,66 +2,25 @@ package cointop
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/fatih/color"
|
"github.com/fatih/color"
|
||||||
|
"github.com/jroimartin/gocui"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Colors ..
|
// colorschemeColors ..
|
||||||
type Colors map[string]interface{}
|
type colorschemeColors map[string]interface{}
|
||||||
|
|
||||||
// Cache ..
|
// ISprintf ...
|
||||||
type Cache map[string]func(...interface{}) string
|
type ISprintf func(...interface{}) string
|
||||||
|
|
||||||
|
// colorCache ..
|
||||||
|
type colorCache map[string]ISprintf
|
||||||
|
|
||||||
// ColorScheme ...
|
// ColorScheme ...
|
||||||
type ColorScheme struct {
|
type ColorScheme struct {
|
||||||
colors Colors
|
colors colorschemeColors
|
||||||
cache Cache
|
cache colorCache
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewColorScheme ...
|
var fgcolorschemeColorsMap = map[string]color.Attribute{
|
||||||
func NewColorScheme(colors Colors) *ColorScheme {
|
|
||||||
return &ColorScheme{
|
|
||||||
colors: colors,
|
|
||||||
cache: make(Cache),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// RowText ...
|
|
||||||
func (c *ColorScheme) RowText(a ...interface{}) string {
|
|
||||||
name := "row_text"
|
|
||||||
return c.color(name, a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (c *ColorScheme) color(name string, a ...interface{}) string {
|
|
||||||
if cached, ok := c.cache[name]; ok {
|
|
||||||
return cached(a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
var colors []color.Attribute
|
|
||||||
if v, ok := c.colors[name+"_fg"].(string); ok {
|
|
||||||
if fg, ok := toFgAttr(v); ok {
|
|
||||||
colors = append(colors, fg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if v, ok := c.colors[name+"_bg"].(string); ok {
|
|
||||||
if bg, ok := toBgAttr(v); ok {
|
|
||||||
colors = append(colors, bg)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if v, ok := c.colors[name+"_bold"].(bool); ok {
|
|
||||||
if bold, ok := toBoldAttr(v); ok {
|
|
||||||
colors = append(colors, bold)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if v, ok := c.colors[name+"_underline"].(bool); ok {
|
|
||||||
if underline, ok := toUnderlineAttr(v); ok {
|
|
||||||
colors = append(colors, underline)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
c.cache[name] = color.New(colors...).SprintFunc()
|
|
||||||
return c.cache[name](a...)
|
|
||||||
}
|
|
||||||
|
|
||||||
var fgColorsMap = map[string]color.Attribute{
|
|
||||||
"black": color.FgBlack,
|
"black": color.FgBlack,
|
||||||
"blue": color.FgBlue,
|
"blue": color.FgBlue,
|
||||||
"cyan": color.FgCyan,
|
"cyan": color.FgCyan,
|
||||||
@ -72,7 +31,7 @@ var fgColorsMap = map[string]color.Attribute{
|
|||||||
"yellow": color.FgYellow,
|
"yellow": color.FgYellow,
|
||||||
}
|
}
|
||||||
|
|
||||||
var bgColorsMap = map[string]color.Attribute{
|
var bgcolorschemeColorsMap = map[string]color.Attribute{
|
||||||
"black": color.BgBlack,
|
"black": color.BgBlack,
|
||||||
"blue": color.BgBlue,
|
"blue": color.BgBlue,
|
||||||
"cyan": color.BgCyan,
|
"cyan": color.BgCyan,
|
||||||
@ -83,27 +42,274 @@ var bgColorsMap = map[string]color.Attribute{
|
|||||||
"yellow": color.BgYellow,
|
"yellow": color.BgYellow,
|
||||||
}
|
}
|
||||||
|
|
||||||
func toFgAttr(c string) (color.Attribute, bool) {
|
var gocuicolorschemeColorsMap = map[string]gocui.Attribute{
|
||||||
attr, ok := fgColorsMap[c]
|
"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 colorschemeColors) *ColorScheme {
|
||||||
|
return &ColorScheme{
|
||||||
|
colors: colors,
|
||||||
|
cache: make(colorCache),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// BaseFg ...
|
||||||
|
func (c *ColorScheme) BaseFg() gocui.Attribute {
|
||||||
|
return c.gocuiFgColor("base")
|
||||||
|
}
|
||||||
|
|
||||||
|
// 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
|
||||||
|
}
|
||||||
|
|
||||||
|
var colors []color.Attribute
|
||||||
|
if v, ok := c.colors[name+"_fg"].(string); ok {
|
||||||
|
if fg, ok := c.toFgAttr(v); ok {
|
||||||
|
colors = append(colors, fg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := c.colors[name+"_bg"].(string); ok {
|
||||||
|
if bg, ok := c.toBgAttr(v); ok {
|
||||||
|
colors = append(colors, bg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := c.colors[name+"_bold"].(bool); ok {
|
||||||
|
if bold, ok := c.toBoldAttr(v); ok {
|
||||||
|
colors = append(colors, bold)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if v, ok := c.colors[name+"_underline"].(bool); ok {
|
||||||
|
if underline, ok := c.toUnderlineAttr(v); ok {
|
||||||
|
colors = append(colors, underline)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
c.cache[name] = color.New(colors...).SprintFunc()
|
||||||
|
return c.cache[name]
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *ColorScheme) color(name string, a ...interface{}) string {
|
||||||
|
return c.toSprintf(name)(a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
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 (c *ColorScheme) toFgAttr(k string) (color.Attribute, bool) {
|
||||||
|
attr, ok := fgcolorschemeColorsMap[k]
|
||||||
return attr, ok
|
return attr, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func toBgAttr(c string) (color.Attribute, bool) {
|
func (c *ColorScheme) toBgAttr(k string) (color.Attribute, bool) {
|
||||||
attr, ok := bgColorsMap[c]
|
attr, ok := bgcolorschemeColorsMap[k]
|
||||||
return attr, ok
|
return attr, ok
|
||||||
}
|
}
|
||||||
|
|
||||||
func toBoldAttr(v bool) (color.Attribute, bool) {
|
func (c *ColorScheme) toBoldAttr(v bool) (color.Attribute, bool) {
|
||||||
return color.Bold, v
|
return color.Bold, v
|
||||||
}
|
}
|
||||||
|
|
||||||
func toUnderlineAttr(v bool) (color.Attribute, bool) {
|
func (c *ColorScheme) toUnderlineAttr(v bool) (color.Attribute, bool) {
|
||||||
return color.Underline, v
|
return color.Underline, v
|
||||||
}
|
}
|
||||||
|
|
||||||
// CointopColorscheme ...
|
func (c *ColorScheme) toGocuiAttr(k string) (gocui.Attribute, bool) {
|
||||||
var CointopColorscheme = `
|
attr, ok := gocuicolorschemeColorsMap[k]
|
||||||
row_text_fg = "white"
|
return attr, ok
|
||||||
row_text_bg = ""
|
}
|
||||||
row_text_bold = false
|
|
||||||
`
|
|
||||||
|
@ -6,6 +6,8 @@ import "github.com/fatih/color"
|
|||||||
type Color color.Color
|
type Color color.Color
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
// Bold color
|
||||||
|
Bold = color.New(color.Bold).SprintFunc()
|
||||||
// Black color
|
// Black color
|
||||||
Black = color.New(color.FgBlack).SprintFunc()
|
Black = color.New(color.FgBlack).SprintFunc()
|
||||||
// BlackBg color
|
// BlackBg color
|
||||||
|
@ -63,10 +63,21 @@ func (ct *Cointop) createConfigIfNotExists() error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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()
|
err = ct.makeConfigFile()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -92,14 +103,6 @@ func (ct *Cointop) makeConfigDir() error {
|
|||||||
func (ct *Cointop) makeConfigFile() error {
|
func (ct *Cointop) makeConfigFile() error {
|
||||||
path := ct.configPath()
|
path := ct.configPath()
|
||||||
if _, err := os.Stat(path); os.IsNotExist(err) {
|
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)
|
fo, err := os.Create(path)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -177,19 +180,22 @@ func (ct *Cointop) configToToml() ([]byte, error) {
|
|||||||
|
|
||||||
var currencyIfc interface{} = ct.currencyconversion
|
var currencyIfc interface{} = ct.currencyconversion
|
||||||
var defaultViewIfc interface{} = ct.defaultView
|
var defaultViewIfc interface{} = ct.defaultView
|
||||||
|
var colorschemeIfc interface{} = ct.colorschemename
|
||||||
|
|
||||||
cmcIfc := map[string]interface{}{
|
cmcIfc := map[string]interface{}{
|
||||||
"pro_api_key": ct.apiKeys.cmc,
|
"pro_api_key": ct.apiKeys.cmc,
|
||||||
}
|
}
|
||||||
var apiChoiceIfc interface{} = ct.apiChoice
|
var apiChoiceIfc interface{} = ct.apiChoice
|
||||||
|
|
||||||
var inputs = &config{
|
var inputs = &config{
|
||||||
Shortcuts: shortcutsIfcs,
|
API: apiChoiceIfc,
|
||||||
Favorites: favoritesIfcs,
|
ColorScheme: colorschemeIfc,
|
||||||
Portfolio: portfolioIfc,
|
CoinMarketCap: cmcIfc,
|
||||||
Currency: currencyIfc,
|
Currency: currencyIfc,
|
||||||
DefaultView: defaultViewIfc,
|
DefaultView: defaultViewIfc,
|
||||||
CoinMarketCap: cmcIfc,
|
Favorites: favoritesIfcs,
|
||||||
API: apiChoiceIfc,
|
Shortcuts: shortcutsIfcs,
|
||||||
|
Portfolio: portfolioIfc,
|
||||||
}
|
}
|
||||||
|
|
||||||
var b bytes.Buffer
|
var b bytes.Buffer
|
||||||
@ -262,7 +268,7 @@ func (ct *Cointop) loadColorSchemeFromConfig() error {
|
|||||||
var colors map[string]interface{}
|
var colors map[string]interface{}
|
||||||
if ct.colorschemename == "" {
|
if ct.colorschemename == "" {
|
||||||
ct.colorschemename = "cointop"
|
ct.colorschemename = "cointop"
|
||||||
if _, err := toml.Decode(CointopColorscheme, &colors); err != nil {
|
if _, err := toml.Decode(DefaultColors, &colors); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,7 +4,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/color"
|
color "github.com/miguelmota/cointop/cointop/common/color"
|
||||||
"github.com/miguelmota/cointop/cointop/common/pad"
|
"github.com/miguelmota/cointop/cointop/common/pad"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -128,7 +128,7 @@ func (ct *Cointop) toggleConvertMenu() error {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ct *Cointop) updateConvertMenu() {
|
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"
|
helpline := " Press the corresponding key to select currency for conversion\n\n"
|
||||||
cnt := 0
|
cnt := 0
|
||||||
h := ct.viewHeight(ct.convertmenuviewname)
|
h := ct.viewHeight(ct.convertmenuviewname)
|
||||||
@ -147,12 +147,12 @@ func (ct *Cointop) updateConvertMenu() {
|
|||||||
}
|
}
|
||||||
shortcut := string(alphanumericcharacters[i])
|
shortcut := string(alphanumericcharacters[i])
|
||||||
if key == ct.currencyconversion {
|
if key == ct.currencyconversion {
|
||||||
shortcut = color.YellowBold("*")
|
shortcut = ct.colorscheme.MenuLabelActive(color.Bold("*"))
|
||||||
key = color.WhiteBold(key)
|
key = ct.colorscheme.Menu(color.Bold(key))
|
||||||
currency = color.YellowBold(currency)
|
currency = ct.colorscheme.MenuLabelActive(color.Bold(currency))
|
||||||
} else {
|
} else {
|
||||||
key = color.White(key)
|
key = ct.colorscheme.Menu(key)
|
||||||
currency = color.Yellow(currency)
|
currency = ct.colorscheme.MenuLabel(currency)
|
||||||
}
|
}
|
||||||
item := fmt.Sprintf(" [ %1s ] %4s %-34s", shortcut, key, currency)
|
item := fmt.Sprintf(" [ %1s ] %4s %-34s", shortcut, key, currency)
|
||||||
cols[cnt] = append(cols[cnt], item)
|
cols[cnt] = append(cols[cnt], item)
|
||||||
|
81
cointop/defaultcolors.go
Normal file
81
cointop/defaultcolors.go
Normal file
@ -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 (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/color"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func (ct *Cointop) updateHeaders() {
|
func (ct *Cointop) updateHeaders() {
|
||||||
@ -18,28 +16,29 @@ func (ct *Cointop) updateHeaders() {
|
|||||||
arrow string
|
arrow string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
baseColor := ct.colorscheme.TableHeaderSprintf()
|
||||||
cm := map[string]*t{
|
cm := map[string]*t{
|
||||||
"rank": &t{color.Black, "[r]ank", 0, 1, " "},
|
"rank": &t{baseColor, "[r]ank", 0, 1, " "},
|
||||||
"name": &t{color.Black, "[n]ame", 0, 11, " "},
|
"name": &t{baseColor, "[n]ame", 0, 11, " "},
|
||||||
"symbol": &t{color.Black, "[s]ymbol", 4, 0, " "},
|
"symbol": &t{baseColor, "[s]ymbol", 4, 0, " "},
|
||||||
"price": &t{color.Black, "[p]rice", 2, 0, " "},
|
"price": &t{baseColor, "[p]rice", 2, 0, " "},
|
||||||
"holdings": &t{color.Black, "[h]oldings", 5, 0, " "},
|
"holdings": &t{baseColor, "[h]oldings", 5, 0, " "},
|
||||||
"balance": &t{color.Black, "[b]alance", 5, 0, " "},
|
"balance": &t{baseColor, "[b]alance", 5, 0, " "},
|
||||||
"marketcap": &t{color.Black, "[m]arket cap", 5, 0, " "},
|
"marketcap": &t{baseColor, "[m]arket cap", 5, 0, " "},
|
||||||
"24hvolume": &t{color.Black, "24H [v]olume", 3, 0, " "},
|
"24hvolume": &t{baseColor, "24H [v]olume", 3, 0, " "},
|
||||||
"1hchange": &t{color.Black, "[1]H%", 5, 0, " "},
|
"1hchange": &t{baseColor, "[1]H%", 5, 0, " "},
|
||||||
"24hchange": &t{color.Black, "[2]4H%", 3, 0, " "},
|
"24hchange": &t{baseColor, "[2]4H%", 3, 0, " "},
|
||||||
"7dchange": &t{color.Black, "[7]D%", 4, 0, " "},
|
"7dchange": &t{baseColor, "[7]D%", 4, 0, " "},
|
||||||
"totalsupply": &t{color.Black, "[t]otal supply", 7, 0, " "},
|
"totalsupply": &t{baseColor, "[t]otal supply", 7, 0, " "},
|
||||||
"availablesupply": &t{color.Black, "[a]vailable supply", 0, 0, " "},
|
"availablesupply": &t{baseColor, "[a]vailable supply", 0, 0, " "},
|
||||||
"percentholdings": &t{color.Black, "%holdings", 2, 0, " "},
|
"percentholdings": &t{baseColor, "%holdings", 2, 0, " "},
|
||||||
"lastupdated": &t{color.Black, "last [u]pdated", 3, 0, " "},
|
"lastupdated": &t{baseColor, "last [u]pdated", 3, 0, " "},
|
||||||
}
|
}
|
||||||
|
|
||||||
for k := range cm {
|
for k := range cm {
|
||||||
cm[k].arrow = " "
|
cm[k].arrow = " "
|
||||||
if ct.sortby == k {
|
if ct.sortby == k {
|
||||||
cm[k].colorfn = color.CyanBg
|
cm[k].colorfn = ct.colorscheme.TableHeaderColumnActiveSprintf()
|
||||||
if ct.sortdesc {
|
if ct.sortdesc {
|
||||||
cm[k].arrow = "▼"
|
cm[k].arrow = "▼"
|
||||||
} else {
|
} else {
|
||||||
|
@ -4,7 +4,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"sort"
|
"sort"
|
||||||
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/color"
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/pad"
|
"github.com/miguelmota/cointop/cointop/common/pad"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -23,7 +22,7 @@ func (ct *Cointop) updateHelp() {
|
|||||||
}
|
}
|
||||||
sort.Strings(keys)
|
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
|
cnt := 0
|
||||||
h := ct.viewHeight(ct.helpviewname)
|
h := ct.viewHeight(ct.helpviewname)
|
||||||
percol := h - 6
|
percol := h - 6
|
||||||
@ -36,7 +35,7 @@ func (ct *Cointop) updateHelp() {
|
|||||||
if cnt%percol == 0 {
|
if cnt%percol == 0 {
|
||||||
cnt = 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)
|
cols[cnt] = append(cols[cnt], item)
|
||||||
cnt = cnt + 1
|
cnt = cnt + 1
|
||||||
}
|
}
|
||||||
|
@ -19,8 +19,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
ct.marketbarview = v
|
ct.marketbarview = v
|
||||||
ct.marketbarview.Frame = false
|
ct.marketbarview.Frame = false
|
||||||
ct.marketbarview.BgColor = gocui.ColorDefault
|
ct.colorscheme.SetViewColor(ct.marketbarview, "marketbar")
|
||||||
ct.marketbarview.FgColor = gocui.ColorDefault
|
|
||||||
go func() {
|
go func() {
|
||||||
ct.updateMarketbar()
|
ct.updateMarketbar()
|
||||||
_, found := ct.cache.Get(ct.marketbarviewname)
|
_, found := ct.cache.Get(ct.marketbarviewname)
|
||||||
@ -38,7 +37,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
ct.chartview = v
|
ct.chartview = v
|
||||||
ct.chartview.Frame = false
|
ct.chartview.Frame = false
|
||||||
ct.chartview.BgColor = gocui.ColorDefault
|
ct.colorscheme.SetViewColor(ct.chartview, "chart")
|
||||||
go func() {
|
go func() {
|
||||||
ct.updateChart()
|
ct.updateChart()
|
||||||
cachekey := strings.ToLower(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.selectedchartrange, " ", "", -1)))
|
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 = v
|
||||||
ct.headersview.Frame = false
|
ct.headersview.Frame = false
|
||||||
ct.headersview.FgColor = gocui.ColorBlack
|
ct.colorscheme.SetViewColor(ct.headersview, "table_header")
|
||||||
ct.headersview.BgColor = gocui.ColorGreen
|
|
||||||
go ct.updateHeaders()
|
go ct.updateHeaders()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +68,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
|
|||||||
ct.tableview = v
|
ct.tableview = v
|
||||||
ct.tableview.Frame = false
|
ct.tableview.Frame = false
|
||||||
ct.tableview.Highlight = true
|
ct.tableview.Highlight = true
|
||||||
ct.tableview.SelBgColor = gocui.ColorCyan
|
ct.colorscheme.SetViewActiveColor(ct.tableview, "table_row_active")
|
||||||
ct.tableview.SelFgColor = gocui.ColorBlack
|
|
||||||
_, found := ct.cache.Get("allcoinsslugmap")
|
_, found := ct.cache.Get("allcoinsslugmap")
|
||||||
if found {
|
if found {
|
||||||
ct.cache.Delete("allcoinsslugmap")
|
ct.cache.Delete("allcoinsslugmap")
|
||||||
@ -88,8 +85,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
|
|||||||
}
|
}
|
||||||
ct.statusbarview = v
|
ct.statusbarview = v
|
||||||
ct.statusbarview.Frame = false
|
ct.statusbarview.Frame = false
|
||||||
ct.statusbarview.BgColor = gocui.ColorCyan
|
ct.colorscheme.SetViewColor(ct.statusbarview, "statusbar")
|
||||||
ct.statusbarview.FgColor = gocui.ColorBlack
|
|
||||||
go ct.updateStatusbar("")
|
go ct.updateStatusbar("")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -101,7 +97,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error {
|
|||||||
ct.searchfield.Editable = true
|
ct.searchfield.Editable = true
|
||||||
ct.searchfield.Wrap = true
|
ct.searchfield.Wrap = true
|
||||||
ct.searchfield.Frame = false
|
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 {
|
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 = v
|
||||||
ct.helpview.Frame = false
|
ct.helpview.Frame = false
|
||||||
ct.helpview.BgColor = gocui.ColorBlack
|
ct.colorscheme.SetViewColor(ct.helpview, "menu")
|
||||||
ct.helpview.FgColor = gocui.ColorWhite
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := g.SetView(ct.portfolioupdatemenuviewname, 1, 1, ct.maxtablewidth-2, maxY-1); err != nil {
|
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 = v
|
||||||
ct.portfolioupdatemenuview.Frame = false
|
ct.portfolioupdatemenuview.Frame = false
|
||||||
ct.portfolioupdatemenuview.BgColor = gocui.ColorBlack
|
ct.colorscheme.SetViewColor(ct.portfolioupdatemenuview, "menu")
|
||||||
ct.portfolioupdatemenuview.FgColor = gocui.ColorWhite
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := g.SetView(ct.inputviewname, 3, 6, 30, 8); err != nil {
|
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.Frame = true
|
||||||
ct.inputview.Editable = true
|
ct.inputview.Editable = true
|
||||||
ct.inputview.Wrap = true
|
ct.inputview.Wrap = true
|
||||||
ct.inputview.BgColor = gocui.ColorBlack
|
ct.colorscheme.SetViewColor(ct.inputview, "menu")
|
||||||
ct.inputview.FgColor = gocui.ColorWhite
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if v, err := g.SetView(ct.convertmenuviewname, 1, 1, ct.maxtablewidth-2, maxY-1); err != nil {
|
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 = v
|
||||||
ct.convertmenuview.Frame = false
|
ct.convertmenuview.Frame = false
|
||||||
ct.convertmenuview.BgColor = gocui.ColorBlack
|
ct.colorscheme.SetViewColor(ct.convertmenuview, "menu")
|
||||||
ct.convertmenuview.FgColor = gocui.ColorWhite
|
|
||||||
|
|
||||||
// run only once on init.
|
// run only once on init.
|
||||||
// this bit of code should be at the bottom
|
// this bit of code should be at the bottom
|
||||||
|
@ -14,7 +14,10 @@ import (
|
|||||||
|
|
||||||
func (ct *Cointop) updateMarketbar() error {
|
func (ct *Cointop) updateMarketbar() error {
|
||||||
maxX := ct.width()
|
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
|
var content string
|
||||||
|
|
||||||
if ct.portfoliovisible {
|
if ct.portfoliovisible {
|
||||||
@ -30,9 +33,9 @@ func (ct *Cointop) updateMarketbar() error {
|
|||||||
var charttitle string
|
var charttitle string
|
||||||
if chartname == "" {
|
if chartname == "" {
|
||||||
chartname = "Portfolio"
|
chartname = "Portfolio"
|
||||||
charttitle = color.Cyan(chartname)
|
charttitle = ct.colorscheme.MarketBarLabelActive(chartname)
|
||||||
} else {
|
} else {
|
||||||
charttitle = fmt.Sprintf("Portfolio - %s", color.Cyan(chartname))
|
charttitle = fmt.Sprintf("Portfolio - %s", ct.colorscheme.MarketBarLabelActive(chartname))
|
||||||
}
|
}
|
||||||
|
|
||||||
var percentChange24H float64
|
var percentChange24H float64
|
||||||
@ -44,14 +47,14 @@ func (ct *Cointop) updateMarketbar() error {
|
|||||||
percentChange24H += n
|
percentChange24H += n
|
||||||
}
|
}
|
||||||
|
|
||||||
color24h := color.White
|
color24h := ct.colorscheme.MarketbarSprintf()
|
||||||
arrow := ""
|
arrow := ""
|
||||||
if percentChange24H > 0 {
|
if percentChange24H > 0 {
|
||||||
color24h = color.Green
|
color24h = ct.colorscheme.MarketbarChangeUpSprintf()
|
||||||
arrow = "▲"
|
arrow = "▲"
|
||||||
}
|
}
|
||||||
if percentChange24H < 0 {
|
if percentChange24H < 0 {
|
||||||
color24h = color.Red
|
color24h = ct.colorscheme.MarketbarChangeDownSprintf()
|
||||||
arrow = "▼"
|
arrow = "▼"
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,7 +62,7 @@ func (ct *Cointop) updateMarketbar() error {
|
|||||||
"[ Chart: %s %s ] Total Portfolio Value: %s • 24H: %s",
|
"[ Chart: %s %s ] Total Portfolio Value: %s • 24H: %s",
|
||||||
charttitle,
|
charttitle,
|
||||||
timeframe,
|
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)),
|
color24h(fmt.Sprintf("%.2f%%%s", percentChange24H, arrow)),
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
@ -97,7 +100,7 @@ func (ct *Cointop) updateMarketbar() error {
|
|||||||
|
|
||||||
content = fmt.Sprintf(
|
content = fmt.Sprintf(
|
||||||
"[ Chart: %s %s ] Global ▶ Market Cap: %s • 24H Volume: %s • BTC Dominance: %.2f%%",
|
"[ Chart: %s %s ] Global ▶ Market Cap: %s • 24H Volume: %s • BTC Dominance: %.2f%%",
|
||||||
color.Cyan(chartname),
|
ct.colorscheme.MarketBarLabelActive(chartname),
|
||||||
timeframe,
|
timeframe,
|
||||||
fmt.Sprintf("%s%s", ct.currencySymbol(), humanize.Commaf(market.TotalMarketCapUSD)),
|
fmt.Sprintf("%s%s", ct.currencySymbol(), humanize.Commaf(market.TotalMarketCapUSD)),
|
||||||
fmt.Sprintf("%s%s", ct.currencySymbol(), humanize.Commaf(market.Total24HVolumeUSD)),
|
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 = fmt.Sprintf("%s %s", logo, content)
|
||||||
content = pad.Right(content, maxX, " ")
|
content = pad.Right(content, maxX, " ")
|
||||||
|
content = ct.colorscheme.Marketbar(content)
|
||||||
|
|
||||||
ct.update(func() {
|
ct.update(func() {
|
||||||
ct.marketbarview.Clear()
|
ct.marketbarview.Clear()
|
||||||
|
@ -7,7 +7,6 @@ import (
|
|||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/color"
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/pad"
|
"github.com/miguelmota/cointop/cointop/common/pad"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -48,8 +47,8 @@ func (ct *Cointop) updatePortfolioUpdateMenu() {
|
|||||||
mode = "Add"
|
mode = "Add"
|
||||||
submitText = "Add"
|
submitText = "Add"
|
||||||
}
|
}
|
||||||
header := color.GreenBg(fmt.Sprintf(" %s Portfolio Entry %s\n\n", mode, pad.Left("[q] close ", ct.maxtablewidth-26, " ")))
|
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", color.Yellow(coin.Name), current)
|
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)
|
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() {
|
ct.update(func() {
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/color"
|
|
||||||
"github.com/miguelmota/cointop/cointop/common/humanize"
|
"github.com/miguelmota/cointop/cointop/common/humanize"
|
||||||
"github.com/miguelmota/cointop/cointop/common/pad"
|
"github.com/miguelmota/cointop/cointop/common/pad"
|
||||||
"github.com/miguelmota/cointop/cointop/common/table"
|
"github.com/miguelmota/cointop/cointop/common/table"
|
||||||
@ -35,20 +34,18 @@ func (ct *Cointop) refreshTable() error {
|
|||||||
for _, coin := range ct.coins {
|
for _, coin := range ct.coins {
|
||||||
unix, _ := strconv.ParseInt(coin.LastUpdated, 10, 64)
|
unix, _ := strconv.ParseInt(coin.LastUpdated, 10, 64)
|
||||||
lastUpdated := time.Unix(unix, 0).Format("15:04:05 Jan 02")
|
lastUpdated := time.Unix(unix, 0).Format("15:04:05 Jan 02")
|
||||||
namecolor := color.White
|
colorbalance := ct.colorscheme.TableColumnPrice
|
||||||
colorprice := color.White
|
color24h := ct.colorscheme.TableColumnChange
|
||||||
colorbalance := color.Cyan
|
|
||||||
color24h := color.White
|
|
||||||
if coin.PercentChange24H > 0 {
|
if coin.PercentChange24H > 0 {
|
||||||
color24h = color.Green
|
color24h = ct.colorscheme.TableColumnChangeUp
|
||||||
}
|
}
|
||||||
if coin.PercentChange24H < 0 {
|
if coin.PercentChange24H < 0 {
|
||||||
color24h = color.Red
|
color24h = ct.colorscheme.TableColumnChangeDown
|
||||||
}
|
}
|
||||||
name := coin.Name
|
name := coin.Name
|
||||||
dots := "..."
|
dots := "..."
|
||||||
star := " "
|
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 {
|
if len(name) > 20 {
|
||||||
name = fmt.Sprintf("%s%s", name[0:18], dots)
|
name = fmt.Sprintf("%s%s", name[0:18], dots)
|
||||||
}
|
}
|
||||||
@ -60,14 +57,14 @@ func (ct *Cointop) refreshTable() error {
|
|||||||
|
|
||||||
ct.table.AddRow(
|
ct.table.AddRow(
|
||||||
rank,
|
rank,
|
||||||
namecolor(pad.Right(fmt.Sprintf("%.22s", name), 21, " ")),
|
ct.colorscheme.TableRow(pad.Right(fmt.Sprintf("%.22s", name), 21, " ")),
|
||||||
ct.colorscheme.RowText(pad.Right(fmt.Sprintf("%.6s", coin.Symbol), 5, " ")),
|
ct.colorscheme.TableRow(pad.Right(fmt.Sprintf("%.6s", coin.Symbol), 5, " ")),
|
||||||
colorprice(fmt.Sprintf("%13s", humanize.Commaf(coin.Price))),
|
ct.colorscheme.TableRow(fmt.Sprintf("%13s", humanize.Commaf(coin.Price))),
|
||||||
color.White(fmt.Sprintf("%15s", strconv.FormatFloat(coin.Holdings, 'f', -1, 64))),
|
ct.colorscheme.TableRow(fmt.Sprintf("%15s", strconv.FormatFloat(coin.Holdings, 'f', -1, 64))),
|
||||||
colorbalance(fmt.Sprintf("%15s", humanize.Commaf(coin.Balance))),
|
colorbalance(fmt.Sprintf("%15s", humanize.Commaf(coin.Balance))),
|
||||||
color24h(fmt.Sprintf("%8.2f%%", coin.PercentChange24H)),
|
color24h(fmt.Sprintf("%8.2f%%", coin.PercentChange24H)),
|
||||||
color.White(fmt.Sprintf("%10.2f%%", percentHoldings)),
|
ct.colorscheme.TableRow(fmt.Sprintf("%10.2f%%", percentHoldings)),
|
||||||
color.White(pad.Right(fmt.Sprintf("%17s", lastUpdated), 80, " ")),
|
ct.colorscheme.TableRow(pad.Right(fmt.Sprintf("%17s", lastUpdated), 80, " ")),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@ -89,39 +86,38 @@ func (ct *Cointop) refreshTable() error {
|
|||||||
}
|
}
|
||||||
unix, _ := strconv.ParseInt(coin.LastUpdated, 10, 64)
|
unix, _ := strconv.ParseInt(coin.LastUpdated, 10, 64)
|
||||||
lastUpdated := time.Unix(unix, 0).Format("15:04:05 Jan 02")
|
lastUpdated := time.Unix(unix, 0).Format("15:04:05 Jan 02")
|
||||||
namecolor := color.White
|
namecolor := ct.colorscheme.TableRow
|
||||||
colorprice := color.Cyan
|
color1h := ct.colorscheme.TableColumnChange
|
||||||
color1h := color.White
|
color24h := ct.colorscheme.TableColumnChange
|
||||||
color24h := color.White
|
color7d := ct.colorscheme.TableColumnChange
|
||||||
color7d := color.White
|
|
||||||
if coin.Favorite {
|
if coin.Favorite {
|
||||||
namecolor = color.Yellow
|
namecolor = ct.colorscheme.TableRowFavorite
|
||||||
}
|
}
|
||||||
if coin.PercentChange1H > 0 {
|
if coin.PercentChange1H > 0 {
|
||||||
color1h = color.Green
|
color1h = ct.colorscheme.TableColumnChangeUp
|
||||||
}
|
}
|
||||||
if coin.PercentChange1H < 0 {
|
if coin.PercentChange1H < 0 {
|
||||||
color1h = color.Red
|
color1h = ct.colorscheme.TableColumnChangeDown
|
||||||
}
|
}
|
||||||
if coin.PercentChange24H > 0 {
|
if coin.PercentChange24H > 0 {
|
||||||
color24h = color.Green
|
color24h = ct.colorscheme.TableColumnChangeUp
|
||||||
}
|
}
|
||||||
if coin.PercentChange24H < 0 {
|
if coin.PercentChange24H < 0 {
|
||||||
color24h = color.Red
|
color24h = ct.colorscheme.TableColumnChangeDown
|
||||||
}
|
}
|
||||||
if coin.PercentChange7D > 0 {
|
if coin.PercentChange7D > 0 {
|
||||||
color7d = color.Green
|
color7d = ct.colorscheme.TableColumnChangeUp
|
||||||
}
|
}
|
||||||
if coin.PercentChange7D < 0 {
|
if coin.PercentChange7D < 0 {
|
||||||
color7d = color.Red
|
color7d = ct.colorscheme.TableColumnChangeDown
|
||||||
}
|
}
|
||||||
name := coin.Name
|
name := coin.Name
|
||||||
dots := "..."
|
dots := "..."
|
||||||
star := " "
|
star := ct.colorscheme.TableRow(" ")
|
||||||
if coin.Favorite {
|
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 {
|
if len(name) > 20 {
|
||||||
name = fmt.Sprintf("%s%s", name[0:18], dots)
|
name = fmt.Sprintf("%s%s", name[0:18], dots)
|
||||||
}
|
}
|
||||||
@ -135,16 +131,16 @@ func (ct *Cointop) refreshTable() error {
|
|||||||
ct.table.AddRow(
|
ct.table.AddRow(
|
||||||
rank,
|
rank,
|
||||||
namecolor(pad.Right(fmt.Sprintf("%.22s", name), 21, " ")),
|
namecolor(pad.Right(fmt.Sprintf("%.22s", name), 21, " ")),
|
||||||
ct.colorscheme.RowText(pad.Right(fmt.Sprintf("%.6s", coin.Symbol), symbolpadding, " ")),
|
ct.colorscheme.TableRow(pad.Right(fmt.Sprintf("%.6s", coin.Symbol), symbolpadding, " ")),
|
||||||
colorprice(fmt.Sprintf("%12s", humanize.Commaf(coin.Price))),
|
ct.colorscheme.TableColumnPrice(fmt.Sprintf("%12s", humanize.Commaf(coin.Price))),
|
||||||
color.White(fmt.Sprintf("%18s", humanize.Commaf(coin.MarketCap))),
|
ct.colorscheme.TableRow(fmt.Sprintf("%18s", humanize.Commaf(coin.MarketCap))),
|
||||||
color.White(fmt.Sprintf("%15s", humanize.Commaf(coin.Volume24H))),
|
ct.colorscheme.TableRow(fmt.Sprintf("%15s", humanize.Commaf(coin.Volume24H))),
|
||||||
color1h(fmt.Sprintf("%8.2f%%", coin.PercentChange1H)),
|
color1h(fmt.Sprintf("%8.2f%%", coin.PercentChange1H)),
|
||||||
color24h(fmt.Sprintf("%8.2f%%", coin.PercentChange24H)),
|
color24h(fmt.Sprintf("%8.2f%%", coin.PercentChange24H)),
|
||||||
color7d(fmt.Sprintf("%8.2f%%", coin.PercentChange7D)),
|
color7d(fmt.Sprintf("%8.2f%%", coin.PercentChange7D)),
|
||||||
color.White(fmt.Sprintf("%21s", humanize.Commaf(coin.TotalSupply))),
|
ct.colorscheme.TableRow(fmt.Sprintf("%21s", humanize.Commaf(coin.TotalSupply))),
|
||||||
color.White(fmt.Sprintf("%18s", humanize.Commaf(coin.AvailableSupply))),
|
ct.colorscheme.TableRow(fmt.Sprintf("%18s", humanize.Commaf(coin.AvailableSupply))),
|
||||||
color.White(fmt.Sprintf("%18s", lastUpdated)),
|
ct.colorscheme.TableRow(fmt.Sprintf("%18s", lastUpdated)),
|
||||||
// TODO: add %percent of cap
|
// TODO: add %percent of cap
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user