1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2025-01-16 05:05:46 +02:00

allow focusing on command log view

This commit is contained in:
Jesse Duffield 2021-04-11 15:01:49 +10:00
parent cf78b86cb5
commit 393ce05860
9 changed files with 121 additions and 31 deletions

View File

@ -41,6 +41,7 @@ For old installations (slightly embarrassing: I didn't realise at the time that
skipUnstageLineWarning: false
skipStashWarning: true
showFileTree: false # for rendering changes files in a tree format
showCommandLog: false
git:
paging:
colorArg: always

View File

@ -36,6 +36,7 @@ type GuiConfig struct {
CommitLength CommitLengthConfig `yaml:"commitLength"`
SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"`
ShowFileTree bool `yaml:"showFileTree"`
ShowCommandLog bool `yaml:"showCommandLog"`
}
type ThemeConfig struct {

View File

@ -148,7 +148,10 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map
extrasWindowSize := 0
if gui.ShowExtrasWindow {
extrasWindowSize = 40 // TODO: make configurable
extrasWindowSize = 10
if gui.currentStaticContext().GetKey() == COMMAND_LOG_CONTEXT_KEY {
extrasWindowSize = 40
}
}
root := &boxlayout.Box{

View File

@ -313,6 +313,29 @@ func (gui *Gui) currentSideContext() Context {
return gui.defaultSideContext()
}
// static as opposed to popup
func (gui *Gui) currentStaticContext() Context {
gui.State.ContextManager.RLock()
defer gui.State.ContextManager.RUnlock()
stack := gui.State.ContextManager.ContextStack
if len(stack) == 0 {
return gui.defaultSideContext()
}
// find the first context in the stack without a popup type
for i := range stack {
context := stack[len(stack)-1-i]
if context.GetKind() != TEMPORARY_POPUP && context.GetKind() != PERSISTENT_POPUP {
return context
}
}
return gui.defaultSideContext()
}
func (gui *Gui) defaultSideContext() Context {
if gui.State.Modes.Filtering.Active() {
return gui.State.Contexts.BranchCommits
@ -362,7 +385,7 @@ func (gui *Gui) onViewFocusChange() error {
currentView := gui.g.CurrentView()
for _, view := range gui.g.Views() {
view.Highlight = view.Name() != "main" && view == currentView
view.Highlight = view.Name() != "main" && view.Name() != "extras" && view == currentView
}
return nil
}

View File

@ -192,6 +192,11 @@ func (gui *Gui) contextTree() ContextTree {
Kind: EXTRAS_CONTEXT,
ViewName: "extras",
Key: COMMAND_LOG_CONTEXT_KEY,
OnGetOptionsMap: gui.getMergingOptions,
OnFocusLost: func() error {
gui.Views.Extras.Autoscroll = true
return nil
},
},
}
}

View File

@ -5,6 +5,12 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
{
displayString: gui.Tr.ToggleShowCommandLog,
onPress: func() error {
currentContext := gui.currentStaticContext()
if gui.ShowExtrasWindow && currentContext.GetKey() == COMMAND_LOG_CONTEXT_KEY {
if err := gui.returnFromContext(); err != nil {
return err
}
}
gui.ShowExtrasWindow = !gui.ShowExtrasWindow
return nil
},
@ -12,12 +18,32 @@ func (gui *Gui) handleCreateExtrasMenuPanel() error {
{
displayString: gui.Tr.FocusCommandLog,
onPress: func() error {
gui.ShowExtrasWindow = true
gui.State.Contexts.CommandLog.SetParentContext(gui.currentSideContext())
return gui.pushContext(gui.State.Contexts.CommandLog)
return gui.handleFocusCommandLog()
},
},
}
return gui.createMenu(gui.Tr.DiffingMenuTitle, menuItems, createMenuOptions{showCancel: true})
return gui.createMenu(gui.Tr.CommandLog, menuItems, createMenuOptions{showCancel: true})
}
func (gui *Gui) handleFocusCommandLog() error {
gui.ShowExtrasWindow = true
gui.State.Contexts.CommandLog.SetParentContext(gui.currentSideContext())
return gui.pushContext(gui.State.Contexts.CommandLog)
}
func (gui *Gui) scrollUpExtra() error {
gui.Views.Extras.Autoscroll = false
return gui.scrollUpView(gui.Views.Extras)
}
func (gui *Gui) scrollDownExtra() error {
gui.Views.Extras.Autoscroll = false
if err := gui.scrollDownView(gui.Views.Extras); err != nil {
return err
}
return nil
}

View File

@ -140,24 +140,6 @@ func (gui *Gui) scrollDownSecondary() error {
return gui.scrollDownView(gui.Views.Secondary)
}
func (gui *Gui) scrollUpExtra() error {
gui.Views.Extras.Autoscroll = false
return gui.scrollUpView(gui.Views.Extras)
}
func (gui *Gui) scrollDownExtra() error {
if gui.atScrollBottom(gui.Views.Extras) {
gui.Views.Extras.Autoscroll = true
}
if err := gui.scrollDownView(gui.Views.Extras); err != nil {
return err
}
return nil
}
func (gui *Gui) scrollUpConfirmationPanel() error {
if gui.Views.Confirmation.Editable {
return nil
@ -183,13 +165,13 @@ func (gui *Gui) handleMouseDownMain() error {
return nil
}
switch gui.g.CurrentView() {
case gui.Views.Files:
switch gui.currentSideContext() {
case gui.State.Contexts.Files:
// set filename, set primary/secondary selected, set line number, then switch context
// I'll need to know it was changed though.
// Could I pass something along to the context change?
return gui.enterFile(false, gui.Views.Main.SelectedLineIdx())
case gui.Views.CommitFiles:
case gui.State.Contexts.CommitFiles:
return gui.enterCommitFile(gui.Views.Main.SelectedLineIdx())
}

View File

@ -466,6 +466,7 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom
RepoPathStack: []string{},
RepoStateMap: map[Repo]*guiState{},
CmdLog: []string{},
ShowExtrasWindow: config.GetUserConfig().Gui.ShowCommandLog,
}
gui.resetState(filterPath, false)
@ -480,6 +481,8 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom
return
}
gui.Views.Extras.Autoscroll = true
if entry.GetSpan() != currentSpan {
fmt.Fprintln(gui.Views.Extras, utils.ColoredString(entry.GetSpan(), color.FgYellow))
currentSpan = entry.GetSpan()

View File

@ -1719,6 +1719,52 @@ func (gui *Gui) GetInitialKeybindings() []*Binding {
Key: gocui.MouseWheelDown,
Handler: gui.scrollDownExtra,
},
{
ViewName: "extras",
Key: gui.getKey(config.Universal.ExtrasMenu),
Handler: gui.handleCreateExtrasMenuPanel,
Description: gui.Tr.LcOpenExtrasMenu,
OpensMenu: true,
},
{
ViewName: "extras",
Tag: "navigation",
Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevItemAlt),
Modifier: gocui.ModNone,
Handler: gui.scrollUpExtra,
},
{
ViewName: "extras",
Tag: "navigation",
Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.PrevItem),
Modifier: gocui.ModNone,
Handler: gui.scrollUpExtra,
},
{
ViewName: "extras",
Tag: "navigation",
Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextItem),
Modifier: gocui.ModNone,
Handler: gui.scrollDownExtra,
},
{
ViewName: "extras",
Tag: "navigation",
Contexts: []string{string(COMMAND_LOG_CONTEXT_KEY)},
Key: gui.getKey(config.Universal.NextItemAlt),
Modifier: gocui.ModNone,
Handler: gui.scrollDownExtra,
},
{
ViewName: "extras",
Tag: "navigation",
Key: gocui.MouseLeft,
Modifier: gocui.ModNone,
Handler: gui.handleFocusCommandLog,
},
}
for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "stash", "menu"} {