Fix audio quality with per-user mixing buffer and prevent TUI layout break on log overflow

This commit is contained in:
Jose Luis Montañes Ojados
2026-01-16 22:33:35 +01:00
parent f83f525600
commit 9675f3764c
4 changed files with 177 additions and 129 deletions

View File

@@ -27,7 +27,7 @@ func main() {
debug := flag.Bool("debug", true, "Enable debug logging to file (default true)")
flag.Parse()
// Disable log output completely to prevent TUI corruption
// Disable log output completely to prevent TUI corruption (stdout is reserved for UI)
log.SetOutput(io.Discard)
// Enable debug file logging if requested
@@ -39,6 +39,8 @@ func main() {
if err == nil {
defer debugFile.Close()
debugLog("TUI Debug started at %s", timestamp)
// Redirect standard log output to debug file initially
log.SetOutput(debugFile)
}
}
@@ -51,16 +53,19 @@ func main() {
// Pass program reference to model for event handlers
m.SetProgram(p)
// Set up log capture
// Set up log capture for UI display
r, w, _ := os.Pipe()
if debugFile != nil {
// Log to both UI (pipe) and Debug File
log.SetOutput(io.MultiWriter(w, debugFile))
} else {
// Log to UI only
log.SetOutput(w)
}
// Make sure logs have timestamp removed (TUI adds it if needed, or we keep it)
log.SetFlags(log.Ltime) // Just time
// Goroutine to capture logs and send them to the UI
go func() {
buf := make([]byte, 1024)
for {
@@ -71,7 +76,6 @@ func main() {
if n > 0 {
lines := string(buf[:n])
// Split by newline and send each line
// Simple split, might need better buffering for partial lines but OK for debug
p.Send(logMsg(lines))
}
}