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.
This commit is contained in:
parent
02dd197abc
commit
69395ccb0a
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue