fix(playback): Improve formatting of code snippets
- Refactor the 'printCodeSnippet' function to draw a complete, correctly padded box around the code. - Each line is now padded with spaces to ensure the right border aligns perfectly at the terminal width.
This commit is contained in:
parent
a08314efb8
commit
d9e7420b31
|
@ -143,11 +143,23 @@ func printCodeSnippet(snippet *chatpb.CodeSnippet) {
|
|||
language := filepath.Base(snippet.GetFilename()) // Still useful for display
|
||||
|
||||
fmt.Println() // Add extra line feed for spacing
|
||||
fmt.Printf("┌─[ Code Snippet: %s ]──────────────────────────────────\n", language)
|
||||
|
||||
// --- Top Border ---
|
||||
topBorder := fmt.Sprintf("┌─[ Code Snippet: %s ]", language)
|
||||
fmt.Printf("%s%s┐\n", topBorder, strings.Repeat("─", termWidth-len(topBorder)-1))
|
||||
|
||||
// --- Content Lines ---
|
||||
for _, line := range strings.Split(strings.TrimSpace(code), "\n") {
|
||||
fmt.Printf("│ %s\n", line)
|
||||
// Calculate padding: total width - borders/padding - text length
|
||||
padding := termWidth - 4 - len(line)
|
||||
if padding < 0 {
|
||||
padding = 0 // Should not happen with wrapping, but as a safeguard
|
||||
}
|
||||
fmt.Printf("│ %s%s │\n", line, strings.Repeat(" ", padding))
|
||||
}
|
||||
fmt.Printf("└─────────────────────────────────────────────────────────\n\n")
|
||||
|
||||
// --- Bottom Border ---
|
||||
fmt.Printf("└%s┘\n\n", strings.Repeat("─", termWidth-2))
|
||||
}
|
||||
|
||||
func printToolCallBox(tc *chatpb.ToolCall) {
|
||||
|
|
Loading…
Reference in New Issue