summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCastor Gemini <[email protected]>2025-08-22 05:31:35 -0500
committerJeff Carr <[email protected]>2025-08-22 05:31:35 -0500
commit684503fd07eb77955271f6497a8365a89e5a027b (patch)
treede975c78042934fc6f57798fed2010142e15ce07
parentb8b64da118c11800416c93e3a0db48744c3af67f (diff)
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.
-rw-r--r--prettyFormat.go43
1 files changed, 20 insertions, 23 deletions
diff --git a/prettyFormat.go b/prettyFormat.go
index 22ea6b1..905aca5 100644
--- a/prettyFormat.go
+++ b/prettyFormat.go
@@ -59,39 +59,36 @@ func printContent(author, timestamp, content string) {
prefix := fmt.Sprintf("✦ %s (%s):", author, timestamp)
fmt.Println(prefix)
- // The available width for the text is the total width minus the tab indent.
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 {
- // Handle empty lines in the original content as paragraph breaks.
- if strings.TrimSpace(line) == "" {
- fmt.Println()
- continue
- }
-
- words := strings.Fields(line)
+ for _, paragraph := range paragraphs {
+ words := strings.Fields(paragraph)
if len(words) == 0 {
+ fmt.Println() // Preserve paragraph breaks
continue
}
- currentLine := indent
- for _, word := range words {
- // Check if adding the next word exceeds the content width.
- if len(currentLine)+len(word)+1 > termWidth {
- fmt.Println(strings.TrimSpace(currentLine))
- currentLine = indent + word
+ // Start the first line of the paragraph.
+ currentLine := indent + words[0]
+
+ for _, word := range words[1:] {
+ // If the next word fits, add it.
+ if len(currentLine)+1+len(word) <= contentWidth {
+ currentLine += " " + word
} else {
- if currentLine == indent {
- currentLine += word
- } else {
- currentLine += " " + word
- }
+ // The word doesn't fit, so print the completed line.
+ fmt.Println(currentLine)
+ // Start a new line with the word that didn't fit.
+ currentLine = indent + word
}
}
- // Print the last line of the paragraph.
- fmt.Println(strings.TrimSpace(currentLine))
+ // Print the last remaining line of the paragraph.
+ fmt.Println(currentLine)
}
}