aboutsummaryrefslogtreecommitdiffstats
path: root/util/text/text.go
diff options
context:
space:
mode:
authorMichael Muré <batolettre@gmail.com>2018-12-23 19:00:51 +0100
committerMichael Muré <batolettre@gmail.com>2018-12-23 19:00:51 +0100
commitf9fc85ac825fec05a26d4029da15b33ae66e4e25 (patch)
tree9e807bf1435001b1763e77c851b6ca1f8b3398be /util/text/text.go
parent0d5bd6b18afde898e610746657a87080235f6222 (diff)
downloadgit-bug-f9fc85ac825fec05a26d4029da15b33ae66e4e25.tar.gz
text: hopefuly fix the handling of chinese
Diffstat (limited to 'util/text/text.go')
-rw-r--r--util/text/text.go17
1 files changed, 10 insertions, 7 deletions
diff --git a/util/text/text.go b/util/text/text.go
index 10b70b01..443728aa 100644
--- a/util/text/text.go
+++ b/util/text/text.go
@@ -98,6 +98,7 @@ func WrapLeftPadded(text string, lineWidth int, leftPad int) (string, int) {
return textBuffer.String(), nbLine
}
+// wordLen return the length of a word, while ignoring the terminal escape sequences
func wordLen(word string) int {
length := 0
escape := false
@@ -119,8 +120,10 @@ func wordLen(word string) int {
return length
}
+// splitWord split a word at the given length, while ignoring the terminal escape sequences
func splitWord(word string, length int) (string, string) {
- result := ""
+ runes := []rune(word)
+ var result []rune
added := 0
escape := false
@@ -128,12 +131,12 @@ func splitWord(word string, length int) (string, string) {
return "", word
}
- for _, char := range word {
- if char == '\x1b' {
+ for _, r := range runes {
+ if r == '\x1b' {
escape = true
}
- result += string(char)
+ result = append(result, r)
if !escape {
added++
@@ -142,14 +145,14 @@ func splitWord(word string, length int) (string, string) {
}
}
- if char == 'm' {
+ if r == 'm' {
escape = false
}
}
- leftover := word[len(result):]
+ leftover := runes[len(result):]
- return result, leftover
+ return string(result), string(leftover)
}
func minInt(a, b int) int {