Skip to content

Commit

Permalink
refactor(error): add background color for debugging
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Oct 7, 2024
1 parent bb3015e commit 4a7bfb4
Showing 1 changed file with 15 additions and 3 deletions.
18 changes: 15 additions & 3 deletions error.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,28 @@ import (
"os"

"github.com/charmbracelet/lipgloss"
"github.com/charmbracelet/x/ansi"
)

var (
errorHeader = lipgloss.NewStyle().Foreground(lipgloss.Color("#F1F1F1")).Background(lipgloss.Color("#FF5F87")).Bold(true).Padding(0, 1).Margin(1).MarginLeft(2).SetString("ERROR")
errorDetails = lipgloss.NewStyle().Foreground(lipgloss.Color("#757575")).Margin(0, 0, 1, 2)
errorHeader = lipgloss.NewStyle().
Foreground(lipgloss.Color("#F1F1F1")).
Background(lipgloss.Color("#FF5F87")).
Bold(true).
Padding(0, 1).
Margin(1).
MarginLeft(2).
SetString("ERROR")
errorDetails = lipgloss.NewStyle().
Background(lipgloss.Color("52")).
Foreground(lipgloss.Color("#757575")).
Margin(0, 0, 1, 2)
)

func printError(title string, err error) {
fmt.Println(lipgloss.JoinHorizontal(lipgloss.Center, errorHeader.String(), title))
fmt.Println(errorDetails.Render(err.Error()))
rendered := errorDetails.Render(err.Error())
fmt.Println(ansi.Strip(rendered))
}

func printErrorFatal(title string, err error) {
Expand Down

0 comments on commit 4a7bfb4

Please sign in to comment.