From 42c16f1882bf2dbe0a81fab4f3c8189d113bc739 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=C3=A1=C5=A1=20Dujava?= <19737748+jdujava@users.noreply.github.com> Date: Sat, 22 Jul 2023 13:24:35 +0200 Subject: [PATCH] Clean image preview on `set preview!` (#1350) Properly clean (`ueberzug`) image preview when disabling it using for example `set preview!`. Also change "clearing" to "cleaning" in docs. --- doc.go | 2 +- docstring.go | 2 +- eval.go | 3 +++ lf.1 | 2 +- ui.go | 8 ++++---- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/doc.go b/doc.go index f4baab2b..5a7e2e2b 100644 --- a/doc.go +++ b/doc.go @@ -674,7 +674,7 @@ Set the path of a cleaner file. The file should be executable. This file is called if previewing is enabled, the previewer is set, and the previously selected file had its preview cache disabled. Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. -Preview clearing is disabled when the value of this option is left empty. +Preview cleaning is disabled when the value of this option is left empty. cursoractivefmt string (default "\033[7m") cursorparentfmt string (default "\033[7m") diff --git a/docstring.go b/docstring.go index 8c4fe02a..ef2d522e 100644 --- a/docstring.go +++ b/docstring.go @@ -706,7 +706,7 @@ Set the path of a cleaner file. The file should be executable. This file is called if previewing is enabled, the previewer is set, and the previously selected file had its preview cache disabled. Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, -and (5) vertical position of preview pane respectively. Preview clearing is +and (5) vertical position of preview pane respectively. Preview cleaning is disabled when the value of this option is left empty. cursoractivefmt string (default "\033[7m") diff --git a/eval.go b/eval.go index 81e46811..334550e2 100644 --- a/eval.go +++ b/eval.go @@ -611,12 +611,14 @@ func (e *setExpr) eval(app *app, args []string) { app.ui.echoerr("preview: value should be empty, 'true', or 'false'") return } + app.ui.loadFile(app, true) case "nopreview": if e.val != "" { app.ui.echoerrf("nopreview: unexpected value: %s", e.val) return } gOpts.preview = false + app.ui.loadFile(app, true) case "preview!": if e.val != "" { app.ui.echoerrf("preview!: unexpected value: %s", e.val) @@ -627,6 +629,7 @@ func (e *setExpr) eval(app *app, args []string) { return } gOpts.preview = !gOpts.preview + app.ui.loadFile(app, true) case "previewer": gOpts.previewer = replaceTilde(e.val) case "promptfmt": diff --git a/lf.1 b/lf.1 index fd4b37ed..da6a08d1 100644 --- a/lf.1 +++ b/lf.1 @@ -825,7 +825,7 @@ Format string of the box drawing characters enabled by the `drawbox` option. cleaner string (default '') (not called if empty) .EE .PP -Set the path of a cleaner file. The file should be executable. This file is called if previewing is enabled, the previewer is set, and the previously selected file had its preview cache disabled. Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. Preview clearing is disabled when the value of this option is left empty. +Set the path of a cleaner file. The file should be executable. This file is called if previewing is enabled, the previewer is set, and the previously selected file had its preview cache disabled. Five arguments are passed to the file, (1) current file name, (2) width, (3) height, (4) horizontal position, and (5) vertical position of preview pane respectively. Preview cleaning is disabled when the value of this option is left empty. .PP .EX cursoractivefmt string (default "\e033[7m") diff --git a/ui.go b/ui.go index 1a286a96..724a1ce8 100644 --- a/ui.go +++ b/ui.go @@ -696,14 +696,14 @@ func (ui *ui) loadFile(app *app, volatile bool) { onSelect(app) } - if !gOpts.preview { - return - } - if volatile { app.nav.previewChan <- "" } + if !gOpts.preview { + return + } + if curr.IsDir() { ui.dirPrev = app.nav.loadDir(curr.path) } else if curr.Mode().IsRegular() {