all repos — llm_aggregator @ 64f25c518cd22ba98fb9ca131b0dd6d654958fbf

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

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}
 24
 25// SimpleLogger implements Logger with io.Writer output
 26type SimpleLogger struct {
 27	writer io.Writer
 28	debug  bool
 29}
 30
 31// NewSimpleLogger creates a new SimpleLogger
 32func NewSimpleLogger(writer io.Writer, debug bool) *SimpleLogger {
 33	return &SimpleLogger{
 34		writer: writer,
 35		debug:  debug,
 36	}
 37}
 38
 39func (sl *SimpleLogger) Logf(format string, args ...any) {
 40	fmt.Fprintf(sl.writer, format+"\n", args...)
 41}
 42
 43func (sl *SimpleLogger) Warningf(format string, args ...any) {
 44	// Use style.Warningf for orange bold WARNING prefix
 45	fmt.Fprintf(sl.writer, "%s\n", style.Warningf(format, args...))
 46}
 47
 48func (sl *SimpleLogger) Debugf(format string, args ...any) {
 49	if sl.debug {
 50		// Use style.Debugf for styled debug output
 51		fmt.Fprintf(sl.writer, "%s\n", style.Debugf(format, args...))
 52	}
 53}
 54
 55func (sl *SimpleLogger) SetStage(stage string)                {}
 56func (sl *SimpleLogger) SetSubStage(stage string)             {}
 57func (sl *SimpleLogger) SetArticleCount(total, processed int) {}
 58
 59// NoopLogger implements Logger with no output
 60type NoopLogger struct{}
 61
 62func (nl *NoopLogger) Logf(format string, args ...any)      {}
 63func (nl *NoopLogger) Warningf(format string, args ...any)  {}
 64func (nl *NoopLogger) Debugf(format string, args ...any)    {}
 65func (nl *NoopLogger) SetStage(stage string)                {}
 66func (nl *NoopLogger) SetSubStage(status string)            {}
 67func (nl *NoopLogger) SetArticleCount(total, processed int) {}
 68
 69// Context provides progress context for components
 70type Context struct {
 71	logger Logger
 72}
 73
 74// NewContext creates a new progress context
 75func NewContext(logger Logger) *Context {
 76	return &Context{
 77		logger: logger,
 78	}
 79}
 80
 81// Logf logs a message
 82func (c *Context) Logf(format string, args ...any) {
 83	if c.logger != nil {
 84		c.logger.Logf(format, args...)
 85	}
 86}
 87
 88// Warningf logs a warning
 89func (c *Context) Warningf(format string, args ...any) {
 90	if c.logger != nil {
 91		c.logger.Warningf(format, args...)
 92	}
 93}
 94
 95// Debugf logs a debug message
 96func (c *Context) Debugf(format string, args ...any) {
 97	if c.logger != nil {
 98		c.logger.Debugf(format, args...)
 99	}
100}