summaryrefslogtreecommitdiff
path: root/menu/git.go
blob: ff3c8e7a2a160184d08bbc694a19a9031ece7f28 (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
46
47
48
49
50
51
52
53
54
package menu

import (
	"github.com/charmbracelet/lipgloss"
	"github.com/ewy1/pik/menu/style"
	"github.com/ewy1/pik/model"
	"strconv"
)

var (
	GitColor     = lipgloss.Color("4")
	GitInfoStyle = style.New(func() lipgloss.Style {
		return lipgloss.NewStyle().Background(GitColor).Border(lipgloss.OuterHalfBlockBorder(), false, false, false, true).BorderBackground(GitColor).Padding(0, 1)
	})
	GitStatusStyle = style.New(func() lipgloss.Style {
		return lipgloss.NewStyle().Bold(true).Background(GitColor).PaddingLeft(1)
	})
	GitAddColor = lipgloss.Color("2")
	GitAddStyle = style.New(func() lipgloss.Style {
		return GitStatusStyle.Get().Foreground(GitAddColor)
	})
	GitRemoveColor = lipgloss.Color("1")
	GitRemoveStyle = style.New(func() lipgloss.Style {
		return GitStatusStyle.Get().Foreground(GitRemoveColor)
	})
	GitChangeColor = lipgloss.Color("5")
	GitChangeStyle = style.New(func() lipgloss.Style {
		return GitStatusStyle.Get().Foreground(GitChangeColor)
	})
)

func Git(info *model.GitInfo) string {
	var parts = []string{
		"  ",
		info.Branch,
	}

	if info.Insertions > 0 {
		parts = append(parts, GitAddStyle.Render("+"+strconv.Itoa(info.Insertions)))
	}
	if info.Deletions > 0 {
		parts = append(parts, GitRemoveStyle.Render("-"+strconv.Itoa(info.Deletions)))
	}
	if info.Changes > 0 {
		parts = append(parts, GitChangeStyle.Render("~"+strconv.Itoa(info.Changes)))
	}
	if info.Changes == 0 && info.Deletions == 0 && info.Insertions == 0 {
		parts = append(parts, GitAddStyle.Render("clean"))
	}

	return GitInfoStyle.Render(lipgloss.JoinHorizontal(lipgloss.Left,
		parts...,
	))
}