2018-08-14 11:05:26 +02:00
|
|
|
package gui
|
|
|
|
|
2018-08-14 14:12:07 +02:00
|
|
|
import (
|
2018-09-05 12:42:11 +02:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
|
|
|
|
2018-08-14 14:12:07 +02:00
|
|
|
"github.com/jesseduffield/gocui"
|
2020-10-04 02:00:48 +02:00
|
|
|
"github.com/jesseduffield/lazygit/pkg/utils"
|
2018-08-14 14:12:07 +02:00
|
|
|
)
|
2018-08-14 11:05:26 +02:00
|
|
|
|
2021-04-02 10:20:40 +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
|
2019-02-24 00:42:24 +02:00
|
|
|
if message == "" {
|
2020-10-04 02:00:48 +02:00
|
|
|
return gui.createErrorPanel(gui.Tr.CommitWithoutMessageErr)
|
2019-02-24 00:42:24 +02:00
|
|
|
}
|
2021-11-14 15:31:35 +02:00
|
|
|
|
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
|
|
|
|
2021-10-24 01:43:48 +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 = ""
|
2019-03-23 03:16:55 +02:00
|
|
|
return nil
|
2021-04-10 03:40:42 +02:00
|
|
|
})
|
2018-08-14 11:05:26 +02:00
|
|
|
}
|
|
|
|
|
2021-04-02 10:20:40 +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),
|
2018-08-15 09:15:31 +02:00
|
|
|
},
|
|
|
|
)
|
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-09-05 15:02:13 +02:00
|
|
|
|
2018-11-30 02:47:14 +02:00
|
|
|
// RenderCommitLength is a function.
|
2018-09-05 15:02:13 +02:00
|
|
|
func (gui *Gui) RenderCommitLength() {
|
2021-12-29 02:50:20 +02:00
|
|
|
if !gui.UserConfig.Gui.CommitLength.Show {
|
2018-09-05 15:02:13 +02:00
|
|
|
return
|
|
|
|
}
|
2021-04-04 15:51:59 +02:00
|
|
|
|
|
|
|
gui.Views.CommitMessage.Subtitle = gui.getBufferLength(gui.Views.CommitMessage)
|
2018-09-05 15:02:13 +02:00
|
|
|
}
|