blob: 21231e1d786ff4908ea41ebf87ab21d79cccfd9a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
package viewport
import (
"git.ewy.one/pik.git/menu/style"
"github.com/charmbracelet/lipgloss"
"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")
}
|