Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion docs/Config.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ gui:
- red
commitLength:
show: true
warningThreshold: 0
mouseEvents: true
skipUnstageLineWarning: false
skipStashWarning: false
Expand Down Expand Up @@ -530,4 +531,4 @@ notARepository: 'create'
```yaml
# to skip without creating a new repo
notARepository: 'skip'
```
```
8 changes: 6 additions & 2 deletions pkg/config/user_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ type ThemeConfig struct {
}

type CommitLengthConfig struct {
Show bool `yaml:"show"`
Show bool `yaml:"show"`
WarningThreshold int `yaml:"warningThreshold"`
}

type GitConfig struct {
Expand Down Expand Up @@ -362,7 +363,10 @@ func GetDefaultConfig() *UserConfig {
CherryPickedCommitFgColor: []string{"blue"},
UnstagedChangesColor: []string{"red"},
},
CommitLength: CommitLengthConfig{Show: true},
CommitLength: CommitLengthConfig{
Show: true,
WarningThreshold: 0,
},
SkipNoStagedFilesWarning: false,
ShowListFooter: true,
ShowCommandLog: true,
Expand Down
29 changes: 24 additions & 5 deletions pkg/gui/commit_message_panel.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package gui

import (
"strconv"
"bufio"
"strings"

"fmt"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/utils"
"github.com/jesseduffield/lazygit/pkg/theme"
)

func (gui *Gui) handleCommitMessageFocused() error {
Expand All @@ -28,9 +29,27 @@ func (gui *Gui) RenderCommitLength() {
return
}

gui.Views.CommitMessage.Subtitle = getBufferLength(gui.Views.CommitMessage)
commitLength := getBufferLength(gui.Views.CommitMessage)
gui.Views.CommitMessage.Subtitle = fmt.Sprintf(" %d ", commitLength)
gui.checkCommitLengthWarning(commitLength)
}

func getBufferLength(view *gocui.View) string {
return " " + strconv.Itoa(strings.Count(view.TextArea.GetContent(), "")-1) + " "
func getBufferLength(view *gocui.View) int {
return strings.Count(view.TextArea.GetContent(), "") - 1
}

func (gui *Gui) checkCommitLengthWarning(commitLength int) {
if gui.c.UserConfig.Gui.CommitLength.WarningThreshold == 0 {
return
}

scanner := bufio.NewScanner(strings.NewReader(gui.Views.CommitMessage.TextArea.GetContent()))

for scanner.Scan() {
if len(scanner.Text()) > gui.c.UserConfig.Gui.CommitLength.WarningThreshold {
gui.Views.CommitMessage.FgColor = gocui.ColorRed
} else {
gui.Views.CommitMessage.FgColor = theme.GocuiDefaultTextColor
}
}
}