-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from ksckaan1/decolorize-log-file-output
Decolorize log file output
- Loading branch information
Showing
2 changed files
with
27 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package project | ||
|
||
import ( | ||
"io" | ||
"regexp" | ||
) | ||
|
||
type decolorizer struct { | ||
w io.Writer | ||
} | ||
|
||
func (d *decolorizer) Write(p []byte) (n int, err error) { | ||
decolorized := rgxANSI.ReplaceAll(p, nil) | ||
_, err = d.w.Write(decolorized) | ||
if err != nil { | ||
return 0, err | ||
} | ||
return len(p), nil | ||
} | ||
|
||
const ansi = "[\u001B\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))" | ||
|
||
var rgxANSI = regexp.MustCompile(ansi) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters