An open API service indexing awesome lists of open source software.

https://github.com/jimschubert/stripansi

Strip ansi escape codes, ala chalk/strip-ansi
https://github.com/jimschubert/stripansi

go golang

Last synced: 20 days ago
JSON representation

Strip ansi escape codes, ala chalk/strip-ansi

Awesome Lists containing this project

README

          

# stripansi

[![GoDoc](https://godoc.org/github.com/jimschubert/stripansi?status.svg)](https://godoc.org/github.com/jimschubert/stripansi)

This is a port of Sindre Sorhus's excellent [chalk/strip-ansi](https://github.com/chalk/strip-ansi) to Go.

It's useful for stripping ANSI escape codes from strings or byte slices, which is often necessary when processing CLI output for logs, tests, or other text-based tools.

## Install

```
$ go get -u github.com/jimschubert/stripansi
```

## Usage

### Strings

```go
package main

import (
"fmt"
"github.com/jimschubert/stripansi"
)

func main() {
result := stripansi.String("\x1b[30mfoo\x1b[0m \x1b[30mbar\x1b[0m \x1b[30mbaz\x1b[0m")
fmt.Println(result)
// Output: foo bar baz
}
```

### Bytes

```go
package main

import (
"fmt"
"github.com/jimschubert/stripansi"
)

func main() {
result := stripansi.Bytes([]byte("\x1b[30mfoo\x1b[0m"))
fmt.Printf("%s\n", result)
// Output: foo
}
```

## License

This is [licensed](./LICENSE) under MIT.