Skip to content

Commit

Permalink
Merge pull request #317 from mark2185/feature/docker-pause
Browse files Browse the repository at this point in the history
  • Loading branch information
jesseduffield committed May 14, 2022
2 parents 2fa6a89 + a03f550 commit 3abff08
Show file tree
Hide file tree
Showing 5 changed files with 67 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 @@ -175,6 +175,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
25 changes: 25 additions & 0 deletions pkg/gui/containers_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,6 +423,31 @@ func (gui *Gui) handleContainersRemoveMenu(g *gocui.Gui, v *gocui.View) error {
return gui.createMenu("", options, len(options), handleMenuPress)
}

func (gui *Gui) PauseContainer(container *commands.Container) error {
return gui.WithWaitingStatus(gui.Tr.PausingStatus, func() (err error) {
if container.Details.State.Paused {
err = container.Unpause()
} else {
err = container.Pause()
}

if err != nil {
return gui.createErrorPanel(gui.g, err.Error())
}

return gui.refreshContainersAndServices()
})
}

func (gui *Gui) handleContainerPause(g *gocui.Gui, v *gocui.View) error {
container, err := gui.getSelectedContainer()
if err != nil {
return nil
}

return gui.PauseContainer(container)
}

func (gui *Gui) handleContainerStop(g *gocui.Gui, v *gocui.View) error {
container, err := gui.getSelectedContainer()
if err != nil {
Expand Down
14 changes: 14 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 Expand Up @@ -290,6 +297,13 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleServiceStop,
Description: gui.Tr.Stop,
},
{
ViewName: "services",
Key: 'p',
Modifier: gocui.ModNone,
Handler: gui.handleServicePause,
Description: gui.Tr.Pause,
},
{
ViewName: "services",
Key: 'r',
Expand Down
12 changes: 12 additions & 0 deletions pkg/gui/services_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,18 @@ func (gui *Gui) handleServiceRemoveMenu(g *gocui.Gui, v *gocui.View) error {
return gui.createServiceCommandMenu(options, gui.Tr.RemovingStatus)
}

func (gui *Gui) handleServicePause(g *gocui.Gui, v *gocui.View) error {
service, err := gui.getSelectedService()
if err != nil {
return nil
}
if service.Container == nil {
return nil
}

return gui.PauseContainer(service.Container)
}

func (gui *Gui) handleServiceStop(g *gocui.Gui, v *gocui.View) error {
service, err := gui.getSelectedService()
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions pkg/i18n/english.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ type TranslationSet struct {
RestartingStatus string
StartingStatus string
StoppingStatus string
PausingStatus string
RemovingStatus string
RunningCustomCommandStatus string
RunningBulkCommandStatus string
RemoveService string
Stop string
Pause string
Restart string
Start string
Rebuild string
Expand Down Expand Up @@ -112,6 +114,7 @@ func englishSet() TranslationSet {
RestartingStatus: "restarting",
StartingStatus: "starting",
StoppingStatus: "stopping",
PausingStatus: "pausing",
RunningCustomCommandStatus: "running custom command",
RunningBulkCommandStatus: "running bulk command",

Expand Down Expand Up @@ -146,6 +149,7 @@ func englishSet() TranslationSet {
RemoveWithVolumes: "remove with volumes",
RemoveService: "remove containers",
Stop: "stop",
Pause: "pause",
Restart: "restart",
Start: "start",
Rebuild: "rebuild",
Expand Down

0 comments on commit 3abff08

Please sign in to comment.