From 2bd41f13304cefc19e7056cf4aeb02bc13c89d08 Mon Sep 17 00:00:00 2001 From: Junegunn Choi Date: Sun, 5 May 2024 13:44:08 +0900 Subject: [PATCH] Reduce flicking when changing the size of the preview window with --border (sleep 1; find .) | fzf --bind 'space:change-preview-window(60%|70%|80%|90%|border-left|border-right|border-vertical|border-top|border-horizontal|border-bottom|border-sharp|border-double|border-block|hidden|left|up|down|right|up|down|)' \ --preview 'cat {}' --color bg:red,preview-bg:blue \ --border --margin 3 --- src/terminal.go | 10 ++++++++-- src/tui/light.go | 31 +++++++++++-------------------- 2 files changed, 19 insertions(+), 22 deletions(-) diff --git a/src/terminal.go b/src/terminal.go index 558bcc6..7de1de6 100644 --- a/src/terminal.go +++ b/src/terminal.go @@ -1288,7 +1288,8 @@ func (t *Terminal) resizeWindows(forcePreview bool) { t.pborder.Close() t.pborder = nil } - if t.pwindow != nil { + hadPreviewWindow := t.hasPreviewWindow() + if hadPreviewWindow { t.pwindow.Close() t.pwindow = nil } @@ -1387,6 +1388,9 @@ func (t *Terminal) resizeWindows(forcePreview bool) { pwidth = util.Max(0, pwidth) pheight = util.Max(0, pheight) t.pwindow = t.tui.NewWindow(y, x, pwidth, pheight, true, noBorder) + if !hadPreviewWindow { + t.pwindow.Erase() + } } verticalPad := 2 minPreviewHeight := 3 @@ -1649,7 +1653,7 @@ func (t *Terminal) printInfo() { case infoDefault: t.move(line+1, 0, t.separatorLen == 0) printSpinner() - t.move(line+1, 2, false) + t.window.Print(" ") // Margin pos = 2 case infoRight: t.move(line+1, 0, false) @@ -1714,6 +1718,7 @@ func (t *Terminal) printInfo() { printSeparator(fillLength, true) } t.window.CPrint(tui.ColInfo, output) + t.window.Print(" ") // Margin return } @@ -2922,6 +2927,7 @@ func (t *Terminal) Loop() { t.initFunc() t.termSize = t.tui.Size() t.resizeWindows(false) + t.window.Erase() t.printPrompt() t.printInfo() t.printHeader() diff --git a/src/tui/light.go b/src/tui/light.go index 244891a..a045b78 100644 --- a/src/tui/light.go +++ b/src/tui/light.go @@ -821,44 +821,32 @@ func (w *LightWindow) drawBorderHorizontal(top, bottom bool) { color = ColPreviewBorder } hw := runeWidth(w.border.top) - pad := repeat(' ', w.width/hw) - - w.Move(0, 0) if top { + w.Move(0, 0) w.CPrint(color, repeat(w.border.top, w.width/hw)) - } else { - w.CPrint(color, pad) } - for y := 1; y < w.height-1; y++ { - w.Move(y, 0) - w.CPrint(color, pad) - } - - w.Move(w.height-1, 0) if bottom { + w.Move(w.height-1, 0) w.CPrint(color, repeat(w.border.bottom, w.width/hw)) - } else { - w.CPrint(color, pad) } } func (w *LightWindow) drawBorderVertical(left, right bool) { - width := w.width - 2 - if !left || !right { - width++ - } + vw := runeWidth(w.border.left) color := ColBorder if w.preview { color = ColPreviewBorder } for y := 0; y < w.height; y++ { - w.Move(y, 0) if left { + w.Move(y, 0) w.CPrint(color, string(w.border.left)) + w.CPrint(color, " ") // Margin } - w.CPrint(color, repeat(' ', width)) if right { + w.Move(y, w.width-vw-1) + w.CPrint(color, " ") // Margin w.CPrint(color, string(w.border.right)) } } @@ -880,7 +868,10 @@ func (w *LightWindow) drawBorderAround(onlyHorizontal bool) { for y := 1; y < w.height-1; y++ { w.Move(y, 0) w.CPrint(color, string(w.border.left)) - w.CPrint(color, repeat(' ', w.width-vw*2)) + w.CPrint(color, " ") // Margin + + w.Move(y, w.width-vw-1) + w.CPrint(color, " ") // Margin w.CPrint(color, string(w.border.right)) } }