Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix linting #368

Merged
merged 1 commit into from
Oct 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 4 additions & 11 deletions pkg/gui/confirmation_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ func (gui *Gui) onNewPopupPanel() {
}

// it is very important that within this function we never include the original prompt in any error messages, because it may contain e.g. a user password
// unparam complains that handleClose is alwans nil but one day it won't be nil.
// nolint:unparam
func (gui *Gui) createConfirmationPanel(g *gocui.Gui, currentView *gocui.View, title, prompt string, handleConfirm, handleClose func(*gocui.Gui, *gocui.View) error) error {
return gui.createPopupPanel(g, currentView, title, prompt, false, handleConfirm, handleClose)
}
Expand Down Expand Up @@ -146,19 +148,10 @@ func (gui *Gui) setKeyBindings(g *gocui.Gui, handleConfirm, handleClose func(*go
return nil
}

// createSpecificErrorPanel allows you to create an error popup, specifying the
// view to be focused when the user closes the popup, and a boolean specifying
// whether we will log the error. If the message may include a user password,
// this function is to be used over the more generic createErrorPanel, with
// willLog set to false
func (gui *Gui) createSpecificErrorPanel(message string, nextView *gocui.View, willLog bool) error {
func (gui *Gui) createErrorPanel(g *gocui.Gui, message string) error {
colorFunction := color.New(color.FgRed).SprintFunc()
coloredMessage := colorFunction(strings.TrimSpace(message))
return gui.createConfirmationPanel(gui.g, nextView, gui.Tr.ErrorTitle, coloredMessage, nil, nil)
}

func (gui *Gui) createErrorPanel(g *gocui.Gui, message string) error {
return gui.createSpecificErrorPanel(message, g.CurrentView(), true)
return gui.createConfirmationPanel(gui.g, g.CurrentView(), gui.Tr.ErrorTitle, coloredMessage, nil, nil)
}

func (gui *Gui) renderConfirmationOptions() error {
Expand Down
10 changes: 5 additions & 5 deletions pkg/gui/containers_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ func (gui *Gui) handleContainerSelect(g *gocui.Gui, v *gocui.View) error {
return nil
}

gui.focusPoint(0, gui.State.Panels.Containers.SelectedLine, len(gui.DockerCommand.DisplayContainers), v)
gui.focusY(gui.State.Panels.Containers.SelectedLine, len(gui.DockerCommand.DisplayContainers), v)

key := "containers-" + container.ID + "-" + gui.getContainerContexts()[gui.State.Panels.Containers.ContextIndex]
if !gui.shouldRefresh(key) {
Expand Down Expand Up @@ -199,7 +199,7 @@ func (gui *Gui) renderContainerStats(container *commands.Container) error {
_ = gui.createErrorPanel(gui.g, err.Error())
}

_ = gui.reRenderString(gui.g, "main", contents)
gui.reRenderStringMain(contents)
})
}

Expand All @@ -211,10 +211,10 @@ func (gui *Gui) renderContainerTop(container *commands.Container) error {
return gui.T.NewTickerTask(time.Second, func(stop chan struct{}) { gui.clearMainView() }, func(stop, notifyStopped chan struct{}) {
contents, err := container.RenderTop()
if err != nil {
_ = gui.reRenderString(gui.g, "main", err.Error())
gui.reRenderStringMain(err.Error())
}

_ = gui.reRenderString(gui.g, "main", contents)
gui.reRenderStringMain(contents)
})
}

Expand Down Expand Up @@ -244,7 +244,7 @@ func (gui *Gui) refreshContainersAndServices() error {
break
}
gui.State.Panels.Services.SelectedLine = i
gui.focusPoint(0, i, len(gui.DockerCommand.Services), gui.getServicesView())
gui.focusY(i, len(gui.DockerCommand.Services), gui.getServicesView())
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/images_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (gui *Gui) handleImageSelect(g *gocui.Gui, v *gocui.View) error {
return gui.renderString(g, "main", gui.Tr.NoImages)
}

gui.focusPoint(0, gui.State.Panels.Images.SelectedLine, len(gui.DockerCommand.Images), v)
gui.focusY(gui.State.Panels.Images.SelectedLine, len(gui.DockerCommand.Images), v)

key := "images-" + Image.ID + "-" + gui.getImageContexts()[gui.State.Panels.Images.ContextIndex]
if !gui.shouldRefresh(key) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/layout.go
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,6 @@ func (gui *Gui) focusPointInView(view *gocui.View) {
}

if state, ok := listViews[view.Name()]; ok {
gui.focusPoint(0, state.selectedLine, state.lineCount, view)
gui.focusY(state.selectedLine, state.lineCount, view)
}
}
2 changes: 1 addition & 1 deletion pkg/gui/menu_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
// list panel functions

