Skip to content

Commit

Permalink
Fix redundant clearing of the windows with non-default bg color
Browse files Browse the repository at this point in the history
  • Loading branch information
junegunn committed Dec 14, 2024
1 parent ec3acb1 commit cdcab26
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions src/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -1531,15 +1531,16 @@ func (t *Terminal) adjustMarginAndPadding() (int, int, [4]int, [4]int) {
return screenWidth, screenHeight, marginInt, paddingInt
}

func (t *Terminal) resizeWindows(forcePreview bool) {
func (t *Terminal) resizeWindows(forcePreview bool, redrawBorder bool) {
t.forcePreview = forcePreview
screenWidth, screenHeight, marginInt, paddingInt := t.adjustMarginAndPadding()
width := screenWidth - marginInt[1] - marginInt[3]
height := screenHeight - marginInt[0] - marginInt[2]

t.prevLines = make([]itemLine, screenHeight)
if t.border != nil {
if t.border != nil && redrawBorder {
t.border.Close()
t.border = nil
}
if t.window != nil {
t.window.Close()
Expand Down Expand Up @@ -1573,7 +1574,7 @@ func (t *Terminal) resizeWindows(forcePreview bool) {
offsets[1] -= 1 + bw
offsets[2] += 1 + bw
}
if t.borderShape != tui.BorderNone {
if t.border == nil && t.borderShape != tui.BorderNone {
t.border = t.tui.NewWindow(
marginInt[0]+offsets[0], marginInt[3]+offsets[1], width+offsets[2], height+offsets[3],
false, tui.MakeBorderStyle(t.borderShape, t.unicode))
Expand Down Expand Up @@ -2935,7 +2936,7 @@ func (t *Terminal) processTabs(runes []rune, prefixWidth int) (string, int) {
}

func (t *Terminal) printAll() {
t.resizeWindows(t.forcePreview)
t.resizeWindows(t.forcePreview, true)
t.printList()
t.printPrompt()
t.printInfo()
Expand Down Expand Up @@ -3561,7 +3562,7 @@ func (t *Terminal) Loop() error {
return err
}
t.termSize = t.tui.Size()
t.resizeWindows(false)
t.resizeWindows(false, false)
t.window.Erase()
t.mutex.Unlock()

Expand Down Expand Up @@ -4037,7 +4038,7 @@ func (t *Terminal) Loop() error {
}
}
updatePreviewWindow := func(forcePreview bool) {
t.resizeWindows(forcePreview)
t.resizeWindows(forcePreview, false)
req(reqPrompt, reqList, reqInfo, reqHeader)
}
toggle := func() bool {
Expand Down
2 changes: 1 addition & 1 deletion src/tui/tui.go
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ type BorderCharacter int
func MakeBorderStyle(shape BorderShape, unicode bool) BorderStyle {
if shape == BorderNone {
return BorderStyle{
shape: BorderRounded,
shape: shape,
top: ' ',
bottom: ' ',
left: ' ',
Expand Down

0 comments on commit cdcab26

Please sign in to comment.