mirror of
https://github.com/shokinn/hosts-go.git
synced 2025-08-23 16:43:02 +00:00
Implement TUI pane navigation
This commit is contained in:
parent
3561d15858
commit
a24041d664
6 changed files with 137 additions and 73 deletions
|
@ -2,41 +2,29 @@ package tui
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"strings"
|
||||
|
||||
"github.com/charmbracelet/lipgloss"
|
||||
)
|
||||
|
||||
var (
|
||||
listStyle = lipgloss.NewStyle().Padding(0, 1)
|
||||
detailStyle = lipgloss.NewStyle().Padding(0, 1)
|
||||
statusStyle = lipgloss.NewStyle().Padding(0, 1).Foreground(lipgloss.Color("240")).Background(lipgloss.Color("236"))
|
||||
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()
|
||||
|
||||
var detail strings.Builder
|
||||
if len(m.hosts.Entries) > 0 {
|
||||
entry := m.hosts.Entries[m.list.Index()]
|
||||
status := "active"
|
||||
if !entry.Active {
|
||||
status = "inactive"
|
||||
}
|
||||
fmt.Fprintf(&detail, "IP: %s\n", entry.IP)
|
||||
fmt.Fprintf(&detail, "Host: %s\n", entry.Hostname)
|
||||
if len(entry.Aliases) > 0 {
|
||||
fmt.Fprintf(&detail, "Aliases: %s\n", strings.Join(entry.Aliases, ", "))
|
||||
}
|
||||
if entry.Comment != "" {
|
||||
fmt.Fprintf(&detail, "Comment: %s\n", entry.Comment)
|
||||
}
|
||||
fmt.Fprintf(&detail, "Status: %s", status)
|
||||
}
|
||||
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(detail.String())
|
||||
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))
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue