From b863e5179d66971e3d918a776ebbfaebb3ab51df Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 26 Apr 2022 17:12:59 -0400 Subject: [PATCH] godox --- ui/pages/repo/log.go | 12 ++++++++++++ ui/pages/repo/logitem.go | 17 +++++++++++++++-- ui/pages/selection/item.go | 1 + 3 files changed, 28 insertions(+), 2 deletions(-) diff --git a/ui/pages/repo/log.go b/ui/pages/repo/log.go index 869219f575444846fada527f48781e9096529bf3..0be7c436102fc07b3f5f11bc85b28232d7d2c39d 100644 --- a/ui/pages/repo/log.go +++ b/ui/pages/repo/log.go @@ -27,14 +27,19 @@ const ( commitView ) +// LogCountMsg is a message that contains the number of commits in a repo. type LogCountMsg int64 +// LogItemsMsg is a message that contains a slice of LogItem. type LogItemsMsg []list.Item +// LogCommitMsg is a message that contains a git commit. type LogCommitMsg *ggit.Commit +// LogDiffMsg is a message that contains a git diff. type LogDiffMsg *ggit.Diff +// Log is a model that displays a list of commits and their diffs. type Log struct { common common.Common selector *selector.Selector @@ -48,6 +53,7 @@ type Log struct { currentDiff *ggit.Diff } +// NewLog creates a new Log model. func NewLog(common common.Common) *Log { l := &Log{ common: common, @@ -68,12 +74,14 @@ func NewLog(common common.Common) *Log { return l } +// SetSize implements common.Component. func (l *Log) SetSize(width, height int) { l.common.SetSize(width, height) l.selector.SetSize(width, height) l.vp.SetSize(width, height) } +// ShortHelp implements key.KeyMap. func (l *Log) ShortHelp() []key.Binding { switch l.activeView { case logView: @@ -108,12 +116,14 @@ func (l *Log) ShortHelp() []key.Binding { } } +// Init implements tea.Model. func (l *Log) Init() tea.Cmd { cmds := make([]tea.Cmd, 0) cmds = append(cmds, l.updateCommitsCmd) return tea.Batch(cmds...) } +// Update implements tea.Model. func (l *Log) Update(msg tea.Msg) (tea.Model, tea.Cmd) { cmds := make([]tea.Cmd, 0) switch msg := msg.(type) { @@ -208,6 +218,7 @@ func (l *Log) Update(msg tea.Msg) (tea.Model, tea.Cmd) { return l, tea.Batch(cmds...) } +// View implements tea.Model. func (l *Log) View() string { switch l.activeView { case logView: @@ -219,6 +230,7 @@ func (l *Log) View() string { } } +// StatusBarInfo returns the status bar info. func (l *Log) StatusBarInfo() string { switch l.activeView { case logView: diff --git a/ui/pages/repo/logitem.go b/ui/pages/repo/logitem.go index b79cf572c137995c9568355f43d174862b002e1c..9464c608ecae601f64218014d50836ef95852a24 100644 --- a/ui/pages/repo/logitem.go +++ b/ui/pages/repo/logitem.go @@ -12,14 +12,17 @@ import ( "github.com/muesli/reflow/truncate" ) +// LogItem is a item in the log list that displays a git commit. type LogItem struct { *git.Commit } +// ID implements selector.IdentifiableItem. func (i LogItem) ID() string { return i.Commit.ID.String() } +// Title returns the item title. Implements list.DefaultItem. func (i LogItem) Title() string { if i.Commit != nil { return strings.Split(i.Commit.Message, "\n")[0] @@ -27,17 +30,27 @@ func (i LogItem) Title() string { return "" } +// Description returns the item description. Implements list.DefaultItem. func (i LogItem) Description() string { return "" } +// FilterValue implements list.Item. func (i LogItem) FilterValue() string { return i.Title() } +// LogItemDelegate is the delegate for LogItem. type LogItemDelegate struct { style *styles.Styles } -func (d LogItemDelegate) Height() int { return 1 } -func (d LogItemDelegate) Spacing() int { return 0 } +// Height returns the item height. Implements list.ItemDelegate. +func (d LogItemDelegate) Height() int { return 1 } + +// Spacing returns the item spacing. Implements list.ItemDelegate. +func (d LogItemDelegate) Spacing() int { return 0 } + +// Update updates the item. Implements list.ItemDelegate. func (d LogItemDelegate) Update(msg tea.Msg, m *list.Model) tea.Cmd { return nil } + +// Render renders the item. Implements list.ItemDelegate. func (d LogItemDelegate) Render(w io.Writer, m list.Model, index int, listItem list.Item) { i, ok := listItem.(LogItem) if !ok { diff --git a/ui/pages/selection/item.go b/ui/pages/selection/item.go index ee91e75229fbc35439412ba3074b6493f4323eae..1b9495c4aeeffe97ee03a41f850409c15afc7fa1 100644 --- a/ui/pages/selection/item.go +++ b/ui/pages/selection/item.go @@ -37,6 +37,7 @@ func (i Item) Description() string { return i.desc } // FilterValue implements list.Item. func (i Item) FilterValue() string { return i.name } +// URL returns the item URL view. func (i Item) URL() string { return i.url.View() }