summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2021-12-22 23:22:08 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2021-12-22 23:23:50 +0900
commitcd2340141100e057005d31e653c0ce7a0f7a4af7 (patch)
tree96a9644c95435daa633ddb241525e87e96020fc1 /src/util
parent176ee6910ffe40d9007ff9bc1b2720e3d729c48a (diff)
Fix rendering of the prompt line when overflow occurs with `--info=inline`
Fix #2692
Diffstat (limited to 'src/util')
-rw-r--r--src/util/util.go2
-rw-r--r--src/util/util_test.go16
2 files changed, 17 insertions, 1 deletions
diff --git a/src/util/util.go b/src/util/util.go
index c16f1af0..c3995bfd 100644
--- a/src/util/util.go
+++ b/src/util/util.go
@@ -26,7 +26,7 @@ func RunesWidth(runes []rune, prefixWidth int, tabstop int, limit int) (int, int
w = runewidth.StringWidth(s) + strings.Count(s, "\n")
}
width += w
- if limit > 0 && width > limit {
+ if width > limit {
return width, idx
}
idx += len(rs)
diff --git a/src/util/util_test.go b/src/util/util_test.go
index 4baa56fb..45a5a2d0 100644
--- a/src/util/util_test.go
+++ b/src/util/util_test.go
@@ -38,3 +38,19 @@ func TestOnce(t *testing.T) {
t.Error("Expected: false")
}
}
+
+func TestRunesWidth(t *testing.T) {
+ for _, args := range [][]int{
+ {100, 5, -1},
+ {3, 4, 3},
+ {0, 1, 0},
+ } {
+ width, overflowIdx := RunesWidth([]rune("hello"), 0, 0, args[0])
+ if width != args[1] {
+ t.Errorf("Expected width: %d, actual: %d", args[1], width)
+ }
+ if overflowIdx != args[2] {
+ t.Errorf("Expected overflow index: %d, actual: %d", args[2], overflowIdx)
+ }
+ }
+}