diff --git a/README.md b/README.md index b1611a3a..c6dda0b5 100644 --- a/README.md +++ b/README.md @@ -224,7 +224,7 @@ These are the default keybindings, which you can override in your configuration. It's possible to lazy load the plugin using Lazy.nvim, this will load the plugins only when it is needed, to enable lazy loading, add this plugin spec to your config. ```lua -cmd = { 'Pioinit', 'Piorun', 'Piocmdh', 'Piocmdf', 'Piolib', 'Piomon', 'Piodebug', 'Piodb' }, +cmd = { 'Pioinit', 'PioLSP', 'Piorun', 'Piocmdh', 'Piocmdf', 'Piolib', 'Piomon', 'Piolsserial', 'Piodebug', 'PioTermList' }, ``` diff --git a/lua/health/platformio.lua b/lua/health/platformio.lua deleted file mode 100644 index 519b3864..00000000 --- a/lua/health/platformio.lua +++ /dev/null @@ -1 +0,0 @@ -return require('platformio.health') diff --git a/lua/platformio/piocmd.lua b/lua/platformio/piocmd.lua index 19a20c4b..2a0b5ab8 100644 --- a/lua/platformio/piocmd.lua +++ b/lua/platformio/piocmd.lua @@ -1,4 +1,5 @@ local utils = require('platformio.utils') +local terminal = require('platformio.terminal') local M = {} function M.piocmd(cmd_table, direction) @@ -7,13 +8,13 @@ function M.piocmd(cmd_table, direction) end if cmd_table[1] == '' then - utils.ToggleTerminal('', direction, nil, utils.get_platformioRootDir()) + terminal.ToggleTerminal('', direction, nil, utils.get_platformioRootDir()) else local cmd = 'pio ' for _, v in pairs(cmd_table) do cmd = cmd .. ' ' .. v end - utils.ToggleTerminal(cmd, direction, nil, utils.get_platformioRootDir()) + terminal.ToggleTerminal(cmd, direction, nil, utils.get_platformioRootDir()) end end diff --git a/lua/platformio/piodebug.lua b/lua/platformio/piodebug.lua index 6bb2df02..a34c0ad8 100644 --- a/lua/platformio/piodebug.lua +++ b/lua/platformio/piodebug.lua @@ -1,4 +1,5 @@ local utils = require('platformio.utils') +local terminal = require('platformio.terminal') local M = {} function M.piodebug(args_table) @@ -8,7 +9,7 @@ function M.piodebug(args_table) local command = 'pio debug --interface=gdb -- -x .pioinit' -- local command = string.format('pio debug --interface=gdb -- -x .pioinit %s', utils.extra) - utils.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) + terminal.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) end return M diff --git a/lua/platformio/pioinit.lua b/lua/platformio/pioinit.lua index 881a002c..5c09406b 100644 --- a/lua/platformio/pioinit.lua +++ b/lua/platformio/pioinit.lua @@ -1,6 +1,7 @@ local M = {} local utils = require('platformio.utils') +local terminal = require('platformio.terminal') local picker = require('platformio.pickers') local boilerplate_gen = require('platformio.boilerplate').boilerplate_gen @@ -12,7 +13,7 @@ local function init_project(board_details, selected_framework) local board_id = utils.sanitize_shell_arg(board_details.id) local framework_arg = utils.sanitize_shell_arg(framework) local command = 'pio project init --board ' .. board_id .. ' --project-option "framework=' .. framework_arg .. '"' - utils.ToggleTerminal(command, 'float', function() + terminal.ToggleTerminal(command, 'float', function() vim.cmd(':PioLSP') boilerplate_gen(framework) end) diff --git a/lua/platformio/piolib.lua b/lua/platformio/piolib.lua index 4fde684d..15e2542e 100644 --- a/lua/platformio/piolib.lua +++ b/lua/platformio/piolib.lua @@ -2,6 +2,7 @@ local M = {} local curl = require('plenary.curl') local utils = require('platformio.utils') +local terminal = require('platformio.terminal') local picker = require('platformio.pickers') function M.piolib(lib_arg_list) @@ -40,7 +41,7 @@ function M.piolib(lib_arg_list) end local pkg_name = owner .. '/' .. name local command = 'pio pkg install --library "' .. pkg_name .. '"' - utils.ToggleTerminal(command, 'float', function() + terminal.ToggleTerminal(command, 'float', function() vim.cmd(':PioLSP') end, utils.get_platformioRootDir()) end) diff --git a/lua/platformio/piolsserial.lua b/lua/platformio/piolsserial.lua index 9e278548..f7944b40 100644 --- a/lua/platformio/piolsserial.lua +++ b/lua/platformio/piolsserial.lua @@ -7,6 +7,9 @@ function M.parse_tty(lines) for k in pairs(M.tty_list) do M.tty_list[k] = nil end + if not lines[1] then + return + end local json_data = vim.json.decode(lines[1]) for key, value in pairs(json_data) do if value['description'] ~= 'n/a' then diff --git a/lua/platformio/piomon.lua b/lua/platformio/piomon.lua index 09c5a6e1..fc19c72c 100644 --- a/lua/platformio/piomon.lua +++ b/lua/platformio/piomon.lua @@ -1,4 +1,5 @@ local utils = require('platformio.utils') +local terminal = require('platformio.terminal') local M = {} function M.piomon(args_table) @@ -21,7 +22,7 @@ function M.piomon(args_table) if command == nil then vim.notify('Usage: Piomon ', vim.log.levels.ERROR) else - utils.ToggleTerminal(command, 'horizontal', nil, utils.get_platformioRootDir()) + terminal.ToggleTerminal(command, 'horizontal', nil, utils.get_platformioRootDir()) end end diff --git a/lua/platformio/piorun.lua b/lua/platformio/piorun.lua index 5a2c8b3a..a5af3f07 100644 --- a/lua/platformio/piorun.lua +++ b/lua/platformio/piorun.lua @@ -1,25 +1,26 @@ local M = {} local utils = require('platformio.utils') +local terminal = require('platformio.terminal') function M.piobuild() local command = 'pio run' -- .. utils.extra - utils.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) + terminal.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) end function M.pioupload() local command = 'pio run --target upload' -- .. utils.extra - utils.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) + terminal.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) end function M.piouploadfs() local command = 'pio run --target uploadfs' -- .. utils.extra - utils.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) + terminal.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) end function M.pioclean() local command = 'pio run --target clean' -- .. utils.extra - utils.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) + terminal.ToggleTerminal(command, 'float', nil, utils.get_platformioRootDir()) end function M.piorun(arg_table) diff --git a/lua/platformio/terminal.lua b/lua/platformio/terminal.lua new file mode 100644 index 00000000..64271508 --- /dev/null +++ b/lua/platformio/terminal.lua @@ -0,0 +1,272 @@ +local M = {} + +local utils = require('platformio.utils') +local config = require('platformio').config + +local function enter() + local shell = vim.o.shell + if utils.is_windows then + return vim.fn.executable('pwsh') and '\r' or '\r\n' + elseif shell:find('nu') then + return '\r' + else + return '\n' + end +end + +local function getPreviousWindow(orig_window) + local prev = { + orig_window = orig_window, + term = nil, + cli = nil, + mon = nil, + float = false, + } + local terms = require('toggleterm.terminal').get_all(true) + if #terms ~= 0 then + for i = 1, #terms do + if terms[i].display_name and terms[i].display_name ~= '' and terms[i].display_name:find('pio', 1) then + local name_splt = utils.strsplit(terms[i].display_name, ':') + if name_splt[1] == 'piocli' then + prev.cli = terms[i] + if terms[i].window == orig_window then + ---@diagnostic disable-next-line: cast-local-type + prev.orig_window = tonumber(name_splt[2]) + prev.term = terms[i] + end + if terms[i].direction == 'float' then + prev.float = true + end + elseif name_splt[1] == 'piomon' then + prev.mon = terms[i] + if terms[i].window == orig_window then + ---@diagnostic disable-next-line: cast-local-type + prev.orig_window = tonumber(name_splt[2]) + prev.term = terms[i] + end + if terms[i].direction == 'float' then + prev.float = true + end + end + end + end + end + return prev +end + +local function send(term, cmd) + vim.fn.chansend(term.job_id, cmd .. enter()) + if vim.api.nvim_buf_is_loaded(term.bufnr) and vim.api.nvim_buf_is_valid(term.bufnr) then + if term.window and vim.api.nvim_win_is_valid(term.window) then + vim.api.nvim_set_current_win(term.window) + vim.api.nvim_buf_call(term.bufnr, function() + local mode = vim.api.nvim_get_mode().mode + if mode == 'n' or mode == 'nt' then + vim.cmd('normal! G') + end + end) + end + end +end + +local function PioTermClose(t) + local orig_window = tonumber(utils.strsplit(t.display_name, ':')[2]) + vim.api.nvim_win_close(t.window, true) + + if orig_window and vim.api.nvim_win_is_valid(orig_window) then + vim.api.nvim_set_current_win(orig_window) + else + vim.api.nvim_set_current_win(0) + end +end + +function M.ToggleTerminal(command, direction, exit_callback, working_dir) + if type(exit_callback) ~= 'function' then + exit_callback = function() end + end + + local status_ok, _ = pcall(require, 'toggleterm') + if not status_ok then + vim.api.nvim_echo({ { 'toggleterm not found!', 'ErrorMsg' } }, true, {}) + return + end + + local title = '' + local pioOpts = {} + + pioOpts.dir = working_dir or vim.fn.getcwd() + + local prev = getPreviousWindow(vim.api.nvim_get_current_win()) + local orig_window = prev.orig_window + + if string.find(command, ' monitor') then + if prev.mon then + local win_type = vim.fn.win_gettype(prev.mon.window) + local win_open = win_type == '' or win_type == 'popup' + if prev.mon.window and (win_open and vim.api.nvim_win_get_buf(prev.mon.window) == prev.mon.bufnr) then + vim.api.nvim_set_current_win(prev.mon.window) + else + prev.mon:open() + end + return + end + title = 'Pio Monitor: [In normal mode press: q or :q to hide; :q! to quit; :PioTermList to list terminals]' + pioOpts.display_name = 'piomon:' .. orig_window + else + if prev.cli then + prev.cli.on_close = function(t) + local ow = tonumber(utils.strsplit(t.display_name, ':')[2]) + if ow and vim.api.nvim_win_is_valid(ow) then + vim.api.nvim_set_current_win(ow) + else + vim.api.nvim_set_current_win(0) + end + exit_callback() + end + + local win_type = vim.fn.win_gettype(prev.cli.window) + local win_open = win_type == '' or win_type == 'popup' + if prev.cli.window and (win_open and vim.api.nvim_win_get_buf(prev.cli.window) == prev.cli.bufnr) then + vim.api.nvim_set_current_win(prev.cli.window) + else + prev.cli:open() + end + vim.defer_fn(function() + if command and command ~= '' then + send(prev.cli, command) + end + end, 50) + return + end + title = 'Pio CLI> [In normal mode press: q or :q to hide; :q! to quit; :PioTermList to list terminals]' + pioOpts.display_name = 'piocli:' .. orig_window + end + pioOpts.direction = direction + + local termConfig = { + hidden = true, -- Start hidden, we'll open it explicitly + hide_numbers = true, + float_opts = { + winblend = 0, + width = function() + return math.ceil(vim.o.columns * 0.85) + end, + height = function() + return math.ceil(vim.o.lines * 0.85) + end, + highlights = { + border = 'FloatBorder', + background = 'NormalFloat', + }, + }, + close_on_exit = false, + + on_open = function(t) + local hl = { bg = '#80a3d4', fg = '#000000' } + + if hl then + vim.api.nvim_set_hl(0, 'MyWinBar', { bg = hl.bg, fg = hl.fg }) + + local winBartitle = '%#MyWinBar#' .. title .. '%*' + vim.api.nvim_set_option_value('winbar', winBartitle, { scope = 'local', win = t.window }) + + -- Following necessary to solve that some time winbar not showing + vim.schedule(function() + vim.api.nvim_set_option_value('winbar', winBartitle, { scope = 'local', win = t.window }) + end) + end + vim.keymap.set('t', '', [[k]], { buffer = t.bufnr }) + vim.keymap.set('n', '', [[a]], { buffer = t.bufnr }) + + vim.keymap.set('n', 'q', function() + PioTermClose(t) + end, { desc = 'PioTermClose', buffer = t.bufnr }) + + if config.debug then + local name_splt = utils.strsplit(t.display_name, ':') + vim.api.nvim_echo({ + { 'ToggleTerm ', 'MoreMsg' }, + { '(Term name: ' .. name_splt[1] .. ')', 'MoreMsg' }, + { '(Prev win ID: ' .. name_splt[2] .. ')', 'MoreMsg' }, + { '(Term Win ID: ' .. t.window .. ')', 'MoreMsg' }, + { '(Term Buffer#: ' .. t.bufnr .. ')', 'MoreMsg' }, + { '(Term id: ' .. t.id .. ')', 'MoreMsg' }, + { '(Job ID: ' .. t.job_id .. ')', 'MoreMsg' }, + }, true, {}) + end + end, + + on_close = function(t) + orig_window = tonumber(utils.strsplit(t.display_name, ':')[2]) + ---@diagnostic disable-next-line: param-type-mismatch + if orig_window and vim.api.nvim_win_is_valid(orig_window) then + vim.api.nvim_set_current_win(orig_window) + else + vim.api.nvim_set_current_win(0) + end + exit_callback() + end, + + on_create = function(t) + local platformio = vim.api.nvim_create_augroup(utils.strsplit(t.display_name, ':')[1], { clear = true }) + + vim.api.nvim_create_autocmd('CmdlineLeave', { + group = platformio, + buffer = t.bufnr, + callback = function() + if vim.v.event and not vim.v.event.abort and vim.v.event.cmdtype == ':' then + local quit = vim.fn.getcmdline() == 'q' + local quitbang = vim.fn.getcmdline() == 'q!' + if quitbang or quit then + local name_splt = utils.strsplit(t.display_name, ':') + if quitbang then + if name_splt[1] == 'piomon' then + local exit = vim.api.nvim_replace_termcodes('exit', true, true, true) + send(t, exit) + else + send(t, 'exit') + end + end + + orig_window = tonumber(name_splt[2]) + vim.schedule(function() + if orig_window and vim.api.nvim_win_is_valid(orig_window) then + vim.api.nvim_set_current_win(orig_window) + else + vim.api.nvim_set_current_win(0) + end + end) + end + end + end, + }) + + vim.api.nvim_create_autocmd('BufUnload', { + group = platformio, + desc = 'toggleterm buffer unloaded', + buffer = t.bufnr, + callback = function(args) + vim.keymap.del('t', '', { buffer = args.buf }) + vim.keymap.del('n', '', { buffer = args.buf }) + + vim.api.nvim_clear_autocmds({ group = utils.strsplit(t.display_name, ':')[1] }) + end, + }) + end, + } + + termConfig = vim.tbl_deep_extend('force', termConfig, pioOpts or {}) + + local terminal = require('toggleterm.terminal').Terminal:new(termConfig) + if prev.term and prev.float then + prev.term:close() + end + terminal:toggle() + vim.defer_fn(function() + if command and command ~= '' then + send(terminal, command) + end + end, 50) +end + +return M diff --git a/lua/platformio/utils.lua b/lua/platformio/utils.lua index b2fe69e2..a3597173 100644 --- a/lua/platformio/utils.lua +++ b/lua/platformio/utils.lua @@ -1,7 +1,5 @@ local M = {} -local config = require('platformio').config - -- M.extra = 'printf \'\\\\n\\\\033[0;33mPlease Press ENTER to continue \\\\033[0m\'; read' M.extra = ' && echo . && echo . && echo Please Press ENTER to continue' @@ -28,298 +26,6 @@ M.is_windows = jit.os == 'Windows' M.devNul = M.is_windows and ' 2>./nul' or ' 2>/dev/null' --- INFO: get current OS enter -function M.enter() - local shell = vim.o.shell - if M.is_windows then - return vim.fn.executable('pwsh') and '\r' or '\r\n' - elseif shell:find('nu') then - return '\r' - else - return '\n' - end -end - --- INFO: get previous window -local function getPreviousWindow(orig_window) - local prev = { - orig_window = orig_window, - term = nil, --active terminal - cli = nil, --cli terminal - mon = nil, --mon terminal - float = false, --is active terminal direction float - } - local terms = require('toggleterm.terminal').get_all(true) - if #terms ~= 0 then - for i = 1, #terms do - if terms[i].display_name and terms[i].display_name ~= '' and terms[i].display_name:find('pio', 1) then - local name_splt = M.strsplit(terms[i].display_name, ':') - if name_splt[1] == 'piocli' then - prev.cli = terms[i] - if terms[i].window == orig_window then - ---@diagnostic disable-next-line: cast-local-type - prev.orig_window = tonumber(name_splt[2]) -- set orig_window to the previous terminal onrig_window - prev.term = terms[i] - end - if terms[i].direction == 'float' then - prev.float = true - end - elseif name_splt[1] == 'piomon' then - prev.mon = terms[i] - if terms[i].window == orig_window then - ---@diagnostic disable-next-line: cast-local-type - prev.orig_window = tonumber(name_splt[2]) -- set orig_window to the previous terminal onrig_window - prev.term = terms[i] - end - if terms[i].direction == 'float' then - prev.float = true - end - end - end - end - end - return prev -end - ------------------------------------------------------- --- INFO: Send command -local function send(term, cmd) - vim.fn.chansend(term.job_id, cmd .. M.enter()) - if vim.api.nvim_buf_is_loaded(term.bufnr) and vim.api.nvim_buf_is_valid(term.bufnr) then - if term.window and vim.api.nvim_win_is_valid(term.window) then --vim.ui.term_has_open_win(term) then - vim.api.nvim_set_current_win(term.window) -- terminal focus - vim.api.nvim_buf_call(term.bufnr, function() - local mode = vim.api.nvim_get_mode().mode - if mode == 'n' or mode == 'nt' then - vim.cmd('normal! G') -- normal command to Goto bottom of buffer (scroll) - end - end) - end - end -end - ------------------------------------------------------- --- INFO: PioTermClose -local function PioTermClose(t) - local orig_window = tonumber(M.strsplit(t.display_name, ':')[2]) - -- close terminal window - vim.api.nvim_win_close(t.window, true) - - -- go back to previous window - if orig_window and vim.api.nvim_win_is_valid(orig_window) then - vim.api.nvim_set_current_win(orig_window) - else - vim.api.nvim_set_current_win(0) - end -end - ------------------------------------------------------- --- INFO: ToggleTerminal -function M.ToggleTerminal(command, direction, exit_callback, working_dir) - if type(exit_callback) ~= 'function' then - exit_callback = function() end - end - - local status_ok, _ = pcall(require, 'toggleterm') - if not status_ok then - vim.api.nvim_echo({ { 'toggleterm not found!', 'ErrorMsg' } }, true, {}) - return - end - - local title = '' - local pioOpts = {} - - pioOpts.dir = working_dir or vim.fn.getcwd() - - -- INFO: set orig_window to current window, or if available get current toggleterm previous window - local prev = getPreviousWindow(vim.api.nvim_get_current_win()) - local orig_window = prev.orig_window - - if string.find(command, ' monitor') then - if prev.mon then -- INFO: if previous monitor terminal already opened ==> reopen - local win_type = vim.fn.win_gettype(prev.mon.window) - local win_open = win_type == '' or win_type == 'popup' - if prev.mon.window and (win_open and vim.api.nvim_win_get_buf(prev.mon.window) == prev.mon.bufnr) then - vim.api.nvim_set_current_win(prev.mon.window) - else - prev.mon:open() - end - return - end - title = 'Pio Monitor: [In normal mode press: q or :q to hide; :q! to quit; :PioTermList to list terminals]' - pioOpts.display_name = 'piomon:' .. orig_window - else -- INFO: if previous cli terminal already opened ==> reopen - if prev.cli then - prev.cli.on_close = function(t) - local ow = tonumber(M.strsplit(t.display_name, ':')[2]) - if ow and vim.api.nvim_win_is_valid(ow) then - vim.api.nvim_set_current_win(ow) - else - vim.api.nvim_set_current_win(0) - end - exit_callback() - end - - local win_type = vim.fn.win_gettype(prev.cli.window) - local win_open = win_type == '' or win_type == 'popup' - if prev.cli.window and (win_open and vim.api.nvim_win_get_buf(prev.cli.window) == prev.cli.bufnr) then - vim.api.nvim_set_current_win(prev.cli.window) - else - prev.cli:open() - end - vim.defer_fn(function() - if command and command ~= '' then - send(prev.cli, command) - end - end, 50) -- 50ms delay, adjust as needed - return - end - title = 'Pio CLI> [In normal mode press: q or :q to hide; :q! to quit; :PioTermList to list terminals]' - pioOpts.display_name = 'piocli:' .. orig_window - end - pioOpts.direction = direction - ------------------------------------------------------ - - -- INFO: termConfig table start - local termConfig = { - hidden = true, -- Start hidden, we'll open it explicitly - hide_numbers = true, - float_opts = { - winblend = 0, - width = function() - return math.ceil(vim.o.columns * 0.85) - end, - height = function() - return math.ceil(vim.o.lines * 0.85) - end, - highlights = { - border = 'FloatBorder', - background = 'NormalFloat', - }, - }, - close_on_exit = false, - - -- INFO: on_open() - on_open = function(t) - -- Get properties of the 'Normal' highlight group (background of main editor) - -- local hl = vim.api.nvim_get_hl(0, { name = 'PmenuSel' }) - -- local hl = { bg = '#e4cf0e', fg = '#0012d9' } - local hl = { bg = '#80a3d4', fg = '#000000' } - - if hl then - vim.api.nvim_set_hl(0, 'MyWinBar', { bg = hl.bg, fg = hl.fg }) - - local winBartitle = '%#MyWinBar#' .. title .. '%*' - vim.api.nvim_set_option_value('winbar', winBartitle, { scope = 'local', win = t.window }) - - -- Following necessary to solve that some time winbar not showing - vim.schedule(function() - vim.api.nvim_set_option_value('winbar', winBartitle, { scope = 'local', win = t.window }) - end) - end - vim.keymap.set('t', '', [[k]], { buffer = t.bufnr }) - vim.keymap.set('n', '', [[a]], { buffer = t.bufnr }) - - vim.keymap.set('n', 'q', function() - PioTermClose(t) - end, { desc = 'PioTermClose', buffer = t.bufnr }) - - if config.debug then - local name_splt = M.strsplit(t.display_name, ':') - vim.api.nvim_echo({ - { 'ToggleTerm ', 'MoreMsg' }, - { '(Term name: ' .. name_splt[1] .. ')', 'MoreMsg' }, - { '(Prev win ID: ' .. name_splt[2] .. ')', 'MoreMsg' }, - { '(Term Win ID: ' .. t.window .. ')', 'MoreMsg' }, - { '(Term Buffer#: ' .. t.bufnr .. ')', 'MoreMsg' }, - { '(Term id: ' .. t.id .. ')', 'MoreMsg' }, - { '(Job ID: ' .. t.job_id .. ')', 'MoreMsg' }, - }, true, {}) - end - end, - - -- INFO: on_close() - on_close = function(t) - orig_window = tonumber(M.strsplit(t.display_name, ':')[2]) - ---@diagnostic disable-next-line: param-type-mismatch - if orig_window and vim.api.nvim_win_is_valid(orig_window) then - vim.api.nvim_set_current_win(orig_window) - else - vim.api.nvim_set_current_win(0) - end - exit_callback() - end, - - -- INFO: on_create() { - on_create = function(t) - local platformio = vim.api.nvim_create_augroup(M.strsplit(t.display_name, ':')[1], { clear = true }) - - -- INFO: CmdlineLeave - vim.api.nvim_create_autocmd('CmdlineLeave', { - group = platformio, - -- pattern = ':', - buffer = t.bufnr, - callback = function() - if vim.v.event and not vim.v.event.abort and vim.v.event.cmdtype == ':' then - local quit = vim.fn.getcmdline() == 'q' - local quitbang = vim.fn.getcmdline() == 'q!' - if quitbang or quit then - local name_splt = M.strsplit(t.display_name, ':') - if quitbang then - if name_splt[1] == 'piomon' then -- monitor terminal - local exit = vim.api.nvim_replace_termcodes('exit', true, true, true) - send(t, exit) - else -- cli terminal - send(t, 'exit') - end - end - - orig_window = tonumber(name_splt[2]) - vim.schedule(function() - -- go back to previous window - if orig_window and vim.api.nvim_win_is_valid(orig_window) then - vim.api.nvim_set_current_win(orig_window) - else - vim.api.nvim_set_current_win(0) - end - end) - end - end - end, - }) - - -- INFO: BufUnload - vim.api.nvim_create_autocmd('BufUnload', { - group = platformio, - desc = 'toggleterm buffer unloaded', - buffer = t.bufnr, - callback = function(args) - vim.keymap.del('t', '', { buffer = args.buf }) - vim.keymap.del('n', '', { buffer = args.buf }) - - -- clear autommmand when quit - vim.api.nvim_clear_autocmds({ group = M.strsplit(t.display_name, ':')[1] }) - end, - }) - end, - } - -- INFO: termConfig table end - - termConfig = vim.tbl_deep_extend('force', termConfig, pioOpts or {}) - - -- INFO: create new terminal - local terminal = require('toggleterm.terminal').Terminal:new(termConfig) - if prev.term and prev.float then - prev.term:close() - end - terminal:toggle() - vim.defer_fn(function() - if command and command ~= '' then - send(terminal, command) - end - end, 50) -- 50ms delay, adjust as needed sgget -end - ---------------------------------------------------------------------------------------- function M.file_exists(name) diff --git a/lua/vim/health/platformio.lua b/lua/vim/health/platformio.lua deleted file mode 100644 index 519b3864..00000000 --- a/lua/vim/health/platformio.lua +++ /dev/null @@ -1 +0,0 @@ -return require('platformio.health')