all repos — llm_aggregator @ f8680f68d04b67101a791bdcffbbb96f0bc740a8

A CLI tool to aggregate RSS feeds and summarise them with LLMs

internal/tui/tui.go (view raw)

 1package tui
 2
 3import (
 4	"fmt"
 5
 6	"codeberg.org/maxwelljensen/llm_aggregator/internal/progress"
 7
 8	tea "github.com/charmbracelet/bubbletea"
 9)
10
11// TUIProgress bridges progress.Progress calls into a running Bubbletea tea.Program.
12type TUIProgress struct {
13	program *tea.Program
14}
15
16// NewTUIProgress wraps an existing tea.Program instance (created by the caller).
17func NewTUIProgress(p *tea.Program) *TUIProgress {
18	return &TUIProgress{
19		program: p,
20	}
21}
22
23// SetStage sends a message to update the main stage.
24func (tp *TUIProgress) SetStage(stage string) {
25	tp.program.Send(StageMsg(stage))
26}
27
28// SetSubStage sends a message to update the sub-status.
29func (tp *TUIProgress) SetSubStage(status string) {
30	tp.program.Send(SubStageMsg(status))
31}
32
33// SetArticleCount sends a message to update the article counts.
34func (tp *TUIProgress) SetArticleCount(total, processed int) {
35	tp.program.Send(ArticleCountMsg{Total: total, Processed: processed})
36}
37
38// SetTokenEstimate sends a message to update the token estimates.
39func (tp *TUIProgress) SetTokenEstimate(total, used int) {
40	tp.program.Send(TokenEstimateMsg{Total: total, Used: used})
41}
42
43// StartWaiting signals that we're waiting for the LLM response.
44func (tp *TUIProgress) StartWaiting() {
45	tp.program.Send(WaitingMsg{})
46}
47
48// Logf sends a generic log message (can be displayed as a sub-status).
49func (tp *TUIProgress) Logf(format string, args ...any) {
50	tp.program.Send(SubStageMsg(fmt.Sprintf(format, args...)))
51}
52
53// Warningf logs a warning.
54func (tp *TUIProgress) Warningf(format string, args ...any) {
55	tp.Logf("⚠️ Warning: "+format, args...)
56}
57
58// Debugf is a no-op in the TUI; debug output is handled via the progress bar.
59func (tp *TUIProgress) Debugf(format string, args ...any) {}
60
61// Run runs the TUI
62func (tp *TUIProgress) Run() error {
63	_, err := tp.program.Run()
64	return err
65}
66
67// Context returns a progress.Context for the TUI
68func (tp *TUIProgress) Context() *progress.Context {
69	return progress.NewContext(tp)
70}
71