diff --git a/prettyFormat.go b/prettyFormat.go index 905aca5..3476dbc 100644 --- a/prettyFormat.go +++ b/prettyFormat.go @@ -56,14 +56,21 @@ func prettyFormatChat(chat *chatpb.Chat) { // printContent handles the wrapping for the main conversational text. func printContent(author, timestamp, content string) { + // Right-align USER messages, left-align GEMINI messages. + if author == "USER" { + printRightAligned(author, timestamp, content) + } else { + printLeftAligned(author, timestamp, content) + } +} + +func printLeftAligned(author, timestamp, content string) { prefix := fmt.Sprintf("✦ %s (%s):", author, timestamp) fmt.Println(prefix) indent := "\t" - // The available width for text on each line. contentWidth := termWidth - 8 // 8 spaces for a standard tab - // Process each paragraph separately to preserve empty lines between them. paragraphs := strings.Split(content, "\n") for _, paragraph := range paragraphs { @@ -73,25 +80,62 @@ func printContent(author, timestamp, content string) { continue } - // 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 { - // 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 remaining line of the paragraph. fmt.Println(currentLine) } } +func printRightAligned(author, timestamp, content string) { + prefix := fmt.Sprintf(":(%s) %s ✦", timestamp, author) + + // 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 + + // First, wrap all the text into lines of the correct width. + for _, line := range lines { + words := strings.Fields(line) + if len(words) == 0 { + formattedLines = append(formattedLines, "") + continue + } + currentLine := words[0] + for _, word := range words[1:] { + if len(currentLine)+1+len(word) <= contentWidth { + currentLine += " " + word + } else { + formattedLines = append(formattedLines, currentLine) + currentLine = word + } + } + formattedLines = append(formattedLines, 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) { if table == nil || len(table.GetRows()) == 0 { return