fix(playback): Correct right-alignment of user messages

- Refactor the 'printRightAligned' function to print the author
  prefix line *before* the content.
- This fixes a bug where the prefix was incorrectly appearing after
  the message body.
This commit is contained in:
Castor Gemini 2025-08-22 05:40:02 -05:00 committed by Jeff Carr
parent 7b65b5b237
commit 9b71be25d0
1 changed files with 13 additions and 23 deletions

View File

@ -94,46 +94,36 @@ func printLeftAligned(author, timestamp, content string) {
}
func printRightAligned(author, timestamp, content string) {
prefix := fmt.Sprintf(":(%s) %s ✦", timestamp, author)
prefix := fmt.Sprintf(":(%%s) %%s ✦", timestamp, author)
// Print the prefix first, right-aligned.
fmt.Printf("%*s\n", termWidth, prefix)
// The available width for the text.
contentWidth := termWidth - 8 // Leave a tab's worth of margin on the left
lines := strings.Split(content, "\n")
var formattedLines []string
paragraphs := strings.Split(content, "\n")
// First, wrap all the text into lines of the correct width.
for _, line := range lines {
words := strings.Fields(line)
for _, paragraph := range paragraphs {
words := strings.Fields(paragraph)
if len(words) == 0 {
formattedLines = append(formattedLines, "")
fmt.Println() // Preserve paragraph breaks
continue
}
currentLine := words[0]
for _, word := range words[1:] {
if len(currentLine)+1+len(word) <= contentWidth {
currentLine += " " + word
} else {
formattedLines = append(formattedLines, currentLine)
// Print the completed line, right-aligned.
fmt.Printf("%*s\n", termWidth, currentLine)
currentLine = word
}
}
formattedLines = append(formattedLines, currentLine)
// Print the last remaining line of the paragraph, right-aligned.
fmt.Printf("%*s\n", termWidth, currentLine)
}
// Now, print the formatted lines with the correct right alignment.
// The prefix is printed last and right-aligned.
for i, line := range formattedLines {
padding := termWidth - len(line)
if i == len(formattedLines)-1 { // Last line gets the prefix
padding = termWidth - len(line) - len(prefix)
}
if padding < 0 {
padding = 0
}
fmt.Printf("%s%s\n", strings.Repeat(" ", padding), line)
}
fmt.Printf("%*s\n", termWidth, prefix)
}
func printTable(table *chatpb.Table) {