From fdbf333e3830308b3e7982010b51bb813f659aec Mon Sep 17 00:00:00 2001 From: sammyette Date: Thu, 8 May 2025 14:29:13 -0400 Subject: [PATCH] feat: allow processors to set if history should be saved --- nature/processors.lua | 8 +++++++- nature/runner.lua | 15 ++++++++------- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/nature/processors.lua b/nature/processors.lua index 660e8bf..f36d7ac 100644 --- a/nature/processors.lua +++ b/nature/processors.lua @@ -36,9 +36,11 @@ function hilbish.processors.execute(command, opts) opts.skip = opts.skip or {} local continue = true + local history for _, processor in ipairs(hilbish.processors.list) do if not contains(opts.skip, processor.name) then local processed = processor.func(command) + if processed.history ~= nil then history = processed.history end if processed.command then command = processed.command end if not processed.continue then continue = false @@ -47,5 +49,9 @@ function hilbish.processors.execute(command, opts) end end - return command, continue + return { + command = command, + continue = continue, + history = history + } end diff --git a/nature/runner.lua b/nature/runner.lua index f87f8e9..cc5b67e 100644 --- a/nature/runner.lua +++ b/nature/runner.lua @@ -123,20 +123,21 @@ end -- @param priv bool function hilbish.runner.run(input, priv) bait.throw('command.preprocess', input) - local input, continue = hilbish.processors.execute(input, { + local processed = hilbish.processors.execute(input, { skip = hilbish.opts.processorSkipList }) - if not continue then + priv = processed.history ~= nil and (not processed.history) or priv + if not processed.continue then finishExec(0, '', true) return end - local command = hilbish.aliases.resolve(input) - bait.throw('command.preexec', input, command) + local command = hilbish.aliases.resolve(processed.command) + bait.throw('command.preexec', processed.command, command) ::rerun:: local runner = hilbish.runner.get(currentRunner) - local ok, out = pcall(runner.run, input) + local ok, out = pcall(runner.run, processed.command) if not ok then io.stderr:write(out .. '\n') finishExec(124, out.input, priv) @@ -144,9 +145,9 @@ function hilbish.runner.run(input, priv) end if out.continue then - local contInput = continuePrompt(input, out.newline) + local contInput = continuePrompt(processed.command, out.newline) if contInput then - input = contInput + processed.command = contInput goto rerun end end