diff options
| author | Jeff Carr <[email protected]> | 2025-08-30 14:42:57 -0500 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2025-08-30 14:42:57 -0500 |
| commit | 7f8f5e3b9b37fccbb357b70e6490823a8b22ae7e (patch) | |
| tree | 11b6f74e8d3f33b3fdb82421cb79653f65685fe8 /prettyFormat.go | |
| parent | c971bfddf74d48d87f10f5f050b1eef3fd12bf20 (diff) | |
basic JSON parsing into genai struc
Diffstat (limited to 'prettyFormat.go')
| -rw-r--r-- | prettyFormat.go | 58 |
1 files changed, 29 insertions, 29 deletions
diff --git a/prettyFormat.go b/prettyFormat.go index 03602bf..c223214 100644 --- a/prettyFormat.go +++ b/prettyFormat.go @@ -7,20 +7,20 @@ package main import ( - "fmt" "path/filepath" "strings" "go.wit.com/lib/protobuf/chatpb" + "go.wit.com/log" ) const termWidth = 100 // The target width for the formatted output boxes. // prettyFormatChat is the main entry point to print a detailed view of a Chat topic. func prettyFormatChat(chat *chatpb.Chat) { - fmt.Printf("\n========================================================\n") - fmt.Printf("== Chat Topic: %s (UUID: %s)\n", chat.GetChatName(), chat.GetUuid()) - fmt.Printf("========================================================\n\n") + log.Printf("\n========================================================\n") + log.Printf("== Chat Topic: %s (UUID: %s)\n", chat.GetChatName(), chat.GetUuid()) + log.Printf("========================================================\n\n") for _, entry := range chat.GetEntries() { author := entry.GetFrom().String() @@ -50,7 +50,7 @@ func prettyFormatChat(chat *chatpb.Chat) { printCodeSnippet(snippet) } } - fmt.Println() + log.Println() } } @@ -65,8 +65,8 @@ func printContent(author, timestamp, content string) { } func printLeftAligned(author, timestamp, content string) { - prefix := fmt.Sprintf("✦ %s (%s):", author, timestamp) - fmt.Println(prefix) + prefix := log.Sprintf("✦ %s (%s):", author, timestamp) + log.Println(prefix) indent := "\t" contentWidth := termWidth - 8 // 8 spaces for a standard tab @@ -76,7 +76,7 @@ func printLeftAligned(author, timestamp, content string) { for _, paragraph := range paragraphs { words := strings.Fields(paragraph) if len(words) == 0 { - fmt.Println() // Preserve paragraph breaks + log.Println() // Preserve paragraph breaks continue } @@ -85,19 +85,19 @@ func printLeftAligned(author, timestamp, content string) { if len(currentLine)+1+len(word) <= contentWidth { currentLine += " " + word } else { - fmt.Println(currentLine) + log.Println(currentLine) currentLine = indent + word } } - fmt.Println(currentLine) + log.Println(currentLine) } } func printRightAligned(author, timestamp, content string) { - prefix := fmt.Sprintf("(%s) %s ✦", timestamp, author) + prefix := log.Sprintf("(%s) %s ✦", timestamp, author) // Print the prefix first, right-aligned. - fmt.Printf("%*s\n", termWidth, prefix) + log.Printf("%*s\n", termWidth, prefix) // The available width for the text. contentWidth := termWidth - 8 // Leave a tab's worth of margin on the left @@ -107,7 +107,7 @@ func printRightAligned(author, timestamp, content string) { for _, paragraph := range paragraphs { words := strings.Fields(paragraph) if len(words) == 0 { - fmt.Println() // Preserve paragraph breaks + log.Println() // Preserve paragraph breaks continue } @@ -117,12 +117,12 @@ func printRightAligned(author, timestamp, content string) { currentLine += " " + word } else { // Print the completed line, right-aligned. - fmt.Printf("%*s\n", termWidth, currentLine) + log.Printf("%*s\n", termWidth, currentLine) currentLine = word } } // Print the last remaining line of the paragraph, right-aligned. - fmt.Printf("%*s\n", termWidth, currentLine) + log.Printf("%*s\n", termWidth, currentLine) } } @@ -130,11 +130,11 @@ func printTable(table *chatpb.Table) { if table == nil || len(table.GetRows()) == 0 { return } - fmt.Println("┌─[ Table Data ]──────────────────────────────────────────") + log.Println("┌─[ Table Data ]──────────────────────────────────────────") for _, row := range table.GetRows() { - fmt.Printf("│ %s\n", strings.Join(row.GetFields(), " │ ")) + log.Printf("│ %s\n", strings.Join(row.GetFields(), " │ ")) } - fmt.Printf("└─────────────────────────────────────────────────────────\n\n") + log.Printf("└─────────────────────────────────────────────────────────\n\n") } func printCodeSnippet(snippet *chatpb.CodeSnippet) { @@ -142,11 +142,11 @@ func printCodeSnippet(snippet *chatpb.CodeSnippet) { code := snippet.GetContent() language := filepath.Base(snippet.GetFilename()) // Still useful for display - fmt.Println() // Add extra line feed for spacing + log.Println() // Add extra line feed for spacing // --- Top Border --- - topBorder := fmt.Sprintf("┌─[ Code Snippet: %s ]", language) - fmt.Printf("%s%s┐\n", topBorder, strings.Repeat("─", termWidth-len(topBorder)-1)) + topBorder := log.Sprintf("┌─[ Code Snippet: %s ]", language) + log.Printf("%s%s┐\n", topBorder, strings.Repeat("─", termWidth-len(topBorder)-1)) // --- Content Lines --- for _, line := range strings.Split(strings.TrimSpace(code), "\n") { @@ -155,17 +155,17 @@ func printCodeSnippet(snippet *chatpb.CodeSnippet) { if padding < 0 { padding = 0 // Should not happen with wrapping, but as a safeguard } - fmt.Printf("│ %s%s │\n", line, strings.Repeat(" ", padding)) + log.Printf("│ %s%s │\n", line, strings.Repeat(" ", padding)) } // --- Bottom Border --- - fmt.Printf("└%s┘\n\n", strings.Repeat("─", termWidth-2)) + log.Printf("└%s┘\n\n", strings.Repeat("─", termWidth-2)) } func printToolCallBox(tc *chatpb.ToolCall) { boxWidth := termWidth - 2 - fmt.Printf(" ╭%s╮\n", strings.Repeat("─", boxWidth)) - header := fmt.Sprintf(" ✔ %s %s (%s)", tc.GetName(), tc.GetInput(), tc.GetDescription()) + log.Printf(" ╭%s╮\n", strings.Repeat("─", boxWidth)) + header := log.Sprintf(" ✔ %s %s (%s)", tc.GetName(), tc.GetInput(), tc.GetDescription()) printWrappedLine(header, boxWidth) printEmptyLine(boxWidth) if stdout := tc.GetOutputStdout(); stdout != "" { @@ -179,7 +179,7 @@ func printToolCallBox(tc *chatpb.ToolCall) { } } printEmptyLine(boxWidth) - fmt.Printf(" ╰%s╯\n", strings.Repeat("─", boxWidth)) + log.Printf(" ╰%s╯\n", strings.Repeat("─", boxWidth)) } func printWrappedLine(text string, width int) { @@ -188,12 +188,12 @@ func printWrappedLine(text string, width int) { return } for len(text) > width { - fmt.Printf(" │ %-*s │\n", width, text[:width]) + log.Printf(" │ %-*s │\n", width, text[:width]) text = text[width:] } - fmt.Printf(" │ %-*s │\n", width, text) + log.Printf(" │ %-*s │\n", width, text) } func printEmptyLine(width int) { - fmt.Printf(" │ %*s │\n", width, "") + log.Printf(" │ %*s │\n", width, "") } |
