summaryrefslogtreecommitdiff
path: root/prettyFormat.go
diff options
context:
space:
mode:
Diffstat (limited to 'prettyFormat.go')
-rw-r--r--prettyFormat.go36
1 files changed, 13 insertions, 23 deletions
diff --git a/prettyFormat.go b/prettyFormat.go
index 62f7f27..ab2c845 100644
--- a/prettyFormat.go
+++ b/prettyFormat.go
@@ -94,46 +94,36 @@ func printLeftAligned(author, timestamp, content string) {
}
func printRightAligned(author, timestamp, content string) {
- prefix := fmt.Sprintf(":(%s) %s ✦", timestamp, author)
+ prefix := fmt.Sprintf(":(%%s) %%s ✦", timestamp, author)
+ // Print the prefix first, right-aligned.
+ fmt.Printf("%*s\n", termWidth, prefix)
+
// 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
+ paragraphs := strings.Split(content, "\n")
- // First, wrap all the text into lines of the correct width.
- for _, line := range lines {
- words := strings.Fields(line)
+ for _, paragraph := range paragraphs {
+ words := strings.Fields(paragraph)
if len(words) == 0 {
- formattedLines = append(formattedLines, "")
+ fmt.Println() // Preserve paragraph breaks
continue
}
+
currentLine := words[0]
for _, word := range words[1:] {
if len(currentLine)+1+len(word) <= contentWidth {
currentLine += " " + word
} else {
- formattedLines = append(formattedLines, currentLine)
+ // Print the completed line, right-aligned.
+ fmt.Printf("%*s\n", termWidth, 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)
+ // Print the last remaining line of the paragraph, right-aligned.
+ fmt.Printf("%*s\n", termWidth, currentLine)
}
- fmt.Printf("%*s\n", termWidth, prefix)
}
func printTable(table *chatpb.Table) {