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// Logf sends a generic log message (can be displayed as a sub-status).
40func (tp *TUIProgress) Logf(format string, args ...any) {
41 tp.program.Send(SubStageMsg(fmt.Sprintf(format, args...)))
42}
43
44// Warningf logs a warning.
45func (tp *TUIProgress) Warningf(format string, args ...any) {
46 tp.Logf("⚠️ Warning: "+format, args...)
47}
48
49// Debugf does nothing in the TUI.
50func (tp *TUIProgress) Debugf(format string, args ...any) {}
51
52// Run runs the TUI
53func (tp *TUIProgress) Run() error {
54 _, err := tp.program.Run()
55 return err
56}
57
58// Context returns a progress.Context for the TUI
59func (tp *TUIProgress) Context() *progress.Context {
60 return progress.NewContext(tp)
61}
62