mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
move goroutine call into the NewTask function
This commit is contained in:
parent
97ce1f14d5
commit
383f8a51e3
6 changed files with 36 additions and 44 deletions
|
|
@ -122,11 +122,9 @@ func (gui *Gui) renderContainerConfig(container *commands.Container) error {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
go gui.T.NewTask(func(stop chan struct{}) {
|
return gui.T.NewTask(func(stop chan struct{}) {
|
||||||
gui.renderString(gui.g, "main", string(data))
|
gui.renderString(gui.g, "main", string(data))
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderContainerStats(container *commands.Container) error {
|
func (gui *Gui) renderContainerStats(container *commands.Container) error {
|
||||||
|
|
@ -173,17 +171,15 @@ func (gui *Gui) renderContainerLogs(container *commands.Container) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderLogsForRegularContainer(container *commands.Container) error {
|
func (gui *Gui) renderLogsForRegularContainer(container *commands.Container) error {
|
||||||
gui.renderLogs(container, gui.Config.UserConfig.CommandTemplates.ContainerLogs, func(cmd *exec.Cmd) {
|
return gui.renderLogs(container, gui.Config.UserConfig.CommandTemplates.ContainerLogs, func(cmd *exec.Cmd) {
|
||||||
mainView := gui.getMainView()
|
mainView := gui.getMainView()
|
||||||
cmd.Stdout = mainView
|
cmd.Stdout = mainView
|
||||||
cmd.Stderr = mainView
|
cmd.Stderr = mainView
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderLogsForTTYContainer(container *commands.Container) error {
|
func (gui *Gui) renderLogsForTTYContainer(container *commands.Container) error {
|
||||||
gui.renderLogs(container, gui.Config.UserConfig.CommandTemplates.ContainerTTYLogs, func(cmd *exec.Cmd) {
|
return gui.renderLogs(container, gui.Config.UserConfig.CommandTemplates.ContainerTTYLogs, func(cmd *exec.Cmd) {
|
||||||
// for some reason just saying cmd.Stdout = mainView does not work here as it does for non-tty containers, so we feed it through line by line
|
// for some reason just saying cmd.Stdout = mainView does not work here as it does for non-tty containers, so we feed it through line by line
|
||||||
r, err := cmd.StdoutPipe()
|
r, err := cmd.StdoutPipe()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
@ -200,12 +196,10 @@ func (gui *Gui) renderLogsForTTYContainer(container *commands.Container) error {
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderLogs(container *commands.Container, template string, setup func(*exec.Cmd)) {
|
func (gui *Gui) renderLogs(container *commands.Container, template string, setup func(*exec.Cmd)) error {
|
||||||
gui.T.NewTickerTask(time.Millisecond*200, nil, func(stop, notifyStopped chan struct{}) {
|
return gui.T.NewTickerTask(time.Millisecond*200, nil, func(stop, notifyStopped chan struct{}) {
|
||||||
gui.clearMainView()
|
gui.clearMainView()
|
||||||
|
|
||||||
cmd := container.TTYLogsCommand()
|
cmd := container.TTYLogsCommand()
|
||||||
|
|
|
||||||
|
|
@ -97,7 +97,7 @@ func (gui *Gui) handleImageSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderImageConfig(mainView *gocui.View, image *commands.Image) error {
|
func (gui *Gui) renderImageConfig(mainView *gocui.View, image *commands.Image) error {
|
||||||
go gui.T.NewTask(func(stop chan struct{}) {
|
return gui.T.NewTask(func(stop chan struct{}) {
|
||||||
padding := 10
|
padding := 10
|
||||||
output := ""
|
output := ""
|
||||||
output += utils.WithPadding("Name: ", padding) + image.Name + "\n"
|
output += utils.WithPadding("Name: ", padding) + image.Name + "\n"
|
||||||
|
|
@ -118,8 +118,6 @@ func (gui *Gui) renderImageConfig(mainView *gocui.View, image *commands.Image) e
|
||||||
|
|
||||||
gui.renderString(gui.g, "main", output)
|
gui.renderString(gui.g, "main", output)
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshImages() error {
|
func (gui *Gui) refreshImages() error {
|
||||||
|
|
|
||||||
|
|
@ -137,12 +137,15 @@ func (gui *Gui) renderServiceLogs(service *commands.Service) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
if service.Container == nil {
|
if service.Container == nil {
|
||||||
go gui.T.NewTask(func(stop chan struct{}) {
|
gui.Log.Warn("container is nil")
|
||||||
|
return gui.T.NewTask(func(stop chan struct{}) {
|
||||||
|
gui.Log.Warn("about to clear main view")
|
||||||
gui.clearMainView()
|
gui.clearMainView()
|
||||||
|
gui.Log.Warn("cleared main view")
|
||||||
})
|
})
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
gui.Log.Warn("about to render container logs for service ", service.Name)
|
||||||
return gui.renderContainerLogs(service.Container)
|
return gui.renderContainerLogs(service.Container)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ func (gui *Gui) handleStatusSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderCredits() error {
|
func (gui *Gui) renderCredits() error {
|
||||||
go gui.T.NewTask(func(stop chan struct{}) {
|
return gui.T.NewTask(func(stop chan struct{}) {
|
||||||
mainView := gui.getMainView()
|
mainView := gui.getMainView()
|
||||||
mainView.Autoscroll = false
|
mainView.Autoscroll = false
|
||||||
mainView.Wrap = true
|
mainView.Wrap = true
|
||||||
|
|
@ -95,12 +95,10 @@ func (gui *Gui) renderCredits() error {
|
||||||
|
|
||||||
gui.renderString(gui.g, "main", dashboardString)
|
gui.renderString(gui.g, "main", dashboardString)
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderAllLogs() error {
|
func (gui *Gui) renderAllLogs() error {
|
||||||
go gui.T.NewTask(func(stop chan struct{}) {
|
return gui.T.NewTask(func(stop chan struct{}) {
|
||||||
mainView := gui.getMainView()
|
mainView := gui.getMainView()
|
||||||
mainView.Autoscroll = true
|
mainView.Autoscroll = true
|
||||||
mainView.Wrap = true
|
mainView.Wrap = true
|
||||||
|
|
@ -129,12 +127,10 @@ func (gui *Gui) renderAllLogs() error {
|
||||||
|
|
||||||
cmd.Wait()
|
cmd.Wait()
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderDockerComposeConfig() error {
|
func (gui *Gui) renderDockerComposeConfig() error {
|
||||||
go gui.T.NewTask(func(stop chan struct{}) {
|
return gui.T.NewTask(func(stop chan struct{}) {
|
||||||
mainView := gui.getMainView()
|
mainView := gui.getMainView()
|
||||||
mainView.Autoscroll = false
|
mainView.Autoscroll = false
|
||||||
mainView.Wrap = true
|
mainView.Wrap = true
|
||||||
|
|
@ -142,8 +138,6 @@ func (gui *Gui) renderDockerComposeConfig() error {
|
||||||
config := gui.DockerCommand.DockerComposeConfig()
|
config := gui.DockerCommand.DockerComposeConfig()
|
||||||
gui.renderString(gui.g, "main", config)
|
gui.renderString(gui.g, "main", config)
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleOpenConfig(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleOpenConfig(g *gocui.Gui, v *gocui.View) error {
|
||||||
|
|
|
||||||
|
|
@ -95,7 +95,7 @@ func (gui *Gui) handleVolumeSelect(g *gocui.Gui, v *gocui.View) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) renderVolumeConfig(mainView *gocui.View, volume *commands.Volume) error {
|
func (gui *Gui) renderVolumeConfig(mainView *gocui.View, volume *commands.Volume) error {
|
||||||
go gui.T.NewTask(func(stop chan struct{}) {
|
return gui.T.NewTask(func(stop chan struct{}) {
|
||||||
mainView.Autoscroll = false
|
mainView.Autoscroll = false
|
||||||
mainView.Wrap = true
|
mainView.Wrap = true
|
||||||
|
|
||||||
|
|
@ -142,8 +142,6 @@ func (gui *Gui) renderVolumeConfig(mainView *gocui.View, volume *commands.Volume
|
||||||
|
|
||||||
gui.renderString(gui.g, "main", output)
|
gui.renderString(gui.g, "main", output)
|
||||||
})
|
})
|
||||||
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func formatMapItem(padding int, k string, v interface{}) string {
|
func formatMapItem(padding int, k string, v interface{}) string {
|
||||||
|
|
|
||||||
|
|
@ -25,25 +25,30 @@ func NewTaskManager(log *logrus.Entry) *TaskManager {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (t *TaskManager) NewTask(f func(stop chan struct{})) error {
|
func (t *TaskManager) NewTask(f func(stop chan struct{})) error {
|
||||||
t.waitingMutex.Lock()
|
|
||||||
defer t.waitingMutex.Unlock()
|
|
||||||
|
|
||||||
if t.currentTask != nil {
|
// TODO: topple the previous task if there is a new one
|
||||||
t.currentTask.Stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
stop := make(chan struct{}, 1) // we don't want to block on this in case the task already returned
|
|
||||||
notifyStopped := make(chan struct{})
|
|
||||||
|
|
||||||
t.currentTask = &Task{
|
|
||||||
stop: stop,
|
|
||||||
notifyStopped: notifyStopped,
|
|
||||||
Log: t.Log,
|
|
||||||
}
|
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
f(stop)
|
t.waitingMutex.Lock()
|
||||||
close(notifyStopped)
|
defer t.waitingMutex.Unlock()
|
||||||
|
|
||||||
|
if t.currentTask != nil {
|
||||||
|
t.currentTask.Stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
stop := make(chan struct{}, 1) // we don't want to block on this in case the task already returned
|
||||||
|
notifyStopped := make(chan struct{})
|
||||||
|
|
||||||
|
t.currentTask = &Task{
|
||||||
|
stop: stop,
|
||||||
|
notifyStopped: notifyStopped,
|
||||||
|
Log: t.Log,
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
|
f(stop)
|
||||||
|
close(notifyStopped)
|
||||||
|
}()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue