Use pgup/pgdown as default paginator keystrokes

This commit is contained in:
Christian Rocha
2020-07-20 12:13:33 -04:00
parent 88469a499e
commit 5a26cb0d8e

View File

@@ -21,17 +21,18 @@ const (
// Model is the Tea model for this user interface. // Model is the Tea model for this user interface.
type Model struct { type Model struct {
Type Type Type Type
Page int Page int
PerPage int PerPage int
TotalPages int TotalPages int
ActiveDot string ActiveDot string
InactiveDot string InactiveDot string
ArabicFormat string ArabicFormat string
UseLeftRightKeys bool UsePgUpPgDownKeys bool
UseUpDownKeys bool UseLeftRightKeys bool
UseHLKeys bool UseUpDownKeys bool
UseJKKeys bool UseHLKeys bool
UseJKKeys bool
} }
// SetTotalPages is a helper function for calculatng the total number of pages // SetTotalPages is a helper function for calculatng the total number of pages
@@ -98,17 +99,18 @@ func (m Model) OnLastPage() bool {
// NewModel creates a new model with defaults. // NewModel creates a new model with defaults.
func NewModel() Model { func NewModel() Model {
return Model{ return Model{
Type: Arabic, Type: Arabic,
Page: 0, Page: 0,
PerPage: 1, PerPage: 1,
TotalPages: 1, TotalPages: 1,
ActiveDot: "•", ActiveDot: "•",
InactiveDot: "○", InactiveDot: "○",
ArabicFormat: "%d/%d", ArabicFormat: "%d/%d",
UseLeftRightKeys: true, UsePgUpPgDownKeys: true,
UseUpDownKeys: false, UseLeftRightKeys: true,
UseHLKeys: true, UseUpDownKeys: false,
UseJKKeys: false, UseHLKeys: true,
UseJKKeys: false,
} }
} }
@@ -116,6 +118,14 @@ func NewModel() Model {
func Update(msg tea.Msg, m Model) (Model, tea.Cmd) { func Update(msg tea.Msg, m Model) (Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.KeyMsg: case tea.KeyMsg:
if m.UsePgUpPgDownKeys {
switch msg.String() {
case "pgup":
m.PrevPage()
case "pgdown":
m.NextPage()
}
}
if m.UseLeftRightKeys { if m.UseLeftRightKeys {
switch msg.String() { switch msg.String() {
case "left": case "left":