diff options
-rw-r--r-- | pkg/gui/arrangement.go | 6 | ||||
-rw-r--r-- | pkg/gui/global_handlers.go | 73 | ||||
-rw-r--r-- | pkg/gui/gui.go | 9 | ||||
-rw-r--r-- | pkg/gui/keybindings.go | 10 | ||||
-rw-r--r-- | pkg/gui/layout.go | 12 |
5 files changed, 78 insertions, 32 deletions
diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go index be2321a9a..4cd9610f9 100644 --- a/pkg/gui/arrangement.go +++ b/pkg/gui/arrangement.go @@ -146,7 +146,7 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map mainPanelsDirection = boxlayout.COLUMN } - cmdLogSize := 40 // TODO: make configurable + extrasWindowSize := 40 // TODO: make configurable root := &boxlayout.Box{ Direction: boxlayout.ROW, @@ -170,8 +170,8 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map Weight: 1, }, { - Window: "cmdLog", - Size: cmdLogSize, + Window: "extras", + Size: extrasWindowSize, }, }, }, diff --git a/pkg/gui/global_handlers.go b/pkg/gui/global_handlers.go index c8c567fd1..cea8be8b0 100644 --- a/pkg/gui/global_handlers.go +++ b/pkg/gui/global_handlers.go @@ -68,6 +68,21 @@ func (gui *Gui) scrollUpView(view *gocui.View) error { func (gui *Gui) scrollDownView(view *gocui.View) error { ox, oy := view.Origin() + scrollHeight := gui.linesToScrollDown(view) + if scrollHeight > 0 { + if err := view.SetOrigin(ox, oy+scrollHeight); err != nil { + return err + } + } + + if manager, ok := gui.viewBufferManagerMap[view.Name()]; ok { + manager.ReadLines(scrollHeight) + } + return nil +} + +func (gui *Gui) linesToScrollDown(view *gocui.View) int { + _, oy := view.Origin() y := oy canScrollPastBottom := gui.Config.GetUserConfig().Gui.ScrollPastBottom if !canScrollPastBottom { @@ -76,27 +91,29 @@ func (gui *Gui) scrollDownView(view *gocui.View) error { } scrollHeight := gui.Config.GetUserConfig().Gui.ScrollHeight scrollableLines := view.ViewLinesHeight() - y - if scrollableLines > 0 { - // margin is about how many lines must still appear if you scroll - // all the way down. In practice every file ends in a newline so it will really - // just show a single line - margin := 1 - if canScrollPastBottom { - margin = 2 - } - if scrollableLines-margin < scrollHeight { - scrollHeight = scrollableLines - margin - } - if oy+scrollHeight >= 0 { - if err := view.SetOrigin(ox, oy+scrollHeight); err != nil { - return err - } - } + if scrollableLines < 0 { + return 0 } - if manager, ok := gui.viewBufferManagerMap[view.Name()]; ok { - manager.ReadLines(scrollHeight) + + // margin is about how many lines must still appear if you scroll + // all the way down. In practice every file ends in a newline so it will really + // just show a single line + margin := 1 + if canScrollPastBottom { + margin = 2 + } + if scrollableLines-margin < scrollHeight { + scrollHeight = scrollableLines - margin + } + if oy+scrollHeight < 0 { + return 0 + } else { + return scrollHeight } - return nil +} + +func (gui *Gui) atScrollBottom(view *gocui.View) bool { + return gui.linesToScrollDown(view) > 0 } func (gui *Gui) scrollUpMain() error { @@ -123,6 +140,24 @@ 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 err := gui.scrollDownView(gui.Views.Extras); err != nil { + return err + } + + if gui.atScrollBottom(gui.Views.Extras) { + gui.Views.Extras.Autoscroll = true + } + + return nil +} + func (gui *Gui) scrollUpConfirmationPanel() error { if gui.Views.Confirmation.Editable { return nil diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index d152200cb..4d104faf2 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -254,7 +254,7 @@ type Views struct { SearchPrefix *gocui.View Limit *gocui.View Suggestions *gocui.View - CmdLog *gocui.View + Extras *gocui.View } type searchingState struct { @@ -475,12 +475,12 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom currentSpan := "" return func(entry oscommands.CmdLogEntry) { - if gui.Views.CmdLog == nil { + if gui.Views.Extras == nil { return } if entry.GetSpan() != currentSpan { - fmt.Fprintln(gui.Views.CmdLog, utils.ColoredString(entry.GetSpan(), color.FgYellow)) + fmt.Fprintln(gui.Views.Extras, utils.ColoredString(entry.GetSpan(), color.FgYellow)) currentSpan = entry.GetSpan() } @@ -489,7 +489,8 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom clrAttr = color.FgMagenta } gui.CmdLog = append(gui.CmdLog, entry.GetCmdStr()) - fmt.Fprintln(gui.Views.CmdLog, " "+utils.ColoredString(entry.GetCmdStr(), clrAttr)) + indentedCmdStr := " " + strings.Replace(entry.GetCmdStr(), "\n", "\n ", -1) + fmt.Fprintln(gui.Views.Extras, utils.ColoredString(indentedCmdStr, clrAttr)) } }() diff --git a/pkg/gui/keybindings.go b/pkg/gui/keybindings.go index ce1e53134..c2a420e8a 100644 --- a/pkg/gui/keybindings.go +++ b/pkg/gui/keybindings.go @@ -1702,6 +1702,16 @@ func (gui *Gui) GetInitialKeybindings() []*Binding { Description: gui.Tr.LcViewBulkSubmoduleOptions, OpensMenu: true, }, + { + ViewName: "extras", + Key: gocui.MouseWheelUp, + Handler: gui.scrollUpExtra, + }, + { + ViewName: "extras", + Key: gocui.MouseWheelDown, + Handler: gui.scrollDownExtra, + }, } for _, viewName := range []string{"status", "branches", "files", "commits", "commitFiles", "stash", "menu"} { diff --git a/pkg/gui/layout.go b/pkg/gui/layout.go index ae9b8ca31..9846e67ef 100644 --- a/pkg/gui/layout.go +++ b/pkg/gui/layout.go @@ -48,7 +48,7 @@ func (gui *Gui) createAllViews() error { {viewPtr: &gui.Views.Suggestions, name: "suggestions"}, {viewPtr: &gui.Views.Confirmation, name: "confirmation"}, {viewPtr: &gui.Views.Limit, name: "limit"}, - {viewPtr: &gui.Views.CmdLog, name: "cmdLog"}, + {viewPtr: &gui.Views.Extras, name: "extras"}, } var err error @@ -135,9 +135,9 @@ func (gui *Gui) createAllViews() error { gui.Views.Information.FgColor = gocui.ColorGreen gui.Views.Information.Frame = false - gui.Views.CmdLog.Title = gui.Tr.CommandLog - gui.Views.CmdLog.FgColor = theme.GocuiDefaultTextColor - gui.Views.CmdLog.Autoscroll = true + gui.Views.Extras.Title = gui.Tr.CommandLog + gui.Views.Extras.FgColor = theme.GocuiDefaultTextColor + gui.Views.Extras.Autoscroll = true if _, err := gui.g.SetCurrentView(gui.defaultSideContext().GetViewName()); err != nil { return err @@ -240,7 +240,7 @@ func (gui *Gui) layout(g *gocui.Gui) error { {viewName: "search", windowName: "search", frame: false}, {viewName: "appStatus", windowName: "appStatus", frame: false}, {viewName: "information", windowName: "information", frame: false}, - {viewName: "cmdLog", windowName: "cmdLog", frame: true}, + {viewName: "extras", windowName: "extras", frame: true}, } for _, arg := range args { @@ -350,7 +350,7 @@ func (gui *Gui) onInitialViewsCreation() error { gui.Views.CommitFiles, gui.Views.Main, gui.Views.Secondary, - gui.Views.CmdLog, + gui.Views.Extras, // bottom line gui.Views.Options, |