local core = require "core" local process = require "process" local debugger = require "plugins.jpdebug.debugger" ---@class shell: runner local shell = debugger.runner:new({ name = "shell", proc = nil ---@type process|nil }) function shell:run(target, name) local opts = { cwd = target.cwd or ".", env = target.env or {}, stdout = process.REDIRECT_PIPE, stderr = process.REDIRECT_PIPE } if target.cmd then self.proc = process.start(target.cmd, opts) if not self.proc then self.error("Could not start process...") return end else self.error(string.format("command not specified for target %s", name)) end self.on_state('running') -- output pump core.add_thread(function() while true do core.redraw = true coroutine.yield(0.016) -- 60FPS local sout = self.proc:read_stdout() local serr = self.proc:read_stderr() if sout == nil or serr == nil then -- Make sure to read stderr for the last time if serr and serr~="" then self.on_stderr(serr) end local exitcode = self.proc:wait(process.WAIT_INFINITE) self.on_exit(exitcode) break end if sout and sout~="" then self.on_stdout(sout) end if serr and serr~="" then self.on_stderr(serr) end end end) end function shell:wait(time) if not self.proc then return end return self.proc:wait(time) end function shell:kill() if not self.proc then return end self.proc:kill() end function shell:terminate() if not self.proc then return end self.proc:terminate() end return shell