mirror of
https://github.com/miguelmota/cointop
synced 2024-11-05 00:00:14 +00:00
some cleanup
Former-commit-id: 07546683f2a9b7af2f4d27fa29633e17416042e7 [formerly 07546683f2a9b7af2f4d27fa29633e17416042e7 [formerly c89078b9dcfb63271fdb57df3cce4f3354a4e297 [formerly c3a1812078
]]]
Former-commit-id: b1622d72f4f26bbf66628daf382df18a7407f93a
Former-commit-id: 5b0373ce01454f12cc068915d0629d6b41797df2 [formerly c340e84436a7b8defdbb3d1d12dad0343e3e39df]
Former-commit-id: a4413dd3dcaa39b30c70eb8e09e18596bf0de916
This commit is contained in:
parent
07b7defed6
commit
4f17e84e65
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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) 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) openLink(g *gocui.Gui, v *gocui.View) error {
|
||||
open.URL(ct.rowLink())
|
||||
return nil
|
||||
}
|
||||
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user