/
commit.go
60 lines (51 loc) · 969 Bytes
/
commit.go
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
55
56
57
58
59
60
package rebase
import (
"fmt"
"io"
table "github.com/calyptia/go-bubble-table"
)
type Commit struct {
command Cmd
title string
hash string
}
func (c *Commit) SetCommand(cmd Cmd) {
c.command = cmd
}
func (c Commit) Render(w io.Writer, model table.Model, index int) {
s := fmt.Sprintf("%s\t%s\t%s", c.command, c.hash, c.title)
if index == model.Cursor() {
s = model.Styles.SelectedRow.Render(s)
}
fmt.Fprintln(w, s)
}
func (c *Commit) String() string {
return fmt.Sprintf("%s %s %s", c.command, c.hash, c.title)
}
type Cmd rune
const (
CmdPick Cmd = 'p'
CmdReword = 'r'
CmdEdit = 'e'
CmdSquash = 's'
CmdFixup = 'f'
CmdDrop = 'd'
)
func (cmd Cmd) String() string {
switch cmd {
case CmdPick:
return "pick"
case CmdReword:
return "reword"
case CmdEdit:
return "edit"
case CmdSquash:
return "squash"
case CmdFixup:
return "fixup"
case CmdDrop:
return "drop"
default:
return string(cmd)
}
}