Skip to content

Commit

Permalink
feat: set lipgloss renderer color profile
Browse files Browse the repository at this point in the history
Add `SetColorProfile` to force change the Lip Gloss renderer color profile.

Needs: charmbracelet/lipgloss#212
Fixes: #63
  • Loading branch information
aymanbagabas committed Aug 1, 2023
1 parent 97dd8c9 commit 7b5aa4f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 1 deletion.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 6 additions & 0 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Check warning on line 288 in logger.go

View check run for this annotation

Codecov / codecov/patch

logger.go#L287-L288

Added lines #L287 - L288 were not covered by tests
}

// With returns a new logger with the given keyvals added.
func (l *Logger) With(keyvals ...interface{}) *Logger {
l.mu.Lock()
Expand Down
7 changes: 7 additions & 0 deletions pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ import (
"os"
"sync"
"time"

"github.com/muesli/termenv"
)

var (
Expand Down Expand Up @@ -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)

Check warning on line 131 in pkg.go

View check run for this annotation

Codecov / codecov/patch

pkg.go#L130-L131

Added lines #L130 - L131 were not covered by tests
}

// GetPrefix returns the prefix for the default logger.
func GetPrefix() string {
return defaultLogger.GetPrefix()
Expand Down

0 comments on commit 7b5aa4f

Please sign in to comment.