Skip to content

Commit

Permalink
chore: update dependencies and fix ansi.Parser usage
Browse files Browse the repository at this point in the history
  • Loading branch information
aymanbagabas committed Nov 21, 2024
1 parent 092d626 commit 47799c7
Show file tree
Hide file tree
Showing 18 changed files with 99 additions and 93 deletions.
2 changes: 1 addition & 1 deletion clipboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var clipboardName = map[string]string{

//nolint:mnd
func handleClipboard(p *ansi.Parser) (string, error) {
parts := bytes.Split(p.Data[:p.DataLen], []byte{';'})
parts := bytes.Split(p.Data(), []byte{';'})
if len(parts) != 3 {
// Invalid, ignore
return "", errInvalid
Expand Down
8 changes: 4 additions & 4 deletions color.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (

//nolint:mnd
func handleTerminalColor(p *ansi.Parser) (string, error) {
parts := bytes.Split(p.Data[:p.DataLen], []byte{';'})
parts := bytes.Split(p.Data(), []byte{';'})
if len(parts) != 2 {
// Invalid, ignore
return "", errInvalid
Expand All @@ -22,7 +22,7 @@ func handleTerminalColor(p *ansi.Parser) (string, error) {
} else {
buf += "Set"
}
switch p.Cmd {
switch p.Cmd() {
case 10:
buf += " foreground color"
case 11:
Expand All @@ -38,13 +38,13 @@ func handleTerminalColor(p *ansi.Parser) (string, error) {

//nolint:mnd
func handleResetTerminalColor(p *ansi.Parser) (string, error) {
parts := bytes.Split(p.Data[:p.DataLen], []byte{';'})
parts := bytes.Split(p.Data(), []byte{';'})
if len(parts) != 1 {
// Invalid, ignore
return "", errInvalid
}
var buf string
switch p.Cmd {
switch p.Cmd() {
case 110:
buf += "Reset foreground color"
case 111:
Expand Down
20 changes: 11 additions & 9 deletions cursor.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

//nolint:mnd
func handleCursor(p *ansi.Parser) (string, error) {
var count int
if p.ParamsLen > 0 {
count = ansi.Param(p.Params[0]).Param()
count := 1
if n, ok := p.Param(0, 1); ok && n > 0 {
count = n
}

cmd := ansi.Cmd(p.Cmd)
cmd := p.Cmd()
isPrivate := cmd.Marker() == '?'
switch cmd.Command() {
case 'A':
Expand All @@ -33,10 +33,12 @@ func handleCursor(p *ansi.Parser) (string, error) {
case 'F':
return fmt.Sprintf("Cursor previous line %d", default1(count)), nil
case 'H':
row := default1(count)
col := 1
if p.ParamsLen > 1 {
col = p.Params[1]
row, col := 1, 1
if n, ok := p.Param(0, 1); ok && n > 0 {
row = n
}
if n, ok := p.Param(1, 1); ok && n > 0 {
col = n
}
return fmt.Sprintf("Set cursor position row=%[1]d col=%[2]d", row, col), nil
case 'n':
Expand All @@ -52,7 +54,7 @@ func handleCursor(p *ansi.Parser) (string, error) {
case 'u':
return "Restore cursor position", nil
case 'q':
return fmt.Sprintf("Set cursor style %s", descCursorStyle(default1(count))), nil
return fmt.Sprintf("Set cursor style %s", descCursorStyle(count)), nil
}
return "", errUnhandled
}
Expand Down
10 changes: 5 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ module github.com/charmbracelet/sequin
go 1.22.8

require (
github.com/charmbracelet/colorprofile v0.1.7
github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241119154431-6bbc36c3d376
github.com/charmbracelet/x/ansi v0.4.6-0.20241113152101-0af7d04e9f32
github.com/charmbracelet/colorprofile v0.1.8
github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241121164047-8448a9be4804
github.com/charmbracelet/x/ansi v0.5.1
github.com/charmbracelet/x/exp/golden v0.0.0-20241029204245-3ef5e7b1ea37
github.com/spf13/cobra v1.8.1
github.com/stretchr/testify v1.9.0
)

require (
github.com/aymanbagabas/go-udiff v0.2.0 // indirect
github.com/charmbracelet/x/term v0.2.0 // indirect
github.com/charmbracelet/x/term v0.2.1 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
Expand All @@ -22,6 +22,6 @@ require (
github.com/rivo/uniseg v0.4.7 // indirect
github.com/spf13/pflag v1.0.5 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
golang.org/x/sys v0.26.0 // indirect
golang.org/x/sys v0.27.0 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
20 changes: 10 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
github.com/aymanbagabas/go-udiff v0.2.0 h1:TK0fH4MteXUDspT88n8CKzvK0X9O2xu9yQjWpi6yML8=
github.com/aymanbagabas/go-udiff v0.2.0/go.mod h1:RE4Ex0qsGkTAJoQdQQCA0uG+nAzJO/pI/QwceO5fgrA=
github.com/charmbracelet/colorprofile v0.1.7 h1:q7PtMQrRBBnLNE2EbtbNUtouu979EivKcDGGaimhyO8=
github.com/charmbracelet/colorprofile v0.1.7/go.mod h1:d3UYToTrNmsD2p9/lbiya16H1WahndM0miDlJWXWf4U=
github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241119154431-6bbc36c3d376 h1:/wHpqHoZa8qAa+dtinZ4dz+oXN39VhC+H6RwjZ1KqNc=
github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241119154431-6bbc36c3d376/go.mod h1:72/7KVsLdRldv/CeBjZx6igXIZ9CFtBzQUmDEbhXZ3w=
github.com/charmbracelet/x/ansi v0.4.6-0.20241113152101-0af7d04e9f32 h1:XLFwv4JzkxkNDTejgtfnRthyA78DEtkK8TyudbFeheY=
github.com/charmbracelet/x/ansi v0.4.6-0.20241113152101-0af7d04e9f32/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
github.com/charmbracelet/colorprofile v0.1.8 h1:PywDeXsiAzlPtkiiKgMEVLvb6nlEuKrMj9+FJBtj4jU=
github.com/charmbracelet/colorprofile v0.1.8/go.mod h1:+jpmObxZl1Dab3H3IMVIPSZTsKcFpjJUv97G0dLqM60=
github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241121164047-8448a9be4804 h1:7CYjb9YMZA4kMhLgGdtlXvq+nu1oyENpMyMQlTvqSFw=
github.com/charmbracelet/lipgloss/v2 v2.0.0-alpha.2.0.20241121164047-8448a9be4804/go.mod h1:F/6E/LGdH3eHCJf2rG8/O3CjlW8cZFL5YJCknJs1GkI=
github.com/charmbracelet/x/ansi v0.5.1 h1:+mg6abP9skvsu/JQZrIJ9Z/4O1YDnLVkpfutar3dUnc=
github.com/charmbracelet/x/ansi v0.5.1/go.mod h1:KBUFw1la39nl0dLl10l5ORDAqGXaeurTQmwyyVKse/Q=
github.com/charmbracelet/x/exp/golden v0.0.0-20241029204245-3ef5e7b1ea37 h1:M35mkGiCDUvhWatGqs9L4RqBzJVi+F0W+QkpiePH0QI=
github.com/charmbracelet/x/exp/golden v0.0.0-20241029204245-3ef5e7b1ea37/go.mod h1:wDlXFlCrmJ8J+swcL/MnGUuYnqgQdW9rhSD61oNMb6U=
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/charmbracelet/x/term v0.2.1 h1:AQeHeLZ1OqSXhrAWpYUtZyX1T3zVxfpZuEQMIQaGIAQ=
github.com/charmbracelet/x/term v0.2.1/go.mod h1:oQ4enTYFV7QN4m0i9mzHrViD7TQKvNEEkHUMCmsxdUg=
github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
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 All @@ -34,8 +34,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.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/sys v0.27.0 h1:wBqf8DvsY9Y/2P8gAfPDEYNuS30J4lPHJxXSb/nJZ+s=
golang.org/x/sys v0.27.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
2 changes: 1 addition & 1 deletion hyperlink.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

//nolint:mnd
func handleHyperlink(p *ansi.Parser) (string, error) {
parts := bytes.Split(p.Data[:p.DataLen], []byte{';'})
parts := bytes.Split(p.Data(), []byte{';'})
if len(parts) != 3 {
// Invalid, ignore
return "", errInvalid
Expand Down
13 changes: 6 additions & 7 deletions kitty.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
)

//nolint:mnd
func handleKitty(parser *ansi.Parser) (string, error) {
func handleKitty(p *ansi.Parser) (string, error) {
flagDesc := func(flag int) string {
var r []string
if flag&1 != 0 {
Expand Down Expand Up @@ -42,11 +42,11 @@ func handleKitty(parser *ansi.Parser) (string, error) {
}

var first int
if parser.ParamsLen > 0 {
first = ansi.Param(parser.Params[0]).Param()
if n, ok := p.Param(0, 0); ok {
first = n
}

cmd := ansi.Cmd(parser.Cmd)
cmd := p.Cmd()
switch cmd.Marker() {
case '?':
return "Request Kitty keyboard", nil
Expand All @@ -58,9 +58,8 @@ func handleKitty(parser *ansi.Parser) (string, error) {
case '<':
return fmt.Sprintf("Pop %d Kitty keyboard flags", first), nil
case '=':
if parser.ParamsLen > 1 {
second := ansi.Param(parser.Params[1]).Param()
return fmt.Sprintf("Set %q Kitty keyboard flags to %q", flagDesc(first), modeDesc(second)), nil
if n, ok := p.Param(1, 0); ok {
return fmt.Sprintf("Set %q Kitty keyboard flags to %q", flagDesc(first), modeDesc(n)), nil
}
}
return "", errUnhandled
Expand Down
9 changes: 4 additions & 5 deletions line.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,13 @@ import (
)

//nolint:mnd
func handleLine(parser *ansi.Parser) (string, error) {
func handleLine(p *ansi.Parser) (string, error) {
var count int
if parser.ParamsLen > 0 {
count = ansi.Param(parser.Params[0]).Param()
if n, ok := p.Param(0, 0); ok {
count = n
}

cmd := ansi.Cmd(parser.Cmd)
switch cmd.Command() {
switch p.Cmd() {
case 'K':
switch count {
case 0:
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ func exec(w *colorprofile.Writer, in []byte) error {
return
}

handler, ok := reg[p.Cmd]
handler, ok := reg[int(p.Cmd())]
if !ok {
_, _ = fmt.Fprintln(w, errStyle.Render(errUnhandled.Error()))
return
Expand Down Expand Up @@ -205,7 +205,7 @@ func exec(w *colorprofile.Writer, in []byte) error {
seqPrint("APC", seq)

switch {
case ansi.HasPrefix(p.Data, []byte("G")):
case ansi.HasPrefix(p.Data(), []byte("G")):
// TODO: Kitty graphics
}

Expand Down
6 changes: 3 additions & 3 deletions main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ var cursor = map[string]string{
// cursor
"save": ansi.SaveCursor,
"restore": ansi.RestoreCursor,
"request pos": ansi.CursorPositionReport,
"request extended pos": ansi.ExtendedCursorPosition,
"invalid request extended pos": strings.Replace(ansi.ExtendedCursorPosition, "6", "7", 1),
"request pos": ansi.RequestCursorPosition,
"request extended pos": ansi.RequestExtendedCursorPosition,
"invalid request extended pos": strings.Replace(ansi.RequestExtendedCursorPosition, "6", "7", 1),
"up 1": ansi.CursorUp1,
"up": ansi.CursorUp(5),
"down 1": ansi.CursorDown1,
Expand Down
10 changes: 7 additions & 3 deletions mode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,13 @@ import (
"github.com/charmbracelet/x/ansi"
)

func handleMode(parser *ansi.Parser) (string, error) {
mode := modeDesc(ansi.Param(parser.Params[0]).Param())
cmd := ansi.Cmd(parser.Cmd)
func handleMode(p *ansi.Parser) (string, error) {
var m int
if n, ok := p.Param(0, 0); ok {
m = n
}
mode := modeDesc(m)
cmd := p.Cmd()
private := ""
if cmd.Marker() == '?' {
private = "private "
Expand Down
2 changes: 1 addition & 1 deletion notify.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

//nolint:mnd
func handleNotify(p *ansi.Parser) (string, error) {
parts := bytes.Split(p.Data[:p.DataLen], []byte{';'})
parts := bytes.Split(p.Data(), []byte{';'})
if len(parts) != 2 {
// Invalid, ignore
return "", errInvalid
Expand Down
2 changes: 1 addition & 1 deletion pointer.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import (

//nolint:mnd
func handlePointerShape(p *ansi.Parser) (string, error) {
parts := bytes.Split(p.Data[:p.DataLen], []byte{';'})
parts := bytes.Split(p.Data(), []byte{';'})
if len(parts) != 2 {
// Invalid, ignore
return "", errInvalid
Expand Down
20 changes: 11 additions & 9 deletions screen.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ import (
)

//nolint:mnd
func handleScreen(parser *ansi.Parser) (string, error) {
func handleScreen(p *ansi.Parser) (string, error) {
var count int
if parser.ParamsLen > 0 {
count = ansi.Param(parser.Params[0]).Param()
if n, ok := p.Param(0, 0); ok {
count = n
}

cmd := ansi.Cmd(parser.Cmd)
cmd := p.Cmd()
switch cmd.Command() {
case 'J':
switch count {
Expand All @@ -27,15 +27,17 @@ func handleScreen(parser *ansi.Parser) (string, error) {
return "Erase entire display", nil
}
case 'r':
top := count
bottom := 0
if parser.ParamsLen > 1 {
bottom = ansi.Param(parser.Params[1]).Param()
top, bot := 1, 0
if n, ok := p.Param(0, 1); ok {
top = n
}
if n, ok := p.Param(1, 0); ok {
bot = n
}
return fmt.Sprintf(
"Set scrolling region to top=%d bottom=%d",
top,
bottom,
bot,
), nil
}

Expand Down
Loading

0 comments on commit 47799c7

Please sign in to comment.