diff --git a/cointop/cointop.go b/cointop/cointop.go index 645702a..71f328a 100644 --- a/cointop/cointop.go +++ b/cointop/cointop.go @@ -72,3 +72,12 @@ func Run() { log.Fatalf("main loop: %v", err) } } + +func (ct *Cointop) quit(g *gocui.Gui, v *gocui.View) error { + return gocui.ErrQuit +} + +func (ct *Cointop) refresh(g *gocui.Gui, v *gocui.View) error { + ct.forcerefresh <- true + return nil +} diff --git a/cointop/help.go b/cointop/help.go index 867983a..1bc1b77 100644 --- a/cointop/help.go +++ b/cointop/help.go @@ -5,6 +5,7 @@ import ( "github.com/miguelmota/cointop/pkg/open" ) +// TODO: create a help menu func (ct *Cointop) openHelp(g *gocui.Gui, v *gocui.View) error { open.URL(ct.helpLink()) return nil diff --git a/cointop/keybindings.go b/cointop/keybindings.go index 1275701..ee2744c 100644 --- a/cointop/keybindings.go +++ b/cointop/keybindings.go @@ -4,35 +4,8 @@ import ( "log" "github.com/jroimartin/gocui" - "github.com/miguelmota/cointop/pkg/open" ) -func (ct *Cointop) setKeybinding(key interface{}, callback func(g *gocui.Gui, v *gocui.View) error) { - var err error - switch t := key.(type) { - case gocui.Key: - err = ct.g.SetKeybinding("", t, gocui.ModNone, callback) - case rune: - err = ct.g.SetKeybinding("", t, gocui.ModNone, callback) - } - if err != nil { - log.Fatal(err) - } -} - -func (ct *Cointop) setKeybindingMod(key interface{}, mod gocui.Modifier, callback func(g *gocui.Gui, v *gocui.View) error) { - var err error - switch t := key.(type) { - case gocui.Key: - err = ct.g.SetKeybinding("", t, mod, callback) - case rune: - err = ct.g.SetKeybinding("", t, mod, callback) - } - if err != nil { - log.Fatal(err) - } -} - func (ct *Cointop) keybindings(g *gocui.Gui) error { ct.setKeybinding(gocui.KeyArrowUp, ct.cursorUp) ct.setKeybinding(gocui.KeyArrowDown, ct.cursorDown) @@ -84,16 +57,28 @@ func (ct *Cointop) keybindings(g *gocui.Gui) error { return nil } -func (ct *Cointop) refresh(g *gocui.Gui, v *gocui.View) error { - ct.forcerefresh <- true - return nil -} - -func (ct *Cointop) openLink(g *gocui.Gui, v *gocui.View) error { - open.URL(ct.rowLink()) - return nil +func (ct *Cointop) setKeybinding(key interface{}, callback func(g *gocui.Gui, v *gocui.View) error) { + var err error + switch t := key.(type) { + case gocui.Key: + err = ct.g.SetKeybinding("", t, gocui.ModNone, callback) + case rune: + err = ct.g.SetKeybinding("", t, gocui.ModNone, callback) + } + if err != nil { + log.Fatal(err) + } } -func (ct *Cointop) quit(g *gocui.Gui, v *gocui.View) error { - return gocui.ErrQuit +func (ct *Cointop) setKeybindingMod(key interface{}, mod gocui.Modifier, callback func(g *gocui.Gui, v *gocui.View) error) { + var err error + switch t := key.(type) { + case gocui.Key: + err = ct.g.SetKeybinding("", t, mod, callback) + case rune: + err = ct.g.SetKeybinding("", t, mod, callback) + } + if err != nil { + log.Fatal(err) + } } diff --git a/cointop/marketbar.go b/cointop/marketbar.go index 09886c4..e1d3d6c 100644 --- a/cointop/marketbar.go +++ b/cointop/marketbar.go @@ -17,7 +17,25 @@ func (ct *Cointop) updateMarketbar() error { timeframe := "7 Day" ct.Update(func() { ct.marketview.Clear() - fmt.Fprintln(ct.marketview, color.White(pad.Right(fmt.Sprintf("%s Chart: %s • Total Market Cap: %s • 24H Volume: %s • BTC Dominance: %.2f%% • Active Currencies: %s • Active Markets: %s", color.Cyan("cointop"), timeframe, humanize.Commaf(market.TotalMarketCapUSD), humanize.Commaf(market.Total24HVolumeUSD), market.BitcoinPercentageOfMarketCap, humanize.Commaf(float64(market.ActiveCurrencies)), humanize.Commaf(float64(market.ActiveMarkets))), maxX, " "))) + fmt.Fprintln( + ct.marketview, + color.White( + pad.Right( + fmt.Sprintf( + "%s Chart: %s • Total Market Cap: %s • 24H Volume: %s • BTC Dominance: %.2f%% • Active Currencies: %s • Active Markets: %s", + color.Cyan("cointop"), + timeframe, + humanize.Commaf(market.TotalMarketCapUSD), + humanize.Commaf(market.Total24HVolumeUSD), + market.BitcoinPercentageOfMarketCap, + humanize.Commaf(float64(market.ActiveCurrencies)), + humanize.Commaf(float64(market.ActiveMarkets)), + ), + maxX, + " ", + ), + ), + ) }) return nil } diff --git a/cointop/sort.go b/cointop/sort.go index 6f6ebc7..97c2330 100644 --- a/cointop/sort.go +++ b/cointop/sort.go @@ -78,6 +78,15 @@ func (ct *Cointop) sortfn(sortby string, desc bool) func(g *gocui.Gui, v *gocui. } } +func (ct *Cointop) getSortColIndex() int { + for i, col := range colorder { + if ct.sortby == col { + return i + } + } + return 0 +} + func (ct *Cointop) sortAsc(g *gocui.Gui, v *gocui.View) error { ct.sortdesc = false ct.sort(ct.sortby, ct.sortdesc, ct.coins) @@ -134,12 +143,3 @@ func (ct *Cointop) sortNextCol(g *gocui.Gui, v *gocui.View) error { ct.rowChanged() return nil } - -func (ct *Cointop) getSortColIndex() int { - for i, col := range colorder { - if ct.sortby == col { - return i - } - } - return 0 -} diff --git a/cointop/table.go b/cointop/table.go index 823ad67..808be34 100644 --- a/cointop/table.go +++ b/cointop/table.go @@ -6,9 +6,11 @@ import ( "strings" "time" + "github.com/jroimartin/gocui" apt "github.com/miguelmota/cointop/pkg/api/types" "github.com/miguelmota/cointop/pkg/color" "github.com/miguelmota/cointop/pkg/humanize" + "github.com/miguelmota/cointop/pkg/open" "github.com/miguelmota/cointop/pkg/table" ) @@ -106,3 +108,8 @@ func (ct *Cointop) rowLink() string { slug := strings.ToLower(strings.Replace(ct.selectedCoin().Name, " ", "-", -1)) return fmt.Sprintf("https://coinmarketcap.com/currencies/%s", slug) } + +func (ct *Cointop) openLink(g *gocui.Gui, v *gocui.View) error { + open.URL(ct.rowLink()) + return nil +}