Return error on update callback

pull/49/head
Miguel Mota 4 years ago
parent 38187de57c
commit ca1987a0f8

@ -91,13 +91,14 @@ func (ct *Cointop) UpdateChart() error {
}
}
ct.Update(func() {
ct.Update(func() error {
if ct.Views.Chart.Backing() == nil {
return
return nil
}
ct.Views.Chart.Backing().Clear()
fmt.Fprint(ct.Views.Chart.Backing(), ct.colorscheme.Chart(body))
return nil
})
return nil
@ -424,14 +425,15 @@ func (ct *Cointop) ToggleCoinChart() error {
// ShowChartLoader shows chart loading indicator
func (ct *Cointop) ShowChartLoader() error {
ct.debuglog("ShowChartLoader()")
ct.Update(func() {
ct.Update(func() error {
if ct.Views.Chart.Backing() == nil {
return
return nil
}
content := "\n\nLoading..."
ct.Views.Chart.Backing().Clear()
fmt.Fprint(ct.Views.Chart.Backing(), ct.colorscheme.Chart(content))
return nil
})
return nil

@ -174,14 +174,15 @@ func (ct *Cointop) updateConvertMenu() {
}
content := fmt.Sprintf("%s%s%s", header, helpline, body)
ct.Update(func() {
ct.Update(func() error {
if ct.Views.ConvertMenu.Backing() == nil {
return
return nil
}
ct.Views.ConvertMenu.Backing().Clear()
ct.Views.ConvertMenu.Backing().Frame = true
fmt.Fprintln(ct.Views.ConvertMenu.Backing(), content)
return nil
})
}
@ -230,14 +231,15 @@ func (ct *Cointop) hideConvertMenu() error {
ct.State.convertMenuVisible = false
ct.SetViewOnBottom(ct.Views.ConvertMenu.Name())
ct.SetActiveView(ct.Views.Table.Name())
ct.Update(func() {
ct.Update(func() error {
if ct.Views.ConvertMenu.Backing() == nil {
return
return nil
}
ct.Views.ConvertMenu.Backing().Clear()
ct.Views.ConvertMenu.Backing().Frame = false
fmt.Fprintln(ct.Views.ConvertMenu.Backing(), "")
return nil
})
return nil
}

@ -58,14 +58,15 @@ func (ct *Cointop) updateHelp() {
versionline := pad.Left(fmt.Sprintf("v%s", ct.Version()), ct.maxTableWidth-5, " ")
content := header + infoline + body + versionline
ct.Update(func() {
ct.Update(func() error {
if ct.Views.Help.Backing() == nil {
return
return nil
}
ct.Views.Help.Backing().Clear()
ct.Views.Help.Backing().Frame = true
fmt.Fprintln(ct.Views.Help.Backing(), content)
return nil
})
}
@ -82,14 +83,15 @@ func (ct *Cointop) hideHelp() error {
ct.State.helpVisible = false
ct.SetViewOnBottom(ct.Views.Help.Name())
ct.SetActiveView(ct.Views.Table.Name())
ct.Update(func() {
ct.Update(func() error {
if ct.Views.Help.Backing() == nil {
return
return nil
}
ct.Views.Help.Backing().Clear()
ct.Views.Help.Backing().Frame = false
fmt.Fprintln(ct.Views.Help.Backing(), "")
return nil
})
return nil
}

@ -143,13 +143,14 @@ func (ct *Cointop) updateMarketbar() error {
content = pad.Right(content, maxX, " ")
content = ct.colorscheme.Marketbar(content)
ct.Update(func() {
ct.Update(func() error {
if ct.Views.Marketbar.Backing() == nil {
return
return nil
}
ct.Views.Marketbar.Backing().Clear()
fmt.Fprintln(ct.Views.Marketbar.Backing(), content)
return nil
})
return nil

@ -81,12 +81,13 @@ func (ct *Cointop) updatePortfolioUpdateMenu() {
label := fmt.Sprintf(" Enter holdings for %s %s", ct.colorscheme.MenuLabel(coin.Name), current)
content := fmt.Sprintf("%s\n%s\n\n%s%s\n\n\n [Enter] %s [ESC] Cancel", header, label, strings.Repeat(" ", 29), coin.Symbol, submitText)
ct.Update(func() {
ct.Update(func() error {
ct.Views.PortfolioUpdateMenu.Backing().Clear()
ct.Views.PortfolioUpdateMenu.Backing().Frame = true
fmt.Fprintln(ct.Views.PortfolioUpdateMenu.Backing(), content)
fmt.Fprintln(ct.Views.Input.Backing(), value)
ct.Views.Input.Backing().SetCursor(len(value), 0)
return nil
})
}
@ -111,9 +112,9 @@ func (ct *Cointop) hidePortfolioUpdateMenu() error {
ct.SetViewOnBottom(ct.Views.PortfolioUpdateMenu.Name())
ct.SetViewOnBottom(ct.Views.Input.Name())
ct.SetActiveView(ct.Views.Table.Name())
ct.Update(func() {
ct.Update(func() error {
if ct.Views.PortfolioUpdateMenu.Backing() == nil {
return
return nil
}
ct.Views.PortfolioUpdateMenu.Backing().Clear()
@ -122,7 +123,9 @@ func (ct *Cointop) hidePortfolioUpdateMenu() error {
ct.Views.Input.Backing().Clear()
fmt.Fprintln(ct.Views.Input.Backing(), "")
return nil
})
return nil
}

@ -63,8 +63,9 @@ func (ct *Cointop) UpdateStatusbar(s string) error {
str = str[:end] + v
ct.Update(func() {
ct.Update(func() error {
ct.Views.Statusbar.Update(str)
return nil
})
return nil

@ -193,9 +193,9 @@ func (ct *Cointop) RefreshTable() error {
ct.highlightRow(currentrow)
}
ct.Update(func() {
ct.Update(func() error {
if ct.Views.Table.Backing() == nil {
return
return nil
}
ct.Views.Table.Backing().Clear()
@ -204,6 +204,7 @@ func (ct *Cointop) RefreshTable() error {
go ct.UpdateTableHeader()
go ct.updateMarketbar()
go ct.UpdateChart()
return nil
})
return nil

@ -89,12 +89,13 @@ func (ct *Cointop) UpdateTableHeader() {
headers = append(headers, str)
}
ct.Update(func() {
ct.Update(func() error {
if ct.Views.TableHeader.Backing() == nil {
return
return nil
}
ct.Views.TableHeader.Backing().Clear()
fmt.Fprintln(ct.Views.TableHeader.Backing(), strings.Join(headers, ""))
return nil
})
}

@ -7,7 +7,7 @@ import (
)
// Update takes a callback which updates the view
func (ct *Cointop) Update(f func()) {
func (ct *Cointop) Update(f func() error) {
ct.debuglog(fmt.Sprintf("Update()"))
if ct.g == nil {
@ -15,8 +15,6 @@ func (ct *Cointop) Update(f func()) {
}
ct.g.Update(func(g *gocui.Gui) error {
f()
return nil
return f()
})
}

Loading…
Cancel
Save