more keybindings

pull/1/head
Jesse Duffield 5 years ago
parent 52ec56289a
commit 4a76f7b65e

@ -49,7 +49,7 @@ func (c *Container) GetColor() color.Attribute {
// MustStopContainer tells us that we must stop the container before removing it
const MustStopContainer = iota
// Remove removes a container
// Remove removes the container
func (c *Container) Remove(options types.ContainerRemoveOptions) error {
if err := c.Client.ContainerRemove(context.Background(), c.ID, options); err != nil {
if strings.Contains(err.Error(), "Stop the container before attempting removal or force remove") {
@ -64,3 +64,13 @@ func (c *Container) Remove(options types.ContainerRemoveOptions) error {
return nil
}
// Stop stops the container
func (c *Container) Stop() error {
return c.Client.ContainerStop(context.Background(), c.ID, nil)
}
// Restart restarts the container
func (c *Container) Restart() error {
return c.Client.ContainerRestart(context.Background(), c.ID, nil)
}

@ -202,6 +202,9 @@ func (gui *Gui) refreshContainers() error {
if len(gui.State.Containers) > 0 && gui.State.Panels.Containers.SelectedLine == -1 {
gui.State.Panels.Containers.SelectedLine = 0
}
if len(gui.State.Containers)-1 < gui.State.Panels.Containers.SelectedLine {
gui.State.Panels.Containers.SelectedLine = len(gui.State.Containers) - 1
}
gui.g.Update(func(g *gocui.Gui) error {
@ -351,3 +354,33 @@ func (gui *Gui) handleContainersRemoveMenu(g *gocui.Gui, v *gocui.View) error {
return gui.createMenu("", options, len(options), handleMenuPress)
}
func (gui *Gui) handleContainerStop(g *gocui.Gui, v *gocui.View) error {
container, err := gui.getSelectedContainer(g)
if err != nil {
return nil
}
return gui.createConfirmationPanel(gui.g, v, gui.Tr.SLocalize("Confirm"), gui.Tr.SLocalize("StopContainer"), func(g *gocui.Gui, v *gocui.View) error {
if err := container.Stop(); err != nil {
return gui.createErrorPanel(gui.g, err.Error())
}
return gui.refreshContainers()
}, nil)
}
func (gui *Gui) handleContainerRestart(g *gocui.Gui, v *gocui.View) error {
container, err := gui.getSelectedContainer(g)
if err != nil {
return nil
}
return gui.WithWaitingStatus(gui.Tr.SLocalize("RestartingStatus"), func() error {
if err := container.Restart(); err != nil {
return gui.createErrorPanel(gui.g, err.Error())
}
return gui.refreshContainers()
})
}

@ -148,12 +148,25 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: ']',
Modifier: gocui.ModNone,
Handler: gui.handleContainersNextContext,
}, {
},
{
ViewName: "containers",
Key: 'd',
Modifier: gocui.ModNone,
Handler: gui.handleContainersRemoveMenu,
},
{
ViewName: "containers",
Key: 's',
Modifier: gocui.ModNone,
Handler: gui.handleContainerStop,
},
{
ViewName: "containers",
Key: 'r',
Modifier: gocui.ModNone,
Handler: gui.handleContainerRestart,
},
}
// TODO: add more views here

@ -778,5 +778,13 @@ func addEnglish(i18nObject *i18n.Bundle) error {
ID: "Confirm",
Other: "Confirm",
},
&i18n.Message{
ID: "StopContainer",
Other: "Are you sure you want to stop this container?",
},
&i18n.Message{
ID: "RestartingStatus",
Other: "restarting",
},
)
}

Loading…
Cancel
Save