@@ -16,6 +16,11 @@ const (
16
16
EscapeStopRune = 'm'
17
17
)
18
18
19
+ // RuneWidth stuff
20
+ var (
21
+ rwCondition = runewidth .NewCondition ()
22
+ )
23
+
19
24
// InsertEveryN inserts the rune every N characters in the string. For ex.:
20
25
// InsertEveryN("Ghost", '-', 1) == "G-h-o-s-t"
21
26
// InsertEveryN("Ghost", '-', 2) == "Gh-os-t"
@@ -79,6 +84,23 @@ func LongestLineLen(str string) int {
79
84
return maxLength
80
85
}
81
86
87
+ // OverrideRuneWidthEastAsianWidth can *probably* help with alignment, and
88
+ // length calculation issues when dealing with Unicode character-set and a
89
+ // non-English language set in the LANG variable.
90
+ //
91
+ // Set this to 'false' to force the "runewidth" library to pretend to deal with
92
+ // English character-set. Be warned that if the text/content you are dealing
93
+ // with contains East Asian character-set, this may result in unexpected
94
+ // behavior.
95
+ //
96
+ // References:
97
+ // * https://github.com/mattn/go-runewidth/issues/64#issuecomment-1221642154
98
+ // * https://github.com/jedib0t/go-pretty/issues/220
99
+ // * https://github.com/jedib0t/go-pretty/issues/204
100
+ func OverrideRuneWidthEastAsianWidth (val bool ) {
101
+ rwCondition .EastAsianWidth = val
102
+ }
103
+
82
104
// Pad pads the given string with as many characters as needed to make it as
83
105
// long as specified (maxLen). This function does not count escape sequences
84
106
// while calculating length of the string. Ex.:
@@ -132,7 +154,7 @@ func RuneCount(str string) int {
132
154
// RuneWidth('︿') == 2
133
155
// RuneWidth(0x27) == 0
134
156
func RuneWidth (r rune ) int {
135
- return runewidth .RuneWidth (r )
157
+ return rwCondition .RuneWidth (r )
136
158
}
137
159
138
160
// RuneWidthWithoutEscSequences is similar to RuneWidth, except for the fact
0 commit comments