From 499d61bddfd2498a21023cdb0231d1a403271b3b Mon Sep 17 00:00:00 2001 From: Hadi <112569860+anotherhadi@users.noreply.github.com> Date: Tue, 26 May 2026 16:35:09 +0200 Subject: [PATCH] add paginator & spilth Signed-off-by: Hadi <112569860+anotherhadi@users.noreply.github.com> --- components.go | 20 ++++++++++++++++++++ style.go | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/components.go b/components.go index 30cb022..8c9e179 100644 --- a/components.go +++ b/components.go @@ -4,6 +4,7 @@ import ( "strings" "charm.land/bubbles/v2/help" + "charm.land/bubbles/v2/paginator" "charm.land/bubbles/v2/textarea" "charm.land/bubbles/v2/viewport" "charm.land/lipgloss/v2" @@ -47,6 +48,25 @@ func NewTextarea(showLineNumbers bool) textarea.Model { return ta } +// NewPaginator returns a dot-style paginator.Model styled with the active theme. +func NewPaginator() paginator.Model { + p := paginator.New() + p.Type = paginator.Dots + p.ActiveDot = S.PagerDotActive + p.InactiveDot = S.PagerDotInactive + return p +} + +// SplitH splits totalHeight into top and bottom sections, accounting for the +// height of statusBar (measured by newline count). +func SplitH(totalHeight int, statusBar string, ratio float64) (top, bottom int) { + statusH := strings.Count(statusBar, "\n") + 1 + available := totalHeight - statusH + top = int(float64(available) * ratio) + bottom = available - top + return +} + // NewViewport returns a viewport.Model with mouse wheel disabled. func NewViewport() viewport.Model { vp := viewport.New() diff --git a/style.go b/style.go index 967b33b..8fe5461 100644 --- a/style.go +++ b/style.go @@ -47,6 +47,10 @@ type Styles struct { // Pre-built panel styles (rounded border) Panel lipgloss.Style PanelFocused lipgloss.Style + + // Pre-rendered pager dot strings + PagerDotActive string + PagerDotInactive string } func newStyles(c colorsYAML) Styles { @@ -102,5 +106,8 @@ func newStyles(c colorsYAML) Styles { PanelFocused: lipgloss.NewStyle(). Border(lipgloss.RoundedBorder()). BorderForeground(b0D), + + PagerDotActive: lipgloss.NewStyle().Foreground(b0D).SetString("•").String(), + PagerDotInactive: lipgloss.NewStyle().Foreground(b03).SetString("•").String(), } }