Files
hego.nvim/lua/hego/monitor.lua
T

41 lines
733 B
Lua

local M = {}
local function candidates(opts)
if opts.monitor_port then
return { opts.monitor_port }
end
return vim.fn.glob("/dev/ttyACM*", false, true)
end
function M.run(opts)
local ports = candidates(opts)
if #ports == 0 then
vim.notify("[hego] ningún /dev/ttyACM*; ¿DK conectado?", vim.log.levels.WARN)
return
end
local exec = require("hego.exec")
local function go(port)
-- tio reconecta solo si el puerto re-enumera (p. ej. tras un flash).
exec.run_async({ "tio", port }, {
title = "hego://monitor",
cwd = vim.fn.getcwd(),
})
end
if #ports == 1 then
return go(ports[1])
end
vim.ui.select(ports, {
prompt = "Monitor serie",
}, function(c)
if c then
go(c)
end
end)
end
return M