1
0
mirror of https://github.com/jesseduffield/lazygit.git synced 2024-12-12 11:15:00 +02:00
lazygit/pkg/gui/commit_message_panel.go

62 lines
1.8 KiB
Go
Raw Normal View History

2018-08-14 11:05:26 +02:00
package gui
import (
2018-09-05 12:42:11 +02:00
"strconv"
"strings"
"github.com/jesseduffield/gocui"
"github.com/jesseduffield/lazygit/pkg/commands/oscommands"
2020-10-04 02:00:48 +02:00
"github.com/jesseduffield/lazygit/pkg/utils"
)
2018-08-14 11:05:26 +02:00
func (gui *Gui) handleCommitConfirm() error {
2021-10-17 04:00:44 +02:00
message := strings.TrimSpace(gui.Views.CommitMessage.TextArea.GetContent())
if message == "" {
2020-10-04 02:00:48 +02:00
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
}
flags := ""
2020-10-03 06:54:55 +02:00
skipHookPrefix := gui.Config.GetUserConfig().Git.SkipHookPrefix
if skipHookPrefix != "" && strings.HasPrefix(message, skipHookPrefix) {
flags = "--no-verify"
}
cmdStr := gui.GitCommand.CommitCmdStr(message, flags)
2021-04-11 11:35:42 +02:00
gui.OnRunCommand(oscommands.NewCmdLogEntry(cmdStr, gui.Tr.Spans.Commit, true))
return gui.withGpgHandling(cmdStr, gui.Tr.CommittingStatus, func() error {
2021-10-17 08:38:59 +02:00
gui.Views.CommitMessage.ClearTextArea()
2021-04-10 03:40:42 +02:00
_ = gui.returnFromContext()
return nil
2021-04-10 03:40:42 +02:00
})
2018-08-14 11:05:26 +02:00
}
func (gui *Gui) handleCommitClose() error {
2020-08-16 05:58:29 +02:00
return gui.returnFromContext()
2018-08-14 11:05:26 +02:00
}
2020-08-16 05:58:29 +02:00
func (gui *Gui) handleCommitMessageFocused() error {
2020-10-04 02:00:48 +02:00
message := utils.ResolvePlaceholderString(
gui.Tr.CommitMessageConfirm,
map[string]string{
2021-04-12 15:05:57 +02:00
"keyBindClose": gui.getKeyDisplay(gui.Config.GetUserConfig().Keybinding.Universal.Return),
"keyBindConfirm": gui.getKeyDisplay(gui.Config.GetUserConfig().Keybinding.Universal.Confirm),
"keyBindNewLine": gui.getKeyDisplay(gui.Config.GetUserConfig().Keybinding.Universal.AppendNewline),
},
)
2020-10-04 02:00:48 +02:00
2021-04-04 16:31:52 +02:00
gui.renderString(gui.Views.Options, message)
2020-03-09 02:34:10 +02:00
return nil
2018-08-14 11:05:26 +02:00
}
2018-09-05 12:42:11 +02:00
func (gui *Gui) getBufferLength(view *gocui.View) string {
2021-10-17 04:00:44 +02:00
return " " + strconv.Itoa(strings.Count(view.TextArea.GetContent(), "")-1) + " "
2018-09-05 12:42:11 +02:00
}
2018-11-30 02:47:14 +02:00
// RenderCommitLength is a function.
func (gui *Gui) RenderCommitLength() {
2020-10-03 06:54:55 +02:00
if !gui.Config.GetUserConfig().Gui.CommitLength.Show {
return
}
2021-04-04 15:51:59 +02:00
gui.Views.CommitMessage.Subtitle = gui.getBufferLength(gui.Views.CommitMessage)
}