feat: added build pristine, build configuration, erase and recover
This commit is contained in:
1 parent
80a2c4d56f
commit
5b1d640d4b
11 files changed
+636
-80
No files matched your search
+69
-30
@@ -11,43 +11,82 @@ function M.ncs(opts, cmd)
|
||||
return full
|
||||
end
|
||||
|
||||
--- Ejecuta async y vuelca la salida a un buffer scratch (no bloquea nvim).
|
||||
function M.run_async(cmd, o)
|
||||
o = o or {}
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(buf, o.title or "hego://run")
|
||||
vim.cmd("botright split")
|
||||
vim.api.nvim_win_set_buf(0, buf)
|
||||
|
||||
local function append(data)
|
||||
if not data or data == "" then
|
||||
return
|
||||
--- Lo único que NO pone `toolchain-manager launch` es ZEPHYR_BASE.
|
||||
function M.zephyr_env(opts)
|
||||
if opts.ncs_root and opts.ncs_version then
|
||||
local zephyr = opts.ncs_root .. "/" .. opts.ncs_version .. "/zephyr"
|
||||
if vim.fn.isdirectory(zephyr) == 1 then
|
||||
return { ZEPHYR_BASE = zephyr }
|
||||
end
|
||||
vim.api.nvim_buf_set_lines(buf, -1, -1, false, vim.split(data, "\n", { plain = true }))
|
||||
vim.api.nvim_win_set_cursor(0, { vim.api.nvim_buf_line_count(buf), 0 })
|
||||
end
|
||||
return {}
|
||||
end
|
||||
|
||||
--- Buffer de terminal reutilizable por nombre.
|
||||
local function prepare_term(name)
|
||||
local buf = vim.fn.bufnr(name)
|
||||
|
||||
if buf ~= -1 then
|
||||
-- Si hay un job vivo en ese terminal, lo paramos antes de reusarlo.
|
||||
local job = vim.b[buf].terminal_job_id
|
||||
if job then
|
||||
pcall(vim.fn.jobstop, job)
|
||||
vim.wait(200, function()
|
||||
return vim.b[buf].terminal_job_id == nil
|
||||
end)
|
||||
end
|
||||
else
|
||||
buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_name(buf, name)
|
||||
vim.bo[buf].bufhidden = "hide"
|
||||
end
|
||||
|
||||
return vim.system(cmd, {
|
||||
vim.cmd("botright split")
|
||||
vim.api.nvim_win_set_buf(0, buf)
|
||||
-- dentro de prepare_term(name), justo antes del return
|
||||
vim.keymap.set("t", "<Esc><Esc>", "<C-\\><C-n>", { buffer = buf, silent = true })
|
||||
|
||||
vim.keymap.set("t", "<C-q>", function()
|
||||
local j = vim.b[buf].terminal_job_id
|
||||
if j then
|
||||
pcall(vim.fn.jobstop, j)
|
||||
end
|
||||
vim.cmd("stopinsert")
|
||||
end, { buffer = buf, silent = true, desc = "hego: detener proceso" })
|
||||
return buf
|
||||
end
|
||||
|
||||
--- Ejecuta en un buffer de terminal (interactivo, ANSI, progreso).
|
||||
--- Misma firma que la versión anterior: no hay que tocar las llamadas.
|
||||
function M.run_async(cmd, o)
|
||||
o = o or {}
|
||||
local buf = prepare_term(o.title or "hego://run")
|
||||
|
||||
-- Fusionamos con el entorno heredado: jobstart REEMPLAZA si le pasas env.
|
||||
local env = vim.tbl_extend("force", vim.fn.environ(), o.env or {})
|
||||
|
||||
local job = vim.fn.jobstart(cmd, {
|
||||
term = true,
|
||||
cwd = o.cwd,
|
||||
text = true,
|
||||
stdout = function(_, d)
|
||||
env = env,
|
||||
on_exit = function(_, code)
|
||||
vim.schedule(function()
|
||||
append(d)
|
||||
vim.b[buf].hego_exit = code
|
||||
if o.on_exit then
|
||||
o.on_exit({ code = code })
|
||||
end
|
||||
end)
|
||||
end,
|
||||
stderr = function(_, d)
|
||||
vim.schedule(function()
|
||||
append(d)
|
||||
end)
|
||||
end,
|
||||
}, function(obj)
|
||||
vim.schedule(function()
|
||||
append("\n[hego] exit: " .. tostring(obj.code))
|
||||
if o.on_exit then
|
||||
o.on_exit(obj)
|
||||
end
|
||||
end)
|
||||
end)
|
||||
})
|
||||
|
||||
if job <= 0 then
|
||||
vim.notify("[hego] no se pudo lanzar el comando", vim.log.levels.ERROR)
|
||||
return
|
||||
end
|
||||
|
||||
-- Arrancamos en terminal-insert; Esc-Esc para salir (LazyVim ya lo mapea).
|
||||
vim.cmd("startinsert")
|
||||
return job
|
||||
end
|
||||
|
||||
return M
|
||||
Reference in new issue
Block a user