internal/progress/progress.go (view raw)
1package progress
2
3import (
4 "fmt"
5 "io"
6
7 "llm_aggregator/internal/style"
8)
9
10// Logger provides logging interface for the aggregator
11type Logger interface {
12 Logf(format string, args ...any)
13 Warningf(format string, args ...any)
14 Debugf(format string, args ...any)
15}
16
17// Progress provides progress reporting interface for TUI
18type Progress interface {
19 Logger
20 SetStage(stage string)
21 SetSubStage(status string)
22 SetArticleCount(total, processed int)
23 SetTokenEstimate(total, used int)
24 StartWaiting()
25}
26
27// SimpleLogger implements Logger with io.Writer output
28type SimpleLogger struct {
29 writer io.Writer
30 debug bool
31}
32
33// NewSimpleLogger creates a new SimpleLogger
34func NewSimpleLogger(writer io.Writer, debug bool) *SimpleLogger {
35 return &SimpleLogger{
36 writer: writer,
37 debug: debug,
38 }
39}
40
41func (sl *SimpleLogger) Logf(format string, args ...any) {
42 fmt.Fprintf(sl.writer, format+"\n", args...)
43}
44
45func (sl *SimpleLogger) Warningf(format string, args ...any) {
46 // Use style.Warningf for orange bold WARNING prefix
47 fmt.Fprintf(sl.writer, "%s\n", style.Warningf(format, args...))
48}
49
50func (sl *SimpleLogger) Debugf(format string, args ...any) {
51 if sl.debug {
52 // Use style.Debugf for styled debug output
53 fmt.Fprintf(sl.writer, "%s\n", style.Debugf(format, args...))
54 }
55}
56
57func (sl *SimpleLogger) SetStage(stage string) {}
58func (sl *SimpleLogger) SetSubStage(stage string) {}
59func (sl *SimpleLogger) SetArticleCount(total, processed int) {}
60func (sl *SimpleLogger) SetTokenEstimate(total, used int) {}
61func (sl *SimpleLogger) StartWaiting() {}
62
63// NoopLogger implements Logger with no output
64type NoopLogger struct{}
65
66func (nl *NoopLogger) Logf(format string, args ...any) {}
67func (nl *NoopLogger) Warningf(format string, args ...any) {}
68func (nl *NoopLogger) Debugf(format string, args ...any) {}
69func (nl *NoopLogger) SetStage(stage string) {}
70func (nl *NoopLogger) SetSubStage(status string) {}
71func (nl *NoopLogger) SetArticleCount(total, processed int) {}
72func (nl *NoopLogger) SetTokenEstimate(total, used int) {}
73func (nl *NoopLogger) StartWaiting() {}
74
75// Context provides progress context for components
76type Context struct {
77 logger Logger
78}
79
80// NewContext creates a new progress context
81func NewContext(logger Logger) *Context {
82 return &Context{
83 logger: logger,
84 }
85}
86
87// Logf logs a message
88func (c *Context) Logf(format string, args ...any) {
89 if c.logger != nil {
90 c.logger.Logf(format, args...)
91 }
92}
93
94// Warningf logs a warning
95func (c *Context) Warningf(format string, args ...any) {
96 if c.logger != nil {
97 c.logger.Warningf(format, args...)
98 }
99}
100
101// Debugf logs a debug message
102func (c *Context) Debugf(format string, args ...any) {
103 if c.logger != nil {
104 c.logger.Debugf(format, args...)
105 }
106}