Improve table resizing, add terminal workaround, and expose last check.
This commit is contained in:
1 parent
a19e6fa711
commit
f2ea1297e8
6 files changed
+43
-5
No files matched your search
@@ -215,6 +215,14 @@ func (l *Limiter) URLReady(pageURL string) time.Time {
|
||||
return l.urlReady(pageURL)
|
||||
}
|
||||
|
||||
// LastCheck is when the URL was last checked by any dibs process, or zero.
|
||||
func (l *Limiter) LastCheck(pageURL string) time.Time {
|
||||
l.mu.Lock()
|
||||
defer l.mu.Unlock()
|
||||
|
||||
return l.lastCheck(pageURL)
|
||||
}
|
||||
|
||||
// Jittered stretches or shrinks d randomly by up to ±20%, but never below
|
||||
// floor.
|
||||
func (l *Limiter) Jittered(d, floor time.Duration) time.Duration {
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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 }
|
||||
|
||||
@@ -174,6 +174,7 @@ func (s *Scheduler) plan(ctx context.Context, cfg *config.Config, host *plugin.H
|
||||
fetchURL: fetchURL,
|
||||
host: strings.ToLower(u.Hostname()),
|
||||
plugin: p,
|
||||
last: s.limiter.LastCheck(fetchURL),
|
||||
next: s.limiter.NextCheck(fetchURL, item.Interval.Duration),
|
||||
})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user