Properly truncate long query string
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Junegunn Choi · committed by Junegunn Choi · parent c2db67c · Browse files · 2 files·+22 added−11 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+22 added−11 removed
- other:+22 added−11 removed
Provenance
- Commit
309e1d8- Tree
85e58a7- Author
Junegunn Choi <junegunn.c@gmail.com>- Committer
Junegunn Choi <junegunn.c@gmail.com>- Parent
c2db67c
2 files changed+22 added−11 removed
modified:src/constants.go+3 added-4 removed
16 unmodified lines17 // Reader18 readerBufferSize = 64 * 102419 20 // Terminal21- initialDelay = 20 * time.Millisecond22- initialDelayTac = 100 * time.Millisecond23- spinnerDuration = 200 * time.Millisecond24- maxPatternLength = 10021+ initialDelay = 20 * time.Millisecond22+ initialDelayTac = 100 * time.Millisecond23+ spinnerDuration = 200 * time.Millisecond24 25 // Matcher26 numPartitionsMultiplier = 827 maxPartitions = 3239 unmodified linesmodified:src/terminal.go+19 added-7 removed
601 unmodified lines602 for i := 0; i < t.window.Height(); i++ {603 t.window.MoveAndClear(i, 0)604 }605 }606+ t.truncateQuery()607 }608 609 func (t *Terminal) move(y int, x int, clear bool) {610 if !t.reverse {17 unmodified lines628 t.window.CPrint(tui.ColNormal, t.strong, string(t.input))629 }630 631 func (t *Terminal) printInfo() {632+ pos := 0633 if t.inlineInfo {632- t.move(0, t.displayWidth([]rune(t.prompt))+t.displayWidth(t.input)+1, true)634+ pos = t.displayWidth([]rune(t.prompt)) + t.displayWidth(t.input) + 1635+ if pos+len(" < ") > t.window.Width() {636+ return637+ }638+ t.move(0, pos, true)639 if t.reading {640 t.window.CPrint(tui.ColSpinner, t.strong, " < ")641 } else {642 t.window.CPrint(tui.ColPrompt, t.strong, " < ")643 }644+ pos += len(" < ")645 } else {646 t.move(1, 0, true)647 if t.reading {648 duration := int64(spinnerDuration)649 idx := (time.Now().UnixNano() % (duration * int64(len(_spinner)))) / duration650 t.window.CPrint(tui.ColSpinner, t.strong, _spinner[idx])651 }652 t.move(1, 2, false)653+ pos = 2654 }655 656 output := fmt.Sprintf("%d/%d", t.merger.Length(), t.count)657 if t.toggleSort {8 unmodified lines666 }667 if t.progress > 0 && t.progress < 100 {668 output += fmt.Sprintf(" (%d%%)", t.progress)669 }670+ if pos+len(output) <= t.window.Width() {662- t.window.CPrint(tui.ColInfo, 0, output)671+ t.window.CPrint(tui.ColInfo, 0, output)672+ }673 }674 675 func (t *Terminal) printHeader() {676 if len(t.header) == 0 {542 unmodified lines1219 }1220 return true, sels1221 }1222 1223+func (t *Terminal) truncateQuery() {1224+ maxPatternLength := util.Max(1, t.window.Width()-t.displayWidth([]rune(t.prompt))-1)1225+ t.input, _ = t.trimRight(t.input, maxPatternLength)1226+ t.cx = util.Constrain(t.cx, 0, len(t.input))1227+}1228+1229 // Loop is called to start Terminal I/O1230 func (t *Terminal) Loop() {1231 // prof := profile.Start(profile.ProfilePath("/tmp/"))1232 <-t.startChan470 unmodified lines1703 }1704 if !doActions(actions, mapkey) {1705 continue1706 }1691- // Truncate the query if it's too long1692- if len(t.input) > maxPatternLength {1693- t.input = t.input[:maxPatternLength]1694- t.cx = util.Constrain(t.cx, 0, maxPatternLength)1695- }1707+ t.truncateQuery()1708 changed = string(previousInput) != string(t.input)1709 } else {1710 if mapkey == tui.Rune {1711 if idx := strings.IndexRune(t.jumpLabels, event.Char); idx >= 0 && idx < t.maxItems() && idx < t.merger.Length() {67 unmodified lines