From b61e2fdd84e69277f96957b759b794d91e38bcab Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Sun, 17 Nov 2019 23:37:23 -0800 Subject: [PATCH] Update method descriptions --- CHANGELOG.md | 6 +++++- cointop/actions.go | 5 +++-- cointop/cache.go | 12 +++++++----- cointop/chart.go | 24 ++++++++++++------------ cointop/coin.go | 10 ++++++---- cointop/cointop.go | 18 +++++++++--------- cointop/cointop_test.go | 1 + cointop/colorscheme.go | 12 ++++++++---- cointop/conversion.go | 6 +++--- cointop/debug.go | 1 + cointop/default_colors.go | 2 +- cointop/events.go | 4 ++-- cointop/favorites.go | 6 +++--- cointop/help.go | 4 ++-- cointop/keybindings.go | 2 +- cointop/layout.go | 6 +++--- cointop/list.go | 6 +++--- cointop/marketbar.go | 4 ++-- cointop/navigation.go | 38 +++++++++++++++++++------------------- cointop/portfolio.go | 14 +++++++------- cointop/quit.go | 4 ++-- cointop/refresh.go | 6 +++--- cointop/save.go | 18 ++++++++++-------- cointop/shortcuts.go | 3 ++- cointop/sort.go | 24 ++++++++++++------------ cointop/statusbar.go | 12 ++++++------ cointop/stdin.go | 6 +++--- cointop/table.go | 36 ++++++++++++++++++------------------ cointop/table_header.go | 8 ++++---- cointop/update.go | 6 +++--- 30 files changed, 161 insertions(+), 143 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 918dd25..849a307 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,9 +4,13 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [1.4.1] - 2019-11-17 +### Fixed +- Fix version ldflags + ## [1.4.0] - 2019-11-17 ### Added -- Keyboard shortcuts to enlarge and shorten chart. +- Keyboard shortcuts to enlarge and shorten chart ## [1.3.6] - 2019-09-15 ### Fixed diff --git a/cointop/actions.go b/cointop/actions.go index a757f87..ac9a53c 100644 --- a/cointop/actions.go +++ b/cointop/actions.go @@ -1,6 +1,7 @@ package cointop -func actionsMap() map[string]bool { +// ActionsMap returns a map of all the available actions +func ActionsMap() map[string]bool { return map[string]bool{ "first_page": true, "help": true, @@ -58,5 +59,5 @@ func actionsMap() map[string]bool { // ActionExists returns true if action exists func (ct *Cointop) ActionExists(action string) bool { - return ct.actionsMap[action] + return ct.ActionsMap[action] } diff --git a/cointop/cache.go b/cointop/cache.go index a278b13..78bccc5 100644 --- a/cointop/cache.go +++ b/cointop/cache.go @@ -8,13 +8,15 @@ import ( "github.com/miguelmota/cointop/cointop/common/filecache" ) -func (ct *Cointop) cacheKey(key string) string { - ct.debuglog("cacheKey()") +// CacheKey returns cached value given key +func (ct *Cointop) CacheKey(key string) string { + ct.debuglog("CacheKey()") return strings.ToLower(fmt.Sprintf("%s_%s", ct.apiChoice, key)) } -func (ct *Cointop) cacheAllCoinsSlugMap() { - ct.debuglog("cacheAllCoinsSlugMap()") +// CacheAllCoinsSlugMap writes the coins map to the memory and disk cache +func (ct *Cointop) CacheAllCoinsSlugMap() { + ct.debuglog("CacheAllCoinsSlugMap()") allCoinsSlugMap := make(map[string]*Coin) ct.State.allCoinsSlugMap.Range(func(key, value interface{}) bool { allCoinsSlugMap[key.(string)] = value.(*Coin) @@ -23,7 +25,7 @@ func (ct *Cointop) cacheAllCoinsSlugMap() { // NOTE: do not override with empty data on startup if len(allCoinsSlugMap) != 0 { - cachekey := ct.cacheKey("allCoinsSlugMap") + cachekey := ct.CacheKey("allCoinsSlugMap") ct.cache.Set(cachekey, allCoinsSlugMap, 10*time.Second) filecache.Set(cachekey, allCoinsSlugMap, 24*time.Hour) } diff --git a/cointop/chart.go b/cointop/chart.go index c5b7b4b..11d8ea9 100644 --- a/cointop/chart.go +++ b/cointop/chart.go @@ -58,7 +58,7 @@ func chartRangesMap() map[string]time.Duration { // UpdateChart updates the chart view func (ct *Cointop) UpdateChart() error { - ct.debuglog("updateChart()") + ct.debuglog("UpdateChart()") if ct.Views.Chart.Backing() == nil { return nil } @@ -94,7 +94,7 @@ func (ct *Cointop) UpdateChart() error { } } - ct.update(func() { + ct.Update(func() { if ct.Views.Chart.Backing() == nil { return } @@ -107,7 +107,7 @@ func (ct *Cointop) UpdateChart() error { // ChartPoints calculates the the chart points func (ct *Cointop) ChartPoints(symbol string, name string) error { - ct.debuglog("chartPoints()") + ct.debuglog("ChartPoints()") maxX := ct.ClampedWidth() chartPointsLock.Lock() @@ -140,7 +140,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error { if keyname == "" { keyname = "globaldata" } - cachekey := ct.cacheKey(fmt.Sprintf("%s_%s", keyname, strings.Replace(ct.State.selectedChartRange, " ", "", -1))) + cachekey := ct.CacheKey(fmt.Sprintf("%s_%s", keyname, strings.Replace(ct.State.selectedChartRange, " ", "", -1))) cached, found := ct.cache.Get(cachekey) if found { @@ -211,7 +211,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error { // PortfolioChart renders the portfolio chart func (ct *Cointop) PortfolioChart() error { - ct.debuglog("portfolioChart()") + ct.debuglog("PortfolioChart()") maxX := ct.ClampedWidth() chartPointsLock.Lock() defer chartPointsLock.Unlock() @@ -348,7 +348,7 @@ func (ct *Cointop) EnlargeChart() error { // NextChartRange sets the chart to the next range option func (ct *Cointop) NextChartRange() error { - ct.debuglog("nextChartRange()") + ct.debuglog("NextChartRange()") sel := 0 max := len(ct.chartRanges) for i, k := range ct.chartRanges { @@ -369,7 +369,7 @@ func (ct *Cointop) NextChartRange() error { // PrevChartRange sets the chart to the prevous range option func (ct *Cointop) PrevChartRange() error { - ct.debuglog("prevChartRange()") + ct.debuglog("PrevChartRange()") sel := 0 for i, k := range ct.chartRanges { if k == ct.State.selectedChartRange { @@ -388,7 +388,7 @@ func (ct *Cointop) PrevChartRange() error { // FirstChartRange sets the chart to the first range option func (ct *Cointop) FirstChartRange() error { - ct.debuglog("firstChartRange()") + ct.debuglog("FirstChartRange()") ct.State.selectedChartRange = ct.chartRanges[0] go ct.UpdateChart() return nil @@ -396,7 +396,7 @@ func (ct *Cointop) FirstChartRange() error { // LastChartRange sets the chart to the last range option func (ct *Cointop) LastChartRange() error { - ct.debuglog("lastChartRange()") + ct.debuglog("LastChartRange()") ct.State.selectedChartRange = ct.chartRanges[len(ct.chartRanges)-1] go ct.UpdateChart() return nil @@ -404,7 +404,7 @@ func (ct *Cointop) LastChartRange() error { // ToggleCoinChart toggles between the global chart and the coin chart func (ct *Cointop) ToggleCoinChart() error { - ct.debuglog("toggleCoinChart()") + ct.debuglog("ToggleCoinChart()") highlightedcoin := ct.HighlightedRowCoin() if ct.State.selectedCoin == highlightedcoin { ct.State.selectedCoin = nil @@ -420,8 +420,8 @@ func (ct *Cointop) ToggleCoinChart() error { // ShowChartLoader shows chart loading indicator func (ct *Cointop) ShowChartLoader() error { - ct.debuglog("showChartLoader()") - ct.update(func() { + ct.debuglog("ShowChartLoader()") + ct.Update(func() { if ct.Views.Chart.Backing() == nil { return } diff --git a/cointop/coin.go b/cointop/coin.go index 248c010..a51a57b 100644 --- a/cointop/coin.go +++ b/cointop/coin.go @@ -23,8 +23,9 @@ type Coin struct { Balance float64 } -func (ct *Cointop) allCoins() []*Coin { - ct.debuglog("allCoins()") +// AllCoins returns a slice of all the coins +func (ct *Cointop) AllCoins() []*Coin { + ct.debuglog("AllCoins()") if ct.State.filterByFavorites { var list []*Coin for i := range ct.State.allCoins { @@ -50,8 +51,9 @@ func (ct *Cointop) allCoins() []*Coin { return ct.State.allCoins } -func (ct *Cointop) coinBySymbol(symbol string) *Coin { - ct.debuglog("coinBySymbol()") +// CoinBySymbol returns the coin struct given the symbol +func (ct *Cointop) CoinBySymbol(symbol string) *Coin { + ct.debuglog("CoinBySymbol()") for i := range ct.State.allCoins { coin := ct.State.allCoins[i] if coin.Symbol == symbol { diff --git a/cointop/cointop.go b/cointop/cointop.go index 05f6f75..13dee5b 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -77,7 +77,7 @@ type State struct { // Cointop cointop type Cointop struct { g *gocui.Gui - actionsMap map[string]bool + ActionsMap map[string]bool apiKeys *APIKeys cache *cache.Cache config config // toml config @@ -97,7 +97,7 @@ type Cointop struct { saveMux sync.Mutex State *State table *table.Table - tableColumnOrder []string + TableColumnOrder []string Views *Views } @@ -159,7 +159,7 @@ func NewCointop(config *Config) (*Cointop, error) { apiKeys: new(APIKeys), forceRefresh: make(chan bool), maxTableWidth: 175, - actionsMap: actionsMap(), + ActionsMap: ActionsMap(), cache: cache.New(1*time.Minute, 2*time.Minute), configFilepath: configFilepath, chartRanges: chartRanges(), @@ -178,7 +178,7 @@ func NewCointop(config *Config) (*Cointop, error) { onlyTable: config.OnlyTable, refreshRate: 60 * time.Second, selectedChartRange: "7D", - shortcutKeys: defaultShortcuts(), + shortcutKeys: DefaultShortcuts(), sortBy: "rank", page: 0, perPage: 100, @@ -187,7 +187,7 @@ func NewCointop(config *Config) (*Cointop, error) { }, chartHeight: 10, }, - tableColumnOrder: tableColumnOrder(), + TableColumnOrder: TableColumnOrder(), Views: &Views{ Chart: NewChartView(), Table: NewTableView(), @@ -252,7 +252,7 @@ func NewCointop(config *Config) (*Cointop, error) { apiKey := os.Getenv("CMC_PRO_API_KEY") if apiKey == "" { if !config.NoPrompts { - ct.apiKeys.cmc = ct.readAPIKeyFromStdin("CoinMarketCap Pro") + ct.apiKeys.cmc = ct.ReadAPIKeyFromStdin("CoinMarketCap Pro") } } else { ct.apiKeys.cmc = apiKey @@ -275,7 +275,7 @@ func NewCointop(config *Config) (*Cointop, error) { } allCoinsSlugMap := make(map[string]*Coin) - coinscachekey := ct.cacheKey("allCoinsSlugMap") + coinscachekey := ct.CacheKey("allCoinsSlugMap") filecache.Get(coinscachekey, &allCoinsSlugMap) for k, v := range allCoinsSlugMap { @@ -314,12 +314,12 @@ func NewCointop(config *Config) (*Cointop, error) { }) var globaldata []float64 - chartcachekey := ct.cacheKey(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.State.selectedChartRange, " ", "", -1))) + chartcachekey := ct.CacheKey(fmt.Sprintf("%s_%s", "globaldata", strings.Replace(ct.State.selectedChartRange, " ", "", -1))) filecache.Get(chartcachekey, &globaldata) ct.cache.Set(chartcachekey, globaldata, 10*time.Second) var market types.GlobalMarketData - marketcachekey := ct.cacheKey("market") + marketcachekey := ct.CacheKey("market") filecache.Get(marketcachekey, &market) ct.cache.Set(marketcachekey, market, 10*time.Second) diff --git a/cointop/cointop_test.go b/cointop/cointop_test.go index f7c76e7..24fe4bd 100644 --- a/cointop/cointop_test.go +++ b/cointop/cointop_test.go @@ -4,6 +4,7 @@ import ( "testing" ) +// TestRun tests that cointop runs func TestRun(t *testing.T) { // Run() } diff --git a/cointop/colorscheme.go b/cointop/colorscheme.go index b2d3457..ccfe0df 100644 --- a/cointop/colorscheme.go +++ b/cointop/colorscheme.go @@ -10,16 +10,16 @@ import ( // TODO: fix hex color support -// colorschemeColors .. +// colorschemeColors is a map of color string names to Attribute types type colorschemeColors map[string]interface{} -// ISprintf ... +// ISprintf is a sprintf interface type ISprintf func(...interface{}) string -// colorCache .. +// colorCache is a map of color string names to sprintf functions type colorCache map[string]ISprintf -// Colorscheme ... +// Colorscheme is the struct for colorscheme type Colorscheme struct { colors colorschemeColors cache colorCache @@ -320,14 +320,17 @@ func (c *Colorscheme) toBgAttr(v string) (fcolor.Attribute, bool) { return 0, false } +// toBoldAttr converts a boolean to an Attribute type func (c *Colorscheme) toBoldAttr(v bool) (fcolor.Attribute, bool) { return fcolor.Bold, v } +// toUnderlineAttr converts a boolean to an Attribute type func (c *Colorscheme) toUnderlineAttr(v bool) (fcolor.Attribute, bool) { return fcolor.Underline, v } +// toGocuiAttr converts a color string name to a gocui Attribute type func (c *Colorscheme) toGocuiAttr(v string) (gocui.Attribute, bool) { if attr, ok := gocuiColorschemeColorsMap[v]; ok { return attr, true @@ -340,6 +343,7 @@ func (c *Colorscheme) toGocuiAttr(v string) (gocui.Attribute, bool) { return 0, false } +// hexToAnsi converts a hex color string to a uint8 ansi code func hexToAnsi(h string) (uint8, bool) { if h == "" { return 0, false diff --git a/cointop/conversion.go b/cointop/conversion.go index b378a66..4ccef1e 100644 --- a/cointop/conversion.go +++ b/cointop/conversion.go @@ -174,7 +174,7 @@ func (ct *Cointop) updateConvertMenu() { } content := fmt.Sprintf("%s%s%s", header, helpline, body) - ct.update(func() { + ct.Update(func() { if ct.Views.ConvertMenu.Backing() == nil { return } @@ -197,7 +197,7 @@ func (ct *Cointop) setCurrencyConverstionFn(convert string) func() error { ct.State.currencyConversion = convert - if err := ct.save(); err != nil { + if err := ct.Save(); err != nil { return err } @@ -230,7 +230,7 @@ func (ct *Cointop) hideConvertMenu() error { ct.State.convertMenuVisible = false ct.SetViewOnBottom(ct.Views.ConvertMenu.Name()) ct.SetActiveView(ct.Views.Table.Name()) - ct.update(func() { + ct.Update(func() { if ct.Views.ConvertMenu.Backing() == nil { return } diff --git a/cointop/debug.go b/cointop/debug.go index 6687f4d..c42d004 100644 --- a/cointop/debug.go +++ b/cointop/debug.go @@ -8,6 +8,7 @@ import ( log "github.com/sirupsen/logrus" ) +// debuglog writs a debug log to stdout func (ct *Cointop) debuglog(msg string) { if !ct.debug { return diff --git a/cointop/default_colors.go b/cointop/default_colors.go index abf4989..4571b14 100644 --- a/cointop/default_colors.go +++ b/cointop/default_colors.go @@ -1,6 +1,6 @@ package cointop -// DefaultColors ... +// DefaultColors is the default color scheme var DefaultColors = ` colorscheme = "cointop" diff --git a/cointop/events.go b/cointop/events.go index f2a185a..66566ee 100644 --- a/cointop/events.go +++ b/cointop/events.go @@ -1,7 +1,7 @@ package cointop // RowChanged is called when the row is updated -func (ct *Cointop) rowChanged() { - ct.debuglog("rowChanged()") +func (ct *Cointop) RowChanged() { + ct.debuglog("RowChanged()") ct.RefreshRowLink() } diff --git a/cointop/favorites.go b/cointop/favorites.go index d770b3a..6d7d8aa 100644 --- a/cointop/favorites.go +++ b/cointop/favorites.go @@ -18,11 +18,11 @@ func (ct *Cointop) toggleFavorite() error { coin.Favorite = true } - if err := ct.save(); err != nil { + if err := ct.Save(); err != nil { return err } - go ct.updateTable() + go ct.UpdateTable() return nil } @@ -31,7 +31,7 @@ func (ct *Cointop) toggleShowFavorites() error { ct.debuglog("toggleShowFavorites()") ct.State.portfolioVisible = false ct.State.filterByFavorites = !ct.State.filterByFavorites - go ct.updateTable() + go ct.UpdateTable() return nil } diff --git a/cointop/help.go b/cointop/help.go index 0be8b41..098e23e 100644 --- a/cointop/help.go +++ b/cointop/help.go @@ -58,7 +58,7 @@ func (ct *Cointop) updateHelp() { versionline := pad.Left(fmt.Sprintf("v%s", ct.Version()), ct.maxTableWidth-5, " ") content := header + infoline + body + versionline - ct.update(func() { + ct.Update(func() { if ct.Views.Help.Backing() == nil { return } @@ -82,7 +82,7 @@ func (ct *Cointop) hideHelp() error { ct.State.helpVisible = false ct.SetViewOnBottom(ct.Views.Help.Name()) ct.SetActiveView(ct.Views.Table.Name()) - ct.update(func() { + ct.Update(func() { if ct.Views.Help.Backing() == nil { return } diff --git a/cointop/keybindings.go b/cointop/keybindings.go index d072b62..9a95ddf 100644 --- a/cointop/keybindings.go +++ b/cointop/keybindings.go @@ -303,7 +303,7 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error { case "toggle_show_favorites": fn = ct.keyfn(ct.toggleShowFavorites) case "save": - fn = ct.keyfn(ct.save) + fn = ct.keyfn(ct.Save) case "quit": fn = ct.keyfn(ct.Quit) view = "" diff --git a/cointop/layout.go b/cointop/layout.go index da0f4e3..5486158 100644 --- a/cointop/layout.go +++ b/cointop/layout.go @@ -106,7 +106,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error { ct.Views.TableHeader.SetBacking(v) ct.Views.TableHeader.Backing().Frame = false ct.colorscheme.SetViewColor(ct.Views.TableHeader.Backing(), "table_header") - go ct.updateTableHeader() + go ct.UpdateTableHeader() } topOffset = topOffset + headerHeight @@ -124,7 +124,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error { } go func() { ct.updateCoins() - ct.updateTable() + ct.UpdateTable() }() } @@ -136,7 +136,7 @@ func (ct *Cointop) layout(g *gocui.Gui) error { ct.Views.Statusbar.SetBacking(v) ct.Views.Statusbar.Backing().Frame = false ct.colorscheme.SetViewColor(ct.Views.Statusbar.Backing(), "statusbar") - go ct.updateStatusbar("") + go ct.UpdateStatusbar("") } } else { if ct.Views.Statusbar.Backing() != nil { diff --git a/cointop/list.go b/cointop/list.go index 40c2755..5741b9c 100644 --- a/cointop/list.go +++ b/cointop/list.go @@ -14,7 +14,7 @@ func (ct *Cointop) updateCoins() error { ct.debuglog("updateCoins()") coinslock.Lock() defer coinslock.Unlock() - cachekey := ct.cacheKey("allCoinsSlugMap") + cachekey := ct.CacheKey("allCoinsSlugMap") var err error var allCoinsSlugMap map[string]types.Coin @@ -60,7 +60,7 @@ func (ct *Cointop) processCoins(coins []types.Coin) { updatecoinsmux.Lock() defer updatecoinsmux.Unlock() - ct.cacheAllCoinsSlugMap() + ct.CacheAllCoinsSlugMap() for _, v := range coins { k := v.Name @@ -138,7 +138,7 @@ func (ct *Cointop) processCoins(coins []types.Coin) { time.AfterFunc(10*time.Millisecond, func() { ct.sort(ct.State.sortBy, ct.State.sortDesc, ct.State.coins, true) - ct.updateTable() + ct.UpdateTable() }) } diff --git a/cointop/marketbar.go b/cointop/marketbar.go index 29a53ef..08c96d1 100644 --- a/cointop/marketbar.go +++ b/cointop/marketbar.go @@ -91,7 +91,7 @@ func (ct *Cointop) updateMarketbar() error { } else { var market types.GlobalMarketData var err error - cachekey := ct.cacheKey("market") + cachekey := ct.CacheKey("market") cached, found := ct.cache.Get(cachekey) if found { @@ -143,7 +143,7 @@ func (ct *Cointop) updateMarketbar() error { content = pad.Right(content, maxX, " ") content = ct.colorscheme.Marketbar(content) - ct.update(func() { + ct.Update(func() { if ct.Views.Marketbar.Backing() == nil { return } diff --git a/cointop/navigation.go b/cointop/navigation.go index 54beaf6..9e6f7f5 100644 --- a/cointop/navigation.go +++ b/cointop/navigation.go @@ -52,7 +52,7 @@ func (ct *Cointop) cursorDown() error { return err } } - ct.rowChanged() + ct.RowChanged() return nil } @@ -76,7 +76,7 @@ func (ct *Cointop) cursorUp() error { return err } } - ct.rowChanged() + ct.RowChanged() return nil } @@ -115,7 +115,7 @@ func (ct *Cointop) pageDown() error { return err } } - ct.rowChanged() + ct.RowChanged() return nil } @@ -146,7 +146,7 @@ func (ct *Cointop) pageUp() error { return err } } - ct.rowChanged() + ct.RowChanged() return nil } @@ -169,7 +169,7 @@ func (ct *Cointop) navigateFirstLine() error { if err := ct.Views.Table.Backing().SetCursor(cx, 0); err != nil { return err } - ct.rowChanged() + ct.RowChanged() return nil } @@ -195,7 +195,7 @@ func (ct *Cointop) navigateLastLine() error { if err := ct.Views.Table.Backing().SetCursor(cx, sy-1); err != nil { return err } - ct.rowChanged() + ct.RowChanged() return nil } @@ -214,7 +214,7 @@ func (ct *Cointop) navigatePageFirstLine() error { if err := ct.Views.Table.Backing().SetCursor(cx, 0); err != nil { return err } - ct.rowChanged() + ct.RowChanged() return nil } @@ -234,7 +234,7 @@ func (ct *Cointop) navigatePageMiddleLine() error { if err := ct.Views.Table.Backing().SetCursor(cx, (sy/2)-1); err != nil { return err } - ct.rowChanged() + ct.RowChanged() return nil } @@ -254,7 +254,7 @@ func (ct *Cointop) navigatePageLastLine() error { if err := ct.Views.Table.Backing().SetCursor(cx, sy-1); err != nil { return err } - ct.rowChanged() + ct.RowChanged() return nil } @@ -267,8 +267,8 @@ func (ct *Cointop) prevPage() error { } ct.setPage(ct.State.page - 1) - ct.updateTable() - ct.rowChanged() + ct.UpdateTable() + ct.RowChanged() return nil } @@ -281,8 +281,8 @@ func (ct *Cointop) nextPage() error { } ct.setPage(ct.State.page + 1) - ct.updateTable() - ct.rowChanged() + ct.UpdateTable() + ct.RowChanged() return nil } @@ -295,8 +295,8 @@ func (ct *Cointop) firstPage() error { } ct.State.page = 0 - ct.updateTable() - ct.rowChanged() + ct.UpdateTable() + ct.RowChanged() return nil } @@ -361,8 +361,8 @@ func (ct *Cointop) lastPage() error { } ct.State.page = ct.getListCount() / ct.State.perPage - ct.updateTable() - ct.rowChanged() + ct.UpdateTable() + ct.RowChanged() return nil } @@ -375,7 +375,7 @@ func (ct *Cointop) goToPageRowIndex(idx int) error { if err := ct.Views.Table.Backing().SetCursor(cx, idx); err != nil { return err } - ct.rowChanged() + ct.RowChanged() return nil } @@ -386,7 +386,7 @@ func (ct *Cointop) goToGlobalIndex(idx int) error { ct.setPage(atpage) rowIndex := (idx % perpage) ct.highlightRow(rowIndex) - ct.updateTable() + ct.UpdateTable() return nil } diff --git a/cointop/portfolio.go b/cointop/portfolio.go index db2d0de..27b4afa 100644 --- a/cointop/portfolio.go +++ b/cointop/portfolio.go @@ -33,7 +33,7 @@ func (ct *Cointop) togglePortfolio() error { ct.State.portfolioVisible = !ct.State.portfolioVisible go ct.UpdateChart() - go ct.updateTable() + go ct.UpdateTable() return nil } @@ -42,7 +42,7 @@ func (ct *Cointop) toggleShowPortfolio() error { ct.State.filterByFavorites = false ct.State.portfolioVisible = true go ct.UpdateChart() - go ct.updateTable() + go ct.UpdateTable() return nil } @@ -82,7 +82,7 @@ func (ct *Cointop) updatePortfolioUpdateMenu() { 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() { + ct.Update(func() { ct.Views.PortfolioUpdateMenu.Backing().Clear() ct.Views.PortfolioUpdateMenu.Backing().Frame = true fmt.Fprintln(ct.Views.PortfolioUpdateMenu.Backing(), content) @@ -112,7 +112,7 @@ func (ct *Cointop) hidePortfolioUpdateMenu() error { ct.SetViewOnBottom(ct.Views.PortfolioUpdateMenu.Name()) ct.SetViewOnBottom(ct.Views.Input.Name()) ct.SetActiveView(ct.Views.Table.Name()) - ct.update(func() { + ct.Update(func() { if ct.Views.PortfolioUpdateMenu.Backing() == nil { return } @@ -158,9 +158,9 @@ func (ct *Cointop) setPortfolioHoldings() error { if shouldDelete { ct.removePortfolioEntry(coin.Name) - ct.updateTable() + ct.UpdateTable() } else { - ct.updateTable() + ct.UpdateTable() ct.goToPageRowIndex(ct.State.lastSelectedRowIndex) } @@ -208,7 +208,7 @@ func (ct *Cointop) setPortfolioEntry(coin string, holdings float64) { p.Holdings = holdings } - if err := ct.save(); err != nil { + if err := ct.Save(); err != nil { log.Fatal(err) } } diff --git a/cointop/quit.go b/cointop/quit.go index 0ca09b2..eb37c63 100644 --- a/cointop/quit.go +++ b/cointop/quit.go @@ -16,11 +16,11 @@ func (ct *Cointop) QuitView() error { ct.debuglog("quitView()") if ct.State.portfolioVisible { ct.State.portfolioVisible = false - return ct.updateTable() + return ct.UpdateTable() } if ct.State.filterByFavorites { ct.State.filterByFavorites = false - return ct.updateTable() + return ct.UpdateTable() } if ct.ActiveViewName() == ct.Views.Table.Name() { return ct.Quit() diff --git a/cointop/refresh.go b/cointop/refresh.go index 90db178..8d383a6 100644 --- a/cointop/refresh.go +++ b/cointop/refresh.go @@ -23,7 +23,7 @@ func (ct *Cointop) refreshAll() error { ct.cache.Delete("market") go func() { ct.updateCoins() - ct.updateTable() + ct.UpdateTable() ct.UpdateChart() }() return nil @@ -33,7 +33,7 @@ func (ct *Cointop) setRefreshStatus() { ct.debuglog("setRefreshStatus()") go func() { ct.loadingTicks("refreshing", 900) - ct.rowChanged() + ct.RowChanged() }() } @@ -42,7 +42,7 @@ func (ct *Cointop) loadingTicks(s string, t int) { interval := 150 k := 0 for i := 0; i < (t / interval); i++ { - ct.updateStatusbar(s + strings.Repeat(".", k)) + ct.UpdateStatusbar(s + strings.Repeat(".", k)) time.Sleep(time.Duration(i*interval) * time.Millisecond) k = k + 1 if k > 3 { diff --git a/cointop/save.go b/cointop/save.go index a1896e9..d3e7d08 100644 --- a/cointop/save.go +++ b/cointop/save.go @@ -2,27 +2,29 @@ package cointop import "log" -func (ct *Cointop) save() error { - ct.debuglog("save()") - ct.setSavingStatus() +// Save saves the cointop settings to the config file +func (ct *Cointop) Save() error { + ct.debuglog("Save()") + ct.SetSavingStatus() if err := ct.saveConfig(); err != nil { log.Fatal(err) } - ct.cacheAllCoinsSlugMap() + ct.CacheAllCoinsSlugMap() return nil } -func (ct *Cointop) setSavingStatus() { - ct.debuglog("setSavingStatus()") +// SetSavingStatus sets the saving indicator in the statusbar +func (ct *Cointop) SetSavingStatus() { + ct.debuglog("SetSavingStatus()") if ct.g == nil { return } go func() { ct.loadingTicks("saving", 590) - ct.updateStatusbar("") - ct.rowChanged() + ct.UpdateStatusbar("") + ct.RowChanged() }() } diff --git a/cointop/shortcuts.go b/cointop/shortcuts.go index 3e8db44..d1d0b53 100644 --- a/cointop/shortcuts.go +++ b/cointop/shortcuts.go @@ -1,6 +1,7 @@ package cointop -func defaultShortcuts() map[string]string { +// DefaultShortcuts is a map of the default shortcuts +func DefaultShortcuts() map[string]string { return map[string]string{"up": "move_up", "down": "move_down", "left": "previous_page", diff --git a/cointop/sort.go b/cointop/sort.go index 912a00c..f616caf 100644 --- a/cointop/sort.go +++ b/cointop/sort.go @@ -68,52 +68,52 @@ func (ct *Cointop) sort(sortBy string, desc bool, list []*Coin, renderHeaders bo }) if renderHeaders { - ct.updateTableHeader() + ct.UpdateTableHeader() } } func (ct *Cointop) sortAsc() error { ct.debuglog("sortAsc()") ct.State.sortDesc = false - ct.updateTable() + ct.UpdateTable() return nil } func (ct *Cointop) sortDesc() error { ct.debuglog("sortDesc()") ct.State.sortDesc = true - ct.updateTable() + ct.UpdateTable() return nil } func (ct *Cointop) sortPrevCol() error { ct.debuglog("sortPrevCol()") - nextsortBy := ct.tableColumnOrder[0] + nextsortBy := ct.TableColumnOrder[0] i := ct.getSortColIndex() k := i - 1 if k < 0 { k = 0 } - nextsortBy = ct.tableColumnOrder[k] + nextsortBy = ct.TableColumnOrder[k] ct.sort(nextsortBy, ct.State.sortDesc, ct.State.coins, true) - ct.updateTable() + ct.UpdateTable() return nil } func (ct *Cointop) sortNextCol() error { ct.debuglog("sortNextCol()") - nextsortBy := ct.tableColumnOrder[0] - l := len(ct.tableColumnOrder) + nextsortBy := ct.TableColumnOrder[0] + l := len(ct.TableColumnOrder) i := ct.getSortColIndex() k := i + 1 if k > l-1 { k = l - 1 } - nextsortBy = ct.tableColumnOrder[k] + nextsortBy = ct.TableColumnOrder[k] ct.sort(nextsortBy, ct.State.sortDesc, ct.State.coins, true) - ct.updateTable() + ct.UpdateTable() return nil } @@ -124,7 +124,7 @@ func (ct *Cointop) sortToggle(sortBy string, desc bool) error { } ct.sort(sortBy, desc, ct.State.coins, true) - ct.updateTable() + ct.UpdateTable() return nil } @@ -137,7 +137,7 @@ func (ct *Cointop) sortfn(sortBy string, desc bool) func(g *gocui.Gui, v *gocui. func (ct *Cointop) getSortColIndex() int { ct.debuglog("getSortColIndex()") - for i, col := range ct.tableColumnOrder { + for i, col := range ct.TableColumnOrder { if ct.State.sortBy == col { return i } diff --git a/cointop/statusbar.go b/cointop/statusbar.go index 87e830f..cfa987a 100644 --- a/cointop/statusbar.go +++ b/cointop/statusbar.go @@ -29,9 +29,9 @@ func (statusbar *StatusbarView) Update(str string) error { return nil } -// updateStatusbar updates the statusbar view -func (ct *Cointop) updateStatusbar(s string) error { - ct.debuglog("updateStatusbar()") +// UpdateStatusbar updates the statusbar view +func (ct *Cointop) UpdateStatusbar(s string) error { + ct.debuglog("UpdateStatusbar()") currpage := ct.currentDisplayPage() totalpages := ct.totalPagesDisplay() var quitText string @@ -63,7 +63,7 @@ func (ct *Cointop) updateStatusbar(s string) error { str = str[:end] + v - ct.update(func() { + ct.Update(func() { ct.Views.Statusbar.Update(str) }) @@ -72,14 +72,14 @@ func (ct *Cointop) updateStatusbar(s string) error { // RefreshRowLink updates the row link in the statusbar func (ct *Cointop) RefreshRowLink() error { - ct.debuglog("refreshRowLink()") + ct.debuglog("RefreshRowLink()") var shortcut string if !open.CommandExists() { shortcut = "[O]Open " } url := ct.RowLinkShort() - ct.updateStatusbar(fmt.Sprintf("%s%s", shortcut, url)) + ct.UpdateStatusbar(fmt.Sprintf("%s%s", shortcut, url)) return nil } diff --git a/cointop/stdin.go b/cointop/stdin.go index ebc5f2a..2c64a20 100644 --- a/cointop/stdin.go +++ b/cointop/stdin.go @@ -9,9 +9,9 @@ import ( log "github.com/sirupsen/logrus" ) -// readAPIKeyFromStdin reads the user inputed API from the stdin prompt -func (ct *Cointop) readAPIKeyFromStdin(name string) string { - ct.debuglog("readAPIKeyFromStdin()") +// ReadAPIKeyFromStdin reads the user inputed API from the stdin prompt +func (ct *Cointop) ReadAPIKeyFromStdin(name string) string { + ct.debuglog("ReadAPIKeyFromStdin()") reader := bufio.NewReader(os.Stdin) fmt.Printf("Enter %s API Key: ", name) text, err := reader.ReadString('\n') diff --git a/cointop/table.go b/cointop/table.go index 1000394..5f4d9ae 100644 --- a/cointop/table.go +++ b/cointop/table.go @@ -24,7 +24,7 @@ func NewTableView() *TableView { } // TableColumnOrder returns the default order of the table columns -func tableColumnOrder() []string { +func TableColumnOrder() []string { return []string{ "rank", "name", @@ -193,15 +193,15 @@ func (ct *Cointop) RefreshTable() error { ct.highlightRow(currentrow) } - ct.update(func() { + ct.Update(func() { if ct.Views.Table.Backing() == nil { return } ct.Views.Table.Backing().Clear() ct.table.Format().Fprint(ct.Views.Table.Backing()) - go ct.rowChanged() - go ct.updateTableHeader() + go ct.RowChanged() + go ct.UpdateTableHeader() go ct.updateMarketbar() go ct.UpdateChart() }) @@ -209,9 +209,9 @@ func (ct *Cointop) RefreshTable() error { return nil } -// updateTable updates the table -func (ct *Cointop) updateTable() error { - ct.debuglog("updateTable()") +// UpdateTable updates the table +func (ct *Cointop) UpdateTable() error { + ct.debuglog("UpdateTable()") ct.State.allCoinsSlugMap.Range(func(key, value interface{}) bool { k := key.(string) if v, ok := value.(*Coin); ok { @@ -233,7 +233,7 @@ func (ct *Cointop) updateTable() error { ct.State.sortDesc = false } - ct.State.coins = ct.getTableCoinsSlice() + ct.State.coins = ct.GetTableCoinsSlice() } ct.sort(ct.State.sortBy, ct.State.sortDesc, ct.State.coins, true) @@ -241,13 +241,13 @@ func (ct *Cointop) updateTable() error { return nil } -// getTableCoinsSlice ... -func (ct *Cointop) getTableCoinsSlice() []*Coin { - ct.debuglog("getTableCoinsSlice()") +// GetTableCoinsSlice returns a slice of the table rows +func (ct *Cointop) GetTableCoinsSlice() []*Coin { + ct.debuglog("GetTableCoinsSlice()") sliced := []*Coin{} start := ct.State.page * ct.State.perPage end := start + ct.State.perPage - allCoins := ct.allCoins() + allCoins := ct.AllCoins() size := len(allCoins) if start < 0 { start = 0 @@ -286,7 +286,7 @@ func (ct *Cointop) getTableCoinsSlice() []*Coin { // HighlightedRowIndex returns the index of the highlighted row func (ct *Cointop) HighlightedRowIndex() int { - ct.debuglog("highlightedRowIndex()") + ct.debuglog("HighlightedRowIndex()") _, y := ct.Views.Table.Backing().Origin() _, cy := ct.Views.Table.Backing().Cursor() idx := y + cy @@ -301,7 +301,7 @@ func (ct *Cointop) HighlightedRowIndex() int { // HighlightedRowCoin returns the coin at the index of the highlighted row func (ct *Cointop) HighlightedRowCoin() *Coin { - ct.debuglog("highlightedRowCoin()") + ct.debuglog("HighlightedRowCoin()") idx := ct.HighlightedRowIndex() if len(ct.State.coins) == 0 { return nil @@ -311,7 +311,7 @@ func (ct *Cointop) HighlightedRowCoin() *Coin { // HighlightedPageRowIndex returns the index of page row of the highlighted row func (ct *Cointop) HighlightedPageRowIndex() int { - ct.debuglog("highlightedPageRowIndex()") + ct.debuglog("HighlightedPageRowIndex()") _, cy := ct.Views.Table.Backing().Cursor() idx := cy if idx < 0 { @@ -323,7 +323,7 @@ func (ct *Cointop) HighlightedPageRowIndex() int { // RowLink returns the row url link func (ct *Cointop) RowLink() string { - ct.debuglog("rowLink()") + ct.debuglog("RowLink()") coin := ct.HighlightedRowCoin() if coin == nil { return "" @@ -334,7 +334,7 @@ func (ct *Cointop) RowLink() string { // RowLinkShort returns a shortened version of the row url link func (ct *Cointop) RowLinkShort() string { - ct.debuglog("rowLinkShort()") + ct.debuglog("RowLinkShort()") link := ct.RowLink() if link != "" { u, err := url.Parse(link) @@ -358,7 +358,7 @@ func (ct *Cointop) RowLinkShort() string { // ToggleTableFullscreen toggles the table fullscreen mode func (ct *Cointop) ToggleTableFullscreen() error { - ct.debuglog("toggleTableFullscreen()") + ct.debuglog("ToggleTableFullscreen()") ct.State.onlyTable = !ct.State.onlyTable if ct.State.onlyTable { } else { diff --git a/cointop/table_header.go b/cointop/table_header.go index 6900087..3c3723e 100644 --- a/cointop/table_header.go +++ b/cointop/table_header.go @@ -15,9 +15,9 @@ func NewTableHeaderView() *TableHeaderView { return &TableHeaderView{NewView("header")} } -// updateTableHeader renders the table header -func (ct *Cointop) updateTableHeader() { - ct.debuglog("updateTableHeader()") +// UpdateTableHeader renders the table header +func (ct *Cointop) UpdateTableHeader() { + ct.debuglog("UpdateTableHeader()") var cols []string type t struct { @@ -89,7 +89,7 @@ func (ct *Cointop) updateTableHeader() { headers = append(headers, str) } - ct.update(func() { + ct.Update(func() { if ct.Views.TableHeader.Backing() == nil { return } diff --git a/cointop/update.go b/cointop/update.go index ec878db..db47091 100644 --- a/cointop/update.go +++ b/cointop/update.go @@ -7,9 +7,9 @@ import ( log "github.com/sirupsen/logrus" ) -// update takes a callback which updates the view -func (ct *Cointop) update(f func()) { - ct.debuglog(fmt.Sprintf("update()")) +// Update takes a callback which updates the view +func (ct *Cointop) Update(f func()) { + ct.debuglog(fmt.Sprintf("Update()")) if ct.g == nil { log.Fatal("gocui is not initialized")