2022-05-08 03:41:13 +02:00
|
|
|
package gui
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/jesseduffield/generics/slices"
|
|
|
|
"github.com/jesseduffield/gocui"
|
|
|
|
"github.com/jesseduffield/lazygit/pkg/theme"
|
|
|
|
)
|
|
|
|
|
|
|
|
type viewNameMapping struct {
|
|
|
|
viewPtr **gocui.View
|
|
|
|
name string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) orderedViews() []*gocui.View {
|
|
|
|
return slices.Map(gui.orderedViewNameMappings(), func(v viewNameMapping) *gocui.View {
|
|
|
|
return *v.viewPtr
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) orderedViewNameMappings() []viewNameMapping {
|
|
|
|
return []viewNameMapping{
|
|
|
|
// first layer. Ordering within this layer does not matter because there are
|
|
|
|
// no overlapping views
|
|
|
|
{viewPtr: &gui.Views.Status, name: "status"},
|
2022-12-30 02:34:01 +02:00
|
|
|
{viewPtr: &gui.Views.Snake, name: "snake"},
|
2022-06-13 03:01:26 +02:00
|
|
|
{viewPtr: &gui.Views.Submodules, name: "submodules"},
|
2022-05-08 03:41:13 +02:00
|
|
|
{viewPtr: &gui.Views.Files, name: "files"},
|
2022-06-13 03:01:26 +02:00
|
|
|
{viewPtr: &gui.Views.Tags, name: "tags"},
|
|
|
|
{viewPtr: &gui.Views.Remotes, name: "remotes"},
|
|
|
|
{viewPtr: &gui.Views.Branches, name: "localBranches"},
|
2022-05-08 03:41:13 +02:00
|
|
|
{viewPtr: &gui.Views.RemoteBranches, name: "remoteBranches"},
|
2022-06-13 03:01:26 +02:00
|
|
|
{viewPtr: &gui.Views.ReflogCommits, name: "reflogCommits"},
|
2022-05-08 03:41:13 +02:00
|
|
|
{viewPtr: &gui.Views.Commits, name: "commits"},
|
|
|
|
{viewPtr: &gui.Views.Stash, name: "stash"},
|
|
|
|
{viewPtr: &gui.Views.SubCommits, name: "subCommits"},
|
|
|
|
{viewPtr: &gui.Views.CommitFiles, name: "commitFiles"},
|
2022-06-13 03:01:26 +02:00
|
|
|
|
|
|
|
{viewPtr: &gui.Views.Staging, name: "staging"},
|
|
|
|
{viewPtr: &gui.Views.StagingSecondary, name: "stagingSecondary"},
|
|
|
|
{viewPtr: &gui.Views.PatchBuilding, name: "patchBuilding"},
|
|
|
|
{viewPtr: &gui.Views.PatchBuildingSecondary, name: "patchBuildingSecondary"},
|
2022-08-06 10:05:00 +02:00
|
|
|
{viewPtr: &gui.Views.MergeConflicts, name: "mergeConflicts"},
|
2022-05-08 03:41:13 +02:00
|
|
|
{viewPtr: &gui.Views.Secondary, name: "secondary"},
|
2022-06-13 03:01:26 +02:00
|
|
|
{viewPtr: &gui.Views.Main, name: "main"},
|
|
|
|
|
2022-05-08 03:41:13 +02:00
|
|
|
{viewPtr: &gui.Views.Extras, name: "extras"},
|
|
|
|
|
|
|
|
// bottom line
|
|
|
|
{viewPtr: &gui.Views.Options, name: "options"},
|
|
|
|
{viewPtr: &gui.Views.AppStatus, name: "appStatus"},
|
|
|
|
{viewPtr: &gui.Views.Information, name: "information"},
|
|
|
|
{viewPtr: &gui.Views.Search, name: "search"},
|
|
|
|
// this view takes up one character. Its only purpose is to show the slash when searching
|
|
|
|
{viewPtr: &gui.Views.SearchPrefix, name: "searchPrefix"},
|
|
|
|
|
|
|
|
// popups.
|
|
|
|
{viewPtr: &gui.Views.CommitMessage, name: "commitMessage"},
|
2023-01-21 13:38:14 +02:00
|
|
|
{viewPtr: &gui.Views.CommitDescription, name: "commitDescription"},
|
2022-05-08 03:41:13 +02:00
|
|
|
{viewPtr: &gui.Views.Menu, name: "menu"},
|
|
|
|
{viewPtr: &gui.Views.Suggestions, name: "suggestions"},
|
|
|
|
{viewPtr: &gui.Views.Confirmation, name: "confirmation"},
|
2022-05-08 04:46:48 +02:00
|
|
|
{viewPtr: &gui.Views.Tooltip, name: "tooltip"},
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
// this guy will cover everything else when it appears
|
|
|
|
{viewPtr: &gui.Views.Limit, name: "limit"},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func (gui *Gui) createAllViews() error {
|
2023-03-18 02:23:31 +02:00
|
|
|
frameRunes := []rune{'─', '│', '┌', '┐', '└', '┘'}
|
|
|
|
switch gui.c.UserConfig.Gui.Border {
|
|
|
|
case "double":
|
|
|
|
frameRunes = []rune{'═', '║', '╔', '╗', '╚', '╝'}
|
|
|
|
case "rounded":
|
|
|
|
frameRunes = []rune{'─', '│', '╭', '╮', '╰', '╯'}
|
|
|
|
case "hidden":
|
|
|
|
frameRunes = []rune{' ', ' ', ' ', ' ', ' ', ' '}
|
|
|
|
}
|
|
|
|
|
2022-05-08 03:41:13 +02:00
|
|
|
var err error
|
|
|
|
for _, mapping := range gui.orderedViewNameMappings() {
|
|
|
|
*mapping.viewPtr, err = gui.prepareView(mapping.name)
|
2023-02-10 14:23:48 +02:00
|
|
|
if err != nil && !gocui.IsUnknownView(err) {
|
2022-05-08 03:41:13 +02:00
|
|
|
return err
|
|
|
|
}
|
2023-03-18 02:23:31 +02:00
|
|
|
(*mapping.viewPtr).FrameRunes = frameRunes
|
2023-03-26 06:24:09 +02:00
|
|
|
(*mapping.viewPtr).FgColor = theme.GocuiDefaultTextColor
|
2022-05-08 03:41:13 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
gui.Views.Options.FgColor = theme.OptionsColor
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.Options.Frame = false
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
gui.Views.SearchPrefix.BgColor = gocui.ColorDefault
|
|
|
|
gui.Views.SearchPrefix.FgColor = gocui.ColorGreen
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.SearchPrefix.Frame = false
|
2023-05-25 13:11:51 +02:00
|
|
|
gui.c.SetViewContent(gui.Views.SearchPrefix, gui.Tr.SearchPrefix)
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
gui.Views.Stash.Title = gui.c.Tr.StashTitle
|
|
|
|
|
|
|
|
gui.Views.Commits.Title = gui.c.Tr.CommitsTitle
|
|
|
|
|
|
|
|
gui.Views.CommitFiles.Title = gui.c.Tr.CommitFiles
|
|
|
|
|
|
|
|
gui.Views.Branches.Title = gui.c.Tr.BranchesTitle
|
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.Remotes.Title = gui.c.Tr.RemotesTitle
|
|
|
|
|
|
|
|
gui.Views.Tags.Title = gui.c.Tr.TagsTitle
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
gui.Views.Files.Title = gui.c.Tr.FilesTitle
|
|
|
|
|
2022-08-06 10:05:00 +02:00
|
|
|
for _, view := range []*gocui.View{gui.Views.Main, gui.Views.Secondary, gui.Views.Staging, gui.Views.StagingSecondary, gui.Views.PatchBuilding, gui.Views.PatchBuildingSecondary, gui.Views.MergeConflicts} {
|
2022-06-13 03:01:26 +02:00
|
|
|
view.Title = gui.c.Tr.DiffTitle
|
|
|
|
view.Wrap = true
|
|
|
|
view.IgnoreCarriageReturns = true
|
|
|
|
view.CanScrollPastBottom = gui.c.UserConfig.Gui.ScrollPastBottom
|
|
|
|
}
|
|
|
|
|
|
|
|
gui.Views.Staging.Title = gui.c.Tr.UnstagedChanges
|
2023-02-15 22:15:12 +02:00
|
|
|
gui.Views.Staging.Highlight = false
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.Staging.Wrap = true
|
|
|
|
|
|
|
|
gui.Views.StagingSecondary.Title = gui.c.Tr.StagedChanges
|
2023-02-15 22:15:12 +02:00
|
|
|
gui.Views.StagingSecondary.Highlight = false
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.StagingSecondary.Wrap = true
|
|
|
|
|
|
|
|
gui.Views.PatchBuilding.Title = gui.Tr.Patch
|
2023-02-15 22:15:12 +02:00
|
|
|
gui.Views.PatchBuilding.Highlight = false
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.PatchBuilding.Wrap = true
|
2022-05-08 03:41:13 +02:00
|
|
|
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.PatchBuildingSecondary.Title = gui.Tr.CustomPatch
|
2023-02-15 22:15:12 +02:00
|
|
|
gui.Views.PatchBuildingSecondary.Highlight = false
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.PatchBuildingSecondary.Wrap = true
|
|
|
|
|
2022-08-06 10:05:00 +02:00
|
|
|
gui.Views.MergeConflicts.Title = gui.c.Tr.MergeConflictsTitle
|
2023-02-15 22:15:12 +02:00
|
|
|
gui.Views.MergeConflicts.Highlight = false
|
2022-08-06 10:05:00 +02:00
|
|
|
gui.Views.MergeConflicts.Wrap = false
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
gui.Views.Limit.Title = gui.c.Tr.NotEnoughSpace
|
|
|
|
gui.Views.Limit.Wrap = true
|
|
|
|
|
|
|
|
gui.Views.Status.Title = gui.c.Tr.StatusTitle
|
|
|
|
|
|
|
|
gui.Views.Search.BgColor = gocui.ColorDefault
|
|
|
|
gui.Views.Search.FgColor = gocui.ColorGreen
|
|
|
|
gui.Views.Search.Editable = true
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.Search.Frame = false
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
gui.Views.AppStatus.BgColor = gocui.ColorDefault
|
|
|
|
gui.Views.AppStatus.FgColor = gocui.ColorCyan
|
|
|
|
gui.Views.AppStatus.Visible = false
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.AppStatus.Frame = false
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
gui.Views.CommitMessage.Visible = false
|
2023-01-21 13:38:14 +02:00
|
|
|
gui.Views.CommitMessage.Title = gui.c.Tr.CommitSummary
|
2022-05-08 03:41:13 +02:00
|
|
|
gui.Views.CommitMessage.Editable = true
|
|
|
|
gui.Views.CommitMessage.Editor = gocui.EditorFunc(gui.commitMessageEditor)
|
|
|
|
|
2023-01-21 13:38:14 +02:00
|
|
|
gui.Views.CommitDescription.Visible = false
|
|
|
|
gui.Views.CommitDescription.Title = gui.c.Tr.CommitDescriptionTitle
|
|
|
|
gui.Views.CommitDescription.Subtitle = gui.Tr.CommitDescriptionSubTitle
|
|
|
|
gui.Views.CommitDescription.FgColor = theme.GocuiDefaultTextColor
|
|
|
|
gui.Views.CommitDescription.Editable = true
|
|
|
|
gui.Views.CommitDescription.Editor = gocui.EditorFunc(gui.commitDescriptionEditor)
|
|
|
|
|
2022-05-08 03:41:13 +02:00
|
|
|
gui.Views.Confirmation.Visible = false
|
2023-01-21 13:38:14 +02:00
|
|
|
gui.Views.Confirmation.Editor = gocui.EditorFunc(gui.promptEditor)
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
gui.Views.Suggestions.Visible = false
|
|
|
|
|
|
|
|
gui.Views.Menu.Visible = false
|
|
|
|
|
2022-05-08 04:46:48 +02:00
|
|
|
gui.Views.Tooltip.Visible = false
|
|
|
|
|
2022-05-08 03:41:13 +02:00
|
|
|
gui.Views.Information.BgColor = gocui.ColorDefault
|
|
|
|
gui.Views.Information.FgColor = gocui.ColorGreen
|
2022-06-13 03:01:26 +02:00
|
|
|
gui.Views.Information.Frame = false
|
2022-05-08 03:41:13 +02:00
|
|
|
|
|
|
|
gui.Views.Extras.Title = gui.c.Tr.CommandLog
|
|
|
|
gui.Views.Extras.Autoscroll = true
|
|
|
|
gui.Views.Extras.Wrap = true
|
|
|
|
|
2022-12-30 02:34:01 +02:00
|
|
|
gui.Views.Snake.Title = gui.c.Tr.SnakeTitle
|
|
|
|
gui.Views.Snake.FgColor = gocui.ColorGreen
|
|
|
|
|
2022-05-08 03:41:13 +02:00
|
|
|
return nil
|
|
|
|
}
|