Add the TUI.

A table with one row per URL, a level-colored log pane and a status bar.
New alerts flash their row and ring the bell. Keys pause, force checks,
open the product page or cart link, and reload the config, which is
validated first and applied in place, keeping each URL's timing.
Headless mode and the TUI now share one watcher.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
OverlordandClaude Bot committed 2026-10-14 12:25:26 +02:00
1 parent 8f0eda5d4d
commit a19e6fa711
14 files changed
+1359 -105

No files matched your search

+19 -9
View File
@@ -111,15 +111,25 @@ func NewEngine(cooldown time.Duration, fx Converter, store Store) *Engine {
return &Engine{cooldown: cooldown, fx: fx, store: store, sent: map[string]Sent{}}
}
// Consider decides whether a checked page makes its item fire. It returns
// the alert, or why an available page does not fire. A page that is not
// available returns neither. An error means the price could not be checked,
// such as when no current exchange rate is available.
func (e *Engine) Consider(ctx context.Context, item config.Item, rep *plugin.Report, now time.Time) (*Alert, string, error) {
if rep == nil || rep.Result == nil || !rep.Result.Available { return nil, "", nil }
// Decision is what Consider made of a checked page.
type Decision struct {
// Alert is set when the item fires.
Alert *Alert
// Qualifies reports whether the page passed the seller and price checks,
// even if the cooldown held the alert back.
Qualifies bool
// Reason says why an available page did not fire.
Reason string
}
// Consider decides whether a checked page makes its item fire. A page that
// is not available decides nothing. An error means the price could not be
// checked, such as when no current exchange rate is available.
func (e *Engine) Consider(ctx context.Context, item config.Item, rep *plugin.Report, now time.Time) (Decision, error) {
if rep == nil || rep.Result == nil || !rep.Result.Available { return Decision{}, nil }
a, why, err := e.qualify(ctx, item, rep, now)
if a == nil { return nil, why, err }
if a == nil { return Decision{Reason: why}, err }
unlock := e.lock()
defer unlock()
@@ -131,7 +141,7 @@ func (e *Engine) Consider(ctx context.Context, item config.Item, rep *plugin.Rep
switch {
case !allowed:
return nil, "in cooldown until " + last.Time.Add(e.cooldown).Format(time.TimeOnly), nil
return Decision{Qualifies: true, Reason: "in cooldown until " + last.Time.Add(e.cooldown).Format(time.TimeOnly)}, nil
case drop && last.Currency == next.Currency:
a.PreviousPrice, a.PreviousCurrency = last.Price, last.Currency
case drop:
@@ -140,7 +150,7 @@ func (e *Engine) Consider(ctx context.Context, item config.Item, rep *plugin.Rep
e.save(item.Name, next)
return a, "", nil
return Decision{Alert: a, Qualifies: true}, nil
}
// sent is what the cooldown remembers of a.
+6 -3
View File
@@ -73,10 +73,12 @@ func TestCooldown(t *testing.T) {
for _, st := range steps {
if strings.HasSuffix(st.name, "new rate") { fx.rate = 1.30 }
a, why, err := e.Consider(ctx, it, st.report, start.Add(st.after))
d, err := e.Consider(ctx, it, st.report, start.Add(st.after))
if err != nil { t.Fatalf("%s: %v", st.name, err) }
if fired := a != nil; fired != st.fires { t.Errorf("%s: fired = %v, want %v (%s)", st.name, fired, st.fires, why) }
a := d.Alert
if fired := a != nil; fired != st.fires { t.Errorf("%s: fired = %v, want %v (%s)", st.name, fired, st.fires, d.Reason) }
if !d.Qualifies { t.Errorf("%s: does not qualify: %s", st.name, d.Reason) }
if a == nil { continue }
prev := ""
@@ -121,7 +123,8 @@ func TestQualify(t *testing.T) {
}
for _, c := range cases {
a, why, err := NewEngine(time.Hour, c.fx, nil).Consider(ctx, c.item, c.report, now)
d, err := NewEngine(time.Hour, c.fx, nil).Consider(ctx, c.item, c.report, now)
a, why := d.Alert, d.Reason
switch {
case c.want == "fire" && a == nil: