summaryrefslogtreecommitdiff
path: root/viewport/scroll.go
diff options
context:
space:
mode:
authorewy <ewy0@protonmail.com>2026-04-29 00:47:34 +0200
committerewy <ewy0@protonmail.com>2026-04-29 00:47:34 +0200
commit630d77e1962b43ee95e88a664f5e8b8993213060 (patch)
tree8849c2a87443cd231786aed53b76dc7e4ea11aed /viewport/scroll.go
parent8efcf029576ad82908b4ae80b2c92022dfb857d2 (diff)
big stuff
* send empty screen after tui confirmation * add scroll view / viewport * auto enable scroll view on short terminals * add motd tips * add subdirs as categories * add inline toggle hotkey (i)
Diffstat (limited to 'viewport/scroll.go')
-rw-r--r--viewport/scroll.go46
1 files changed, 46 insertions, 0 deletions
diff --git a/viewport/scroll.go b/viewport/scroll.go
new file mode 100644
index 0000000..809fe17
--- /dev/null
+++ b/viewport/scroll.go
@@ -0,0 +1,46 @@
+package viewport
+
+import (
+ "github.com/charmbracelet/lipgloss"
+ "pik/menu/style"
+ "strings"
+)
+
+var (
+ ScrollTop = StyleBarBackground.Render("╷")
+ ScrollSpace = StyleBarBackground.Render("│")
+ ScrollBarTopEnd = StyleBar.Render("╓")
+ ScrollBar = StyleBar.Render("║")
+ ScrollBarBottomEnd = StyleBar.Render("╙")
+ ScrollBottom = StyleBarBackground.Render("╵")
+)
+
+var (
+ StyleBar = style.New(func() lipgloss.Style {
+ return lipgloss.NewStyle()
+ })
+ StyleBarBackground = style.New(func() lipgloss.Style {
+ return StyleBar.Get().Faint(true)
+ })
+)
+
+func WithScroll(input string, barBegin int, barEnd int) string {
+ lines := strings.Split(input, "\n")
+ for i, line := range lines {
+ selection := ScrollSpace
+ switch {
+ case i == barBegin:
+ selection = StyleBar.Render(ScrollBarTopEnd)
+ case i == 0:
+ selection = StyleBarBackground.Render(ScrollTop)
+ case i == barEnd:
+ selection = StyleBar.Render(ScrollBarBottomEnd)
+ case i > barBegin && i < barEnd:
+ selection = StyleBar.Render(ScrollBar)
+ case i == len(lines)-1:
+ selection = StyleBar.Render(ScrollBottom)
+ }
+ lines[i] = selection + " " + line
+ }
+ return strings.Join(lines, "\n")
+}