Merge pull request #378 from jesseduffield/small-improvements

This commit is contained in:
Jesse Duffield 2022-10-10 20:59:34 -07:00 committed by GitHub
commit 950936b178
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 136 additions and 4 deletions

View file

@ -42,8 +42,11 @@ logs:
commandTemplates: commandTemplates:
dockerCompose: docker-compose dockerCompose: docker-compose
restartService: '{{ .DockerCompose }} restart {{ .Service.Name }}' restartService: '{{ .DockerCompose }} restart {{ .Service.Name }}'
startService: '{{ .DockerCompose }} start {{ .Service.Name }}' up: '{{ .DockerCompose }} up -d'
down: '{{ .DockerCompose }} down'
downWithVolumes: '{{ .DockerCompose }} down --volumes'
upService: '{{ .DockerCompose }} up -d {{ .Service.Name }}' upService: '{{ .DockerCompose }} up -d {{ .Service.Name }}'
startService: '{{ .DockerCompose }} start {{ .Service.Name }}'
stopService: '{{ .DockerCompose }} stop {{ .Service.Name }}' stopService: '{{ .DockerCompose }} stop {{ .Service.Name }}'
serviceLogs: '{{ .DockerCompose }} logs --since=60m --follow {{ .Service.Name }}' serviceLogs: '{{ .DockerCompose }} logs --since=60m --follow {{ .Service.Name }}'
viewServiceLogs: '{{ .DockerCompose }} logs --follow {{ .Service.Name }}' viewServiceLogs: '{{ .DockerCompose }} logs --follow {{ .Service.Name }}'

View file

@ -43,6 +43,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>S</kbd>: start <kbd>S</kbd>: start
<kbd>a</kbd>: anbinden <kbd>a</kbd>: anbinden
<kbd>m</kbd>: zeige Protokolle <kbd>m</kbd>: zeige Protokolle
<kbd>U</kbd>: up project
<kbd>D</kbd>: down project
<kbd>[</kbd>: vorheriges Tab <kbd>[</kbd>: vorheriges Tab
<kbd>]</kbd>: nächstes Tab <kbd>]</kbd>: nächstes Tab
<kbd>R</kbd>: zeige Neustartoptionen <kbd>R</kbd>: zeige Neustartoptionen

View file

@ -43,6 +43,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>S</kbd>: start <kbd>S</kbd>: start
<kbd>a</kbd>: attach <kbd>a</kbd>: attach
<kbd>m</kbd>: view logs <kbd>m</kbd>: view logs
<kbd>U</kbd>: up project
<kbd>D</kbd>: down project
<kbd>[</kbd>: previous tab <kbd>[</kbd>: previous tab
<kbd>]</kbd>: next tab <kbd>]</kbd>: next tab
<kbd>R</kbd>: view restart options <kbd>R</kbd>: view restart options

View file

@ -43,6 +43,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>S</kbd>: start <kbd>S</kbd>: start
<kbd>a</kbd>: verbinden <kbd>a</kbd>: verbinden
<kbd>m</kbd>: bekijk logs <kbd>m</kbd>: bekijk logs
<kbd>U</kbd>: up project
<kbd>D</kbd>: down project
<kbd>[</kbd>: vorige tab <kbd>[</kbd>: vorige tab
<kbd>]</kbd>: volgende tab <kbd>]</kbd>: volgende tab
<kbd>R</kbd>: bekijk herstart opties <kbd>R</kbd>: bekijk herstart opties

View file

@ -43,6 +43,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>S</kbd>: start <kbd>S</kbd>: start
<kbd>a</kbd>: przyczep <kbd>a</kbd>: przyczep
<kbd>m</kbd>: pokaż logi <kbd>m</kbd>: pokaż logi
<kbd>U</kbd>: up project
<kbd>D</kbd>: down project
<kbd>[</kbd>: poprzednia zakładka <kbd>[</kbd>: poprzednia zakładka
<kbd>]</kbd>: następna zakładka <kbd>]</kbd>: następna zakładka
<kbd>R</kbd>: pokaż opcje restartu <kbd>R</kbd>: pokaż opcje restartu

View file

