summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--internal/tui/entries.go10
-rw-r--r--internal/tui/entries_test.go12
-rw-r--r--internal/tui/report.go16
-rw-r--r--internal/tui/report_test.go42
-rw-r--r--internal/version.go2
5 files changed, 79 insertions, 3 deletions
diff --git a/internal/tui/entries.go b/internal/tui/entries.go
index 57255b1..46374ea 100644
--- a/internal/tui/entries.go
+++ b/internal/tui/entries.go
@@ -358,6 +358,14 @@ func (m *EntriesModel) updateNormalMode(keyMsg tea.KeyPressMsg) {
m.moveCursor(-m.halfPage())
m.pendingG = false
m.pendingD = false
+ case "pgdown":
+ m.moveCursor(m.pageSize())
+ m.pendingG = false
+ m.pendingD = false
+ case "pgup":
+ m.moveCursor(-m.pageSize())
+ m.pendingG = false
+ m.pendingD = false
case "ctrl+f":
m.moveCursor(m.pageSize())
m.pendingG = false
@@ -406,7 +414,7 @@ func (m *EntriesModel) View(styles Styles) string {
rows := m.renderTimelineTable(styles)
body := title + "\n\n" + rows
- body += "\n\n" + styles.Hint.Render("j/k rows, h/l columns, Enter edit cell, s save, / search, D day-off datepicker, dd delete")
+ body += "\n\n" + styles.Hint.Render("j/k rows, PgUp/PgDn page, h/l columns, Enter edit cell, s save, / search, D day-off datepicker, dd delete")
return styles.Body.Render(body + m.renderStatus(styles))
}
diff --git a/internal/tui/entries_test.go b/internal/tui/entries_test.go
index 8d6bf1f..baebf56 100644
--- a/internal/tui/entries_test.go
+++ b/internal/tui/entries_test.go
@@ -140,6 +140,18 @@ func TestEntriesNavigationKeys(t *testing.T) {
if model.cursor >= before {
t.Fatalf("cursor after ctrl+u = %d, want less than %d", model.cursor, before)
}
+
+ model.cursor = 0
+ model.offset = 0
+ model, _ = model.Update(keyCode(tea.KeyPgDown))
+ if got, want := model.cursor, model.pageSize(); got != want {
+ t.Fatalf("cursor after pgdown = %d, want %d", got, want)
+ }
+
+ model, _ = model.Update(keyCode(tea.KeyPgUp))
+ if model.cursor != 0 {
+ t.Fatalf("cursor after pgup = %d, want 0", model.cursor)
+ }
}
func TestEntriesSearchAndFilter(t *testing.T) {
diff --git a/internal/tui/report.go b/internal/tui/report.go
index 28b60f7..193b230 100644
--- a/internal/tui/report.go
+++ b/internal/tui/report.go
@@ -91,6 +91,12 @@ func (m *ReportModel) Update(msg tea.Msg) (ReportModel, tea.Cmd) {
case "k", "up":
m.moveCursor(-1)
m.pendingG = false
+ case "pgdown":
+ m.moveCursor(m.pageSize())
+ m.pendingG = false
+ case "pgup":
+ m.moveCursor(-m.pageSize())
+ m.pendingG = false
case "G":
m.cursor = m.rowCount() - 1
m.ensureCursorVisible()
@@ -153,7 +159,7 @@ func (m *ReportModel) View(styles Styles) string {
toHours(week.Values["work"]),
toHours(week.BufferSeconds),
)
- hint := "j/k scroll, gg/G top/bottom, ]w/[w week nav, v verbose"
+ hint := "j/k scroll, PgUp/PgDn page, gg/G top/bottom, ]w/[w week nav, v verbose"
body := header + "\n\n" + strings.Join(lines, "\n") + "\n\n" + summary + "\n" + hint
if m.warn != "" {
@@ -255,6 +261,14 @@ func (m *ReportModel) listRows() int {
return rows
}
+func (m *ReportModel) pageSize() int {
+ page := m.listRows()
+ if page < 1 {
+ return 1
+ }
+ return page
+}
+
func (m *ReportModel) rowCount() int {
if len(m.weeks) == 0 {
return 0
diff --git a/internal/tui/report_test.go b/internal/tui/report_test.go
index e37a209..63f78a4 100644
--- a/internal/tui/report_test.go
+++ b/internal/tui/report_test.go
@@ -4,6 +4,7 @@ import (
"strings"
"testing"
+ tea "charm.land/bubbletea/v2"
"codeberg.org/snonux/timesamurai/internal/worktime"
)
@@ -50,6 +51,21 @@ func TestReportScrollingAndTopBottom(t *testing.T) {
}
}
+func TestReportPageScrollingWithPgKeys(t *testing.T) {
+ model := NewReportModel(sampleWeeksWithDayCount(20))
+ model.SetSize(120, 11)
+
+ model, _ = model.Update(keyCode(tea.KeyPgDown))
+ if got, want := model.cursor, model.pageSize(); got != want {
+ t.Fatalf("cursor after pgdown = %d, want %d", got, want)
+ }
+
+ model, _ = model.Update(keyCode(tea.KeyPgUp))
+ if model.cursor != 0 {
+ t.Fatalf("cursor after pgup = %d, want 0", model.cursor)
+ }
+}
+
func TestReportVerboseToggle(t *testing.T) {
model := NewReportModel(sampleWeeks())
model.SetSize(120, 12)
@@ -121,3 +137,29 @@ func sampleWeeks() []worktime.WeekReport {
},
}
}
+
+func sampleWeeksWithDayCount(count int) []worktime.WeekReport {
+ days := make([]worktime.DayReport, 0, count)
+ for idx := 0; idx < count; idx++ {
+ days = append(days, worktime.DayReport{
+ DayLabel: "Day",
+ Marker: " ",
+ Epoch: int64(idx + 1),
+ Values: map[string]int64{
+ "work": 8 * 3600,
+ },
+ })
+ }
+
+ return []worktime.WeekReport{
+ {
+ WeekLabel: "10",
+ CumulativeBalanceSeconds: 2 * 3600,
+ BufferSeconds: 1 * 3600,
+ Values: map[string]int64{
+ "work": 20 * 3600,
+ },
+ Days: days,
+ },
+ }
+}
diff --git a/internal/version.go b/internal/version.go
index 18e6b9e..cb166dd 100644
--- a/internal/version.go
+++ b/internal/version.go
@@ -1,3 +1,3 @@
package internal
-const Version = "v0.6.0"
+const Version = "v0.7.0"