Add chart loading label

pull/42/head
Miguel Mota 5 years ago
parent 3be23ec912
commit 96cab2b405
No known key found for this signature in database
GPG Key ID: 67EC1161588A00F9

@ -92,6 +92,7 @@ func (ct *Cointop) UpdateChart() error {
} }
} }
ct.update(func() { ct.update(func() {
if ct.Views.Chart.Backing() == nil { if ct.Views.Chart.Backing() == nil {
return return
@ -108,6 +109,7 @@ func (ct *Cointop) ChartPoints(symbol string, name string) error {
maxX := ct.maxTableWidth - 3 maxX := ct.maxTableWidth - 3
chartPointsLock.Lock() chartPointsLock.Lock()
defer chartPointsLock.Unlock() defer chartPointsLock.Unlock()
// TODO: not do this (SoC) // TODO: not do this (SoC)
go ct.updateMarketbar() go ct.updateMarketbar()
@ -209,6 +211,7 @@ func (ct *Cointop) PortfolioChart() error {
maxX := ct.maxTableWidth - 3 maxX := ct.maxTableWidth - 3
chartPointsLock.Lock() chartPointsLock.Lock()
defer chartPointsLock.Unlock() defer chartPointsLock.Unlock()
// TODO: not do this (SoC) // TODO: not do this (SoC)
go ct.updateMarketbar() go ct.updateMarketbar()
@ -374,7 +377,23 @@ func (ct *Cointop) ToggleCoinChart() error {
ct.State.selectedCoin = highlightedcoin ct.State.selectedCoin = highlightedcoin
} }
go ct.ShowChartLoader()
go ct.UpdateChart() go ct.UpdateChart()
go ct.updateMarketbar() go ct.updateMarketbar()
return nil return nil
} }
// ShowChartLoader shows chart loading indicator
func (ct *Cointop) ShowChartLoader() error {
ct.update(func() {
if ct.Views.Chart.Backing() == nil {
return
}
content := "\n\nLoading..."
ct.Views.Chart.Backing().Clear()
fmt.Fprint(ct.Views.Chart.Backing(), ct.colorscheme.Chart(content))
})
return nil
}

@ -149,7 +149,7 @@ func (s *Service) GetAllCoinData(convert string, ch chan []apitypes.Coin) error
func (s *Service) GetCoinGraphData(symbol, name string, start, end int64) (apitypes.CoinGraph, error) { func (s *Service) GetCoinGraphData(symbol, name string, start, end int64) (apitypes.CoinGraph, error) {
ret := apitypes.CoinGraph{} ret := apitypes.CoinGraph{}
days := strconv.Itoa(util.CalcDays(start, end)) days := strconv.Itoa(util.CalcDays(start, end))
chart, err := s.client.CoinsIDMarketChart(strings.ToLower(name), "usd", days) chart, err := s.client.CoinsIDMarketChart(util.NameToSlug(name), "usd", days)
if err != nil { if err != nil {
return ret, err return ret, err
} }

@ -23,6 +23,7 @@ func NewPortfolioUpdateMenuView() *PortfolioUpdateMenuView {
func (ct *Cointop) togglePortfolio() error { func (ct *Cointop) togglePortfolio() error {
ct.State.filterByFavorites = false ct.State.filterByFavorites = false
ct.State.portfolioVisible = !ct.State.portfolioVisible ct.State.portfolioVisible = !ct.State.portfolioVisible
go ct.UpdateChart()
go ct.updateTable() go ct.updateTable()
return nil return nil
} }
@ -30,6 +31,7 @@ func (ct *Cointop) togglePortfolio() error {
func (ct *Cointop) toggleShowPortfolio() error { func (ct *Cointop) toggleShowPortfolio() error {
ct.State.filterByFavorites = false ct.State.filterByFavorites = false
ct.State.portfolioVisible = true ct.State.portfolioVisible = true
go ct.UpdateChart()
go ct.updateTable() go ct.updateTable()
return nil return nil
} }
@ -39,6 +41,7 @@ func (ct *Cointop) togglePortfolioUpdateMenu() error {
if ct.State.portfolioUpdateMenuVisible { if ct.State.portfolioUpdateMenuVisible {
return ct.showPortfolioUpdateMenu() return ct.showPortfolioUpdateMenu()
} }
return ct.hidePortfolioUpdateMenu() return ct.hidePortfolioUpdateMenu()
} }

@ -43,6 +43,8 @@ func tableColumnOrder() []string {
} }
} }
const dots = "..."
// RefreshTable refreshes the table // RefreshTable refreshes the table
func (ct *Cointop) RefreshTable() error { func (ct *Cointop) RefreshTable() error {
maxX := ct.width() maxX := ct.width()
@ -74,7 +76,6 @@ func (ct *Cointop) RefreshTable() error {
color24h = ct.colorscheme.TableColumnChangeDown color24h = ct.colorscheme.TableColumnChangeDown
} }
name := coin.Name name := coin.Name
dots := "..."
star := " " star := " "
rank := fmt.Sprintf("%s%v", star, ct.colorscheme.TableRow(fmt.Sprintf("%6v ", coin.Rank))) rank := fmt.Sprintf("%s%v", star, ct.colorscheme.TableRow(fmt.Sprintf("%6v ", coin.Rank)))
if len(name) > 20 { if len(name) > 20 {
@ -143,7 +144,6 @@ func (ct *Cointop) RefreshTable() error {
color7d = ct.colorscheme.TableColumnChangeDown color7d = ct.colorscheme.TableColumnChangeDown
} }
name := coin.Name name := coin.Name
dots := "..."
star := ct.colorscheme.TableRow(" ") star := ct.colorscheme.TableRow(" ")
if coin.Favorite { if coin.Favorite {
star = ct.colorscheme.TableRowFavorite("*") star = ct.colorscheme.TableRowFavorite("*")
@ -312,7 +312,7 @@ func (ct *Cointop) RowLinkShort() string {
path = parts[len(parts)-1] path = parts[len(parts)-1]
} }
return fmt.Sprintf("http://%s/.../%s", host, path) return fmt.Sprintf("http://%s/%s/%s", host, dots, path)
} }
return "" return ""

@ -36,12 +36,18 @@ func (view *View) SetBacking(gocuiView *gocui.View) {
view.backing = gocuiView view.backing = gocuiView
} }
// Height returns thejview height // Height returns the view height
func (view *View) Height() int { func (view *View) Height() int {
_, h := view.backing.Size() _, h := view.backing.Size()
return h return h
} }
// Width returns the view width
func (view *View) Width() int {
w, _ := view.backing.Size()
return w
}
// Name returns the view's name // Name returns the view's name
func (view *View) Name() string { func (view *View) Name() string {
return view.name return view.name

Loading…
Cancel
Save