@ -43,6 +43,8 @@ _This file is auto-generated. To update, make the changes in the pkg/i18n direct
<kbd>S</kbd>: start <kbd>S</kbd>: start
<kbd>a</kbd>: bağlan/iliştir <kbd>a</kbd>: bağlan/iliştir
<kbd>m</kbd>: kayıt defterini görüntüle <kbd>m</kbd>: kayıt defterini görüntüle
<kbd>U</kbd>: up project
<kbd>D</kbd>: down project
<kbd>[</kbd>: önceki sekme <kbd>[</kbd>: önceki sekme
<kbd>]</kbd>: sonraki sekme <kbd>]</kbd>: sonraki sekme
<kbd>R</kbd>: yeniden başlatma seçeneklerini görüntüle <kbd>R</kbd>: yeniden başlatma seçeneklerini görüntüle

View file

@ -57,6 +57,10 @@ func (c *Container) GetDisplayStrings(isFocused bool) []string {
func (c *Container) displayPorts() string { func (c *Container) displayPorts() string {
portStrings := lo.Map(c.Container.Ports, func(port types.Port, _ int) string { portStrings := lo.Map(c.Container.Ports, func(port types.Port, _ int) string {
if port.PublicPort == 0 {
return fmt.Sprintf("%d\\%s", port.PrivatePort, port.Type)
}
// docker ps will show '0.0.0.0:80->80/tcp' but we'll show // docker ps will show '0.0.0.0:80->80/tcp' but we'll show
// '80->80/tcp' instead to save space (unless the IP is something other than // '80->80/tcp' instead to save space (unless the IP is something other than
// 0.0.0.0) // 0.0.0.0)

View file

@ -141,6 +141,14 @@ type CommandTemplatesConfig struct {
// UpService ups the service (creates and starts) // UpService ups the service (creates and starts)
UpService string `yaml:"upService,omitempty"` UpService string `yaml:"upService,omitempty"`
// Runs "docker-compose up -d"
Up string `yaml:"up,omitempty"`
// downs everything
Down string `yaml:"down,omitempty"`
// downs and removes volumes
DownWithVolumes string `yaml:"downWithVolumes,omitempty"`
// DockerCompose is for your docker-compose command. You may want to combine a // DockerCompose is for your docker-compose command. You may want to combine a
// few different docker-compose.yml files together, in which case you can set // few different docker-compose.yml files together, in which case you can set
// this to "docker-compose -f foo/docker-compose.yml -f // this to "docker-compose -f foo/docker-compose.yml -f
@ -351,6 +359,9 @@ func GetDefaultConfig() UserConfig {
DockerCompose: "docker-compose", DockerCompose: "docker-compose",
RestartService: "{{ .DockerCompose }} restart {{ .Service.Name }}", RestartService: "{{ .DockerCompose }} restart {{ .Service.Name }}",
StartService: "{{ .DockerCompose }} start {{ .Service.Name }}", StartService: "{{ .DockerCompose }} start {{ .Service.Name }}",
Up: "{{ .DockerCompose }} up -d",
Down: "{{ .DockerCompose }} down",
DownWithVolumes: "{{ .DockerCompose }} down --volumes",
UpService: "{{ .DockerCompose }} up -d {{ .Service.Name }}", UpService: "{{ .DockerCompose }} up -d {{ .Service.Name }}",
RebuildService: "{{ .DockerCompose }} up -d --build {{ .Service.Name }}", RebuildService: "{{ .DockerCompose }} up -d --build {{ .Service.Name }}",
RecreateService: "{{ .DockerCompose }} up -d --force-recreate {{ .Service.Name }}", RecreateService: "{{ .DockerCompose }} up -d --force-recreate {{ .Service.Name }}",

View file

@ -109,6 +109,12 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Modifier: gocui.ModNone, Modifier: gocui.ModNone,
Handler: gui.autoScrollMain, Handler: gui.autoScrollMain,
}, },
{
ViewName: "",
Key: gocui.KeyHome,
Modifier: gocui.ModNone,
Handler: gui.jumpToTopMain,
},
{ {
ViewName: "", ViewName: "",
Key: 'x', Key: 'x',
@ -339,6 +345,20 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Handler: gui.handleServiceRenderLogsToMain, Handler: gui.handleServiceRenderLogsToMain,
Description: gui.Tr.ViewLogs, Description: gui.Tr.ViewLogs,
}, },
{
ViewName: "services",
Key: 'U',
Modifier: gocui.ModNone,
Handler: gui.handleProjectUp,
Description: gui.Tr.UpProject,
},
{
ViewName: "services",
Key: 'D',
Modifier: gocui.ModNone,
Handler: gui.handleProjectDown,
Description: gui.Tr.DownProject,
},
{ {
ViewName: "services", ViewName: "services",
Key: '[', Key: '[',

View file

@ -66,6 +66,13 @@ func (gui *Gui) autoScrollMain(g *gocui.Gui, v *gocui.View) error {
return nil return nil
} }
func (gui *Gui) jumpToTopMain(g *gocui.Gui, v *gocui.View) error {
gui.getMainView().Autoscroll = false
_ = gui.getMainView().SetOrigin(0, 0)
_ = gui.getMainView().SetCursor(0, 0)
return nil
}
func (gui *Gui) onMainTabClick(tabIndex int) error { func (gui *Gui) onMainTabClick(tabIndex int) error {
gui.Log.Warn(tabIndex) gui.Log.Warn(tabIndex)

View file

@ -254,7 +254,7 @@ func (gui *Gui) handleServiceUp(g *gocui.Gui, v *gocui.View) error {
return nil return nil
} }
return gui.WithWaitingStatus(gui.Tr.UppingStatus, func() error { return gui.WithWaitingStatus(gui.Tr.UppingServiceStatus, func() error {
if err := service.Up(); err != nil { if err := service.Up(); err != nil {
return gui.createErrorPanel(err.Error()) return gui.createErrorPanel(err.Error())
} }
@ -325,6 +325,69 @@ func (gui *Gui) handleServiceRenderLogsToMain(g *gocui.Gui, v *gocui.View) error
return gui.runSubprocess(c) return gui.runSubprocess(c)
} }
func (gui *Gui) handleProjectUp(g *gocui.Gui, v *gocui.View) error {
return gui.createConfirmationPanel(gui.Tr.Confirm, gui.Tr.ConfirmUpProject, func(g *gocui.Gui, v *gocui.View) error {
cmdStr := utils.ApplyTemplate(
gui.Config.UserConfig.CommandTemplates.Up,
gui.DockerCommand.NewCommandObject(commands.CommandObject{}),
)
return gui.WithWaitingStatus(gui.Tr.UppingProjectStatus, func() error {
if err := gui.OSCommand.RunCommand(cmdStr); err != nil {
return gui.createErrorPanel(err.Error())
}
return nil
})
}, nil)
}
func (gui *Gui) handleProjectDown(g *gocui.Gui, v *gocui.View) error {
downCommand := utils.ApplyTemplate(
gui.Config.UserConfig.CommandTemplates.Down,
gui.DockerCommand.NewCommandObject(commands.CommandObject{}),
)
downWithVolumesCommand := utils.ApplyTemplate(
gui.Config.UserConfig.CommandTemplates.DownWithVolumes,
gui.DockerCommand.NewCommandObject(commands.CommandObject{}),
)
options := []*commandOption{
{
description: gui.Tr.Down,
command: downCommand,
f: func() error {
return gui.WithWaitingStatus(gui.Tr.DowningStatus, func() error {
if err := gui.OSCommand.RunCommand(downCommand); err != nil {
return gui.createErrorPanel(err.Error())
}
return nil
})
},
},
{
description: gui.Tr.DownWithVolumes,
command: downWithVolumesCommand,
f: func() error {
return gui.WithWaitingStatus(gui.Tr.DowningStatus, func() error {
if err := gui.OSCommand.RunCommand(downWithVolumesCommand); err != nil {
return gui.createErrorPanel(err.Error())
}
return nil
})
},
},
{
description: gui.Tr.Cancel,
f: func() error { return nil },
},
}
handleMenuPress := func(index int) error { return options[index].f() }
return gui.createMenu("", options, len(options), handleMenuPress)
}
func (gui *Gui) handleServiceRestartMenu(g *gocui.Gui, v *gocui.View) error { func (gui *Gui) handleServiceRestartMenu(g *gocui.Gui, v *gocui.View) error {
service, err := gui.getSelectedService() service, err := gui.getSelectedService()
if err != nil { if err != nil {

View file

@ -17,6 +17,7 @@ type TranslationSet struct {
OpenConfig string OpenConfig string
EditConfig string EditConfig string
ConfirmQuit string ConfirmQuit string
ConfirmUpProject string
ErrorOccurred string ErrorOccurred string
ConnectionFailed string ConnectionFailed string
UnattachableContainerError string UnattachableContainerError string
@ -41,9 +42,11 @@ type TranslationSet struct {
RestartingStatus string RestartingStatus string
StartingStatus string StartingStatus string
StoppingStatus string StoppingStatus string
UppingStatus string UppingProjectStatus string
UppingServiceStatus string
PausingStatus string PausingStatus string
RemovingStatus string RemovingStatus string
DowningStatus string
RunningCustomCommandStatus string RunningCustomCommandStatus string
RunningBulkCommandStatus string RunningBulkCommandStatus string
RemoveService string RemoveService string
@ -51,6 +54,8 @@ type TranslationSet struct {
Stop string Stop string
Pause string Pause string
Restart string Restart string
Down string
DownWithVolumes string
Start string Start string
Rebuild string Rebuild string
Recreate string Recreate string
@ -58,6 +63,8 @@ type TranslationSet struct {
NextContext string NextContext string
Attach string Attach string
ViewLogs string ViewLogs string
UpProject string
DownProject string
ServicesTitle string ServicesTitle string
ContainersTitle string ContainersTitle string
StandaloneContainersTitle string StandaloneContainersTitle string
@ -118,7 +125,9 @@ func englishSet() TranslationSet {
RestartingStatus: "restarting", RestartingStatus: "restarting",
StartingStatus: "starting", StartingStatus: "starting",
StoppingStatus: "stopping", StoppingStatus: "stopping",
UppingStatus: "upping", UppingServiceStatus: "upping service",
UppingProjectStatus: "upping project",
DowningStatus: "downing",
PausingStatus: "pausing", PausingStatus: "pausing",
RunningCustomCommandStatus: "running custom command", RunningCustomCommandStatus: "running custom command",
RunningBulkCommandStatus: "running bulk command", RunningBulkCommandStatus: "running bulk command",
@ -156,6 +165,8 @@ func englishSet() TranslationSet {
Stop: "stop", Stop: "stop",
Pause: "pause", Pause: "pause",
Restart: "restart", Restart: "restart",
Down: "down project",
DownWithVolumes: "down project with volumes",
Start: "start", Start: "start",
Rebuild: "rebuild", Rebuild: "rebuild",
Recreate: "recreate", Recreate: "recreate",
@ -163,6 +174,8 @@ func englishSet() TranslationSet {
NextContext: "next tab", NextContext: "next tab",
Attach: "attach", Attach: "attach",
ViewLogs: "view logs", ViewLogs: "view logs",
UpProject: "up project",
DownProject: "down project",
RemoveImage: "remove image", RemoveImage: "remove image",
RemoveVolume: "remove volume", RemoveVolume: "remove volume",
RemoveWithoutPrune: "remove without deleting untagged parents", RemoveWithoutPrune: "remove without deleting untagged parents",
@ -209,6 +222,7 @@ func englishSet() TranslationSet {
NoVolumes: "No volumes", NoVolumes: "No volumes",
ConfirmQuit: "Are you sure you want to quit?", ConfirmQuit: "Are you sure you want to quit?",
ConfirmUpProject: "Are you sure you want to 'up' your docker compose project?",
MustForceToRemoveContainer: "You cannot remove a running container unless you force it. Do you want to force it?", MustForceToRemoveContainer: "You cannot remove a running container unless you force it. Do you want to force it?",
NotEnoughSpace: "Not enough space to render panels", NotEnoughSpace: "Not enough space to render panels",
ConfirmPruneImages: "Are you sure you want to prune all unused images?", ConfirmPruneImages: "Are you sure you want to prune all unused images?",