602b14c086e9bd35179d87325b4f14c2153bf394

Author
Ayman Bagabas <ayman.bagabas@gmail.com>
Committer
Ayman Bagabas <ayman.bagabas@gmail.com>
Date

Message

feat: add tui pagination

Diff

  1diff --git a/go.mod b/go.mod
  2index ba47ca75d6ee3e7709cf16f79e033d0906abc76d..d5f7682a9923cb74f8bca15d843e3081c3d6d8f1 100644
  3--- a/go.mod
  4+++ b/go.mod
  5@@ -5,7 +5,7 @@ go 1.17
  6 require (
  7 	github.com/alecthomas/chroma v0.10.0
  8 	github.com/caarlos0/env/v6 v6.9.1
  9-	github.com/charmbracelet/bubbles v0.10.3-0.20220208194203-1d489252fe50
 10+	github.com/charmbracelet/bubbles v0.10.4-0.20220302223835-88562515cf7b
 11 	github.com/charmbracelet/bubbletea v0.19.4-0.20220208181305-42cd4c31919c
 12 	github.com/charmbracelet/glamour v0.4.0
 13 	github.com/charmbracelet/lipgloss v0.4.0
 14diff --git a/go.sum b/go.sum
 15index 207c617905fa6f899b6a1286b71e63744c42a92d..cee667d313c1218357ce9eccd76647357f1d76e0 100644
 16--- a/go.sum
 17+++ b/go.sum
 18@@ -21,8 +21,8 @@ github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuP
 19 github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
 20 github.com/caarlos0/env/v6 v6.9.1 h1:zOkkjM0F6ltnQ5eBX6IPI41UP/KDGEK7rRPwGCNos8k=
 21 github.com/caarlos0/env/v6 v6.9.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc=
 22-github.com/charmbracelet/bubbles v0.10.3-0.20220208194203-1d489252fe50 h1:hAsXGdqKHVoEbBlvReSfz8X605xddHMBFSxSrCaSSO4=
 23-github.com/charmbracelet/bubbles v0.10.3-0.20220208194203-1d489252fe50/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
 24+github.com/charmbracelet/bubbles v0.10.4-0.20220302223835-88562515cf7b h1:o+LFpRn1fXtu1hDJLtBFjp7tMZ8AqwSpl84w1TnUj0Y=
 25+github.com/charmbracelet/bubbles v0.10.4-0.20220302223835-88562515cf7b/go.mod h1:jOA+DUF1rjZm7gZHcNyIVW+YrBPALKfpGVdJu8UiJsA=
 26 github.com/charmbracelet/bubbletea v0.19.3/go.mod h1:VuXF2pToRxDUHcBUcPmCRUHRvFATM4Ckb/ql1rBl3KA=
 27 github.com/charmbracelet/bubbletea v0.19.4-0.20220208181305-42cd4c31919c h1:hcS4xdVQwblKo8xuA5gRO/jql+yCVfnBlOwWcZrxOmA=
 28 github.com/charmbracelet/bubbletea v0.19.4-0.20220208181305-42cd4c31919c/go.mod h1:5nPeULOIxbAMykb3ggwhw1kruS7nP+Y4Za9yEH4J27U=
 29diff --git a/internal/tui/bubbles/git/log/bubble.go b/internal/tui/bubbles/git/log/bubble.go
 30index 95e6b7b5598a937b3a7c1b762be43f0b8150d1fa..787eff599c1d4f149140e817664c6049964254a5 100644
 31--- a/internal/tui/bubbles/git/log/bubble.go
 32+++ b/internal/tui/bubbles/git/log/bubble.go
 33@@ -104,7 +104,7 @@ func NewBubble(repo types.Repo, styles *style.Styles, width, widthMargin, height
 34 	l := list.New([]list.Item{}, itemDelegate{styles}, width-widthMargin, height-heightMargin)
 35 	l.SetShowFilter(false)
 36 	l.SetShowHelp(false)
 37-	l.SetShowPagination(false)
 38+	l.SetShowPagination(true)
 39 	l.SetShowStatusBar(false)
 40 	l.SetShowTitle(false)
 41 	l.SetFilteringEnabled(false)
 42@@ -136,7 +136,9 @@ func NewBubble(repo types.Repo, styles *style.Styles, width, widthMargin, height
 43 func (b *Bubble) reset() tea.Cmd {
 44 	b.state = logState
 45 	b.list.Select(0)
 46-	return b.updateItems()
 47+	cmd := b.updateItems()
 48+	b.SetSize(b.width, b.height)
 49+	return cmd
 50 }
 51 
 52 func (b *Bubble) updateItems() tea.Cmd {
 53@@ -169,6 +171,7 @@ func (b *Bubble) SetSize(width, height int) {
 54 	b.commitViewport.Viewport.Width = width - b.widthMargin
 55 	b.commitViewport.Viewport.Height = height - b.heightMargin
 56 	b.list.SetSize(width-b.widthMargin, height-b.heightMargin)
 57+	b.list.Styles.PaginationStyle = b.style.LogPaginator.Copy().Width(width - b.widthMargin)
 58 }
 59 
 60 func (b *Bubble) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
 61diff --git a/internal/tui/bubbles/git/refs/bubble.go b/internal/tui/bubbles/git/refs/bubble.go
 62index 6796f0914019a59e7c76ec01e71619a3e2505e82..0c99b4cbb7bd26a5d8f381de779285955c60f7e3 100644
 63--- a/internal/tui/bubbles/git/refs/bubble.go
 64+++ b/internal/tui/bubbles/git/refs/bubble.go
 65@@ -80,7 +80,7 @@ func NewBubble(repo types.Repo, styles *style.Styles, width, widthMargin, height
 66 	l := list.NewModel([]list.Item{}, itemDelegate{styles}, width-widthMargin, height-heightMargin)
 67 	l.SetShowFilter(false)
 68 	l.SetShowHelp(false)
 69-	l.SetShowPagination(false)
 70+	l.SetShowPagination(true)
 71 	l.SetShowStatusBar(false)
 72 	l.SetShowTitle(false)
 73 	l.SetFilteringEnabled(false)
 74@@ -107,7 +107,9 @@ func (b *Bubble) SetBranch(ref *plumbing.Reference) (tea.Model, tea.Cmd) {
 75 }
 76 
 77 func (b *Bubble) reset() tea.Cmd {
 78-	return b.updateItems()
 79+	cmd := b.updateItems()
 80+	b.SetSize(b.width, b.height)
 81+	return cmd
 82 }
 83 
 84 func (b *Bubble) Init() tea.Cmd {
 85@@ -118,6 +120,7 @@ func (b *Bubble) SetSize(width, height int) {
 86 	b.width = width
 87 	b.height = height
 88 	b.list.SetSize(width-b.widthMargin, height-b.heightMargin)
 89+	b.list.Styles.PaginationStyle = b.style.RefPaginator.Copy().Width(width - b.widthMargin)
 90 }
 91 
 92 func (b *Bubble) Help() []types.HelpEntry {
 93diff --git a/internal/tui/bubbles/git/tree/bubble.go b/internal/tui/bubbles/git/tree/bubble.go
 94index 805aa5865088bc0ddfd734dd241312f67db9ac6f..1a7be03f101ad990185f6f4d4c8a069613e40a22 100644
 95--- a/internal/tui/bubbles/git/tree/bubble.go
 96+++ b/internal/tui/bubbles/git/tree/bubble.go
 97@@ -135,7 +135,7 @@ func NewBubble(repo types.Repo, styles *style.Styles, width, widthMargin, height
 98 	l := list.New([]list.Item{}, itemDelegate{styles}, width-widthMargin, height-heightMargin)
 99 	l.SetShowFilter(false)
100 	l.SetShowHelp(false)
101-	l.SetShowPagination(false)
102+	l.SetShowPagination(true)
103 	l.SetShowStatusBar(false)
104 	l.SetShowTitle(false)
105 	l.SetFilteringEnabled(false)
106@@ -164,7 +164,9 @@ func (b *Bubble) reset() tea.Cmd {
107 	b.path = ""
108 	b.state = treeState
109 	b.lastSelected = make([]int, 0)
110-	return b.updateItems()
111+	cmd := b.updateItems()
112+	b.SetSize(b.width, b.height)
113+	return cmd
114 }
115 
116 func (b *Bubble) Init() tea.Cmd {
117@@ -177,6 +179,7 @@ func (b *Bubble) SetSize(width, height int) {
118 	b.fileViewport.Viewport.Width = width - b.widthMargin
119 	b.fileViewport.Viewport.Height = height - b.heightMargin
120 	b.list.SetSize(width-b.widthMargin, height-b.heightMargin)
121+	b.list.Styles.PaginationStyle = b.style.LogPaginator.Copy().Width(width - b.widthMargin)
122 }
123 
124 func (b *Bubble) Help() []types.HelpEntry {
125diff --git a/internal/tui/style/style.go b/internal/tui/style/style.go
126index bc997ed31d03c6d46ad65931995f307bdca62393..e7c386fc4fa2cc00b05a3ca735dfc81d3afefb73 100644
127--- a/internal/tui/style/style.go
128+++ b/internal/tui/style/style.go
129@@ -51,12 +51,14 @@ type Styles struct {
130 	LogCommitBody     lipgloss.Style
131 	LogCommitStatsAdd lipgloss.Style
132 	LogCommitStatsDel lipgloss.Style
133+	LogPaginator      lipgloss.Style
134 
135 	RefItemSelector lipgloss.Style
136 	RefItemActive   lipgloss.Style
137 	RefItemInactive lipgloss.Style
138 	RefItemBranch   lipgloss.Style
139 	RefItemTag      lipgloss.Style
140+	RefPaginator    lipgloss.Style
141 
142 	TreeItemSelector lipgloss.Style
143 	TreeItemActive   lipgloss.Style
144@@ -225,6 +227,10 @@ func DefaultStyles() *Styles {
145 		Foreground(lipgloss.Color("#FD5B5B")).
146 		Bold(true)
147 
148+	s.LogPaginator = lipgloss.NewStyle().
149+		Margin(0).
150+		Align(lipgloss.Center)
151+
152 	s.RefItemSelector = s.LogItemSelector.Copy()
153 
154 	s.RefItemActive = s.LogItemActive.Copy()
155@@ -236,6 +242,8 @@ func DefaultStyles() *Styles {
156 	s.RefItemTag = lipgloss.NewStyle().
157 		Foreground(lipgloss.Color("#A3A322"))
158 
159+	s.RefPaginator = s.LogPaginator.Copy()
160+
161 	s.TreeItemSelector = s.LogItemSelector.Copy()
162 
163 	s.TreeItemActive = s.LogItemActive.Copy()