mirror of
https://github.com/Maks1mS/bubbles.git
synced 2025-03-14 04:53:43 +03:00
Add more keybinding options to pager
This commit is contained in:
parent
b931aeaf0f
commit
821de006ee
@ -28,6 +28,10 @@ type Model struct {
|
|||||||
InactiveDot string
|
InactiveDot string
|
||||||
ArabicFormat string
|
ArabicFormat string
|
||||||
RTL bool
|
RTL bool
|
||||||
|
UseLeftRightKeys bool
|
||||||
|
UseUpDownKeys bool
|
||||||
|
UseHLKeys bool
|
||||||
|
UseJKKeys bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetTotalPages is a helper method for calculatng the total number of pages
|
// SetTotalPages is a helper method for calculatng the total number of pages
|
||||||
@ -45,6 +49,18 @@ func (m *Model) SetTotalPages(items int) int {
|
|||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m *Model) prevPage() {
|
||||||
|
if m.Page > 0 {
|
||||||
|
m.Page--
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (m *Model) nextPage() {
|
||||||
|
if m.Page < m.TotalPages-1 {
|
||||||
|
m.Page++
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// NewModel creates a new model with defaults
|
// NewModel creates a new model with defaults
|
||||||
func NewModel() Model {
|
func NewModel() Model {
|
||||||
return Model{
|
return Model{
|
||||||
@ -55,28 +71,51 @@ func NewModel() Model {
|
|||||||
InactiveDot: "○",
|
InactiveDot: "○",
|
||||||
ArabicFormat: "%d/%d",
|
ArabicFormat: "%d/%d",
|
||||||
RTL: false,
|
RTL: false,
|
||||||
|
UseLeftRightKeys: true,
|
||||||
|
UseUpDownKeys: false,
|
||||||
|
UseHLKeys: true,
|
||||||
|
UseJKKeys: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 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, model tea.Model) (tea.Model, tea.Cmd) {
|
func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
|
||||||
m, ok := model.(Model)
|
|
||||||
if !ok {
|
|
||||||
return tea.ModelAssertionErr, nil
|
|
||||||
}
|
|
||||||
switch msg := msg.(type) {
|
switch msg := msg.(type) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
|
if m.UseLeftRightKeys {
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "left":
|
case "left":
|
||||||
if m.Page > 0 {
|
m.prevPage()
|
||||||
m.Page--
|
|
||||||
}
|
|
||||||
case "right":
|
case "right":
|
||||||
if m.Page < m.TotalPages-1 {
|
m.nextPage()
|
||||||
m.Page++
|
}
|
||||||
|
}
|
||||||
|
if m.UseUpDownKeys {
|
||||||
|
switch msg.String() {
|
||||||
|
case "up":
|
||||||
|
m.prevPage()
|
||||||
|
case "down":
|
||||||
|
m.nextPage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.UseHLKeys {
|
||||||
|
switch msg.String() {
|
||||||
|
case "h":
|
||||||
|
m.prevPage()
|
||||||
|
case "l":
|
||||||
|
m.nextPage()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if m.UseJKKeys {
|
||||||
|
switch msg.String() {
|
||||||
|
case "j":
|
||||||
|
m.prevPage()
|
||||||
|
case "k":
|
||||||
|
m.nextPage()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return m, nil
|
return m, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user