Fix panic on extremely short terminals

Fix #3889
pull/3893/head
Junegunn Choi 3 months ago
parent bee7bc5324
commit b02bf9b6bb
No known key found for this signature in database
GPG Key ID: 254BC280FEF9C627

@ -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

Loading…
Cancel
Save