summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2020-11-24 19:03:59 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2020-11-24 19:03:59 +0900
commit1efef88b6e853cdca86e3d83793f391102b1cc0f (patch)
tree378dff4389235d45ac0ffe3f7d3d2db96c2c6ac7
parent7acdaf0b4335a6c089bce5b73ff23aeb3b9d9c92 (diff)
Improve trim function to handle longer strings
Fix #2258
-rw-r--r--src/terminal.go12
1 files changed, 6 insertions, 6 deletions
diff --git a/src/terminal.go b/src/terminal.go
index 0a174822..a294f26d 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -656,8 +656,6 @@ func (t *Terminal) displayWidth(runes []rune) int {
const (
minWidth = 4
minHeight = 4
-
- maxDisplayWidthCalc = 1024
)
func calculateSize(base int, size sizeSpec, occupied int, minSize int, pad int) int {
@@ -1116,13 +1114,15 @@ func (t *Terminal) displayWidthWithLimit(runes []rune, prefixWidth int, limit in
}
func (t *Terminal) trimLeft(runes []rune, width int) ([]rune, int32) {
- if len(runes) > maxDisplayWidthCalc && len(runes) > width {
- trimmed := len(runes) - width
- return runes[trimmed:], int32(trimmed)
+ var trimmed int32
+ // Assume that each rune takes at least one column on screen
+ if len(runes) > width {
+ diff := len(runes) - width
+ trimmed = int32(diff)
+ runes = runes[diff:]
}
currentWidth := t.displayWidth(runes)
- var trimmed int32
for currentWidth > width && len(runes) > 0 {
runes = runes[1:]