From 06a8eb115c100816e3ceccff875010a84416beee Mon Sep 17 00:00:00 2001 From: Jesse Duffield Date: Sun, 11 Apr 2021 22:03:55 +1000 Subject: [PATCH] make command log size configurable --- docs/Config.md | 3 ++- pkg/config/user_config.go | 4 ++++ pkg/gui/arrangement.go | 3 ++- pkg/gui/command_log_panel.go | 37 ++++++++++++++++++++++++++++++++++++ pkg/gui/gui.go | 27 -------------------------- 5 files changed, 45 insertions(+), 29 deletions(-) create mode 100644 pkg/gui/command_log_panel.go diff --git a/docs/Config.md b/docs/Config.md index 337e23b54..1df5c6f87 100644 --- a/docs/Config.md +++ b/docs/Config.md @@ -41,7 +41,8 @@ gui: skipUnstageLineWarning: false skipStashWarning: true showFileTree: false # for rendering changes files in a tree format - showCommandLog: + showCommandLog: true + commandLogSize: 1 git: paging: colorArg: always diff --git a/pkg/config/user_config.go b/pkg/config/user_config.go index c2790ce6d..7fd26a708 100644 --- a/pkg/config/user_config.go +++ b/pkg/config/user_config.go @@ -37,6 +37,7 @@ type GuiConfig struct { SkipNoStagedFilesWarning bool `yaml:"skipNoStagedFilesWarning"` ShowFileTree bool `yaml:"showFileTree"` ShowCommandLog bool `yaml:"showCommandLog"` + CommandLogSize int `yaml:"commandLogSize"` } type ThemeConfig struct { @@ -297,6 +298,9 @@ func GetDefaultConfig() *UserConfig { }, CommitLength: CommitLengthConfig{Show: true}, SkipNoStagedFilesWarning: false, + ShowCommandLog: true, + ShowFileTree: false, + CommandLogSize: 8, }, Git: GitConfig{ Paging: PagingConfig{ diff --git a/pkg/gui/arrangement.go b/pkg/gui/arrangement.go index f5fd02d23..a788fa8d3 100644 --- a/pkg/gui/arrangement.go +++ b/pkg/gui/arrangement.go @@ -150,7 +150,8 @@ func (gui *Gui) getWindowDimensions(informationStr string, appStatus string) map extrasWindowSize := 0 if gui.ShowExtrasWindow { - extrasWindowSize = 10 + frameSize := 2 + extrasWindowSize = gui.Config.GetUserConfig().Gui.CommandLogSize + frameSize if gui.currentStaticContext().GetKey() == COMMAND_LOG_CONTEXT_KEY { extrasWindowSize = 40 } diff --git a/pkg/gui/command_log_panel.go b/pkg/gui/command_log_panel.go new file mode 100644 index 000000000..bd037aa7d --- /dev/null +++ b/pkg/gui/command_log_panel.go @@ -0,0 +1,37 @@ +package gui + +import ( + "fmt" + "strings" + + "github.com/fatih/color" + "github.com/jesseduffield/lazygit/pkg/commands/oscommands" + "github.com/jesseduffield/lazygit/pkg/theme" + "github.com/jesseduffield/lazygit/pkg/utils" +) + +func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) { + // closing over this so that nobody else can modify it + currentSpan := "" + + return func(entry oscommands.CmdLogEntry) { + if gui.Views.Extras == nil { + return + } + + gui.Views.Extras.Autoscroll = true + + if entry.GetSpan() != currentSpan { + fmt.Fprint(gui.Views.Extras, "\n"+utils.ColoredString(entry.GetSpan(), color.FgYellow)) + currentSpan = entry.GetSpan() + } + + clrAttr := theme.DefaultTextColor + if !entry.GetCommandLine() { + clrAttr = color.FgMagenta + } + gui.CmdLog = append(gui.CmdLog, entry.GetCmdStr()) + indentedCmdStr := " " + strings.Replace(entry.GetCmdStr(), "\n", "\n ", -1) + fmt.Fprint(gui.Views.Extras, "\n"+utils.ColoredString(indentedCmdStr, clrAttr)) + } +} diff --git a/pkg/gui/gui.go b/pkg/gui/gui.go index f6c273859..c29fcb99c 100644 --- a/pkg/gui/gui.go +++ b/pkg/gui/gui.go @@ -474,39 +474,12 @@ func NewGui(log *logrus.Entry, gitCommand *commands.GitCommand, oSCommand *oscom gui.watchFilesForChanges() onRunCommand := gui.GetOnRunCommand() - oSCommand.SetOnRunCommand(onRunCommand) gui.OnRunCommand = onRunCommand return gui, nil } -func (gui *Gui) GetOnRunCommand() func(entry oscommands.CmdLogEntry) { - // closing over this so that nobody else can modify it - currentSpan := "" - - return func(entry oscommands.CmdLogEntry) { - if gui.Views.Extras == nil { - return - } - - gui.Views.Extras.Autoscroll = true - - if entry.GetSpan() != currentSpan { - fmt.Fprintln(gui.Views.Extras, utils.ColoredString(entry.GetSpan(), color.FgYellow)) - currentSpan = entry.GetSpan() - } - - clrAttr := theme.DefaultTextColor - if !entry.GetCommandLine() { - clrAttr = color.FgMagenta - } - gui.CmdLog = append(gui.CmdLog, entry.GetCmdStr()) - indentedCmdStr := " " + strings.Replace(entry.GetCmdStr(), "\n", "\n ", -1) - fmt.Fprintln(gui.Views.Extras, utils.ColoredString(indentedCmdStr, clrAttr)) - } -} - // Run setup the gui with keybindings and start the mainloop func (gui *Gui) Run() error { recordEvents := recordingEvents()