Skip to content

Commit

Permalink
allow toggling container pause
Browse files Browse the repository at this point in the history
  • Loading branch information
mark2185 authored and jesseduffield committed May 9, 2022
1 parent 846cadd commit 7e1110a
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 0 deletions.
12 changes: 12 additions & 0 deletions pkg/commands/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
18 changes: 18 additions & 0 deletions pkg/gui/containers_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
7 changes: 7 additions & 0 deletions pkg/gui/keybindings.go
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
2 changes: 2 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type TranslationSet struct {
RemoveService string
Stop string
Restart string
Pause string
Rebuild string
Recreate string
PreviousContext string
Expand Down Expand Up @@ -138,6 +139,7 @@ func englishSet() TranslationSet {
RemoveService: "remove containers",
Stop: "stop",
Restart: "restart",
Pause: "toggle pause",
Rebuild: "rebuild",
Recreate: "recreate",
PreviousContext: "previous tab",
Expand Down

0 comments on commit 7e1110a

Please sign in to comment.