local M = {} --- Envuelve un binario (west, nrfutil...) en el entorno NCS. function M.ncs(opts, cmd) local full = { "nrfutil", "toolchain-manager", "launch" } if opts.ncs_version then vim.list_extend(full, { "--ncs-version", opts.ncs_version }) end vim.list_extend(full, { "--" }) vim.list_extend(full, 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 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 vim.system(cmd, { cwd = o.cwd, text = true, stdout = function(_, d) vim.schedule(function() append(d) 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) end return M