Created
October 31, 2018 00:36
-
-
Save jaytaylor/da22e042be9253a148095fe47a664aa4 to your computer and use it in GitHub Desktop.
ANSI terminal color-codes cleaner for Go.
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
package main | |
import ( | |
"fmt" | |
"io/ioutil" | |
"regexp" | |
"github.com/spf13/cobra" | |
) | |
var ( | |
doClean bool | |
rootCmd = &cobra.Command{ | |
Use: "a-test-by-jay", | |
Short: "just a test", | |
Long: "just a test", | |
Args: cobra.MinimumNArgs(1), | |
Run: func(cmd *cobra.Command, args []string) { | |
expr := regexp.MustCompile(`\x1B\[[0-?]*[ -/]*[@-~]`) | |
data, err := ioutil.ReadFile(args[0]) | |
if err != nil { | |
panic(err) | |
} | |
if doClean { | |
data = expr.ReplaceAll(data, []byte{}) | |
} | |
fmt.Println(string(data)) | |
}, | |
} | |
) | |
func init() { | |
rootCmd.PersistentFlags().BoolVarP(&doClean, "clean", "c", false, "Activate regexp ANSI color cleaning") | |
} | |
func main() { | |
if err := rootCmd.Execute(); err != nil { | |
panic(err) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment