summaryrefslogtreecommitdiffstats
path: root/pkg/gui/panels/commit_message_panel.go
blob: baef870cfbe2b0c45b0c335483d3313bf9fa8602 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package main

import "github.com/jesseduffield/gocui"

func handleCommitConfirm(g *gocui.Gui, v *gocui.View) error {
	message := trimmedContent(v)
	if message == "" {
		return createErrorPanel(g, "You cannot commit without a commit message")
	}
	if output, err := gitCommit(g, message); err != nil {
		if err == errNoUsername {
			return createErrorPanel(g, err.Error())
		}
		return createErrorPanel(g, output)
	}
	refreshFiles(g)
	v.Clear()
	v.SetCursor(0, 0)
	g.SetViewOnBottom("commitMessage")
	switchFocus(g, v, getFilesView(g))
	return refreshCommits(g)
}

func handleCommitClose(g *gocui.Gui, v *gocui.View) error {
	g.SetViewOnBottom("commitMessage")
	return switchFocus(g, v, getFilesView(g))
}

func handleNewlineCommitMessage(g *gocui.Gui, v *gocui.View) error {
	// resising ahead of time so that the top line doesn't get hidden to make
	// room for the cursor on the second line
	x0, y0, x1, y1 := getConfirmationPanelDimensions(g, v.Buffer())
	if _, err := g.SetView("commitMessage", x0, y0, x1, y1+1, 0); err != nil {
		if err != gocui.ErrUnknownView {
			return err
		}
	}

	v.EditNewLine()
	return nil
}

func handleCommitFocused(g *gocui.Gui, v *gocui.View) error {
	return renderString(g, "options", "esc: close, enter: confirm")
}