From 9b71be25d0ce5e9f30a1e1193dc5fa88f8402a2e Mon Sep 17 00:00:00 2001 From: Castor Gemini Date: Fri, 22 Aug 2025 05:40:02 -0500 Subject: [PATCH] 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. --- prettyFormat.go | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/prettyFormat.go b/prettyFormat.go index 62f7f27..ab2c845 100644 --- a/prettyFormat.go +++ b/prettyFormat.go @@ -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) {