mirror of
https://github.com/jesseduffield/lazydocker.git
synced 2026-07-25 08:31:03 +00:00
slightly more responsive
This commit is contained in:
parent
9db6eeac9d
commit
3c9437f801
1 changed files with 47 additions and 43 deletions
|
|
@ -178,58 +178,62 @@ func (gui *Gui) renderContainerLogs(container *commands.Container) error {
|
||||||
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
|
mainView.Wrap = gui.Config.UserConfig.Gui.WrapMainPanel
|
||||||
|
|
||||||
return 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.renderContainerLogsAux(container, stop, notifyStopped)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
command := utils.ApplyTemplate(
|
func (gui *Gui) renderContainerLogsAux(container *commands.Container, stop, notifyStopped chan struct{}) {
|
||||||
gui.Config.UserConfig.CommandTemplates.ContainerLogs,
|
gui.clearMainView()
|
||||||
gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}),
|
|
||||||
)
|
|
||||||
cmd := gui.OSCommand.RunCustomCommand(command)
|
|
||||||
|
|
||||||
// Ensure the child process is treated as a group, as the child process spawns
|
command := utils.ApplyTemplate(
|
||||||
// its own children. Termination requires sending the signal to the group
|
gui.Config.UserConfig.CommandTemplates.ContainerLogs,
|
||||||
// process ID.
|
gui.DockerCommand.NewCommandObject(commands.CommandObject{Container: container}),
|
||||||
gui.OSCommand.PrepareForChildren(cmd)
|
)
|
||||||
|
cmd := gui.OSCommand.RunCustomCommand(command)
|
||||||
|
|
||||||
mainView := gui.getMainView()
|
// Ensure the child process is treated as a group, as the child process spawns
|
||||||
cmd.Stdout = mainView
|
// its own children. Termination requires sending the signal to the group
|
||||||
cmd.Stderr = mainView
|
// process ID.
|
||||||
|
gui.OSCommand.PrepareForChildren(cmd)
|
||||||
|
|
||||||
cmd.Start()
|
mainView := gui.getMainView()
|
||||||
|
cmd.Stdout = mainView
|
||||||
|
cmd.Stderr = mainView
|
||||||
|
|
||||||
go func() {
|
cmd.Start()
|
||||||
<-stop
|
|
||||||
if err := gui.OSCommand.Kill(cmd); err != nil {
|
go func() {
|
||||||
gui.Log.Warn(err)
|
<-stop
|
||||||
}
|
if err := gui.OSCommand.Kill(cmd); err != nil {
|
||||||
gui.Log.Info("killed container logs process")
|
gui.Log.Warn(err)
|
||||||
|
}
|
||||||
|
gui.Log.Info("killed container logs process")
|
||||||
|
return
|
||||||
|
}()
|
||||||
|
|
||||||
|
cmd.Wait()
|
||||||
|
|
||||||
|
// if we are here because the task has been stopped, we should return
|
||||||
|
// if we are here then the container must have exited, meaning we should wait until it's back again before
|
||||||
|
ticker := time.NewTicker(time.Millisecond * 100)
|
||||||
|
defer ticker.Stop()
|
||||||
|
for {
|
||||||
|
select {
|
||||||
|
case <-stop:
|
||||||
return
|
return
|
||||||
}()
|
case <-ticker.C:
|
||||||
|
result, err := container.Inspect()
|
||||||
cmd.Wait()
|
if err != nil {
|
||||||
|
// if we get an error, then the container has probably been removed so we'll get out of here
|
||||||
// if we are here because the task has been stopped, we should return
|
gui.Log.Error(err)
|
||||||
// if we are here then the container must have exited, meaning we should wait until it's back again before
|
notifyStopped <- struct{}{}
|
||||||
L:
|
return
|
||||||
for {
|
}
|
||||||
select {
|
if result.State.Running {
|
||||||
case <-stop:
|
|
||||||
return
|
return
|
||||||
default:
|
|
||||||
result, err := container.Inspect()
|
|
||||||
if err != nil {
|
|
||||||
// if we get an error, then the container has probably been removed so we'll get out of here
|
|
||||||
gui.Log.Error(err)
|
|
||||||
notifyStopped <- struct{}{}
|
|
||||||
return
|
|
||||||
}
|
|
||||||
if result.State.Running {
|
|
||||||
break L
|
|
||||||
}
|
|
||||||
time.Sleep(time.Millisecond * 100)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) refreshContainersAndServices() error {
|
func (gui *Gui) refreshContainersAndServices() error {
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue