From b3cb2dc2b48d1b93538a15b809491c0261c225f0 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Mon, 30 Oct 2023 09:40:24 +1100 Subject: [PATCH] Add `on-redraw` hook command (#1479) * Add `on-redraw` hook command * Add documentation --- doc.go | 5 +++++ docstring.go | 6 ++++++ eval.go | 7 +++++++ lf.1 | 7 +++++++ 4 files changed, 25 insertions(+) diff --git a/doc.go b/doc.go index 54944c80..3cab825e 100644 --- a/doc.go +++ b/doc.go @@ -208,6 +208,7 @@ The following special shell commands are used to customize the behavior of lf wh pre-cd on-cd on-select + on-redraw on-quit The following commands/keybindings are provided by default: @@ -1110,6 +1111,10 @@ This shell command can be defined to be executed after changing a directory. This shell command can be defined to be executed after the selection changes. + on-redraw + +This shell command can be defined to be executed after the screen is redrawn or if the terminal is resized. + on-quit This shell command can be defined to be executed before quit. diff --git a/docstring.go b/docstring.go index a9ff5096..9f3e8ef0 100644 --- a/docstring.go +++ b/docstring.go @@ -212,6 +212,7 @@ when defined: pre-cd on-cd on-select + on-redraw on-quit The following commands/keybindings are provided by default: @@ -1202,6 +1203,11 @@ This shell command can be defined to be executed after changing a directory. This shell command can be defined to be executed after the selection changes. + on-redraw + +This shell command can be defined to be executed after the screen is redrawn or +if the terminal is resized. + on-quit This shell command can be defined to be executed before quit. diff --git a/eval.go b/eval.go index ff04308e..47c8eebf 100644 --- a/eval.go +++ b/eval.go @@ -1151,6 +1151,12 @@ func onChdir(app *app) { } } +func onRedraw(app *app) { + if cmd, ok := gOpts.cmds["on-redraw"]; ok { + cmd.eval(app, nil) + } +} + func onSelect(app *app) { if cmd, ok := gOpts.cmds["on-select"]; ok { cmd.eval(app, nil) @@ -1944,6 +1950,7 @@ func (e *callExpr) eval(app *app, args []string) { dir.boundPos(app.nav.height) } app.ui.loadFile(app, true) + onRedraw(app) case "load": if !app.nav.init { return diff --git a/lf.1 b/lf.1 index 8d4ed29f..e9f98903 100644 --- a/lf.1 +++ b/lf.1 @@ -231,6 +231,7 @@ The following special shell commands are used to customize the behavior of lf wh pre-cd on-cd on-select + on-redraw on-quit .EE .PP @@ -1332,6 +1333,12 @@ This shell command can be defined to be executed after changing a directory. .PP This shell command can be defined to be executed after the selection changes. .PP +.EX + on-redraw +.EE +.PP +This shell command can be defined to be executed after the screen is redrawn or if the terminal is resized. +.PP .EX on-quit .EE