summaryrefslogtreecommitdiff
path: root/internal/client/ui/ui.go
blob: b03df5923f0b779ea10542337f773792586dcfb5 (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
package ui

import (
	"fmt"
	"strings"

	tea "github.com/charmbracelet/bubbletea"
	"github.com/charmbracelet/lipgloss"
)

type ModelTransition struct {
	Model tea.Model
}

func AddBorderHeader(header string, headerOffset int, style lipgloss.Style, render string) string {
	b := style.GetBorderStyle()
	body := style.UnsetBorderTop().Render(render)

	bodyWidth, headerWidth := lipgloss.Width(body), lipgloss.Width(header)
	leftCornerWidth, rightCornerWidth := lipgloss.Width(b.TopLeft), lipgloss.Width(b.TopRight)
	topWidth := bodyWidth - leftCornerWidth - rightCornerWidth

	leftWidth := headerOffset
	rightWidth := topWidth - leftWidth - headerWidth

	topStyle := lipgloss.NewStyle().
		Background(style.GetBorderTopBackground()).
		Foreground(style.GetBorderTopForeground())

	left := b.TopLeft + strings.Repeat(b.Top, leftWidth)
	right := topStyle.Render(strings.Repeat(b.Top, rightWidth) + b.TopRight)

	borderTop := lipgloss.NewStyle().
		Inline(true).
		MaxWidth(bodyWidth).
		Background(style.GetBorderTopBackground()).
		Foreground(style.GetBorderTopForeground()).
		Render(fmt.Sprintf("%s%s%s", left, header, right))

	return lipgloss.JoinVertical(lipgloss.Left, borderTop, body)
}