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

58 lines
1.5 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"
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())
2021-12-25 14:54:46 +02:00
gui.State.failedCommitMessage = message
if message == "" {
2020-10-04 02:00:48 +02:00
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
}
2022-01-08 05:10:01 +02:00
cmdObj := gui.Git.Commit.CommitCmdObj(message)
2022-01-05 03:01:59 +02:00
gui.logAction(gui.Tr.Actions.Commit)
2021-12-07 12:59:36 +02:00
_ = gui.returnFromContext()
2021-12-07 12:59:36 +02:00
return gui.withGpgHandling(cmdObj, gui.Tr.CommittingStatus, func() error {
2021-10-17 08:38:59 +02:00
gui.Views.CommitMessage.ClearTextArea()
2021-12-25 14:54:46 +02:00
gui.State.failedCommitMessage = ""
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-12-29 02:50:20 +02:00
"keyBindClose": gui.getKeyDisplay(gui.UserConfig.Keybinding.Universal.Return),
"keyBindConfirm": gui.getKeyDisplay(gui.UserConfig.Keybinding.Universal.Confirm),
"keyBindNewLine": gui.getKeyDisplay(gui.UserConfig.Keybinding.Universal.AppendNewline),
},
)
2020-10-04 02:00:48 +02:00
2022-01-15 03:04:00 +02:00
return gui.renderString(gui.Views.Options, message)
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() {
2021-12-29 02:50:20 +02:00
if !gui.UserConfig.Gui.CommitLength.Show {
return
}
2021-04-04 15:51:59 +02:00
gui.Views.CommitMessage.Subtitle = gui.getBufferLength(gui.Views.CommitMessage)
}