From 7f38cf2ab2f68d298169f76a4bf217cf8614804b Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Thu, 10 Nov 2022 19:27:28 +1100 Subject: [PATCH] fix some things --- pkg/gui/container_logs.go | 11 ++++------- pkg/gui/panels/side_list_panel.go | 6 +++--- pkg/gui/tasks_adapter.go | 5 ++++- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/pkg/gui/container_logs.go b/pkg/gui/container_logs.go index 7efe06bb..b74fba94 100644 --- a/pkg/gui/container_logs.go +++ b/pkg/gui/container_logs.go @@ -21,8 +21,9 @@ func (gui *Gui) renderContainerLogsToMain(container *commands.Container) tasks.T Func: func(stop, notifyStopped chan struct{}) { gui.renderContainerLogsToMainAux(container, stop, notifyStopped) }, - Duration: time.Millisecond * 200, - Before: nil, + Duration: time.Millisecond * 200, + // TODO: see why this isn't working (when switching from Top tab to Logs tab in the services panel, the tops tab's content isn't removed) + Before: func(stop chan struct{}) { gui.clearMainView() }, Wrap: gui.Config.UserConfig.Gui.WrapMainPanel, Autoscroll: true, }) @@ -34,11 +35,7 @@ func (gui *Gui) renderContainerLogsToMainAux(container *commands.Container, stop notifyStopped <- struct{}{} }() - ctx, ctxCancel := context.WithCancel(context.Background()) - go func() { - <-stop - ctxCancel() - }() + ctx := stopIntoCtx(stop) mainView := gui.Views.Main diff --git a/pkg/gui/panels/side_list_panel.go b/pkg/gui/panels/side_list_panel.go index f5473880..36b6fd3e 100644 --- a/pkg/gui/panels/side_list_panel.go +++ b/pkg/gui/panels/side_list_panel.go @@ -6,6 +6,7 @@ import ( "github.com/go-errors/errors" "github.com/jesseduffield/gocui" + "github.com/jesseduffield/lazydocker/pkg/tasks" "github.com/jesseduffield/lazydocker/pkg/utils" "github.com/samber/lo" ) @@ -63,7 +64,7 @@ var _ ISideListPanel = &SideListPanel[int]{} type IGui interface { HandleClick(v *gocui.View, itemCount int, selectedLine *int, handleSelect func() error) error - RenderStringMain(message string) + NewSimpleRenderStringTask(getContent func() string) tasks.TaskFunc FocusY(selectedLine int, itemCount int, view *gocui.View) ShouldRefresh(contextKey string) bool GetMainView() *gocui.View @@ -107,8 +108,7 @@ func (self *SideListPanel[T]) HandleSelect() error { } if self.NoItemsMessage != "" { - // TODO: use task for this - self.Gui.RenderStringMain(self.NoItemsMessage) + self.Gui.NewSimpleRenderStringTask(func() string { return self.NoItemsMessage }) } return nil diff --git a/pkg/gui/tasks_adapter.go b/pkg/gui/tasks_adapter.go index 18214ce0..b282502c 100644 --- a/pkg/gui/tasks_adapter.go +++ b/pkg/gui/tasks_adapter.go @@ -35,6 +35,9 @@ func (gui *Gui) NewRenderStringTask(opts RenderStringTaskOpts) tasks.TaskFunc { Autoscroll: opts.Autoscroll, Wrap: opts.Wrap, Func: func(stop chan struct{}) { + // GetStrContent may be a slow function, so we clear the main view first + // so that we're not seeing the previous tab's content appear. + gui.clearMainView() gui.RenderStringMain(opts.GetStrContent()) }, } @@ -81,7 +84,7 @@ func (gui *Gui) NewTickerTask(opts TickerTaskOpts) tasks.TaskFunc { gui.Log.Info("exiting ticker task due to notifyStopped channel") return case <-stop: - gui.Log.Info("exiting ticker task due to stopped cahnnel") + gui.Log.Info("exiting ticker task due to stopped channel") return case <-tickChan.C: gui.Log.Info("running ticker task again")