hosts-go/internal/tui/view.go

33 lines
1 KiB
Go

package tui
import (
"fmt"
"github.com/charmbracelet/lipgloss"
)
var (
listStyle = lipgloss.NewStyle().Padding(0, 1)
detailStyle = lipgloss.NewStyle().Padding(0, 1)
focusedStyle = lipgloss.NewStyle().BorderStyle(lipgloss.RoundedBorder()).BorderForeground(lipgloss.Color("62"))
statusStyle = lipgloss.NewStyle().Padding(0, 1).Foreground(lipgloss.Color("240")).Background(lipgloss.Color("236"))
)
// View renders the two-pane layout.
func (m Model) View() string {
listView := m.list.View()
detailView := m.detail.View()
left := listStyle.Width(m.width / 2).Height(m.height).Render(listView)
right := detailStyle.Width(m.width - m.width/2).Height(m.height).Render(detailView)
if m.focus == listPane {
left = focusedStyle.Render(left)
} else {
right = focusedStyle.Render(right)
}
panes := lipgloss.JoinHorizontal(lipgloss.Top, left, right)
status := fmt.Sprintf("VIEW MODE • %d entries", len(m.hosts.Entries))
bar := statusStyle.Width(m.width).Render(status)
return lipgloss.JoinVertical(lipgloss.Left, panes, bar)
}