45 lines
1.2 KiB
Lua
45 lines
1.2 KiB
Lua
-- QQdock.nvim — Persistent adaptive terminal dock
|
|
--
|
|
-- 依赖 toggleterm.nvim
|
|
--
|
|
-- 用法:
|
|
-- local Q = require('QQdock')
|
|
-- Q.shell() -- 打开/关闭普通 shell
|
|
-- Q.open('reasonix') -- 打开/关闭 Reasonix
|
|
-- Q.open('lazygit') -- 打开/关闭 lazygit
|
|
|
|
local M = {}
|
|
|
|
local terms = {}
|
|
|
|
---Open or toggle a persistent terminal running `cmd`.
|
|
---When the window is wider than tall, the terminal opens on the right side (vertical split),
|
|
---taking 45% of the width. When taller than wide, it opens at the bottom (horizontal split),
|
|
---taking 40% of the height.
|
|
---@param cmd string|nil The command to run, or nil for a plain shell.
|
|
function M.open(cmd)
|
|
local ui = vim.api.nvim_list_uis()[1]
|
|
if not ui then
|
|
return
|
|
end
|
|
local tall = ui.height > ui.width
|
|
local name = cmd or '__shell__'
|
|
|
|
if not terms[name] or not terms[name]:is_open() then
|
|
terms[name] = require('toggleterm.terminal').Terminal:new({
|
|
direction = tall and 'horizontal' or 'vertical',
|
|
cmd = cmd,
|
|
size = tall and math.floor(ui.height * 0.4) or math.floor(ui.width * 0.45),
|
|
})
|
|
end
|
|
|
|
terms[name]:toggle()
|
|
end
|
|
|
|
---Toggle a plain shell terminal.
|
|
function M.shell()
|
|
M.open(nil)
|
|
end
|
|
|
|
return M
|