38 lines
964 B
Lua
38 lines
964 B
Lua
-- addons/QQdock.lua — 持久化自适应终端
|
||
--
|
||
-- 注意:这是 QQdock.nvim 插件的本地副本(根分区只读,无法通过 lazy 装远程插件)
|
||
-- 远程仓库:https://git.qyhhh.top/newbie/QQdock.nvim
|
||
--
|
||
-- 用法:
|
||
-- local Q = require('addons.QQdock')
|
||
-- Q.shell() -- <c-t> 普通终端
|
||
-- Q.open('reasonix') -- <C-i> Reasonix
|
||
-- Q.open('lazygit') -- <leader>gg lazygit
|
||
|
||
local M = {}
|
||
|
||
local terms = {}
|
||
|
||
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
|
||
|
||
function M.shell()
|
||
M.open(nil)
|
||
end
|
||
|
||
return M
|