2
2
mirror of https://github.com/Hilbis/Hilbish synced 2025-05-10 22:33:22 +00:00

feat: allow processors to set if history should be saved

This commit is contained in:
sammyette 2025-05-08 14:29:13 -04:00
parent 95a85eedd2
commit fdbf333e38
Signed by: sammyette
GPG Key ID: 904FC49417B44DCD
2 changed files with 15 additions and 8 deletions

View File

@ -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

View File

@ -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