feat: expose size config via M.setup({size={horizontal,vertical}})
This commit is contained in:
parent
8981eebd1a
commit
898ab9caaa
|
|
@ -2,6 +2,14 @@
|
||||||
--
|
--
|
||||||
-- 特性:持久化终端实例、自适应窗口方向(横屏右分屏/竖屏下分屏)、依赖 toggleterm.nvim
|
-- 特性:持久化终端实例、自适应窗口方向(横屏右分屏/竖屏下分屏)、依赖 toggleterm.nvim
|
||||||
--
|
--
|
||||||
|
-- 配置(可选):
|
||||||
|
-- require('QQdock').setup({
|
||||||
|
-- size = {
|
||||||
|
-- horizontal = 10, -- 竖屏下方终端高度(行数)
|
||||||
|
-- vertical = 40, -- 横屏右侧终端宽度(列数)
|
||||||
|
-- },
|
||||||
|
-- })
|
||||||
|
--
|
||||||
-- 用法:
|
-- 用法:
|
||||||
-- local Q = require('QQdock')
|
-- local Q = require('QQdock')
|
||||||
-- Q.shell() -- 打开/关闭普通 shell
|
-- Q.shell() -- 打开/关闭普通 shell
|
||||||
|
|
@ -10,8 +18,20 @@
|
||||||
|
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local config = {
|
||||||
|
size = {
|
||||||
|
horizontal = nil, -- nil = toggleterm 默认值
|
||||||
|
vertical = nil,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
local terms = {} -- 缓存终端实例,key 是命令名(nil = 普通 shell)
|
local terms = {} -- 缓存终端实例,key 是命令名(nil = 普通 shell)
|
||||||
|
|
||||||
|
---@param opts { size?: { horizontal?: integer, vertical?: integer } }
|
||||||
|
function M.setup(opts)
|
||||||
|
config = vim.tbl_deep_extend('force', config, opts or {})
|
||||||
|
end
|
||||||
|
|
||||||
function M.open(cmd)
|
function M.open(cmd)
|
||||||
local ui = vim.api.nvim_list_uis()[1]
|
local ui = vim.api.nvim_list_uis()[1]
|
||||||
if not ui then
|
if not ui then
|
||||||
|
|
@ -19,12 +39,17 @@ function M.open(cmd)
|
||||||
end
|
end
|
||||||
local tall = ui.height > ui.width
|
local tall = ui.height > ui.width
|
||||||
local name = cmd or '__shell__'
|
local name = cmd or '__shell__'
|
||||||
|
local opts = {
|
||||||
if not terms[name] or not terms[name]:is_open() then
|
|
||||||
terms[name] = require('toggleterm.terminal').Terminal:new({
|
|
||||||
direction = tall and 'horizontal' or 'vertical',
|
direction = tall and 'horizontal' or 'vertical',
|
||||||
cmd = cmd,
|
cmd = cmd,
|
||||||
})
|
}
|
||||||
|
local sz = tall and config.size.horizontal or config.size.vertical
|
||||||
|
if sz then
|
||||||
|
opts.size = sz
|
||||||
|
end
|
||||||
|
|
||||||
|
if not terms[name] or not terms[name]:is_open() then
|
||||||
|
terms[name] = require('toggleterm.terminal').Terminal:new(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
terms[name]:toggle()
|
terms[name]:toggle()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue