Added way to have multiple runners and created shell runner

This commit is contained in:
U-ENGINEERO\joppe.blondel
2025-10-23 16:17:09 +02:00
parent e89a6f815e
commit f9b8d67b5c
5 changed files with 87 additions and 62 deletions

View File

@ -6,8 +6,32 @@ local View = require "core.view"
local process = require "process" -- Child Processes API
local config = require "core.config"
core.jpdebug = {}
-- Global list of all the runners
local runner_shell = require("plugins.jpdebug.runners.shell")
core.jpdebug.runners = {
runner_shell
}
-- A list of created views
local active_views = {}
-- Local helper functions for debugging --------------------------
---@diagnostic disable-next-line: unused-function
local function dump(o)
if type(o) == 'table' then
local s = '{ '
for k,v in pairs(o) do
if type(k) ~= 'number' then k = '"'..k..'"' end
s = s .. '['..k..'] = ' .. dump(v) .. ','
end
return s .. '} '
else
return tostring(o)
end
end
-- ---------- JPDebugView: a simple scrollable log view ----------
---@class JPDebugView : core.view
local JPDebugView = View:extend()
@ -94,36 +118,51 @@ local function run_target(target, name)
active_views[title] = view
end
local opts = {
cwd = target.cwd,
stdout = process.REDIRECT_PIPE,
stderr = process.REDIRECT_PIPE
}
view:clear()
local proc = process.start({"lua", target.file}, opts)
-- Check if we have a runner
---@diagnostic disable-next-line: unused-local
for i,runner in ipairs(core.jpdebug.runners) do
if runner.name and runner.name == target.type then
-- Found a runner
local proc = runner:run(target.cmd, {
cwd = target.cwd or ".",
env = target.env or {},
stdout = process.REDIRECT_PIPE,
stderr = process.REDIRECT_PIPE
}, name)
-- background pump (non-blocking I/O)
core.add_thread(function()
while true do
coroutine.yield(0.016) -- ~60fps
local out = proc:read_stdout()
if out == nil then
-- stdout pipe closed: try drain stderr and break when both closed
local err = proc:read_stderr()
if err ~= nil and err ~= "" then view:push("stderr", err) end
break
if proc == nil then
core.error("[jpdebug] Could not run the target")
return
end
if out ~= "" then view:push("stdout", out) end
local err = proc:read_stderr()
if err ~= nil and err ~= "" then view:push("stderr", err) end
end
local code = proc:wait(process.WAIT_INFINITE)
view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code)))
end)
return view
view:clear()
-- background pump (non-blocking I/O)
core.add_thread(function()
while true do
coroutine.yield(0.016) -- ~60fps
local out = proc:read_stdout()
if out == nil then
-- stdout pipe closed: try drain stderr and break when both closed
local err = proc:read_stderr()
if err ~= nil and err ~= "" then view:push("stderr", err) end
break
end
if out ~= "" then view:push("stdout", out) end
local err = proc:read_stderr()
if err ~= nil and err ~= "" then view:push("stderr", err) end
end
local code = proc:wait(process.WAIT_INFINITE)
view:push("stdout", ("\n[exit] code=%s\n"):format(tostring(code)))
end)
return view
end
end
-- No suitable runners found
core.error("[jpdebug] No suitable runners found for target %s", name)
end
---@diagnostic disable-next-line: param-type-mismatch
command.add(nil, {
["jpdebug:run"] = function()
local targets = get_targets()