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

83 lines
2.1 KiB
Go
Raw Normal View History

2018-08-14 11:05:26 +02:00
package gui
import (
"os/exec"
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
// runSyncOrAsyncCommand takes the output of a command that may have returned
// either no error, an error, or a subprocess to execute, and if a subprocess
// needs to be set on the gui object, it does so, and then returns the error
// the bool returned tells us whether the calling code should continue
func (gui *Gui) runSyncOrAsyncCommand(sub *exec.Cmd, err error) (bool, error) {
2018-08-14 11:05:26 +02:00
if err != nil {
if err != gui.Errors.ErrSubProcess {
2020-03-28 02:47:54 +02:00
return false, gui.surfaceError(err)
2018-08-14 11:05:26 +02:00
}
}
if sub != nil {
gui.SubProcess = sub
return false, gui.Errors.ErrSubProcess
2018-08-14 11:05:26 +02:00
}
return true, nil
}
func (gui *Gui) handleCommitConfirm() error {
commitMessageView := gui.getCommitMessageView()
message := gui.trimmedContent(commitMessageView)
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"
}
ok, err := gui.runSyncOrAsyncCommand(gui.GitCommand.Commit(message, flags))
if err != nil {
return err
}
if !ok {
return nil
}
gui.clearEditorView(commitMessageView)
2020-08-16 05:58:29 +02:00
_ = gui.returnFromContext()
return gui.refreshSidePanels(refreshOptions{mode: ASYNC})
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{
"keyBindClose": "esc",
"keyBindConfirm": "enter",
2020-07-21 23:15:33 +02:00
"keyBindNewLine": "tab",
},
)
2020-10-04 02:00:48 +02:00
2020-08-15 08:36:39 +02:00
gui.renderString("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 {
return " " + strconv.Itoa(strings.Count(view.Buffer(), "")-1) + " "
}
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
}
2018-12-08 07:54:54 +02:00
v := gui.getCommitMessageView()
v.Subtitle = gui.getBufferLength(v)
}