Improve table resizing, add terminal workaround, and expose last check.

This commit is contained in:
Overlord committed 2026-10-14 12:37:27 +02:00
1 parent a19e6fa711
commit f2ea1297e8
6 files changed
+43 -5

No files matched your search

+4 -1
View File
@@ -87,7 +87,8 @@ type Model struct {
rows []watch.Status
results map[string]*result // by configured URL
cursor int
offset int // the first table row on screen
offset int // the first table row on screen
widths []int // the column widths, reset by resizes and reloads
logs []LogLine
log viewport.Model
@@ -138,6 +139,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) {
case tea.WindowSizeMsg:
m.width, m.height = msg.Width, msg.Height
m.widths = nil
m.layout()
case tickMsg:
m.now = time.Time(msg)
@@ -152,6 +154,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case reloadMsg:
m.reloading = false
m.rows = m.ctl.Statuses()
m.widths = nil
m.clampCursor()
if msg.err != nil { m.setNote(reloadError(msg.err), true) } else { m.setNote(reloadNote(msg.summary), false) }
case openMsg:
+9 -2
View File
@@ -40,8 +40,8 @@ var columns = []struct {
{"STATUS", 9, 9},
{"PRICE", 5, 16},
{"SELLER", 6, 11},
{"LAST", 4, 9},
{"NEXT", 4, 10},
{"LAST", 10, 10},
{"NEXT", 9, 9},
}
// layout sizes the table and the log pane to the window.
@@ -96,6 +96,13 @@ func (m *Model) table() string {
for j, c := range cells[i] { widths[j] = max(widths[j], min(ansi.StringWidth(c), columns[j].max)) }
}
// Columns only grow, so they do not shift every time a price or a time
// gets shorter.
if len(m.widths) == len(widths) {
for i := range widths { widths[i] = max(widths[i], m.widths[i]) }
}
m.widths = append(m.widths[:0], widths...)
// The ITEM column gives way first when the window is narrow.
total := 2
for _, w := range widths { total += w + 2 }