pull/15/head 1.0.4
Miguel Mota 6 years ago
parent ca7b105a9b
commit 70748c8e66

@ -503,6 +503,14 @@ Action|Description
- A: Press <kbd>q</kbd> to quit the open view/window.
- Q: I'm getting the error `open /dev/tty: no such device or address`.
-A: Usually this error occurs when cointop is running as a daemon or slave which means that there is no terminal allocated, so `/dev/tty` doesn't exist for that process. Try running it with the following environment variables:
```bash
DEV_IN=/dev/stdout DEV_OUT=/dev/stdin cointop
```
## Development
### Go

@ -69,16 +69,13 @@ type Cointop struct {
convertmenuvisible bool
}
// Instance running cointop instance
var Instance *Cointop
// Run runs cointop
func Run() {
// New initializes cointop
func New() *Cointop {
var debug bool
if os.Getenv("DEBUG") != "" {
debug = true
}
ct := Cointop{
ct := &Cointop{
api: api.NewCMC(),
refreshticker: time.NewTicker(1 * time.Minute),
sortby: "rank",
@ -142,7 +139,6 @@ func Run() {
convertmenuviewname: "convertmenu",
currencyconversion: "USD",
}
Instance = &ct
err := ct.setupConfig()
if err != nil {
log.Fatal(err)
@ -162,7 +158,15 @@ func Run() {
marketcachekey := "market"
fcache.Get(marketcachekey, &market)
ct.cache.Set(marketcachekey, market, 10*time.Second)
err = ct.api.Ping()
if err != nil {
log.Fatal(err)
}
return ct
}
// Run runs cointop
func (ct *Cointop) Run() {
g, err := gocui.NewGui(gocui.Output256)
if err != nil {
log.Fatalf("new gocui: %v", err)
@ -195,8 +199,10 @@ func (ct *Cointop) quitView() error {
}
// Exit safely exit application
func Exit() {
if Instance != nil {
Instance.g.Close()
func (ct *Cointop) Exit() {
if ct.g != nil {
ct.g.Close()
} else {
os.Exit(0)
}
}

@ -3,7 +3,6 @@ package main
import (
"flag"
"fmt"
"time"
"github.com/miguelmota/cointop/cointop"
)
@ -11,27 +10,19 @@ import (
var version = "1.0.1"
func main() {
var ver bool
var ver, test bool
flag.BoolVar(&ver, "v", false, "Version")
var test bool
flag.BoolVar(&test, "test", false, "Run test")
flag.Parse()
if ver {
fmt.Println(version)
return
} else if test {
doTest()
} else {
cointop.New().Run()
}
if test {
runTest()
return
}
cointop.Run()
}
func runTest() {
go func() {
cointop.Run()
}()
time.Sleep(1 * time.Second)
cointop.Exit()
func doTest() {
cointop.New().Exit()
}

@ -1,6 +1,7 @@
package coinmarketcap
import (
"errors"
"fmt"
"strconv"
"strings"
@ -19,6 +20,20 @@ func New() *Service {
return &Service{}
}
// Ping ping API
func (s *Service) Ping() error {
ticker, err := cmc.Ticker(&cmc.TickerOptions{
Symbol: "ETH",
})
if err != nil {
return errors.New("failed to ping")
}
if ticker == nil {
return errors.New("failed to ping")
}
return nil
}
func getLimitedCoinData(convert string, offset int) (map[string]apitypes.Coin, error) {
ret := make(map[string]apitypes.Coin)
max := 100

@ -6,6 +6,7 @@ import (
// Interface interface
type Interface interface {
Ping() error
GetAllCoinData(convert string) (map[string]types.Coin, error)
GetCoinGraphData(coin string, start int64, end int64) (types.CoinGraph, error)
GetGlobalMarketGraphData(start int64, end int64) (types.MarketGraph, error)

Loading…
Cancel
Save