aboutsummaryrefslogtreecommitdiffstats
path: root/util/text/left_padded.go
diff options
context:
space:
mode:
authorYang Zhang <yang_zhang@iapcm.ac.cn>2019-01-01 21:52:05 +0800
committerYang Zhang <yang_zhang@iapcm.ac.cn>2019-01-01 21:52:05 +0800
commit5cf7b19dcce89f847f6f6d62685abaeca2b63e1c (patch)
treebd3653b0485adc55d20c8a6cd6959657b047dd3a /util/text/left_padded.go
parente29188e6ff686897c296246baee54641d076825f (diff)
downloadgit-bug-5cf7b19dcce89f847f6f6d62685abaeca2b63e1c.tar.gz
Make runewidth treat ambiguous rune as short and fix ui display
Diffstat (limited to 'util/text/left_padded.go')
-rw-r--r--util/text/left_padded.go9
1 files changed, 8 insertions, 1 deletions
diff --git a/util/text/left_padded.go b/util/text/left_padded.go
index 24bd4d09..43e84966 100644
--- a/util/text/left_padded.go
+++ b/util/text/left_padded.go
@@ -7,6 +7,13 @@ import (
"strings"
)
+// Force runewidth not to treat ambiguous runes as wide chars, so that things
+// like unicode ellipsis/up/down/left/right glyphs can have correct runewidth
+// and can be displayed correctly in terminals.
+func init() {
+ runewidth.DefaultCondition.EastAsianWidth = false
+}
+
// LeftPadMaxLine pads a string on the left by a specified amount and pads the
// string on the right to fill the maxLength
func LeftPadMaxLine(text string, length, leftPad int) string {
@@ -15,7 +22,7 @@ func LeftPadMaxLine(text string, length, leftPad int) string {
scrWidth := runewidth.StringWidth(text)
// truncate and ellipse if needed
if scrWidth+leftPad > length {
- rightPart = runewidth.Truncate(text, length-leftPad, "...")
+ rightPart = runewidth.Truncate(text, length-leftPad, "…")
} else if scrWidth+leftPad < length {
rightPart = runewidth.FillRight(text, length-leftPad)
}