e5ac4a1fec
All panels wrapped in titled rounded borders (╭─ Title ──╮). Focused panel gets accent-colored border, unfocused panels get muted border. - Monitors panel: titled "Monitors", focused when detail is closed - Logs panel: titled "Logs", always unfocused (passive display) - Detail panel: titled with monitor name, focused when open Table's own RoundedBorder replaced with HiddenBorder — the titled panel border provides the visual frame, table uses space-separated columns internally. Consistent chrome across all panels.
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package tui
|
|
|
|
import (
|
|
"strings"
|
|
|
|
"github.com/charmbracelet/lipgloss"
|
|
)
|
|
|
|
func (m Model) titledPanel(title, content string, width int, focused bool) string {
|
|
borderColor := m.theme.Border
|
|
titleColor := m.theme.Muted
|
|
if focused {
|
|
borderColor = m.theme.Accent
|
|
titleColor = m.theme.Accent
|
|
}
|
|
|
|
bc := lipgloss.NewStyle().Foreground(borderColor)
|
|
tc := lipgloss.NewStyle().Foreground(titleColor).Bold(true)
|
|
|
|
innerW := width - 2
|
|
if innerW < 10 {
|
|
innerW = 10
|
|
}
|
|
|
|
titleRendered := tc.Render(" " + title + " ")
|
|
titleLen := len([]rune(title)) + 2
|
|
fillLen := innerW - titleLen - 1
|
|
if fillLen < 0 {
|
|
fillLen = 0
|
|
}
|
|
|
|
top := bc.Render("╭─") + titleRendered + bc.Render(strings.Repeat("─", fillLen)+"╮")
|
|
|
|
contentStyle := lipgloss.NewStyle().Width(innerW).MaxWidth(innerW)
|
|
inner := contentStyle.Render(content)
|
|
|
|
var lines []string
|
|
lines = append(lines, top)
|
|
for _, line := range strings.Split(inner, "\n") {
|
|
lines = append(lines, bc.Render("│")+line+strings.Repeat(" ", max(0, innerW-lipgloss.Width(line)))+bc.Render("│"))
|
|
}
|
|
lines = append(lines, bc.Render("╰"+strings.Repeat("─", innerW)+"╯"))
|
|
|
|
return strings.Join(lines, "\n")
|
|
}
|
|
|
|
func max(a, b int) int {
|
|
if a > b {
|
|
return a
|
|
}
|
|
return b
|
|
}
|