mirror of
https://github.com/taigrr/gico.git
synced 2026-04-01 18:58:59 -07:00
add keybinds and Update for paginator
This commit is contained in:
@@ -3,6 +3,7 @@ package main
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/charmbracelet/bubbles/help"
|
"github.com/charmbracelet/bubbles/help"
|
||||||
@@ -117,6 +118,7 @@ func (m CommitLog) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
|
m.Paginator.SetTotalPages(len(m.Commits[m.YearDay]))
|
||||||
m.Paginator, cmd = m.Paginator.Update(msg)
|
m.Paginator, cmd = m.Paginator.Update(msg)
|
||||||
return m, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
@@ -128,6 +130,8 @@ func newPaginator() paginator.Model {
|
|||||||
p.ActiveDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "235", Dark: "252"}).Render("•")
|
p.ActiveDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "235", Dark: "252"}).Render("•")
|
||||||
p.InactiveDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "250", Dark: "238"}).Render("•")
|
p.InactiveDot = lipgloss.NewStyle().Foreground(lipgloss.AdaptiveColor{Light: "250", Dark: "238"}).Render("•")
|
||||||
p.SetTotalPages(1)
|
p.SetTotalPages(1)
|
||||||
|
p.KeyMap.NextPage = key.NewBinding(key.WithKeys("h", "j"))
|
||||||
|
p.KeyMap.PrevPage = key.NewBinding(key.WithKeys("k", "l"))
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -143,8 +147,15 @@ func (m CommitLog) View() string {
|
|||||||
if len(m.Commits[m.YearDay]) == 0 {
|
if len(m.Commits[m.YearDay]) == 0 {
|
||||||
return "No commits to display"
|
return "No commits to display"
|
||||||
}
|
}
|
||||||
|
var b strings.Builder
|
||||||
return fmt.Sprintf("%v", m.Commits[m.YearDay])
|
b.WriteString("\nCommit Log\n\n")
|
||||||
|
m.Paginator.SetTotalPages(len(m.Commits[m.YearDay]))
|
||||||
|
start, end := m.Paginator.GetSliceBounds(len(m.Commits[m.YearDay]))
|
||||||
|
for _, item := range m.Commits[m.YearDay][start:end] {
|
||||||
|
b.WriteString(item.String() + "\n")
|
||||||
|
}
|
||||||
|
b.WriteString(m.Paginator.View())
|
||||||
|
return b.String()
|
||||||
// return fmt.Sprintf("This is the Commit Log, selected %v", "sd")
|
// return fmt.Sprintf("This is the Commit Log, selected %v", "sd")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ type (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (c Commit) String() string {
|
func (c Commit) String() string {
|
||||||
return fmt.Sprintf("%s\t%s\t%s\t%s\n",
|
return fmt.Sprintf("%s\t%s\t%s\t%s",
|
||||||
c.TimeStamp.Format("0"+time.Kitchen),
|
c.TimeStamp.Format("0"+time.Kitchen),
|
||||||
c.Author, c.Repo,
|
c.Author, c.Repo,
|
||||||
strings.TrimSpace(c.Message))
|
strings.TrimSpace(c.Message))
|
||||||
|
|||||||
Reference in New Issue
Block a user