From e61682b24cbf947735531011e33f20a3c32d0b5a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Thu, 27 Oct 2022 17:16:39 +0200 Subject: [PATCH] Added termext.CleanString --- README.md | 2 +- termext/colors.go | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 75f7c7b..586ab92 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,6 @@ BFB goext library A collection of general & useful library methods -Every subfolder is a seperate dependency and can be imported individually +This should not have any heavy dependencies (gin, mongo, etc) and add missing basic language features... Potentially needs `export GOPRIVATE="gogs.mikescher.com"` \ No newline at end of file diff --git a/termext/colors.go b/termext/colors.go index 87dc61c..689b80b 100644 --- a/termext/colors.go +++ b/termext/colors.go @@ -1,5 +1,7 @@ package termext +import "strings" + const ( colorReset = "\033[0m" colorRed = "\033[31m" @@ -43,3 +45,17 @@ func Gray(v string) string { func White(v string) string { return colorWhite + v + colorReset } + +func CleanString(v string) string { + v = strings.ReplaceAll(v, colorReset, "") + v = strings.ReplaceAll(v, colorRed, "") + v = strings.ReplaceAll(v, colorGreen, "") + v = strings.ReplaceAll(v, colorYellow, "") + v = strings.ReplaceAll(v, colorBlue, "") + v = strings.ReplaceAll(v, colorPurple, "") + v = strings.ReplaceAll(v, colorCyan, "") + v = strings.ReplaceAll(v, colorGray, "") + v = strings.ReplaceAll(v, colorWhite, "") + + return v +}