mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-07-31 14:24:25 +03:00
simplify things
This commit is contained in:
@ -37,8 +37,12 @@ func (gui *Gui) renderDiff() error {
|
|||||||
// which becomes an option when you bring up the diff menu, but when you're just
|
// which becomes an option when you bring up the diff menu, but when you're just
|
||||||
// flicking through branches it will be using the local branch name.
|
// flicking through branches it will be using the local branch name.
|
||||||
func (gui *Gui) currentDiffTerminals() []string {
|
func (gui *Gui) currentDiffTerminals() []string {
|
||||||
|
currentView := gui.g.CurrentView()
|
||||||
|
if currentView == nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
names := []string{}
|
names := []string{}
|
||||||
switch gui.g.CurrentView().Name() {
|
switch currentView.Name() {
|
||||||
case "files":
|
case "files":
|
||||||
// not supporting files for now
|
// not supporting files for now
|
||||||
// file, err := gui.getSelectedFile()
|
// file, err := gui.getSelectedFile()
|
||||||
@ -100,18 +104,22 @@ func (gui *Gui) currentDiffTerminals() []string {
|
|||||||
func (gui *Gui) currentDiffTerminal() string {
|
func (gui *Gui) currentDiffTerminal() string {
|
||||||
names := gui.currentDiffTerminals()
|
names := gui.currentDiffTerminals()
|
||||||
if len(names) == 0 {
|
if len(names) == 0 {
|
||||||
return "HEAD"
|
return ""
|
||||||
}
|
}
|
||||||
return names[0]
|
return names[0]
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) diffStr() string {
|
func (gui *Gui) diffStr() string {
|
||||||
left := gui.State.Diff.Ref
|
output := gui.State.Diff.Ref
|
||||||
|
|
||||||
right := gui.currentDiffTerminal()
|
right := gui.currentDiffTerminal()
|
||||||
if gui.State.Diff.Reverse {
|
if right != "" {
|
||||||
left, right = right, left
|
output += " " + right
|
||||||
}
|
}
|
||||||
return fmt.Sprintf("%s %s", left, right)
|
if gui.State.Diff.Reverse {
|
||||||
|
output += " -R"
|
||||||
|
}
|
||||||
|
return output
|
||||||
}
|
}
|
||||||
|
|
||||||
func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error {
|
func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error {
|
||||||
@ -126,19 +134,9 @@ func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error
|
|||||||
name := name
|
name := name
|
||||||
menuItems = append(menuItems, []*menuItem{
|
menuItems = append(menuItems, []*menuItem{
|
||||||
{
|
{
|
||||||
displayString: fmt.Sprintf("%s %s", gui.Tr.SLocalize("diffFrom"), name),
|
displayString: fmt.Sprintf("%s %s", gui.Tr.SLocalize("diff"), name),
|
||||||
onPress: func() error {
|
onPress: func() error {
|
||||||
gui.State.Diff.Ref = name
|
gui.State.Diff.Ref = name
|
||||||
gui.State.Diff.Reverse = false
|
|
||||||
// can scope this down based on current view but too lazy right now
|
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayString: fmt.Sprintf("%s %s", gui.Tr.SLocalize("diffTo"), name),
|
|
||||||
onPress: func() error {
|
|
||||||
gui.State.Diff.Ref = name
|
|
||||||
gui.State.Diff.Reverse = true
|
|
||||||
// can scope this down based on current view but too lazy right now
|
// can scope this down based on current view but too lazy right now
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||||
},
|
},
|
||||||
@ -148,43 +146,33 @@ func (gui *Gui) handleCreateDiffingMenuPanel(g *gocui.Gui, v *gocui.View) error
|
|||||||
|
|
||||||
menuItems = append(menuItems, []*menuItem{
|
menuItems = append(menuItems, []*menuItem{
|
||||||
{
|
{
|
||||||
displayString: gui.Tr.SLocalize("enterRefToDiffFrom"),
|
displayString: gui.Tr.SLocalize("enterRefToDiff"),
|
||||||
onPress: func() error {
|
onPress: func() error {
|
||||||
return gui.createPromptPanel(gui.g, v, gui.Tr.SLocalize("enteRefName"), "", func(g *gocui.Gui, promptView *gocui.View) error {
|
return gui.createPromptPanel(gui.g, v, gui.Tr.SLocalize("enteRefName"), "", func(g *gocui.Gui, promptView *gocui.View) error {
|
||||||
gui.State.Diff.Ref = strings.TrimSpace(promptView.Buffer())
|
gui.State.Diff.Ref = strings.TrimSpace(promptView.Buffer())
|
||||||
gui.State.Diff.Reverse = false
|
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
|
||||||
})
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
|
||||||
displayString: gui.Tr.SLocalize("enterRefToDiffTo"),
|
|
||||||
onPress: func() error {
|
|
||||||
return gui.createPromptPanel(gui.g, v, gui.Tr.SLocalize("enteRefName"), "", func(g *gocui.Gui, promptView *gocui.View) error {
|
|
||||||
gui.State.Diff.Ref = strings.TrimSpace(promptView.Buffer())
|
|
||||||
gui.State.Diff.Reverse = true
|
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
}...)
|
}...)
|
||||||
|
|
||||||
menuItems = append(menuItems, &menuItem{
|
|
||||||
displayString: gui.Tr.SLocalize("swapDiff"),
|
|
||||||
onPress: func() error {
|
|
||||||
gui.State.Diff.Reverse = !gui.State.Diff.Reverse
|
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
|
||||||
},
|
|
||||||
})
|
|
||||||
|
|
||||||
if gui.inDiffMode() {
|
if gui.inDiffMode() {
|
||||||
menuItems = append(menuItems, &menuItem{
|
menuItems = append(menuItems, []*menuItem{
|
||||||
displayString: gui.Tr.SLocalize("exitDiffMode"),
|
{
|
||||||
onPress: func() error {
|
displayString: gui.Tr.SLocalize("swapDiff"),
|
||||||
gui.State.Diff = DiffState{}
|
onPress: func() error {
|
||||||
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
gui.State.Diff.Reverse = !gui.State.Diff.Reverse
|
||||||
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||||
|
},
|
||||||
},
|
},
|
||||||
})
|
{
|
||||||
|
displayString: gui.Tr.SLocalize("exitDiffMode"),
|
||||||
|
onPress: func() error {
|
||||||
|
gui.State.Diff = DiffState{}
|
||||||
|
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}...)
|
||||||
}
|
}
|
||||||
|
|
||||||
return gui.createMenu(gui.Tr.SLocalize("DiffingMenuTitle"), menuItems, createMenuOptions{showCancel: true})
|
return gui.createMenu(gui.Tr.SLocalize("DiffingMenuTitle"), menuItems, createMenuOptions{showCancel: true})
|
||||||
|
@ -151,7 +151,7 @@ func (gui *Gui) layout(g *gocui.Gui) error {
|
|||||||
information = donate + " " + information
|
information = donate + " " + information
|
||||||
}
|
}
|
||||||
if gui.inDiffMode() {
|
if gui.inDiffMode() {
|
||||||
information = utils.ColoredString(fmt.Sprintf("%s %s %s", gui.Tr.SLocalize("showingGitDiff"), gui.diffStr(), utils.ColoredString(gui.Tr.SLocalize("(reset)"), color.Underline)), color.FgMagenta, color.Bold)
|
information = utils.ColoredString(fmt.Sprintf("%s %s %s", gui.Tr.SLocalize("showingGitDiff"), "git diff "+gui.diffStr(), utils.ColoredString(gui.Tr.SLocalize("(reset)"), color.Underline)), color.FgMagenta, color.Bold)
|
||||||
} else if gui.inFilterMode() {
|
} else if gui.inFilterMode() {
|
||||||
information = utils.ColoredString(fmt.Sprintf("%s '%s' %s", gui.Tr.SLocalize("filteringBy"), gui.State.FilterPath, utils.ColoredString(gui.Tr.SLocalize("(reset)"), color.Underline)), color.FgRed, color.Bold)
|
information = utils.ColoredString(fmt.Sprintf("%s '%s' %s", gui.Tr.SLocalize("filteringBy"), gui.State.FilterPath, utils.ColoredString(gui.Tr.SLocalize("(reset)"), color.Underline)), color.FgRed, color.Bold)
|
||||||
} else if len(gui.State.CherryPickedCommits) > 0 {
|
} else if len(gui.State.CherryPickedCommits) > 0 {
|
||||||
|
@ -1108,17 +1108,11 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
ID: "MustExitFilterModePrompt",
|
ID: "MustExitFilterModePrompt",
|
||||||
Other: "Command not available in filtered mode. Exit filtered mode?",
|
Other: "Command not available in filtered mode. Exit filtered mode?",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "diffFrom",
|
ID: "diff",
|
||||||
Other: "diff from",
|
Other: "diff",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "diffTo",
|
ID: "enterRefToDiff",
|
||||||
Other: "diff to",
|
Other: "enter ref to diff",
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "enterRefToDiffFrom",
|
|
||||||
Other: "enter ref to diff from",
|
|
||||||
}, &i18n.Message{
|
|
||||||
ID: "enterRefToDiffTo",
|
|
||||||
Other: "enter ref to diff to",
|
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "enteRefName",
|
ID: "enteRefName",
|
||||||
Other: "enter ref:",
|
Other: "enter ref:",
|
||||||
@ -1136,7 +1130,7 @@ func addEnglish(i18nObject *i18n.Bundle) error {
|
|||||||
Other: "open diff menu",
|
Other: "open diff menu",
|
||||||
}, &i18n.Message{
|
}, &i18n.Message{
|
||||||
ID: "showingGitDiff",
|
ID: "showingGitDiff",
|
||||||
Other: "showing git diff:",
|
Other: "showing output for:",
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user