summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJunegunn Choi <junegunn.c@gmail.com>2017-02-18 23:17:29 +0900
committerJunegunn Choi <junegunn.c@gmail.com>2017-02-18 23:17:29 +0900
commit309e1d8619f5a31eec797ab93c89702bb2c71f78 (patch)
tree85e58a79128983ef054339c5a0cba50fcdaddd02 /src
parentc2db67c1c086f0bbebf4802abb3fb9335ee46662 (diff)
Properly truncate long query string
Diffstat (limited to 'src')
-rw-r--r--src/constants.go7
-rw-r--r--src/terminal.go26
2 files changed, 22 insertions, 11 deletions
diff --git a/src/constants.go b/src/constants.go
index d5246db6..cf91ce51 100644
--- a/src/constants.go
+++ b/src/constants.go
@@ -18,10 +18,9 @@ const (
readerBufferSize = 64 * 1024
// Terminal
- initialDelay = 20 * time.Millisecond
- initialDelayTac = 100 * time.Millisecond
- spinnerDuration = 200 * time.Millisecond
- maxPatternLength = 100
+ initialDelay = 20 * time.Millisecond
+ initialDelayTac = 100 * time.Millisecond
+ spinnerDuration = 200 * time.Millisecond
// Matcher
numPartitionsMultiplier = 8
diff --git a/src/terminal.go b/src/terminal.go
index 5853022a..f75480e6 100644
--- a/src/terminal.go
+++ b/src/terminal.go
@@ -603,6 +603,7 @@ func (t *Terminal) resizeWindows() {
t.window.MoveAndClear(i, 0)
}
}
+ t.truncateQuery()
}
func (t *Terminal) move(y int, x int, clear bool) {
@@ -628,13 +629,19 @@ func (t *Terminal) printPrompt() {
}
func (t *Terminal) printInfo() {
+ pos := 0
if t.inlineInfo {
- t.move(0, t.displayWidth([]rune(t.prompt))+t.displayWidth(t.input)+1, true)
+ pos = t.displayWidth([]rune(t.prompt)) + t.displayWidth(t.input) + 1
+ if pos+len(" < ") > t.window.Width() {
+ return
+ }
+ t.move(0, pos, true)
if t.reading {
t.window.CPrint(tui.ColSpinner, t.strong, " < ")
} else {
t.window.CPrint(tui.ColPrompt, t.strong, " < ")
}
+ pos += len(" < ")
} else {
t.move(1, 0, true)
if t.reading {
@@ -643,6 +650,7 @@ func (t *Terminal) printInfo() {
t.window.CPrint(tui.ColSpinner, t.strong, _spinner[idx])
}
t.move(1, 2, false)
+ pos = 2
}
output := fmt.Sprintf("%d/%d", t.merger.Length(), t.count)
@@ -659,7 +667,9 @@ func (t *Terminal) printInfo() {
if t.progress > 0 && t.progress < 100 {
output += fmt.Sprintf(" (%d%%)", t.progress)
}
- t.window.CPrint(tui.ColInfo, 0, output)
+ if pos+len(output) <= t.window.Width() {
+ t.window.CPrint(tui.ColInfo, 0, output)
+ }
}
func (t *Terminal) printHeader() {
@@ -1210,6 +1220,12 @@ func (t *Terminal) buildPlusList(template string, forcePlus bool) (bool, []*Item
return true, sels
}
+func (t *Terminal) truncateQuery() {
+ maxPatternLength := util.Max(1, t.window.Width()-t.displayWidth([]rune(t.prompt))-1)
+ t.input, _ = t.trimRight(t.input, maxPatternLength)
+ t.cx = util.Constrain(t.cx, 0, len(t.input))
+}
+
// Loop is called to start Terminal I/O
func (t *Terminal) Loop() {
// prof := profile.Start(profile.ProfilePath("/tmp/"))
@@ -1688,11 +1704,7 @@ func (t *Terminal) Loop() {
if !doActions(actions, mapkey) {
continue
}
- // Truncate the query if it's too long
- if len(t.input) > maxPatternLength {
- t.input = t.input[:maxPatternLength]
- t.cx = util.Constrain(t.cx, 0, maxPatternLength)
- }
+ t.truncateQuery()
changed = string(previousInput) != string(t.input)
} else {
if mapkey == tui.Rune {