From 7e1110a5f14eb812e1da58991731bb2c7c3a7b98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Luka=20Marku=C5=A1i=C4=87?= Date: Mon, 9 May 2022 20:39:00 +1000 Subject: [PATCH] allow toggling container pause --- pkg/commands/container.go | 12 ++++++++++++ pkg/gui/containers_panel.go | 18 ++++++++++++++++++ pkg/gui/keybindings.go | 7 +++++++ pkg/i18n/english.go | 2 ++ 4 files changed, 39 insertions(+) diff --git a/pkg/commands/container.go b/pkg/commands/container.go index ad9f95a33..a16ce8330 100644 --- a/pkg/commands/container.go +++ b/pkg/commands/container.go @@ -366,6 +366,18 @@ func (c *Container) Stop() error { return c.Client.ContainerStop(context.Background(), c.ID, nil) } +// Pause pauses the container +func (c *Container) Pause() error { + c.Log.Warn(fmt.Sprintf("pausing container %s", c.Name)) + return c.Client.ContainerPause(context.Background(), c.ID) +} + +// Unpause unpauses the container +func (c *Container) Unpause() error { + c.Log.Warn(fmt.Sprintf("unpausing container %s", c.Name)) + return c.Client.ContainerUnpause(context.Background(), c.ID) +} + // Restart restarts the container func (c *Container) Restart() error { c.Log.Warn(fmt.Sprintf("restarting container %s", c.Name)) diff --git a/pkg/gui/containers_panel.go b/pkg/gui/containers_panel.go index 85a332dca..4ccaf007c 100644 --- a/pkg/gui/containers_panel.go +++ b/pkg/gui/containers_panel.go @@ -474,6 +474,24 @@ func (gui *Gui) handleContainersRemoveMenu(g *gocui.Gui, v *gocui.View) error { return gui.createMenu("", options, len(options), handleMenuPress) } +func (gui *Gui) handleContainerPause(g *gocui.Gui, v *gocui.View) error { + container, err := gui.getSelectedContainer() + if err != nil { + return nil + } + + if container.Details.State.Paused { + err = container.Unpause() + } else { + err = container.Pause() + } + + if err != nil { + return gui.createErrorPanel(gui.g, err.Error()) + } + return nil +} + func (gui *Gui) handleContainerStop(g *gocui.Gui, v *gocui.View) error { container, err := gui.getSelectedContainer() if err != nil { diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index cfb9c42f8..598b42d82 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -220,6 +220,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Handler: gui.handleHideStoppedContainers, Description: gui.Tr.HideStopped, }, + { + ViewName: "containers", + Key: 'p', + Modifier: gocui.ModNone, + Handler: gui.handleContainerPause, + Description: gui.Tr.Pause, + }, { ViewName: "containers", Key: 's', diff --git a/pkg/i18n/english.go b/pkg/i18n/english.go index ce509b63a..c6234a00c 100644 --- a/pkg/i18n/english.go +++ b/pkg/i18n/english.go @@ -45,6 +45,7 @@ type TranslationSet struct { RemoveService string Stop string Restart string + Pause string Rebuild string Recreate string PreviousContext string @@ -138,6 +139,7 @@ func englishSet() TranslationSet { RemoveService: "remove containers", Stop: "stop", Restart: "restart", + Pause: "toggle pause", Rebuild: "rebuild", Recreate: "recreate", PreviousContext: "previous tab",