mirror of https://github.com/miguelmota/cointop
update callback
Former-commit-id: 4452cab78acae295dea978e6838d62b862b4fbe1 [formerly 4452cab78acae295dea978e6838d62b862b4fbe1 [formerly 2db8e14e33e1008a435fb84eb9de312a70752870 [formerly 9b237bf21a
]]]
Former-commit-id: cfa7c8d52ce17a373fa29f75a8b65ceea66afa7f
Former-commit-id: ab4eeba33fc0bd48bbd3c9046cb3bdd851d566c3 [formerly 1894a0300e55eb15e7acbd53995645829a697338]
Former-commit-id: 9d00db9d072a064afc7e5c09894c35e1414c7863
pull/15/head
parent
ad9ab777d8
commit
a3546916b3
@ -1,21 +0,0 @@
|
||||
package cointop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/miguelmota/cointop/pkg/color"
|
||||
"github.com/miguelmota/cointop/pkg/humanize"
|
||||
"github.com/miguelmota/cointop/pkg/pad"
|
||||
)
|
||||
|
||||
func (ct *Cointop) updateMarket() error {
|
||||
maxX, _ := ct.g.Size()
|
||||
market, err := ct.api.GetGlobalMarketData()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
timeframe := "7 Day"
|
||||
ct.marketview.Clear()
|
||||
fmt.Fprintln(ct.marketview, 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, color.WhiteBold(humanize.Commaf(market.TotalMarketCapUSD)), humanize.Commaf(market.Total24HVolumeUSD), market.BitcoinPercentageOfMarketCap, humanize.Commaf(float64(market.ActiveCurrencies)), humanize.Commaf(float64(market.ActiveMarkets))), maxX, " "))
|
||||
return nil
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package cointop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/miguelmota/cointop/pkg/color"
|
||||
"github.com/miguelmota/cointop/pkg/humanize"
|
||||
"github.com/miguelmota/cointop/pkg/pad"
|
||||
)
|
||||
|
||||
func (ct *Cointop) updateMarket() error {
|
||||
maxX := ct.Width()
|
||||
market, err := ct.api.GetGlobalMarketData()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
timeframe := "7 Day"
|
||||
ct.Update(func() {
|
||||
ct.marketview.Clear()
|
||||
fmt.Fprintln(ct.marketview, 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, color.WhiteBold(humanize.Commaf(market.TotalMarketCapUSD)), humanize.Commaf(market.Total24HVolumeUSD), market.BitcoinPercentageOfMarketCap, humanize.Commaf(float64(market.ActiveCurrencies)), humanize.Commaf(float64(market.ActiveMarkets))), maxX, " "))
|
||||
})
|
||||
return nil
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package cointop
|
||||
|
||||
// Size returns window width and height
|
||||
func (ct *Cointop) Size() (int, int) {
|
||||
return ct.g.Size()
|
||||
}
|
||||
|
||||
// Width returns window width
|
||||
func (ct *Cointop) Width() int {
|
||||
w, _ := ct.Size()
|
||||
return w
|
||||
}
|
||||
|
||||
// Height returns window height
|
||||
func (ct *Cointop) Height() int {
|
||||
_, h := ct.Size()
|
||||
return h
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
package cointop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/jroimartin/gocui"
|
||||
"github.com/miguelmota/cointop/pkg/pad"
|
||||
)
|
||||
|
||||
func (ct *Cointop) updateStatus(s string) {
|
||||
maxX, _ := ct.g.Size()
|
||||
ct.g.Update(func(g *gocui.Gui) error {
|
||||
ct.statusview.Clear()
|
||||
fmt.Fprintln(ct.statusview, pad.Right(fmt.Sprintf("[q]uit [← →]page %s", s), maxX, " "))
|
||||
return nil
|
||||
})
|
||||
}
|
||||
|
||||
func (ct *Cointop) refreshRowLink() {
|
||||
url := ct.rowLink()
|
||||
ct.g.Update(func(g *gocui.Gui) error {
|
||||
ct.updateStatus(fmt.Sprintf("[↵]%s", url))
|
||||
return nil
|
||||
})
|
||||
}
|
@ -0,0 +1,22 @@
|
||||
package cointop
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/miguelmota/cointop/pkg/pad"
|
||||
)
|
||||
|
||||
func (ct *Cointop) updateStatusbar(s string) {
|
||||
maxX := ct.Width()
|
||||
ct.Update(func() {
|
||||
ct.statusbarview.Clear()
|
||||
fmt.Fprintln(ct.statusbarview, pad.Right(fmt.Sprintf("[q]uit [← →]page %s", s), maxX, " "))
|
||||
})
|
||||
}
|
||||
|
||||
func (ct *Cointop) refreshRowLink() {
|
||||
url := ct.rowLink()
|
||||
ct.Update(func() {
|
||||
ct.updateStatusbar(fmt.Sprintf("[↵]%s", url))
|
||||
})
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package cointop
|
||||
|
||||
import "github.com/jroimartin/gocui"
|
||||
|
||||
// Update update view
|
||||
func (ct *Cointop) Update(f func()) {
|
||||
ct.g.Update(func(g *gocui.Gui) error {
|
||||
f()
|
||||
return nil
|
||||
})
|
||||
}
|
Loading…
Reference in New Issue