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:
parent
b8b64da118
commit
684503fd07
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue