Update method descriptions

pull/49/head 1.4.1
Miguel Mota 5 years ago
parent 6f286490be
commit b61e2fdd84

@ -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

@ -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]
}

@ -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)
}

@ -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
}

@ -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 {

@ -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)

@ -4,6 +4,7 @@ import (
"testing"
)
// TestRun tests that cointop runs
func TestRun(t *testing.T) {
// Run()
}

@ -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

@ -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
}

@ -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

@ -1,6 +1,6 @@
package cointop
// DefaultColors ...
// DefaultColors is the default color scheme
var DefaultColors = `
colorscheme = "cointop"

@ -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()
}

@ -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
}

@ -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
}

@ -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 = ""

@ -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 {

@ -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()
})
}

@ -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
}

@ -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
}

@ -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)
}
}

@ -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()

@ -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 {

@ -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()
}()
}

@ -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",

@ -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
}

@ -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
}

@ -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')

@ -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 {

@ -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
}

@ -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")

Loading…
Cancel
Save