feat(tui): split available width evenly between NAME and HISTORY columns
This commit is contained in:
+24
-11
@@ -195,19 +195,31 @@ func fmtStatus(status string, paused bool) string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) nameWidth() int {
|
func (m Model) dynamicWidths() (nameW, sparkW int) {
|
||||||
w := m.termWidth - 105
|
fixed := 6 + 10 + 10 + 8 + 8 + 7 + 9 // #, TYPE, STATUS, LATENCY, UPTIME, SSL, RETRY
|
||||||
if w < 13 {
|
overhead := 30 // cell padding + borders
|
||||||
w = 13
|
avail := m.termWidth - 6 - fixed - overhead
|
||||||
|
if avail < 30 {
|
||||||
|
avail = 30
|
||||||
}
|
}
|
||||||
if w > 40 {
|
nameW = avail / 2
|
||||||
w = 40
|
sparkW = avail - nameW - 4 // -4 for spark column padding
|
||||||
|
if nameW < 13 {
|
||||||
|
nameW = 13
|
||||||
}
|
}
|
||||||
return w
|
if nameW > 40 {
|
||||||
|
nameW = 40
|
||||||
|
}
|
||||||
|
if sparkW < 10 {
|
||||||
|
sparkW = 10
|
||||||
|
}
|
||||||
|
if sparkW > 40 {
|
||||||
|
sparkW = 40
|
||||||
|
}
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
func (m Model) viewSitesTab() string {
|
func (m Model) viewSitesTab() string {
|
||||||
const sparkWidth = 20
|
|
||||||
|
|
||||||
if len(m.sites) == 0 {
|
if len(m.sites) == 0 {
|
||||||
welcome := lipgloss.NewStyle().
|
welcome := lipgloss.NewStyle().
|
||||||
@@ -222,6 +234,7 @@ func (m Model) viewSitesTab() string {
|
|||||||
return "\n" + welcome
|
return "\n" + welcome
|
||||||
}
|
}
|
||||||
|
|
||||||
|
nameW, sparkWidth := m.dynamicWidths()
|
||||||
colWidths := []int{6, 0, 10, 10, 8, 8, sparkWidth + 4, 7, 9}
|
colWidths := []int{6, 0, 10, 10, 8, 8, sparkWidth + 4, 7, 9}
|
||||||
|
|
||||||
var groupRows map[int]bool
|
var groupRows map[int]bool
|
||||||
@@ -242,7 +255,7 @@ func (m Model) viewSitesTab() string {
|
|||||||
}
|
}
|
||||||
rows = append(rows, []string{
|
rows = append(rows, []string{
|
||||||
strconv.Itoa(i + 1),
|
strconv.Itoa(i + 1),
|
||||||
m.zones.Mark(fmt.Sprintf("site-%d", i), arrow+" "+limitStr(site.Name, m.nameWidth()-2)),
|
m.zones.Mark(fmt.Sprintf("site-%d", i), arrow+" "+limitStr(site.Name, nameW-2)),
|
||||||
"group",
|
"group",
|
||||||
fmtStatus(site.Status, site.Paused),
|
fmtStatus(site.Status, site.Paused),
|
||||||
subtleStyle.Render("—"),
|
subtleStyle.Render("—"),
|
||||||
@@ -260,9 +273,9 @@ func (m Model) viewSitesTab() string {
|
|||||||
if i+1 >= len(m.sites) || m.sites[i+1].ParentID != site.ParentID {
|
if i+1 >= len(m.sites) || m.sites[i+1].ParentID != site.ParentID {
|
||||||
prefix = "└"
|
prefix = "└"
|
||||||
}
|
}
|
||||||
name = prefix + " " + limitStr(name, m.nameWidth()-2)
|
name = prefix + " " + limitStr(name, nameW-2)
|
||||||
} else {
|
} else {
|
||||||
name = limitStr(name, m.nameWidth())
|
name = limitStr(name, nameW)
|
||||||
}
|
}
|
||||||
|
|
||||||
hist, _ := m.engine.GetHistory(site.ID)
|
hist, _ := m.engine.GetHistory(site.ID)
|
||||||
|
|||||||
Reference in New Issue
Block a user