Repository: jesseduffield/lazygit
File: pkg/gui/views.go (Go)

Code before:

	gui.Views.Confirmation.Visible = false
	gui.Views.Confirmation.Editor = gocui.EditorFunc(gui.promptEditor)

	gui.Views.Suggestions.Visible = false

	gui.Views.Menu.Visible = false

	gui.Views.Tooltip.Visible = false

	gui.Views.Information.BgColor = gocui.ColorDefault
	gui.Views.Information.FgColor = gocui.ColorGreen
	gui.Views.Information.Frame = false

	gui.Views.Extras.Title = gui.c.Tr.CommandLog
	gui.Views.Extras.Autoscroll = true
	gui.Views.Extras.Wrap = true

	gui.Views.Snake.Title = gui.c.Tr.SnakeTitle
	gui.Views.Snake.FgColor = gocui.ColorGreen

	if gui.c.UserConfig.Gui.ShowPanelJumps {
		jumpBindings := gui.c.UserConfig.Keybinding.Universal.JumpToBlock
		jumpLabels := make([]string, len(jumpBindings))
		for i, binding := range jumpBindings {
			jumpLabels[i] = fmt.Sprintf("[%s] ", binding)
		}

		gui.Views.Status.TitlePrefix = jumpLabels[0]

		gui.Views.Files.TitlePrefix = jumpLabels[1]
		gui.Views.Worktrees.TitlePrefix = jumpLabels[1]
		gui.Views.Submodules.TitlePrefix = jumpLabels[1]

		gui.Views.Branches.TitlePrefix = jumpLabels[2]
		gui.Views.Remotes.TitlePrefix = jumpLabels[2]
		gui.Views.Tags.TitlePrefix = jumpLabels[2]

		gui.Views.Commits.TitlePrefix = jumpLabels[3]
		gui.Views.ReflogCommits.TitlePrefix = jumpLabels[3]

		gui.Views.Stash.TitlePrefix = jumpLabels[4]
	}

	return nil
}


Review comment (refactor):
I'd prefer to make the space not part of what the client sets as the prefix. While it makes the implementation in gocui simpler, it's not as nice of an API. Clients should be able to set any string as the prefix and have it look right automatically. This will also make it possible to draw a piece of frame instead of a space, see below.

Oh btw, you can slightly simplify this code by using `lo.Map`:
```
		jumpLabels := lo.Map(jumpBindings, func(binding string, _ int) string {
			return fmt.Sprintf("[%s]", binding)
		})
```

Code after:

	gui.Views.Confirmation.Visible = false
	gui.Views.Confirmation.Editor = gocui.EditorFunc(gui.promptEditor)

	gui.Views.Suggestions.Visible = false

	gui.Views.Menu.Visible = false

	gui.Views.Tooltip.Visible = false

	gui.Views.Information.BgColor = gocui.ColorDefault
	gui.Views.Information.FgColor = gocui.ColorGreen
	gui.Views.Information.Frame = false

	gui.Views.Extras.Title = gui.c.Tr.CommandLog
	gui.Views.Extras.Autoscroll = true
	gui.Views.Extras.Wrap = true

	gui.Views.Snake.Title = gui.c.Tr.SnakeTitle
	gui.Views.Snake.FgColor = gocui.ColorGreen

	if gui.c.UserConfig.Gui.ShowPanelJumps {
		jumpBindings := gui.c.UserConfig.Keybinding.Universal.JumpToBlock
		jumpLabels := lo.Map(jumpBindings, func(binding string, _ int) string {
			return fmt.Sprintf("[%s]", binding)
		})

		gui.Views.Status.TitlePrefix = jumpLabels[0]

		gui.Views.Files.TitlePrefix = jumpLabels[1]
		gui.Views.Worktrees.TitlePrefix = jumpLabels[1]
		gui.Views.Submodules.TitlePrefix = jumpLabels[1]

		gui.Views.Branches.TitlePrefix = jumpLabels[2]
		gui.Views.Remotes.TitlePrefix = jumpLabels[2]
		gui.Views.Tags.TitlePrefix = jumpLabels[2]

		gui.Views.Commits.TitlePrefix = jumpLabels[3]
		gui.Views.ReflogCommits.TitlePrefix = jumpLabels[3]

		gui.Views.Stash.TitlePrefix = jumpLabels[4]
	}

	return nil
}