diff options
| author | Junegunn Choi <junegunn.c@gmail.com> | 2024-06-23 11:27:03 +0900 |
|---|---|---|
| committer | Junegunn Choi <junegunn.c@gmail.com> | 2024-06-23 11:27:03 +0900 |
| commit | b02bf9b6bbf9adf2017d3c1342bde34ea9813ab5 (patch) | |
| tree | 9acb22ff35dff2a451c0355ef7f7960ab80b5b03 | |
| parent | bee7bc5324581c0516a732266759672407f2635b (diff) | |
| download | fzf-b02bf9b6bbf9adf2017d3c1342bde34ea9813ab5.tar.gz | |
Fix panic on extremely short terminals
Fix #3889
| -rw-r--r-- | src/terminal.go | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/terminal.go b/src/terminal.go index a9e2f48e..a70329c0 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1724,6 +1724,9 @@ func (t *Terminal) updatePromptOffset() ([]rune, []rune) { func (t *Terminal) promptLine() int { if t.headerFirst { max := t.window.Height() - 1 + if max <= 0 { // Extremely short terminal + return 0 + } if !t.noSeparatorLine() { max-- } @@ -1759,9 +1762,14 @@ func (t *Terminal) trimMessage(message string, maxWidth int) string { func (t *Terminal) printInfo() { pos := 0 line := t.promptLine() - move := func(y int, x int, clear bool) { + maxHeight := t.window.Height() + move := func(y int, x int, clear bool) bool { + if y < 0 || y >= maxHeight { + return false + } t.move(y, x, clear) t.markOtherLine(y) + return true } printSpinner := func() { if t.reading { @@ -1800,7 +1808,9 @@ func (t *Terminal) printInfo() { if t.infoStyle == infoHidden { if t.separatorLen > 0 { - move(line+1, 0, false) + if !move(line+1, 0, false) { + return + } printSeparator(t.window.Width()-1, false) } return @@ -1844,12 +1854,16 @@ func (t *Terminal) printInfo() { switch t.infoStyle { case infoDefault: - move(line+1, 0, t.separatorLen == 0) + if !move(line+1, 0, t.separatorLen == 0) { + return + } printSpinner() t.window.Print(" ") // Margin pos = 2 case infoRight: - move(line+1, 0, false) + if !move(line+1, 0, false) { + return + } case infoInlineRight: pos = t.promptLen + t.queryLen[0] + t.queryLen[1] + 1 case infoInline: @@ -1921,7 +1935,9 @@ func (t *Terminal) printInfo() { if t.infoStyle == infoInlineRight { if t.separatorLen > 0 { - move(line+1, 0, false) + if !move(line+1, 0, false) { + return + } printSeparator(t.window.Width()-1, false) } return |
