From 7b5aa4fbc6eb1973e4c58541cfa9136e1da5f297 Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Tue, 1 Aug 2023 15:08:21 -0400 Subject: [PATCH] feat: set lipgloss renderer color profile Add `SetColorProfile` to force change the Lip Gloss renderer color profile. Needs: https://github.com/charmbracelet/lipgloss/pull/212 Fixes: https://github.com/charmbracelet/log/pull/63 --- go.mod | 2 +- go.sum | 2 ++ logger.go | 6 ++++++ pkg.go | 7 +++++++ 4 files changed, 16 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index ee87f50..780f370 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/charmbracelet/log go 1.17 require ( - github.com/charmbracelet/lipgloss v0.7.1 + github.com/charmbracelet/lipgloss v0.7.2-0.20230801122447-b9dc267bfb97 github.com/go-logfmt/logfmt v0.6.0 github.com/muesli/termenv v0.15.2 github.com/stretchr/testify v1.8.4 diff --git a/go.sum b/go.sum index ea8dfa6..5199403 100644 --- a/go.sum +++ b/go.sum @@ -2,6 +2,8 @@ github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiE github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/charmbracelet/lipgloss v0.7.1 h1:17WMwi7N1b1rVWOjMT+rCh7sQkvDU75B2hbZpc5Kc1E= github.com/charmbracelet/lipgloss v0.7.1/go.mod h1:yG0k3giv8Qj8edTCbbg6AlQ5e8KNWpFujkNawKNhE2c= +github.com/charmbracelet/lipgloss v0.7.2-0.20230801122447-b9dc267bfb97 h1:RPT8YsyfzoQdtruljiWTpcpx6X0DQQepCN39z/gIXTU= +github.com/charmbracelet/lipgloss v0.7.2-0.20230801122447-b9dc267bfb97/go.mod h1:p4eYUZZJ/0oXTuCQKFF8mqyKCz0ja6y+7DniDDw5KKU= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= diff --git a/logger.go b/logger.go index 73805bd..c72decf 100644 --- a/logger.go +++ b/logger.go @@ -282,6 +282,12 @@ func (l *Logger) SetCallerOffset(offset int) { l.callerOffset = offset } +// SetColorProfile force sets the underlying Lip Gloss renderer color profile +// for the TextFormatter. +func (l *Logger) SetColorProfile(profile termenv.Profile) { + l.re.SetColorProfile(profile) +} + // With returns a new logger with the given keyvals added. func (l *Logger) With(keyvals ...interface{}) *Logger { l.mu.Lock() diff --git a/pkg.go b/pkg.go index 2b35b4a..50bcd41 100644 --- a/pkg.go +++ b/pkg.go @@ -8,6 +8,8 @@ import ( "os" "sync" "time" + + "github.com/muesli/termenv" ) var ( @@ -124,6 +126,11 @@ func SetPrefix(prefix string) { defaultLogger.SetPrefix(prefix) } +// SetColorProfile force set the Lip Gloss color profile for the TextFormatter. +func SetColorProfile(profile termenv.Profile) { + defaultLogger.SetColorProfile(profile) +} + // GetPrefix returns the prefix for the default logger. func GetPrefix() string { return defaultLogger.GetPrefix()