From ca1987a0f8a6c0968c36559785483e13c8b1ecdc Mon Sep 17 00:00:00 2001 From: Miguel Mota Date: Sun, 29 Dec 2019 16:54:42 -0800 Subject: [PATCH] Return error on update callback --- cointop/chart.go | 10 ++++++---- cointop/conversion.go | 10 ++++++---- cointop/help.go | 10 ++++++---- cointop/marketbar.go | 5 +++-- cointop/portfolio.go | 9 ++++++--- cointop/statusbar.go | 3 ++- cointop/table.go | 5 +++-- cointop/table_header.go | 5 +++-- cointop/update.go | 6 ++---- 9 files changed, 37 insertions(+), 26 deletions(-) diff --git a/cointop/chart.go b/cointop/chart.go index 983aff7..a7a23ae 100644 --- a/cointop/chart.go +++ b/cointop/chart.go @@ -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 diff --git a/cointop/conversion.go b/cointop/conversion.go index 4ccef1e..167a747 100644 --- a/cointop/conversion.go +++ b/cointop/conversion.go @@ -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 } diff --git a/cointop/help.go b/cointop/help.go index 098e23e..e74d180 100644 --- a/cointop/help.go +++ b/cointop/help.go @@ -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 } diff --git a/cointop/marketbar.go b/cointop/marketbar.go index 08c96d1..cae9227 100644 --- a/cointop/marketbar.go +++ b/cointop/marketbar.go @@ -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 diff --git a/cointop/portfolio.go b/cointop/portfolio.go index 2430daf..7c695a1 100644 --- a/cointop/portfolio.go +++ b/cointop/portfolio.go @@ -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 } diff --git a/cointop/statusbar.go b/cointop/statusbar.go index cfa987a..4390a19 100644 --- a/cointop/statusbar.go +++ b/cointop/statusbar.go @@ -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 diff --git a/cointop/table.go b/cointop/table.go index 5f4d9ae..60d3407 100644 --- a/cointop/table.go +++ b/cointop/table.go @@ -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 diff --git a/cointop/table_header.go b/cointop/table_header.go index 3c3723e..dc71c37 100644 --- a/cointop/table_header.go +++ b/cointop/table_header.go @@ -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 }) } diff --git a/cointop/update.go b/cointop/update.go index a5183fb..fb95833 100644 --- a/cointop/update.go +++ b/cointop/update.go @@ -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() }) }