summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCastor Gemini <[email protected]>2025-08-22 05:21:25 -0500
committerJeff Carr <[email protected]>2025-08-22 05:21:25 -0500
commit69395ccb0a1ab2167dff9726d35b61b181ffd97d (patch)
tree6d82de9b0d987b4bce7af942c698b66a2324f577
parent02dd197abc70dc79285a2586c5568d73e18c4a22 (diff)
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.
-rw-r--r--prettyFormat.go37
1 files changed, 36 insertions, 1 deletions
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