Files
cli/pkg/utils/string_utils.go
zeekay 0c6bfc2498 Run gofmt to fix formatting issues
Fixed formatting in:
- cmd/blockchaincmd/export_test.go
- cmd/commands.go
- pkg/models/sidecar.go
- pkg/utils/string_utils.go
- tests/e2e/commands/blockchain.go
- tests/e2e/commands/subnet_sov.go
- tests/e2e/testcases/blockchain/convert/suite.go
- tests/e2e/utils/blockchain.go
- tests/e2e/utils/constants.go
- tests/e2e/utils/files.go
- tests/e2e/utils/ledger.go
- tests/e2e/utils/test_types_test.go
2025-10-02 08:37:34 +00:00

27 lines
781 B
Go

// Copyright (C) 2022-2025, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
package utils
import (
"regexp"
"strings"
)
// RemoveLineCleanChars removes ANSI escape codes and other terminal control characters from a string
// This is useful for cleaning up command output before pattern matching
func RemoveLineCleanChars(s string) string {
// Remove ANSI escape codes (color codes, cursor movements, etc.)
ansiRegex := regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
s = ansiRegex.ReplaceAllString(s, "")
// Remove carriage returns
s = strings.ReplaceAll(s, "\r", "")
// Remove other common control characters
controlRegex := regexp.MustCompile(`[\x00-\x08\x0B-\x0C\x0E-\x1F]`)
s = controlRegex.ReplaceAllString(s, "")
return s
}