func (gui *Gui) handleMenuSelect(g *gocui.Gui, v *gocui.View) error {
gui.focusPoint(0, gui.State.Panels.Menu.SelectedLine, gui.State.MenuItemCount, v)
gui.focusY(gui.State.Panels.Menu.SelectedLine, gui.State.MenuItemCount, v)
return nil
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/gui/services_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ func (gui *Gui) handleServiceSelect(g *gocui.Gui, v *gocui.View) error {
containerID = service.Container.ID
}

gui.focusPoint(0, gui.State.Panels.Services.SelectedLine, len(gui.DockerCommand.Services), v)
gui.focusY(gui.State.Panels.Services.SelectedLine, len(gui.DockerCommand.Services), v)

key := "services-" + service.ID + "-" + containerID + "-" + gui.getServiceContexts()[gui.State.Panels.Services.ContextIndex]
if !gui.shouldRefresh(key) {
Expand Down Expand Up @@ -118,10 +118,10 @@ func (gui *Gui) renderServiceTop(service *commands.Service) error {
return gui.T.NewTickerTask(time.Second, func(stop chan struct{}) { gui.clearMainView() }, func(stop, notifyStopped chan struct{}) {
contents, err := service.RenderTop()
if err != nil {
_ = gui.reRenderString(gui.g, "main", err.Error())
gui.reRenderStringMain(err.Error())
}

_ = gui.reRenderString(gui.g, "main", contents)
gui.reRenderStringMain(contents)
})
}

Expand Down
23 changes: 16 additions & 7 deletions pkg/gui/view_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ func (gui *Gui) switchFocus(g *gocui.Gui, oldView, newView *gocui.View, returnin
}

// if the cursor down past the last item, move it to the last line
// nolint:unparam
func (gui *Gui) focusPoint(selectedX int, selectedY int, lineCount int, v *gocui.View) {
if selectedY < 0 || selectedY > lineCount {
return
Expand Down Expand Up @@ -192,12 +193,16 @@ func (gui *Gui) focusPoint(selectedX int, selectedY int, lineCount int, v *gocui
}
}

func (gui *Gui) focusY(selectedY int, lineCount int, v *gocui.View) {
gui.focusPoint(0, selectedY, lineCount, v)
}

func (gui *Gui) cleanString(s string) string {
output := string(bom.Clean([]byte(s)))
return utils.NormalizeLinefeeds(output)
}

func (gui *Gui) setViewContent(g *gocui.Gui, v *gocui.View, s string) error {
func (gui *Gui) setViewContent(v *gocui.View, s string) error {
v.Clear()
fmt.Fprint(v, gui.cleanString(s))
return nil
Expand All @@ -216,21 +221,25 @@ func (gui *Gui) renderString(g *gocui.Gui, viewName, s string) error {
if err := v.SetCursor(0, 0); err != nil {
return err
}
return gui.setViewContent(gui.g, v, s)
return gui.setViewContent(v, s)
})
return nil
}

// reRenderString sets the main view's content, without changing its origin
func (gui *Gui) reRenderStringMain(s string) {
gui.reRenderString("main", s)
}

// reRenderString sets the view's content, without changing its origin
func (gui *Gui) reRenderString(g *gocui.Gui, viewName, s string) error {
g.Update(func(*gocui.Gui) error {
v, err := g.View(viewName)
func (gui *Gui) reRenderString(viewName, s string) {
gui.g.Update(func(*gocui.Gui) error {
v, err := gui.g.View(viewName)
if err != nil {
return nil // return gracefully if view has been deleted
}
return gui.setViewContent(gui.g, v, s)
return gui.setViewContent(v, s)
})
return nil
}

func (gui *Gui) optionsMapToString(optionsMap map[string]string) string {
Expand Down
2 changes: 1 addition & 1 deletion pkg/gui/volumes_panel.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func (gui *Gui) handleVolumeSelect(g *gocui.Gui, v *gocui.View) error {
return gui.renderString(g, "main", gui.Tr.NoVolumes)
}

gui.focusPoint(0, gui.State.Panels.Volumes.SelectedLine, len(gui.DockerCommand.Volumes), v)
gui.focusY(gui.State.Panels.Volumes.SelectedLine, len(gui.DockerCommand.Volumes), v)

key := "volumes-" + volume.Name + "-" + gui.getVolumeContexts()[gui.State.Panels.Volumes.ContextIndex]
if !gui.shouldRefresh(key) {
Expand Down