diff --git a/pkg/commands/docker.go b/pkg/commands/docker.go index 56ced398..2dc5e6ae 100644 --- a/pkg/commands/docker.go +++ b/pkg/commands/docker.go @@ -107,6 +107,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat // MonitorContainerStats is a function func (c *DockerCommand) MonitorContainerStats() { + // TODO: pass in a stop channel to these so we don't restart every time we come back from a subprocess go c.MonitorCLIContainerStats() go c.MonitorClientContainerStats() } @@ -150,7 +151,9 @@ func (c *DockerCommand) MonitorCLIContainerStats() { func (c *DockerCommand) MonitorClientContainerStats() { // periodically loop through running containers and see if we need to create a monitor goroutine for any // every second we check if we need to spawn a new goroutine - for range time.Tick(time.Second) { + ticker := time.NewTicker(time.Second) + defer ticker.Stop() + for range ticker.C { for _, container := range c.Containers { if !container.MonitoringStats { go c.createClientStatMonitor(container) diff --git a/pkg/gui/app_status_manager.go b/pkg/gui/app_status_manager.go index 980fbc07..20a81120 100644 --- a/pkg/gui/app_status_manager.go +++ b/pkg/gui/app_status_manager.go @@ -1,6 +1,8 @@ package gui import ( + "time" + "github.com/jesseduffield/gocui" "github.com/jesseduffield/lazydocker/pkg/utils" ) @@ -49,15 +51,25 @@ func (m *statusManager) getStatusString() string { // WithWaitingStatus wraps a function and shows a waiting status while the function is still executing func (gui *Gui) WithWaitingStatus(name string, f func() error) error { go func() { - gui.g.Update(func(g *gocui.Gui) error { - gui.statusManager.addWaitingStatus(name) - return nil - }) + gui.statusManager.addWaitingStatus(name) - defer gui.g.Update(func(g *gocui.Gui) error { + defer func() { gui.statusManager.removeStatus(name) - return nil - }) + }() + + go func() { + ticker := time.NewTicker(time.Millisecond * 50) + defer ticker.Stop() + for range ticker.C { + appStatus := gui.statusManager.getStatusString() + if appStatus == "" { + return + } + if err := gui.renderString(gui.g, "appStatus", appStatus); err != nil { + gui.Log.Warn(err) + } + } + }() if err := f(); err != nil { gui.g.Update(func(g *gocui.Gui) error { diff --git a/pkg/gui/confirmation_panel.go b/pkg/gui/confirmation_panel.go index 7ebf8477..c0bd26e7 100644 --- a/pkg/gui/confirmation_panel.go +++ b/pkg/gui/confirmation_panel.go @@ -79,6 +79,7 @@ func (gui *Gui) prepareConfirmationPanel(currentView *gocui.View, title, prompt return nil, err } confirmationView.HasLoader = hasLoader + gui.g.StartTicking() confirmationView.Title = title confirmationView.Wrap = true confirmationView.FgColor = gocui.ColorWhite diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index 410303e7..db171219 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -214,14 +214,6 @@ func (gui *Gui) promptAnonymousReporting() error { }) } -func (gui *Gui) renderAppStatus() error { - appStatus := gui.statusManager.getStatusString() - if appStatus != "" { - return gui.renderString(gui.g, "appStatus", appStatus) - } - return nil -} - func (gui *Gui) renderGlobalOptions() error { return gui.renderOptionsMap(map[string]string{ "PgUp/PgDn": gui.Tr.Scroll, @@ -236,7 +228,9 @@ func (gui *Gui) goEvery(interval time.Duration, function func() error) { currentSessionIndex := gui.State.SessionIndex _ = function() // time.Tick doesn't run immediately so we'll do that here // TODO: maybe change go func() { - for range time.Tick(interval) { + ticker := time.NewTicker(interval) + defer ticker.Stop() + for range ticker.C { if gui.State.SessionIndex > currentSessionIndex { return } @@ -276,7 +270,6 @@ func (gui *Gui) Run() error { dockerRefreshInterval := gui.Config.UserConfig.Update.DockerRefreshInterval go func() { gui.waitForIntro.Wait() - gui.goEvery(time.Millisecond*50, gui.renderAppStatus) gui.goEvery(time.Millisecond*30, gui.reRenderMain) gui.goEvery(dockerRefreshInterval, gui.refreshProject) gui.goEvery(dockerRefreshInterval, gui.refreshContainersAndServices) @@ -285,7 +278,7 @@ func (gui *Gui) Run() error { gui.goEvery(time.Millisecond*1000, gui.checkForContextChange) }() - go gui.DockerCommand.MonitorContainerStats() + gui.DockerCommand.MonitorContainerStats() go func() { for err := range gui.ErrorChan {