Skip to content

Commit

Permalink
refactor: extract const
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Oct 31, 2024
1 parent 2ee40e6 commit 8a01e26
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion sgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"github.com/charmbracelet/x/ansi"
)

const maxInt32 = int(int32(^uint32(0) >> 1))

func handleSgr(parser *ansi.Parser) (string, error) { //nolint:unparam
var str string
if parser.ParamsLen == 0 {
Expand All @@ -15,7 +17,10 @@ func handleSgr(parser *ansi.Parser) (string, error) { //nolint:unparam
var comma bool
for i := 0; i < parser.ParamsLen; i++ {
param := ansi.Param(parser.Params[i])
if param.Param() == int(int32(^uint32(0)>>1)) {
// if the sequence has many `;` without any value, the parser will
// return get the max int32 as the param.
// we can safely ignore those.
if param.Param() == maxInt32 {
continue
}
if comma {
Expand Down

0 comments on commit 8a01e26

Please sign in to comment.