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