From 69395ccb0a1ab2167dff9726d35b61b181ffd97d Mon Sep 17 00:00:00 2001 From: Castor Gemini Date: Fri, 22 Aug 2025 05:21:25 -0500 Subject: [PATCH] fix(playback): Implement word wrapping for content - Add a new 'printContent' function to handle word wrapping for the main conversational text in the detailed playback view. - This ensures that long lines of text are correctly wrapped to the terminal width, improving readability. --- prettyFormat.go | 37 ++++++++++++++++++++++++++++++++++++- 1 file changed, 36 insertions(+), 1 deletion(-) diff --git a/prettyFormat.go b/prettyFormat.go index 2c07c0e..a360275 100644 --- a/prettyFormat.go +++ b/prettyFormat.go @@ -36,7 +36,7 @@ func prettyFormatChat(chat *chatpb.Chat) { content := entry.GetContent() if content != "" { - fmt.Printf("✦ %s (%s):\n%s\n", author, formattedTime, strings.TrimSpace(content)) + printContent(author, formattedTime, content) } if table := entry.GetTable(); table != nil { @@ -54,6 +54,41 @@ func prettyFormatChat(chat *chatpb.Chat) { } } +// printContent handles the wrapping for the main conversational text. +func printContent(author, timestamp, content string) { + prefix := fmt.Sprintf("✦ %s (%s): ", author, timestamp) + + // The available width for the text is the total width minus the prefix length. + contentWidth := termWidth - len(prefix) + if contentWidth < 10 { // Ensure we have a reasonable minimum width + contentWidth = 10 + } + + lines := strings.Split(strings.TrimSpace(content), "\n") + + // Print the first line with the prefix. + firstLine := lines[0] + fmt.Printf("%s", prefix) + for len(firstLine) > contentWidth { + fmt.Printf("%s\n", firstLine[:contentWidth]) + firstLine = firstLine[contentWidth:] + // Subsequent wrapped lines need an indent matching the prefix length. + fmt.Printf("%s", strings.Repeat(" ", len(prefix))) + } + fmt.Printf("%s\n", firstLine) + + // Print subsequent paragraphs with the same wrapping logic. + for _, line := range lines[1:] { + fmt.Printf("%s", strings.Repeat(" ", len(prefix))) + for len(line) > contentWidth { + fmt.Printf("%s\n", line[:contentWidth]) + line = line[contentWidth:] + fmt.Printf("%s", strings.Repeat(" ", len(prefix))) + } + fmt.Printf("%s\n", line) + } +} + func printTable(table *chatpb.Table) { if table == nil || len(table.GetRows()) == 0 { return