docs: clean up verbose comments in TUI main.go

This commit is contained in:
Jeremie Fraeys 2026-02-18 14:45:44 -05:00
parent 3775bc3ee0
commit b889b5403d
No known key found for this signature in database

View file

@ -149,22 +149,8 @@ func main() {
}
}()
// Initialize logger
// Note: In original code, logger was created inside initialModel.
// Here we create it and pass it to controller.
// We use slog.LevelError as default from original code.
// But original code imported "log/slog".
// We use internal/logging package.
// Check logging package signature.
// Original: logger := logging.NewLogger(slog.LevelError, false)
// We need to import "log/slog" in main if we use slog constants.
// Or use logging package constants if available.
// Let's check logging package.
// Assuming logging.NewLogger takes (slog.Level, bool).
// I'll import "log/slog".
// Wait, I need to import "log/slog"
logger := logging.NewLogger(-4, false) // -4 is slog.LevelError value. Or I can import log/slog.
// Initialize logger with error level and no debug output
logger := logging.NewLogger(-4, false) // -4 = slog.LevelError
// Initialize State and Controller
var effectiveAPIKey string
@ -182,32 +168,23 @@ func main() {
controller: ctrl,
}
// Run TUI app
// Run TUI program with graceful shutdown on SIGINT/SIGTERM
p := tea.NewProgram(appModel, tea.WithAltScreen(), tea.WithMouseAllMotion())
// Ensure we restore the terminal even if panic or error occurs
// Note: p.Run() usually handles this, but explicit cleanup is safer
// if we want to ensure the alt screen is exited.
// We can't defer p.ReleaseTerminal() here because p is created here.
// But we can defer a function that calls it.
// Set up signal handling for graceful shutdown
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
// Run program and handle signals
go func() {
<-sigChan
p.Quit()
}()
if _, err := p.Run(); err != nil {
// Attempt to restore terminal before logging error
_ = p.ReleaseTerminal()
log.Printf("Error running TUI: %v", err)
return
}
// Explicitly restore terminal after program exits
_ = p.ReleaseTerminal()
}