Add addcustominfo command (#2012)
Co-authored-by: Joe Lim <50560759+joelim-work@users.noreply.github.com>
This commit is contained in:
1 parent
ff0c7f1c96
commit
17971fd66e
9 files changed
+269
-14
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
|
||||
"github.com/Xuanwo/go-locale"
|
||||
"github.com/mattn/go-runewidth"
|
||||
@@ -391,6 +392,37 @@ func deletePathRecursive[T any](m map[string]T, path string) {
|
||||
}
|
||||
}
|
||||
|
||||
// This function is used to remove style-related ANSI escape sequences from
|
||||
// a given string.
|
||||
//
|
||||
// *Note*: this function is based entirely on `printLength()` and strips only
|
||||
// style-related escape sequences and the `erase in line` sequence. Other codes
|
||||
// (e.g., cursor moves), as well as broken escape sequences, aren't removed.
|
||||
// This prevents mismatches between the two functions and avoids misalignment
|
||||
// when rendering the UI.
|
||||
func stripAnsi(s string) string {
|
||||
var b strings.Builder
|
||||
slen := len(s)
|
||||
for i := 0; i < slen; i++ {
|
||||
r, w := utf8.DecodeRuneInString(s[i:])
|
||||
|
||||
if r == gEscapeCode && i+1 < slen && s[i+1] == '[' {
|
||||
j := strings.IndexAny(s[i:min(slen, i+64)], "mK")
|
||||
if j == -1 {
|
||||
continue
|
||||
}
|
||||
|
||||
i += j
|
||||
continue
|
||||
}
|
||||
|
||||
i += w - 1
|
||||
b.WriteRune(r)
|
||||
}
|
||||
|
||||
return b.String()
|
||||
}
|
||||
|
||||
// We don't need no generic code
|
||||
// We don't need no type control
|
||||
// No dark templates in compiler
|
||||
|
||||
Reference in new issue
Block a user