Skip to content

Commit

Permalink
refactor(tui): rename variables and fix ling warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Feb 17, 2022
1 parent 8fa4404 commit 6b86cf7
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 23 deletions.
4 changes: 2 additions & 2 deletions internal/tui/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (b Bubble) footerView() string {
var h []gittypes.HelpEntry
if b.state != errorState {
h = []gittypes.HelpEntry{
{"tab", "section"},
{Key: "tab", Value: "section"},
}
if box, ok := b.boxes[b.activeBox].(gittypes.BubbleHelper); ok {
help := box.Help()
Expand All @@ -169,7 +169,7 @@ func (b Bubble) footerView() string {
}
}
}
h = append(h, gittypes.HelpEntry{"q", "quit"})
h = append(h, gittypes.HelpEntry{Key: "q", Value: "quit"})
for i, v := range h {
fmt.Fprint(w, helpEntryRender(v, b.styles))
if i != len(h)-1 {
Expand Down
8 changes: 4 additions & 4 deletions internal/tui/bubbles/git/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,10 +110,10 @@ func (b *Bubble) Help() []types.HelpEntry {
h := []types.HelpEntry{}
h = append(h, b.boxes[b.state].(types.BubbleHelper).Help()...)
if b.repo.Name() != "config" {
h = append(h, types.HelpEntry{"R", "readme"})
h = append(h, types.HelpEntry{"F", "files"})
h = append(h, types.HelpEntry{"C", "commits"})
h = append(h, types.HelpEntry{"B", "branches"})
h = append(h, types.HelpEntry{Key: "R", Value: "readme"})
h = append(h, types.HelpEntry{Key: "F", Value: "files"})
h = append(h, types.HelpEntry{Key: "C", Value: "commits"})
h = append(h, types.HelpEntry{Key: "B", Value: "branches"})
}
return h
}
Expand Down
12 changes: 6 additions & 6 deletions internal/tui/bubbles/git/log/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const (
)

type item struct {
*types.Commit
*object.Commit
}

func (i item) Title() string {
Expand Down Expand Up @@ -229,28 +229,28 @@ func (b *Bubble) loadCommit() tea.Cmd {
// https://github.com/go-git/go-git/issues/281
tree, err := c.Tree()
if err != nil {
return types.ErrMsg{err}
return types.ErrMsg{Err: err}
}
var parent *object.Commit
parentTree := &object.Tree{}
if c.NumParents() > 0 {
parent, err = c.Parents().Next()
if err != nil {
return types.ErrMsg{err}
return types.ErrMsg{Err: err}
}
parentTree, err = parent.Tree()
if err != nil {
return types.ErrMsg{err}
return types.ErrMsg{Err: err}
}
}
ctx, cancel := context.WithTimeout(context.TODO(), types.MaxPatchWait)
defer cancel()
patch, err := parentTree.PatchContext(ctx, tree)
if err != nil {
return types.ErrMsg{err}
return types.ErrMsg{Err: err}
}
return commitMsg{
commit: c.Commit.Commit,
commit: c.Commit,
tree: tree,
parent: parent,
parentTree: parentTree,
Expand Down
10 changes: 5 additions & 5 deletions internal/tui/bubbles/git/tree/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (b *Bubble) updateItems() tea.Cmd {
its := make(items, 0)
t, err := b.repo.Tree(b.ref, b.path)
if err != nil {
return func() tea.Msg { return types.ErrMsg{err} }
return func() tea.Msg { return types.ErrMsg{Err: err} }
}
tw := object.NewTreeWalker(t, false, map[plumbing.Hash]bool{})
defer tw.Close()
Expand Down Expand Up @@ -307,18 +307,18 @@ func (b *Bubble) View() string {
func (b *Bubble) loadFile(i item) tea.Cmd {
return func() tea.Msg {
if !i.Mode().IsFile() || i.file == nil {
return types.ErrMsg{types.ErrInvalidFile}
return types.ErrMsg{Err: types.ErrInvalidFile}
}
bin, err := i.file.IsBinary()
if err != nil {
return types.ErrMsg{err}
return types.ErrMsg{Err: err}
}
if bin {
return types.ErrMsg{types.ErrBinaryFile}
return types.ErrMsg{Err: types.ErrBinaryFile}
}
c, err := i.file.Contents()
if err != nil {
return types.ErrMsg{err}
return types.ErrMsg{Err: err}
}
return fileMsg{
content: c,
Expand Down
6 changes: 1 addition & 5 deletions internal/tui/bubbles/git/types/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,7 @@ type Repo interface {
Tree(*plumbing.Reference, string) (*object.Tree, error)
}

type Commit struct {
*object.Commit
}

type Commits []*Commit
type Commits []*object.Commit

func (cl Commits) Len() int { return len(cl) }
func (cl Commits) Swap(i, j int) { cl[i], cl[j] = cl[j], cl[i] }
Expand Down
2 changes: 1 addition & 1 deletion internal/tui/bubbles/selection/bubble.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {

func (b *Bubble) Help() []gittypes.HelpEntry {
return []gittypes.HelpEntry{
{"↑/↓", "navigate"},
{Key: "↑/↓", Value: "navigate"},
}
}

Expand Down

0 comments on commit 6b86cf7

Please sign in to comment.