mirror of
https://github.com/Maks1mS/bubbles.git
synced 2024-12-24 14:44:38 +03:00
Make Paginator more idomatic Bubble Tea (per v0.12.x)
This commit is contained in:
parent
a07ab1d6af
commit
0fd072ddcc
@ -115,7 +115,7 @@ func NewModel() Model {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update is the Tea update function which binds keystrokes to pagination.
|
// Update is the Tea update function which binds keystrokes to pagination.
|
||||||
func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
|
func (m Model) Update(msg tea.Msg) (Model, tea.Cmd) {
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
if m.UsePgUpPgDownKeys {
|
if m.UsePgUpPgDownKeys {
|
||||||
@ -164,16 +164,16 @@ func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// View renders the pagination to a string.
|
// View renders the pagination to a string.
|
||||||
func View(m Model) string {
|
func (m Model) View() string {
|
||||||
switch m.Type {
|
switch m.Type {
|
||||||
case Dots:
|
case Dots:
|
||||||
return dotsView(m)
|
return m.dotsView()
|
||||||
default:
|
default:
|
||||||
return arabicView(m)
|
return m.arabicView()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func dotsView(m Model) string {
|
func (m Model) dotsView() string {
|
||||||
var s string
|
var s string
|
||||||
for i := 0; i < m.TotalPages; i++ {
|
for i := 0; i < m.TotalPages; i++ {
|
||||||
if i == m.Page {
|
if i == m.Page {
|
||||||
@ -185,7 +185,7 @@ func dotsView(m Model) string {
|
|||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
func arabicView(m Model) string {
|
func (m Model) arabicView() string {
|
||||||
return fmt.Sprintf(m.ArabicFormat, m.Page+1, m.TotalPages)
|
return fmt.Sprintf(m.ArabicFormat, m.Page+1, m.TotalPages)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user