From 5cdb6edd93d56500704da4ae2250f89ef7e5cf39 Mon Sep 17 00:00:00 2001 From: Joe Lim <50560759+joelim-work@users.noreply.github.com> Date: Sat, 1 Nov 2025 18:34:09 +1100 Subject: [PATCH] Fix implementation of silent commands (#2245) * Fix implementation of silent commands * Update `CHANGELOG.md` --- CHANGELOG.md | 1 + eval.go | 40 +++++++++++++++++----------------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d3dc1cfc..bd87507b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,6 +38,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), - A bug where setting `drawbox` could lead to scrolling outside the view is now fixed (#2210) (#2218). - The preview cache is now not cleared when setting `ratios` to its current value (#2218). - Filtering is fixed when using special characters in the search pattern if the `filtermethod` is `text` (#2231). +- Custom commands that output messages (e.g. `cmd greet echo 'hello world'`) now display properly (#2245). ## [r38](https://github.com/gokcehan/lf/releases/tag/r38) diff --git a/eval.go b/eval.go index 4aae3ae5..b5ed247b 100644 --- a/eval.go +++ b/eval.go @@ -979,6 +979,23 @@ func exitCompMenu(app *app) { func (e *callExpr) eval(app *app, _ []string) { os.Setenv("lf_count", strconv.Itoa(e.count)) + silentCmds := []string{ + "addcustominfo", + "draw", + "load", + "push", + "redraw", + "source", + "sync", + "tty-write", + "on-focus-gained", + "on-focus-lost", + "on-init", + } + if !slices.Contains(silentCmds, e.name) && app.ui.cmdPrefix != ">" { + app.ui.echo("") + } + switch e.name { case "quit": app.quitChan <- struct{}{} @@ -2270,29 +2287,6 @@ func (e *callExpr) eval(app *app, _ []string) { } cmd.eval(app, e.args) } - - // commands that run silently or write messages shouldn't clear existing messages - keepMsgCmds := []string{ - "addcustominfo", - "draw", - "echo", - "echoerr", - "echomsg", - "load", - "push", - "redraw", - "source", - "sync", - "tty-write", - "cmd-enter", - "cmd-interrupt", - "on-focus-gained", - "on-focus-lost", - "on-init", - } - if !slices.Contains(keepMsgCmds, e.name) && app.ui.cmdPrefix != ">" { - app.ui.echo("") - } } func (e *execExpr) eval(app *app, args []string) {