fix(playback): Correct content indentation logic

- Refactor the word-wrapping algorithm in 'printContent' to
  ensure every line of conversational text is correctly
  prepended with a tab character.
- This fixes the issue where only the first line of a wrapped
  paragraph was being indented.
This commit is contained in:
Castor Gemini 2025-08-22 05:31:35 -05:00 committed by Jeff Carr
parent b8b64da118
commit 684503fd07
1 changed files with 20 additions and 23 deletions

View File

@ -59,39 +59,36 @@ func printContent(author, timestamp, content string) {
prefix := fmt.Sprintf("✦ %s (%s):", author, timestamp) prefix := fmt.Sprintf("✦ %s (%s):", author, timestamp)
fmt.Println(prefix) fmt.Println(prefix)
// The available width for the text is the total width minus the tab indent.
indent := "\t" indent := "\t"
// The available width for text on each line.
contentWidth := termWidth - 8 // 8 spaces for a standard tab
lines := strings.Split(strings.TrimSpace(content), "\n") // Process each paragraph separately to preserve empty lines between them.
paragraphs := strings.Split(content, "\n")
for _, line := range lines { for _, paragraph := range paragraphs {
// Handle empty lines in the original content as paragraph breaks. words := strings.Fields(paragraph)
if strings.TrimSpace(line) == "" {
fmt.Println()
continue
}
words := strings.Fields(line)
if len(words) == 0 { if len(words) == 0 {
fmt.Println() // Preserve paragraph breaks
continue continue
} }
currentLine := indent // Start the first line of the paragraph.
for _, word := range words { currentLine := indent + words[0]
// Check if adding the next word exceeds the content width.
if len(currentLine)+len(word)+1 > termWidth { for _, word := range words[1:] {
fmt.Println(strings.TrimSpace(currentLine)) // If the next word fits, add it.
currentLine = indent + word if len(currentLine)+1+len(word) <= contentWidth {
currentLine += " " + word
} else { } else {
if currentLine == indent { // The word doesn't fit, so print the completed line.
currentLine += word fmt.Println(currentLine)
} else { // Start a new line with the word that didn't fit.
currentLine += " " + word currentLine = indent + word
}
} }
} }
// Print the last line of the paragraph. // Print the last remaining line of the paragraph.
fmt.Println(strings.TrimSpace(currentLine)) fmt.Println(currentLine)
} }
} }