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
+42 -4

No files matched your search

+20 -1
View File
@@ -5,10 +5,13 @@ import (
"errors" "errors"
"io" "io"
"log/slog" "log/slog"
"os"
"os/signal" "os/signal"
"strings"
"syscall" "syscall"
tea "charm.land/bubbletea/v2" tea "charm.land/bubbletea/v2"
"github.com/charmbracelet/colorprofile"
"git.security-command.org/Overlord/dibs/internal/config" "git.security-command.org/Overlord/dibs/internal/config"
"git.security-command.org/Overlord/dibs/internal/tui" "git.security-command.org/Overlord/dibs/internal/tui"
@@ -26,7 +29,7 @@ func runTUI(cfg *config.Config, stderr io.Writer) int {
w, err := newWatcher(ctx, cfg, logger, slog.LevelDebug) w, err := newWatcher(ctx, cfg, logger, slog.LevelDebug)
if err != nil { return fail(stderr, "watch", err) } if err != nil { return fail(stderr, "watch", err) }
p := tea.NewProgram(tui.New(w, cfg.Path, logs), tea.WithContext(ctx)) p := tea.NewProgram(tui.New(w, cfg.Path, logs), append(terminalOptions(), tea.WithContext(ctx))...)
done := make(chan struct{}) done := make(chan struct{})
go func() { go func() {
@@ -46,3 +49,19 @@ func runTUI(cfg *config.Config, stderr io.Writer) int {
return 0 return 0
} }
// terminalOptions works around terminals that claim to be xterm but are not.
// Under a TERM the renderer does not know, it redraws with plain writes only.
// The color profile is detected from the real environment first, so colors stay.
func terminalOptions() []tea.ProgramOption {
if os.Getenv("TERMINAL_EMULATOR") != "JetBrains-JediTerm" { return nil }
profile := colorprofile.Detect(os.Stdout, os.Environ())
env := []string{"TERM=jediterm"}
for _, kv := range os.Environ() {
if !strings.HasPrefix(kv, "TERM=") { env = append(env, kv) }
}
return []tea.ProgramOption{tea.WithEnvironment(env), tea.WithColorProfile(profile)}
}
+1 -1
View File
@@ -10,6 +10,7 @@ require (
github.com/andybalholm/cascadia v1.3.4 github.com/andybalholm/cascadia v1.3.4
github.com/bogdanfinn/fhttp v0.6.9 github.com/bogdanfinn/fhttp v0.6.9
github.com/bogdanfinn/tls-client v1.16.0 github.com/bogdanfinn/tls-client v1.16.0
github.com/charmbracelet/colorprofile v0.4.3
github.com/charmbracelet/x/ansi v0.11.9 github.com/charmbracelet/x/ansi v0.11.9
github.com/gen2brain/beeep v0.11.2 github.com/gen2brain/beeep v0.11.2
github.com/pelletier/go-toml/v2 v2.4.3 github.com/pelletier/go-toml/v2 v2.4.3
@@ -27,7 +28,6 @@ require (
github.com/bogdanfinn/quic-go-utls v1.0.10-utls // indirect github.com/bogdanfinn/quic-go-utls v1.0.10-utls // indirect
github.com/bogdanfinn/utls v1.7.8-barnius // indirect github.com/bogdanfinn/utls v1.7.8-barnius // indirect
github.com/bogdanfinn/websocket v1.5.6-barnius // indirect github.com/bogdanfinn/websocket v1.5.6-barnius // indirect
github.com/charmbracelet/colorprofile v0.4.3 // indirect
github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4 // indirect github.com/charmbracelet/ultraviolet v0.0.0-20261008173134-6b8d4baf91b4 // indirect
github.com/charmbracelet/x/term v0.2.2 // indirect github.com/charmbracelet/x/term v0.2.2 // indirect
github.com/charmbracelet/x/termios v0.1.1 // indirect github.com/charmbracelet/x/termios v0.1.1 // indirect
+8
View File
@@ -215,6 +215,14 @@ func (l *Limiter) URLReady(pageURL string) time.Time {
return l.urlReady(pageURL) 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 // Jittered stretches or shrinks d randomly by up to ±20%, but never below
// floor. // floor.
func (l *Limiter) Jittered(d, floor time.Duration) time.Duration { func (l *Limiter) Jittered(d, floor time.Duration) time.Duration {
+3
View File
@@ -88,6 +88,7 @@ type Model struct {
results map[string]*result // by configured URL results map[string]*result // by configured URL
cursor int 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 logs []LogLine
log viewport.Model log viewport.Model
@@ -138,6 +139,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
switch msg := msg.(type) { switch msg := msg.(type) {
case tea.WindowSizeMsg: case tea.WindowSizeMsg:
m.width, m.height = msg.Width, msg.Height m.width, m.height = msg.Width, msg.Height
m.widths = nil
m.layout() m.layout()
case tickMsg: case tickMsg:
m.now = time.Time(msg) m.now = time.Time(msg)
@@ -152,6 +154,7 @@ func (m *Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
case reloadMsg: case reloadMsg:
m.reloading = false m.reloading = false
m.rows = m.ctl.Statuses() m.rows = m.ctl.Statuses()
m.widths = nil
m.clampCursor() m.clampCursor()
if msg.err != nil { m.setNote(reloadError(msg.err), true) } else { m.setNote(reloadNote(msg.summary), false) } if msg.err != nil { m.setNote(reloadError(msg.err), true) } else { m.setNote(reloadNote(msg.summary), false) }
case openMsg: case openMsg:
+9 -2
View File
@@ -40,8 +40,8 @@ var columns = []struct {
{"STATUS", 9, 9}, {"STATUS", 9, 9},
{"PRICE", 5, 16}, {"PRICE", 5, 16},
{"SELLER", 6, 11}, {"SELLER", 6, 11},
{"LAST", 4, 9}, {"LAST", 10, 10},
{"NEXT", 4, 10}, {"NEXT", 9, 9},
} }
// layout sizes the table and the log pane to the window. // 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)) } 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. // The ITEM column gives way first when the window is narrow.
total := 2 total := 2
for _, w := range widths { total += w + 2 } for _, w := range widths { total += w + 2 }
+1
View File
@@ -174,6 +174,7 @@ func (s *Scheduler) plan(ctx context.Context, cfg *config.Config, host *plugin.H
fetchURL: fetchURL, fetchURL: fetchURL,
host: strings.ToLower(u.Hostname()), host: strings.ToLower(u.Hostname()),
plugin: p, plugin: p,
last: s.limiter.LastCheck(fetchURL),
next: s.limiter.NextCheck(fetchURL, item.Interval.Duration), next: s.limiter.NextCheck(fetchURL, item.Interval.Duration),
}) })
} }