mirror of
https://github.com/jesseduffield/lazygit.git
synced 2025-03-31 22:22:14 +02:00
WIP: standardising how we render to main
This commit is contained in:
parent
0f7b2c45d7
commit
3c87ff4eff
@ -13,6 +13,10 @@ import (
|
||||
// list panel functions
|
||||
|
||||
func (gui *Gui) getSelectedBranch() *commands.Branch {
|
||||
if len(gui.State.Branches) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
selectedLine := gui.State.Panels.Branches.SelectedLine
|
||||
if selectedLine == -1 {
|
||||
return nil
|
||||
@ -26,27 +30,32 @@ func (gui *Gui) handleBranchSelect() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = "Log"
|
||||
|
||||
// This really shouldn't happen: there should always be a master branch
|
||||
if len(gui.State.Branches) == 0 {
|
||||
return gui.newStringTask("main", gui.Tr.SLocalize("NoBranchesThisRepo"))
|
||||
}
|
||||
branch := gui.getSelectedBranch()
|
||||
|
||||
if gui.inDiffMode() {
|
||||
return gui.renderDiff()
|
||||
}
|
||||
|
||||
cmd := gui.OSCommand.ExecutableFromString(
|
||||
gui.GitCommand.GetBranchGraphCmdStr(branch.Name),
|
||||
)
|
||||
if err := gui.newCmdTask("main", cmd); err != nil {
|
||||
gui.Log.Error(err)
|
||||
refreshOpts := refreshMainOpts{
|
||||
main: &viewUpdateOpts{
|
||||
title: "Log",
|
||||
task: {
|
||||
kind: RENDER_STRING,
|
||||
str: gui.Tr.SLocalize("NoBranchesThisRepo"),
|
||||
},
|
||||
},
|
||||
}
|
||||
return nil
|
||||
|
||||
branch := gui.getSelectedBranch()
|
||||
if branch == nil {
|
||||
refreshOpts.main.task = func() error { return gui.newStringTask("main", gui.Tr.SLocalize("NoBranchesThisRepo")) }
|
||||
} else {
|
||||
cmd := gui.OSCommand.ExecutableFromString(
|
||||
gui.GitCommand.GetBranchGraphCmdStr(branch.Name),
|
||||
)
|
||||
|
||||
refreshOpts.main.task = func() error { return gui.newPtyTask("main", cmd) }
|
||||
}
|
||||
|
||||
return gui.refreshMain(refreshOpts)
|
||||
}
|
||||
|
||||
// gui.refreshStatus is called at the end of this because that's when we can
|
||||
|
@ -18,20 +18,22 @@ func (gui *Gui) exitDiffMode() error {
|
||||
}
|
||||
|
||||
func (gui *Gui) renderDiff() error {
|
||||
gui.getMainView().Title = "Diff"
|
||||
gui.splitMainPanel(false)
|
||||
filterArg := ""
|
||||
if gui.inFilterMode() {
|
||||
filterArg = fmt.Sprintf(" -- %s", gui.State.FilterPath)
|
||||
}
|
||||
return gui.refreshMain(refreshMainOpts{
|
||||
main: &viewUpdateOpts{
|
||||
title: "Diff",
|
||||
task: func() error {
|
||||
filterArg := ""
|
||||
if gui.inFilterMode() {
|
||||
filterArg = fmt.Sprintf(" -- %s", gui.State.FilterPath)
|
||||
}
|
||||
|
||||
cmd := gui.OSCommand.ExecutableFromString(
|
||||
fmt.Sprintf("git diff --color %s %s", gui.diffStr(), filterArg),
|
||||
)
|
||||
if err := gui.newPtyTask("main", cmd); err != nil {
|
||||
gui.Log.Error(err)
|
||||
}
|
||||
return nil
|
||||
cmd := gui.OSCommand.ExecutableFromString(
|
||||
fmt.Sprintf("git diff --color %s %s", gui.diffStr(), filterArg),
|
||||
)
|
||||
return gui.newPtyTask("main", cmd)
|
||||
},
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
// currentDiffTerminals returns the current diff terminals of the currently selected item.
|
||||
|
69
pkg/gui/main_panels.go
Normal file
69
pkg/gui/main_panels.go
Normal file
@ -0,0 +1,69 @@
|
||||
package gui
|
||||
|
||||
import "os/exec"
|
||||
|
||||
type viewUpdateOpts struct {
|
||||
title string
|
||||
task func() error
|
||||
}
|
||||
|
||||
type refreshMainOpts struct {
|
||||
main *viewUpdateOpts
|
||||
secondary *viewUpdateOpts
|
||||
}
|
||||
|
||||
// constants for updateTask's kind field
|
||||
const (
|
||||
RENDER_STRING = iota
|
||||
RUN_FUNCTION
|
||||
RUN_COMMAND
|
||||
)
|
||||
|
||||
type updateTask struct {
|
||||
kind int
|
||||
str string
|
||||
f func(chan struct{}) error
|
||||
cmd *exec.Cmd
|
||||
}
|
||||
|
||||
func (gui *Gui) createRenderStringTask(str string) {
|
||||
|
||||
}
|
||||
|
||||
func (gui *Gui) refreshMain(opts refreshMainOpts) error {
|
||||
mainView := gui.getMainView()
|
||||
secondaryView := gui.getSecondaryView()
|
||||
|
||||
if opts.main != nil {
|
||||
mainView.Title = opts.main.title
|
||||
if err := opts.main.task(); err != nil {
|
||||
gui.Log.Error(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
gui.splitMainPanel(opts.secondary != nil)
|
||||
|
||||
if opts.secondary != nil {
|
||||
secondaryView.Title = opts.secondary.title
|
||||
if err := opts.secondary.task(); err != nil {
|
||||
gui.Log.Error(err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (gui *Gui) splitMainPanel(splitMainPanel bool) {
|
||||
gui.State.SplitMainPanel = splitMainPanel
|
||||
|
||||
// no need to set view on bottom when splitMainPanel is false: it will have zero size anyway thanks to our view arrangement code.
|
||||
if splitMainPanel {
|
||||
_, _ = gui.g.SetViewOnTop("secondary")
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) isMainPanelSplit() bool {
|
||||
return gui.State.SplitMainPanel
|
||||
}
|
@ -19,30 +19,28 @@ func (gui *Gui) getSelectedReflogCommit() *commands.Commit {
|
||||
}
|
||||
|
||||
func (gui *Gui) handleReflogCommitSelect() error {
|
||||
if gui.popupPanelFocused() {
|
||||
return nil
|
||||
}
|
||||
|
||||
gui.splitMainPanel(false)
|
||||
|
||||
gui.getMainView().Title = "Reflog Entry"
|
||||
|
||||
commit := gui.getSelectedReflogCommit()
|
||||
if commit == nil {
|
||||
return gui.newStringTask("main", "No reflog history")
|
||||
}
|
||||
if gui.inDiffMode() {
|
||||
return gui.renderDiff()
|
||||
}
|
||||
|
||||
cmd := gui.OSCommand.ExecutableFromString(
|
||||
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.FilterPath),
|
||||
)
|
||||
if err := gui.newPtyTask("main", cmd); err != nil {
|
||||
gui.Log.Error(err)
|
||||
refreshOpts := refreshMainOpts{
|
||||
main: &viewUpdateOpts{
|
||||
title: "Reflog Entry",
|
||||
},
|
||||
}
|
||||
|
||||
return nil
|
||||
commit := gui.getSelectedReflogCommit()
|
||||
if commit == nil {
|
||||
refreshOpts.main.task = func() error { return gui.newStringTask("main", "No reflog history") }
|
||||
} else {
|
||||
cmd := gui.OSCommand.ExecutableFromString(
|
||||
gui.GitCommand.ShowCmdStr(commit.Sha, gui.State.FilterPath),
|
||||
)
|
||||
|
||||
refreshOpts.main.task = func() error { return gui.newPtyTask("main", cmd) }
|
||||
}
|
||||
|
||||
return gui.refreshMain(refreshOpts)
|
||||
}
|
||||
|
||||
// the reflogs panel is the only panel where we cache data, in that we only
|
||||
|
@ -368,16 +368,3 @@ func (gui *Gui) clearEditorView(v *gocui.View) {
|
||||
_ = v.SetCursor(0, 0)
|
||||
_ = v.SetOrigin(0, 0)
|
||||
}
|
||||
|
||||
func (gui *Gui) splitMainPanel(state bool) {
|
||||
gui.State.SplitMainPanel = state
|
||||
|
||||
// no need to set view on bottom when state is false: it will have zero size anyway thanks to our view arrangement code.
|
||||
if state {
|
||||
_, _ = gui.g.SetViewOnTop("secondary")
|
||||
}
|
||||
}
|
||||
|
||||
func (gui *Gui) isMainPanelSplit() bool {
|
||||
return gui.State.SplitMainPanel
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user