Skip to content

Commit

Permalink
chore(deps): replace shampoo with colorprofile
Browse files Browse the repository at this point in the history
  • Loading branch information
bashbunni committed Oct 10, 2024
1 parent 95e061c commit 47ce960
Show file tree
Hide file tree
Showing 13 changed files with 70 additions and 97 deletions.
6 changes: 3 additions & 3 deletions context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"testing"

"github.com/charmbracelet/shampoo"
"github.com/charmbracelet/colorprofile"
"github.com/stretchr/testify/require"
)

Expand All @@ -16,14 +16,14 @@ func TestLogContext_empty(t *testing.T) {
}

func TestLogContext_simple(t *testing.T) {
l := New(shampoo.NewWriter(io.Discard, os.Environ()))
l := New(colorprofile.NewWriter(io.Discard, os.Environ()))
ctx := WithContext(context.Background(), l)
require.Equal(t, l, FromContext(ctx))
}

func TestLogContext_fields(t *testing.T) {
var buf bytes.Buffer
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
l.SetLevel(DebugLevel)
ctx := WithContext(context.Background(), l.With("foo", "bar"))
l = FromContext(ctx)
Expand Down
18 changes: 5 additions & 13 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,29 +3,21 @@ module github.com/charmbracelet/log
go 1.19

require (
github.com/charmbracelet/lipgloss v0.12.2-0.20240722162534-2390dea254e8
github.com/charmbracelet/shampoo v0.0.0-20240807160433-2fdf07ab2f73
github.com/charmbracelet/colorprofile v0.1.1
github.com/charmbracelet/lipgloss v0.13.1-0.20240822211938-b89f1a3db2a4
github.com/go-logfmt/logfmt v0.6.0
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20231006140011-7918f672742d
)

require (
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
github.com/charmbracelet/x/ansi v0.1.5-0.20240807160011-7b9bd9980386 // indirect
github.com/charmbracelet/x/input v0.1.3 // indirect
github.com/charmbracelet/x/term v0.1.1 // indirect
github.com/charmbracelet/x/windows v0.1.2 // indirect
github.com/charmbracelet/x/ansi v0.3.2 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.16 // indirect
github.com/muesli/cancelreader v0.2.2 // indirect
github.com/muesli/termenv v0.15.2 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rivo/uniseg v0.4.7 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.23.0 // indirect
golang.org/x/sys v0.26.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
39 changes: 10 additions & 29 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,36 +1,19 @@
github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k=
github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8=
github.com/charmbracelet/lipgloss v0.12.2-0.20240722162534-2390dea254e8 h1:7SMpm8y17K515kM1Q/tiOrSm1jb3hJh94W+LXHWKv+U=
github.com/charmbracelet/lipgloss v0.12.2-0.20240722162534-2390dea254e8/go.mod h1:LCQCsVTQm+lcQLFSiHwSvQUqRXtry1v/2KCfKxdsCeY=
github.com/charmbracelet/shampoo v0.0.0-20240807160433-2fdf07ab2f73 h1:0jbSZZFsjfd8+wAbSX5IX5iTbam8moe81Jt9vpCnxL4=
github.com/charmbracelet/shampoo v0.0.0-20240807160433-2fdf07ab2f73/go.mod h1:McJMdgyoMSHqV0p+ejH4i0jaaK5SAYUp8EgRqUjLBxI=
github.com/charmbracelet/x/ansi v0.1.5-0.20240807160011-7b9bd9980386 h1:aOjzT+GwoykWSR1HiE4nFz+2HD+M7jKa5B3jl6BZhUo=
github.com/charmbracelet/x/ansi v0.1.5-0.20240807160011-7b9bd9980386/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/input v0.1.3 h1:oy4TMhyGQsYs/WWJwu1ELUMFnjiUAXwtDf048fHbCkg=
github.com/charmbracelet/x/input v0.1.3/go.mod h1:1gaCOyw1KI9e2j00j/BBZ4ErzRZqa05w0Ghn83yIhKU=
github.com/charmbracelet/x/term v0.1.1 h1:3cosVAiPOig+EV4X9U+3LDgtwwAoEzJjNdwbXDjF6yI=
github.com/charmbracelet/x/term v0.1.1/go.mod h1:wB1fHt5ECsu3mXYusyzcngVWWlu1KKUmmLhfgr/Flxw=
github.com/charmbracelet/x/windows v0.1.2 h1:Iumiwq2G+BRmgoayww/qfcvof7W/3uLoelhxojXlRWg=
github.com/charmbracelet/x/windows v0.1.2/go.mod h1:GLEO/l+lizvFDBPLIOk+49gdX49L9YWMB5t+DZd0jkQ=
github.com/charmbracelet/colorprofile v0.1.1 h1:YsvIsmZ2bazhejG+5g5MPPMpllc7Ks66Nk8l3IvGJ2g=
github.com/charmbracelet/colorprofile v0.1.1/go.mod h1:1htIKZYeI4TQs+OykPvpuBTUbUJxBYeSYBDIZuejMj0=
github.com/charmbracelet/lipgloss v0.13.1-0.20240822211938-b89f1a3db2a4 h1:BuZojjzjQ89wObGNVxJzFqyeh2S6Crbwhybb8bZNveI=
github.com/charmbracelet/lipgloss v0.13.1-0.20240822211938-b89f1a3db2a4/go.mod h1:ZbN5GVH/VrXHPRa1lZqZ1HWJyayJHJYaf9ywsCuI9zQ=
github.com/charmbracelet/x/ansi v0.3.2 h1:wsEwgAN+C9U06l9dCVMX0/L3x7ptvY1qmjMwyfE6USY=
github.com/charmbracelet/x/ansi v0.3.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/x/term v0.2.0 h1:cNB9Ot9q8I711MyZ7myUR5HFWL/lc3OpU8jZ4hwm0x0=
github.com/charmbracelet/x/term v0.2.0/go.mod h1:GVxgxAbjUrmpvIINHIQnJJKpMlHiZ4cktEQCN6GWyF0=
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=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4=
github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM=
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY=
github.com/lucasb-eyer/go-colorful v1.2.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0=
github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc=
github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELUXHmA=
github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo=
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand All @@ -39,10 +22,8 @@ github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavM
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.23.0 h1:YfKFowiIMvtgl1UERQoTPPToxltDeZfbj4H7dVUCwmM=
golang.org/x/sys v0.23.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
Expand Down
12 changes: 6 additions & 6 deletions json_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"runtime"
"testing"

"github.com/charmbracelet/shampoo"
"github.com/charmbracelet/colorprofile"
"github.com/stretchr/testify/require"
)

func TestJson(t *testing.T) {
var buf bytes.Buffer
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
l.SetFormatter(JSONFormatter)
cases := []struct {
name string
Expand Down Expand Up @@ -127,7 +127,7 @@ func TestJson(t *testing.T) {

func TestJsonCaller(t *testing.T) {
var buf bytes.Buffer
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
l.SetFormatter(JSONFormatter)
l.SetReportCaller(true)
l.SetLevel(DebugLevel)
Expand Down Expand Up @@ -169,7 +169,7 @@ func TestJsonCaller(t *testing.T) {

func TestJsonTime(t *testing.T) {
var buf bytes.Buffer
logger := New(shampoo.NewWriter(&buf, os.Environ()))
logger := New(colorprofile.NewWriter(&buf, os.Environ()))
logger.SetTimeFunction(_zeroTime)
logger.SetFormatter(JSONFormatter)
logger.SetReportTimestamp(true)
Expand All @@ -179,7 +179,7 @@ func TestJsonTime(t *testing.T) {

func TestJsonPrefix(t *testing.T) {
var buf bytes.Buffer
logger := New(shampoo.NewWriter(&buf, os.Environ()))
logger := New(colorprofile.NewWriter(&buf, os.Environ()))
logger.SetFormatter(JSONFormatter)
logger.SetPrefix("my-prefix")
logger.Info("info")
Expand All @@ -193,7 +193,7 @@ func TestJsonCustomKey(t *testing.T) {
TimestampKey = oldTsKey
}()
TimestampKey = "other-time"
logger := New(shampoo.NewWriter(&buf, os.Environ()))
logger := New(colorprofile.NewWriter(&buf, os.Environ()))
logger.SetTimeFunction(_zeroTime)
logger.SetFormatter(JSONFormatter)
logger.SetReportTimestamp(true)
Expand Down
4 changes: 2 additions & 2 deletions logfmt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import (
"os"
"testing"

"github.com/charmbracelet/shampoo"
"github.com/charmbracelet/colorprofile"
"github.com/stretchr/testify/assert"
)

func TestLogfmt(t *testing.T) {
var buf bytes.Buffer
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
l.SetFormatter(LogfmtFormatter)
cases := []struct {
name string
Expand Down
6 changes: 3 additions & 3 deletions logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (l *Logger) handle(level Level, ts time.Time, frames []runtime.Frame, msg i
if _, err := l.b.WriteTo(l.w); err != nil {
if errors.Is(err, io.ErrShortWrite) {
// Reset the buffer even if the lengths don't match up. If we're
// using shampoo's Writer, it will strip the ansi sequences based on
// using colorprofile's Writer, it will strip the ansi sequences based on
// the color profile which can cause this error.
l.b.Reset()
}
Expand Down Expand Up @@ -285,10 +285,10 @@ func (l *Logger) SetOutput(w io.Writer) {
// Reuse cached renderers
// TODO is this still relevant?
// if v, ok := registry.Load(w); ok {
// l.re = v.(*shampoo.Writer)
// l.re = v.(*colorprofile.Writer)
// } else {
// // TODO calculate background color (termenv.colorcache used to do this)
// l.re = shampoo.NewWriter(w, os.Environ())
// l.re = colorprofile.NewWriter(w, os.Environ())
// registry.Store(w, l.re)
// }
}
Expand Down
8 changes: 4 additions & 4 deletions logger_121_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import (
"testing"
"time"

"github.com/charmbracelet/shampoo"
"github.com/charmbracelet/colorprofile"
"github.com/stretchr/testify/assert"
)

func TestSlogSimple(t *testing.T) {
var buf bytes.Buffer
h := New(shampoo.NewWriter(&buf, os.Environ()))
h := New(colorprofile.NewWriter(&buf, os.Environ()))
h.SetLevel(DebugLevel)
l := slog.New(h)
cases := []struct {
Expand Down Expand Up @@ -75,7 +75,7 @@ func TestSlogSimple(t *testing.T) {

func TestSlogWith(t *testing.T) {
var buf bytes.Buffer
h := New(shampoo.NewWriter(&buf, os.Environ()))
h := New(colorprofile.NewWriter(&buf, os.Environ()))
h.SetLevel(DebugLevel)
l := slog.New(h).With("a", "b")
cases := []struct {
Expand Down Expand Up @@ -126,7 +126,7 @@ func TestSlogWith(t *testing.T) {

func TestSlogWithGroup(t *testing.T) {
var buf bytes.Buffer
h := New(shampoo.NewWriter(&buf, os.Environ()))
h := New(colorprofile.NewWriter(&buf, os.Environ()))
l := slog.New(h).WithGroup("charm").WithGroup("bracelet")
cases := []struct {
name string
Expand Down
12 changes: 6 additions & 6 deletions logger_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import (
"testing"
"time"

"github.com/charmbracelet/shampoo"
"github.com/charmbracelet/colorprofile"
"github.com/stretchr/testify/assert"
)

func TestSubLogger(t *testing.T) {
var buf bytes.Buffer
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
cases := []struct {
name string
expected string
Expand Down Expand Up @@ -82,7 +82,7 @@ func TestWrongLevel(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
buf.Reset()
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
l.SetLevel(c.level)
l.Info("info")
assert.Equal(t, c.expected, buf.String())
Expand All @@ -92,7 +92,7 @@ func TestWrongLevel(t *testing.T) {

func TestLogFormatter(t *testing.T) {
var buf bytes.Buffer
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
l.SetLevel(DebugLevel)
cases := []struct {
name string
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestLogFormatter(t *testing.T) {

func TestEmptyMessage(t *testing.T) {
var buf bytes.Buffer
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
cases := []struct {
name string
expected string
Expand Down Expand Up @@ -198,7 +198,7 @@ func TestLogWithPrefix(t *testing.T) {
for _, c := range cases {
t.Run(c.name, func(t *testing.T) {
buf.Reset()
l := New(shampoo.NewWriter(&buf, os.Environ()))
l := New(colorprofile.NewWriter(&buf, os.Environ()))
l.SetPrefix(c.prefix)
l.Info(c.msg)
assert.Equal(t, c.expected, buf.String())
Expand Down
6 changes: 3 additions & 3 deletions options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"os"
"testing"

"github.com/charmbracelet/shampoo"
"github.com/charmbracelet/colorprofile"
"github.com/stretchr/testify/require"
)

Expand All @@ -17,7 +17,7 @@ func TestOptions(t *testing.T) {
ReportCaller: true,
Fields: []interface{}{"foo", "bar"},
}
logger := NewWithOptions(shampoo.NewWriter(io.Discard, os.Environ()), opts)
logger := NewWithOptions(colorprofile.NewWriter(io.Discard, os.Environ()), opts)
require.Equal(t, ErrorLevel, logger.GetLevel())
require.True(t, logger.reportCaller)
require.False(t, logger.reportTimestamp)
Expand All @@ -29,7 +29,7 @@ func TestOptions(t *testing.T) {

func TestCallerFormatter(t *testing.T) {
var buf bytes.Buffer
l := NewWithOptions(shampoo.NewWriter(&buf, os.Environ()), Options{ReportCaller: true})
l := NewWithOptions(colorprofile.NewWriter(&buf, os.Environ()), Options{ReportCaller: true})
frames := l.frames(0)
frame, _ := frames.Next()
file, line, fn := frame.File, frame.Line, frame.Function
Expand Down
2 changes: 1 addition & 1 deletion pkg.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func SetPrefix(prefix string) {
// TODO
// SetColorProfile force sets the underlying Lip Gloss renderer color profile
// for the TextFormatter.
// func SetColorProfile(profile shampoo.Profile) {
// func SetColorProfile(profile colorprofile.Profile) {
// Default().SetColorProfile(profile)
// }

Expand Down
Loading

0 comments on commit 47ce960

Please sign in to comment.