From 0d571ca1d154222f8f8d9515054ed2cbb4f40fac Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 14 Nov 2024 20:25:39 -0500 Subject: [PATCH] chore: update dependencies --- go.mod | 2 +- go.sum | 4 ++-- writer.go | 25 +++++++++++++------------ 3 files changed, 16 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index dc3f6f3..ed9ff5c 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/charmbracelet/colorprofile go 1.18 require ( - github.com/charmbracelet/x/ansi v0.4.6-0.20241114164159-aea15a2cc929 + github.com/charmbracelet/x/ansi v0.5.0 github.com/charmbracelet/x/term v0.2.1 github.com/lucasb-eyer/go-colorful v1.2.0 github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e diff --git a/go.sum b/go.sum index 82c8ce7..36d55bc 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/charmbracelet/x/ansi v0.4.6-0.20241114164159-aea15a2cc929 h1:CxDzlAZwEEcq5DNjRlx+RQ0acLKBg/J5ZmvW+db9kAc= -github.com/charmbracelet/x/ansi v0.4.6-0.20241114164159-aea15a2cc929/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= +github.com/charmbracelet/x/ansi v0.5.0 h1:o94cKkWJRaiNQYbfz5WOLrbg9hULaryyKvWm+oLX7js= +github.com/charmbracelet/x/ansi v0.5.0/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw= github.com/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ= github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg= github.com/lucasb-eyer/go-colorful v1.2.0 h1:1nnpGOrhyZZuNyfu1QjKiUICQ74+3FNCN69Aj6K7nkY= diff --git a/writer.go b/writer.go index 7d0c76f..e15bbdd 100644 --- a/writer.go +++ b/writer.go @@ -58,7 +58,7 @@ func (w *Writer) downsample(p []byte) (int, error) { seq, _, read, newState := ansi.DecodeSequence(p, state, parser) switch { - case ansi.HasCsiPrefix(seq) && parser.Cmd == 'm': + case ansi.HasCsiPrefix(seq) && parser.Cmd() == 'm': handleSgr(w, parser, &buf) default: // If we're not a style SGR sequence, just write the bytes. @@ -81,8 +81,9 @@ func (w *Writer) WriteString(s string) (n int, err error) { func handleSgr(w *Writer, p *ansi.Parser, buf *bytes.Buffer) { var style ansi.Style - for i := 0; i < p.ParamsLen; i++ { - param := ansi.Parameter(p.Params[i]) + params := p.Params() + for i := 0; i < len(params); i++ { + param := params[i] switch param := param.Param(0); param { case 0: @@ -96,7 +97,7 @@ func handleSgr(w *Writer, p *ansi.Parser, buf *bytes.Buffer) { style = style.ForegroundColor( w.Profile.Convert(ansi.BasicColor(param - 30))) //nolint:gosec case 38: // 16 or 24-bit foreground color - c := readColor(&i, p.Params) + c := readColor(&i, params) if w.Profile > ANSI { continue } @@ -113,7 +114,7 @@ func handleSgr(w *Writer, p *ansi.Parser, buf *bytes.Buffer) { style = style.BackgroundColor( w.Profile.Convert(ansi.BasicColor(param - 40))) //nolint:gosec case 48: // 16 or 24-bit background color - c := readColor(&i, p.Params) + c := readColor(&i, params) if w.Profile > ANSI { continue } @@ -124,7 +125,7 @@ func handleSgr(w *Writer, p *ansi.Parser, buf *bytes.Buffer) { } style = style.DefaultBackgroundColor() case 58: // 16 or 24-bit underline color - c := readColor(&i, p.Params) + c := readColor(&i, params) if w.Profile > ANSI { continue } @@ -155,22 +156,22 @@ func handleSgr(w *Writer, p *ansi.Parser, buf *bytes.Buffer) { _, _ = buf.WriteString(style.String()) } -func readColor(idxp *int, params []int) (c ansi.Color) { +func readColor(idxp *int, params []ansi.Parameter) (c ansi.Color) { i := *idxp paramsLen := len(params) if i > paramsLen-1 { return } // Note: we accept both main and subparams here - switch param := ansi.Parameter(params[i+1]); param.Param(0) { + switch param := params[i+1]; param.Param(0) { case 2: // RGB if i > paramsLen-4 { return } c = color.RGBA{ - R: uint8(ansi.Parameter(params[i+2]).Param(0)), //nolint:gosec - G: uint8(ansi.Parameter(params[i+3]).Param(0)), //nolint:gosec - B: uint8(ansi.Parameter(params[i+4]).Param(0)), //nolint:gosec + R: uint8(params[i+2].Param(0)), //nolint:gosec + G: uint8(params[i+3].Param(0)), //nolint:gosec + B: uint8(params[i+4].Param(0)), //nolint:gosec A: 0xff, } *idxp += 4 @@ -178,7 +179,7 @@ func readColor(idxp *int, params []int) (c ansi.Color) { if i > paramsLen-2 { return } - c = ansi.ExtendedColor(ansi.Parameter(params[i+2]).Param(0)) //nolint:gosec + c = ansi.ExtendedColor(params[i+2].Param(0)) //nolint:gosec *idxp += 2 } return