all repos — llm_aggregator @ d3fad3374aee5ee549219c1387a0c5d87ce1a99b

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	"llm_aggregator/internal/progress"
 7
 8	tea "github.com/charmbracelet/bubbletea"
 9)
10
11// TUIProgress implements the progress.Progress interface for TUI
12type TUIProgress struct {
13	program *tea.Program
14}
15
16// NewTUIProgress creates a new TUIProgress.
17// It now accepts the program instance instead of creating one.
18func NewTUIProgress(p *tea.Program) *TUIProgress {
19	return &TUIProgress{
20		program: p,
21	}
22}
23
24// SetStage sends a message to update the main stage.
25func (tp *TUIProgress) SetStage(stage string) {
26	tp.program.Send(StageMsg(stage))
27}
28
29// SetSubStage sends a message to update the sub-status.
30func (tp *TUIProgress) SetSubStage(status string) {
31	tp.program.Send(SubStageMsg(status))
32}
33
34// SetArticleCount sends a message to update the article counts.
35func (tp *TUIProgress) SetArticleCount(total, processed int) {
36	tp.program.Send(ArticleCountMsg{Total: total, Processed: processed})
37}
38
39// SetTokenEstimate sends a message to update the token estimates.
40func (tp *TUIProgress) SetTokenEstimate(total, used int) {
41	tp.program.Send(TokenEstimateMsg{Total: total, Used: used})
42}
43
44// StartWaiting signals that we're waiting for the LLM response.
45func (tp *TUIProgress) StartWaiting() {
46	tp.program.Send(WaitingMsg{})
47}
48
49// Logf sends a generic log message (can be displayed as a sub-status).
50func (tp *TUIProgress) Logf(format string, args ...any) {
51	tp.program.Send(SubStageMsg(fmt.Sprintf(format, args...)))
52}
53
54// Warningf logs a warning.
55func (tp *TUIProgress) Warningf(format string, args ...any) {
56	tp.Logf("⚠️ Warning: "+format, args...)
57}
58
59// Debugf does nothing in the TUI.
60func (tp *TUIProgress) Debugf(format string, args ...any) {}
61
62// Run runs the TUI
63func (tp *TUIProgress) Run() error {
64	_, err := tp.program.Run()
65	return err
66}
67
68// Context returns a progress.Context for the TUI
69func (tp *TUIProgress) Context() *progress.Context {
70	return progress.NewContext(tp)
71}
72