Skip to content

Commit

Permalink
fix: hide ansi pattern in utils behind a sync.Once like other regexps
Browse files Browse the repository at this point in the history
  • Loading branch information
carlmontanari committed Jul 27, 2023
1 parent e35f8e5 commit e29f46e
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions util/bytes.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,21 @@ package util
import (
"bytes"
"regexp"
"sync"
)

const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?" +
"\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))"

var ansiPattern *regexp.Regexp //nolint: gochecknoglobals
var (
ansiPattern *regexp.Regexp //nolint: gochecknoglobals
ansiPatternOnce sync.Once //nolint: gochecknoglobals
)

func getAnsiPattern() *regexp.Regexp {
if ansiPattern == nil {
ansiPatternOnce.Do(func() {
ansiPattern = regexp.MustCompile(ansi)
}
})

return ansiPattern
}
Expand Down

0 comments on commit e29f46e

Please sign in to comment.