mirror of
https://github.com/acedanger/shell.git
synced 2025-12-05 22:50:18 -08:00
Fix TUI newline display issue
- Add processEscapeSequences() function to convert literal \n to actual newlines - Apply fix to backup success, error, and running output displays - Add TUI binary to gitignore - Include comprehensive documentation of the fix Resolves issue where backup output showed literal escape sequences instead of properly formatted text with line breaks.
This commit is contained in:
23
tui/main.go
23
tui/main.go
@@ -580,8 +580,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
duration = m.backupStatus[msg.service].Duration
|
||||
}
|
||||
|
||||
// Process output to handle escape sequences properly
|
||||
processedOutput := processEscapeSequences(msg.output)
|
||||
|
||||
m.viewport.SetContent(fmt.Sprintf("✅ Backup completed successfully for %s!\n\nDuration: %s\n\n%s\n\n📋 Full Output:\n%s",
|
||||
msg.service, duration, summaryText, msg.output))
|
||||
msg.service, duration, summaryText, processedOutput))
|
||||
|
||||
case backupErrorMsg:
|
||||
if m.backupStatus[msg.service] != nil {
|
||||
@@ -614,8 +617,11 @@ func (m Model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||
errorAnalysis = "\n💡 This might be a disk space issue. Check available storage."
|
||||
}
|
||||
|
||||
// Process error output to handle escape sequences properly
|
||||
processedError := processEscapeSequences(msg.error)
|
||||
|
||||
m.viewport.SetContent(fmt.Sprintf("❌ Backup failed for %s!\n\nDuration: %s%s\n\n🚨 Error Details:\n%s",
|
||||
msg.service, duration, errorAnalysis, msg.error))
|
||||
msg.service, duration, errorAnalysis, processedError))
|
||||
|
||||
case spinner.TickMsg:
|
||||
m.spinner, cmd = m.spinner.Update(msg)
|
||||
@@ -667,8 +673,11 @@ func (m *Model) updateViewportForRunningService(service string, outputForDisplay
|
||||
}
|
||||
}
|
||||
|
||||
// Process output to handle escape sequences properly
|
||||
processedOutput := processEscapeSequences(outputForDisplay)
|
||||
|
||||
m.viewport.SetContent(fmt.Sprintf("⏳ Backup in progress for %s...\n\n%s %d%%\nElapsed: %s%s\n\n📋 Latest output:\n%s\n\nPress 'x' to stop the backup.",
|
||||
service, progressBar, progress, elapsed.Round(time.Second), etaStr, outputForDisplay))
|
||||
service, progressBar, progress, elapsed.Round(time.Second), etaStr, processedOutput))
|
||||
}
|
||||
|
||||
func (m Model) View() string {
|
||||
@@ -1257,6 +1266,14 @@ func createProgressBar(progress int) string {
|
||||
return fmt.Sprintf("[%s]", bar)
|
||||
}
|
||||
|
||||
// Helper function to process escape sequences in output text
|
||||
func processEscapeSequences(text string) string {
|
||||
processed := strings.ReplaceAll(text, "\\n", "\n")
|
||||
processed = strings.ReplaceAll(processed, "\\t", "\t")
|
||||
processed = strings.ReplaceAll(processed, "\\r", "\r")
|
||||
return processed
|
||||
}
|
||||
|
||||
// Start a progress ticker for time-based progress estimation
|
||||
func (m Model) startProgressTicker(service string) tea.Cmd {
|
||||
return tea.Tick(time.Second*2, func(t time.Time) tea.Msg {
|
||||
|
||||
Reference in New Issue
Block a user