summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJesse Duffield Duffield <jesseduffieldduffield@Jesses-MacBook-Pro-3.local>2019-02-24 17:05:17 +1100
committerJesse Duffield Duffield <jesseduffieldduffield@Jesses-MacBook-Pro-3.local>2019-02-24 17:05:17 +1100
commit639df512f3c7cb97ba7a4ab904f52457617384d0 (patch)
tree26f3d2f460f113f34887a0d6656084d75ba87833
parenta8858cbd12bd2ef5766f2436a7d43e4ff1c4ca9f (diff)
decolorise strings before calculating padwidths
-rw-r--r--pkg/utils/utils.go11
1 files changed, 9 insertions, 2 deletions
diff --git a/pkg/utils/utils.go b/pkg/utils/utils.go
index 417823b84..b704c2576 100644
--- a/pkg/utils/utils.go
+++ b/pkg/utils/utils.go
@@ -7,6 +7,7 @@ import (
"os"
"path/filepath"
"reflect"
+ "regexp"
"strings"
"time"
@@ -159,6 +160,11 @@ func renderDisplayableList(items []Displayable, isFocused bool) (string, error)
return strings.Join(paddedDisplayStrings, "\n"), nil
}
+func decolorise(str string) string {
+ re := regexp.MustCompile(`\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]`)
+ return re.ReplaceAllString(str, "")
+}
+
func getPadWidths(stringArrays [][]string) []int {
if len(stringArrays[0]) <= 1 {
return []int{}
@@ -166,8 +172,9 @@ func getPadWidths(stringArrays [][]string) []int {
padWidths := make([]int, len(stringArrays[0])-1)
for i := range padWidths {
for _, strings := range stringArrays {
- if len(strings[i]) > padWidths[i] {
- padWidths[i] = len(strings[i])
+ uncoloredString := decolorise(strings[i])
+ if len(uncoloredString) > padWidths[i] {
+ padWidths[i] = len(uncoloredString)
}
}
}