From a85ce898a1cd685ee19a282be5b283f536c0d67f Mon Sep 17 00:00:00 2001 From: Jackie Li Date: Sun, 12 Mar 2023 12:24:44 +0000 Subject: [PATCH] try to fix #916 (#1146) --- app.go | 39 +++++++++++++++++++++++++++++++++++++-- complete.go | 1 + doc.go | 5 +++++ docstring.go | 5 +++++ eval.go | 5 +++++ lf.1 | 7 +++++++ 6 files changed, 60 insertions(+), 2 deletions(-) diff --git a/app.go b/app.go index 58f73942..24e3ae51 100644 --- a/app.go +++ b/app.go @@ -471,6 +471,10 @@ func (app *app) loop() { } } +type cleanFunc func() + +var noopCleanFunc = func() {} + // This function is used to run a shell command. Modes are as follows: // // Prefix Wait Async Stdin Stdout Stderr UI action @@ -478,7 +482,8 @@ func (app *app) loop() { // % No No Yes Yes Yes Statline for input/output // ! Yes No Yes Yes Yes Pause and then resume // & No Yes No No No Do nothing -func (app *app) runShell(s string, args []string, prefix string) { +// $| No No Pipe Yes Yes Pause, Pipe execute, return cleanup to resume +func (app *app) runShell(s string, args []string, prefix string) cleanFunc { app.nav.exportFiles() app.ui.exportSizes() exportOpts() @@ -488,6 +493,24 @@ func (app *app) runShell(s string, args []string, prefix string) { var out io.Reader var err error switch prefix { + case "$|": + var stdin io.WriteCloser + stdin, err = cmd.StdinPipe() + if err != nil { + log.Printf("writing stdin: %s", err) + } + app.cmdIn = stdin + cmd.Stdout = os.Stdout + cmd.Stderr = os.Stderr + + app.nav.previewChan <- "" + app.nav.dirPreviewChan <- nil + + if err := app.ui.suspend(); err != nil { + log.Printf("suspend: %s", err) + } + + err = cmd.Start() case "$", "!": cmd.Stdin = os.Stdin cmd.Stdout = os.Stdout @@ -512,7 +535,7 @@ func (app *app) runShell(s string, args []string, prefix string) { case "%": shellSetPG(cmd) if app.ui.cmdPrefix == ">" { - return + return noopCleanFunc } stdin, err := cmd.StdinPipe() if err != nil { @@ -585,5 +608,17 @@ func (app *app) runShell(s string, args []string, prefix string) { log.Printf("running shell: %s", err) } }() + case "$|": + return func() { + if err := cmd.Wait(); err != nil { + log.Printf("running shell: %s", err) + } + app.nav.renew() + if err := app.ui.resume(); err != nil { + app.quit() + os.Exit(3) + } + } } + return noopCleanFunc } diff --git a/complete.go b/complete.go index a65bc290..1dcd7736 100644 --- a/complete.go +++ b/complete.go @@ -12,6 +12,7 @@ var ( gCmdWords = []string{ "set", "map", + "maps", "cmap", "cmd", "quit", diff --git a/doc.go b/doc.go index 27f090af..bd796a20 100644 --- a/doc.go +++ b/doc.go @@ -79,6 +79,7 @@ The following commands are provided by lf: mark-remove (modal) (default '"') tag tag-toggle (default 't') + maps The following command line commands are provided by lf: @@ -600,6 +601,10 @@ Delete the next word in forward direction. Capitalize/uppercase/lowercase the current word and jump to the next word. + maps + +List all key mappings. + # Options This section shows information about options to customize the behavior. diff --git a/docstring.go b/docstring.go index 9c0186e7..a8fcfc42 100644 --- a/docstring.go +++ b/docstring.go @@ -82,6 +82,7 @@ The following commands are provided by lf: mark-remove (modal) (default '"') tag tag-toggle (default 't') + maps The following command line commands are provided by lf: @@ -627,6 +628,10 @@ Delete the next word in forward direction. Capitalize/uppercase/lowercase the current word and jump to the next word. + maps + +List all key mappings. + # Options This section shows information about options to customize the behavior. diff --git a/eval.go b/eval.go index f8713ba1..579ad58e 100644 --- a/eval.go +++ b/eval.go @@ -2076,6 +2076,11 @@ func (e *callExpr) eval(app *app, args []string) { app.ui.cmdAccLeft = acc update(app) + case "maps": + cleanUp := app.runShell("$PAGER", nil, "$|") + io.Copy(app.cmdIn, listBinds(gOpts.keys)) + app.cmdIn.Close() + cleanUp() default: cmd, ok := gOpts.cmds[e.name] if !ok { diff --git a/lf.1 b/lf.1 index 0a38ff6c..f7c3ea5b 100644 --- a/lf.1 +++ b/lf.1 @@ -94,6 +94,7 @@ The following commands are provided by lf: mark-remove (modal) (default '"') tag tag-toggle (default 't') + maps .EE .PP The following command line commands are provided by lf: @@ -740,6 +741,12 @@ Delete the next word in forward direction. .EE .PP Capitalize/uppercase/lowercase the current word and jump to the next word. +.PP +.EX + maps +.EE +.PP +List all key mappings. .SH OPTIONS This section shows information about options to customize the behavior. Character ':' is used as the separator for list options '[]int' and '[]string'. .PP