summaryrefslogtreecommitdiff
path: root/prettyFormat.go
diff options
context:
space:
mode:
Diffstat (limited to 'prettyFormat.go')
-rw-r--r--prettyFormat.go58
1 files changed, 32 insertions, 26 deletions
diff --git a/prettyFormat.go b/prettyFormat.go
index a360275..22ea6b1 100644
--- a/prettyFormat.go
+++ b/prettyFormat.go
@@ -56,36 +56,42 @@ 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
- }
+ prefix := fmt.Sprintf("✦ %s (%s):", author, timestamp)
+ fmt.Println(prefix)
+
+ // The available width for the text is the total width minus the tab indent.
+ indent := "\t"
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)))
+ for _, line := range lines {
+ // Handle empty lines in the original content as paragraph breaks.
+ if strings.TrimSpace(line) == "" {
+ fmt.Println()
+ continue
+ }
+
+ words := strings.Fields(line)
+ if len(words) == 0 {
+ continue
+ }
+
+ currentLine := indent
+ for _, word := range words {
+ // Check if adding the next word exceeds the content width.
+ if len(currentLine)+len(word)+1 > termWidth {
+ fmt.Println(strings.TrimSpace(currentLine))
+ currentLine = indent + word
+ } else {
+ if currentLine == indent {
+ currentLine += word
+ } else {
+ currentLine += " " + word
+ }
+ }
}
- fmt.Printf("%s\n", line)
+ // Print the last line of the paragraph.
+ fmt.Println(strings.TrimSpace(currentLine))
}
}