From c3bcf40e435f94eea9375bf35e76c536c6d431d7 Mon Sep 17 00:00:00 2001 From: xdrm-brackets Date: Sat, 7 Jul 2018 14:27:48 +0200 Subject: [PATCH] fix align for format characters --- clifmt/symbols.go | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/clifmt/symbols.go b/clifmt/symbols.go index d4d539d..f7369a1 100644 --- a/clifmt/symbols.go +++ b/clifmt/symbols.go @@ -2,6 +2,7 @@ package clifmt import ( "fmt" + "strings" ) var title_index = 0 @@ -29,8 +30,21 @@ func Title(s string) { } func Align(s string) { + + // 1. print string fmt.Printf("%s", s) - for i := len(s); i < align_offset; i++ { + + // 2. get actual size + size := len(s) + + // 3. remove \033[XYm format characters + size -= (len(strings.Split(s, "\033")) - 0) * 6 + + // 3. add 1 char for each \033[0m + size += len(strings.Split(s, "\033[0m")) - 1 + + // 4. print trailing spaces + for i := size; i < align_offset; i++ { fmt.Printf(" ") } }