From ae65cc58d7e4e7d5d5cf82ce8690435fe3c3b4c7 Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Mon, 1 Feb 2021 01:19:18 -0800 Subject: [PATCH] Add newline to market bar on resize --- cointop/cointop.go | 2 ++ cointop/layout.go | 39 ++++++++++++++++++++------------------- cointop/marketbar.go | 20 +++++++++++++++++++- cointop/table.go | 3 +-- 4 files changed, 42 insertions(+), 22 deletions(-) diff --git a/cointop/cointop.go b/cointop/cointop.go index f7b7102..9b930d4 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -57,6 +57,7 @@ type State struct { hideChart bool hideStatusbar bool lastSelectedRowIndex int + marketBarHeight int page int perPage int portfolio *Portfolio @@ -221,6 +222,7 @@ func NewCointop(config *Config) (*Cointop, error) { hideMarketbar: config.HideMarketbar, hideChart: config.HideChart, hideStatusbar: config.HideStatusbar, + marketBarHeight: 1, onlyTable: config.OnlyTable, refreshRate: 60 * time.Second, selectedChartRange: "7D", diff --git a/cointop/layout.go b/cointop/layout.go index 2c05308..4970188 100644 --- a/cointop/layout.go +++ b/cointop/layout.go @@ -17,7 +17,7 @@ func (ct *Cointop) layout() error { topOffset := 0 headerHeight := 1 - marketbarHeight := 1 + marketbarHeight := ct.State.marketBarHeight chartHeight := ct.State.chartHeight statusbarHeight := 1 @@ -25,6 +25,7 @@ func (ct *Cointop) layout() error { ct.State.hideMarketbar = true ct.State.hideChart = true ct.State.hideStatusbar = true + marketbarHeight = 0 } if ct.State.hideMarketbar { @@ -39,8 +40,15 @@ func (ct *Cointop) layout() error { statusbarHeight = 0 } - if !ct.State.hideMarketbar { - if err := ct.ui.SetView(ct.Views.Marketbar, 0, topOffset, maxX, 2); err != nil { + if ct.State.hideMarketbar { + if ct.Views.Marketbar.Backing() != nil { + if err := ct.g.DeleteView(ct.Views.Marketbar.Name()); err != nil { + return err + } + ct.Views.Marketbar.SetBacking(nil) + } + } else { + if err := ct.ui.SetView(ct.Views.Marketbar, 0, topOffset, maxX, marketbarHeight+1); err != nil { ct.Views.Marketbar.SetFrame(false) ct.Views.Marketbar.SetFgColor(ct.colorscheme.gocuiFgColor(ct.Views.Marketbar.Name())) ct.Views.Marketbar.SetBgColor(ct.colorscheme.gocuiBgColor(ct.Views.Marketbar.Name())) @@ -53,19 +61,19 @@ func (ct *Cointop) layout() error { } }() } - } else { - if ct.Views.Marketbar.Backing() != nil { - if err := ct.g.DeleteView(ct.Views.Marketbar.Name()); err != nil { - return err - } - ct.Views.Marketbar.SetBacking(nil) - } } topOffset = topOffset + marketbarHeight - if !ct.State.hideChart { - if err := ct.ui.SetView(ct.Views.Chart, 0, topOffset, maxX, topOffset+chartHeight+marketbarHeight); err != nil { + if ct.State.hideChart { + if ct.Views.Chart.Backing() != nil { + if err := ct.g.DeleteView(ct.Views.Chart.Name()); err != nil { + return err + } + ct.Views.Chart.SetBacking(nil) + } + } else { + if err := ct.ui.SetView(ct.Views.Chart, 0, topOffset, maxX, topOffset+chartHeight); err != nil { ct.Views.Chart.Clear() ct.Views.Chart.SetFrame(false) ct.Views.Chart.SetFgColor(ct.colorscheme.gocuiFgColor(ct.Views.Chart.Name())) @@ -80,13 +88,6 @@ func (ct *Cointop) layout() error { } }() } - } else { - if ct.Views.Chart.Backing() != nil { - if err := ct.g.DeleteView(ct.Views.Chart.Name()); err != nil { - return err - } - ct.Views.Chart.SetBacking(nil) - } } tableOffsetX := ct.State.tableOffsetX diff --git a/cointop/marketbar.go b/cointop/marketbar.go index fd8d182..67917be 100644 --- a/cointop/marketbar.go +++ b/cointop/marketbar.go @@ -3,6 +3,7 @@ package cointop import ( "fmt" "math" + "strings" "time" types "github.com/miguelmota/cointop/pkg/api/types" @@ -32,6 +33,7 @@ func (ct *Cointop) UpdateMarketbar() error { var content string if ct.IsPortfolioVisible() { + ct.State.marketBarHeight = 1 total := ct.GetPortfolioTotal() totalstr := humanize.Commaf(total) if !(ct.State.currencyConversion == "BTC" || ct.State.currencyConversion == "ETH" || total < 1) { @@ -85,6 +87,11 @@ func (ct *Cointop) UpdateMarketbar() error { color24h(fmt.Sprintf("%.2f%%%s", percentChange24H, arrow)), ) } else { + ct.State.marketBarHeight = 1 + if ct.width() < 125 { + ct.State.marketBarHeight = 2 + } + var market types.GlobalMarketData var err error cachekey := ct.CacheKey("market") @@ -130,11 +137,22 @@ func (ct *Cointop) UpdateMarketbar() error { ) } + separator1 := "•" + separator2 := "•" + offset := strings.Repeat(" ", 12) + if ct.width() < 105 { + separator1 = "\n" + offset + } else if ct.width() < 125 { + separator2 = "\n" + offset + } + content = fmt.Sprintf( - "%sGlobal ▶ Market Cap: %s • 24H Volume: %s • BTC Dominance: %.2f%%", + "%sGlobal ▶ Market Cap: %s %s 24H Volume: %s %s BTC Dominance: %.2f%%", chartInfo, fmt.Sprintf("%s%s", ct.CurrencySymbol(), humanize.Commaf0(market.TotalMarketCapUSD)), + separator1, fmt.Sprintf("%s%s", ct.CurrencySymbol(), humanize.Commaf0(market.Total24HVolumeUSD)), + separator2, market.BitcoinPercentageOfMarketCap, ) } diff --git a/cointop/table.go b/cointop/table.go index 601b85e..c76c18f 100644 --- a/cointop/table.go +++ b/cointop/table.go @@ -224,8 +224,7 @@ func (ct *Cointop) RowLinkShort() string { func (ct *Cointop) ToggleTableFullscreen() error { ct.debuglog("ToggleTableFullscreen()") ct.State.onlyTable = !ct.State.onlyTable - if ct.State.onlyTable { - } else { + if !ct.State.onlyTable { // NOTE: cached values are initial config settings. // If the only-table config was set then toggle // all other initial hidden views.