feat: terminal persistence (toggle show/hide), size 40%-45% like IDE split

This commit is contained in:
QQ 2026-06-11 16:53:09 +08:00
parent bb1a4df9fa
commit e45a3b991e
1 changed files with 17 additions and 12 deletions

View File

@ -38,22 +38,27 @@ G.map({
{ 'n', '<right>', ':vertical resize +5<CR>' }, { 'n', '<right>', ':vertical resize +5<CR>' },
}) })
-- 终端 / Reasonix横屏→右侧,竖屏→下方 -- 终端 / Reasonix横屏→右侧45%屏宽),竖屏→下方40%屏高),持久化 buffer按 c-t/c-i 切换显隐)
do do
local function split_term(ui, cmd) local terms = {} -- 缓存,复用同一个终端实例
local function split_term(cmd)
local ui = vim.api.nvim_list_uis()[1]
local tall = ui.height > ui.width local tall = ui.height > ui.width
local term = require('toggleterm.terminal').Terminal:new({ local name = cmd or '__shell__'
-- 横屏→右侧(垂直分屏);竖屏→下方(水平分屏) if not terms[name] or not terms[name]:is_open() then
direction = tall and 'horizontal' or 'vertical', terms[name] = require('toggleterm.terminal').Terminal:new({
cmd = cmd, direction = tall and 'horizontal' or 'vertical',
size = tall and 10 or 40, cmd = cmd,
}) size = tall and math.floor(ui.height * 0.4) or math.floor(ui.width * 0.45),
term:toggle() })
end
terms[name]:toggle()
end end
G.map({ G.map({
{ 'n', '<c-t>', function() split_term(vim.api.nvim_list_uis()[1]) end, { noremap = true } }, { 'n', '<c-t>', function() split_term() end, { noremap = true } },
{ 'i', '<c-t>', function() split_term(vim.api.nvim_list_uis()[1]) end, { noremap = true } }, { 'i', '<c-t>', function() split_term() end, { noremap = true } },
{ 'n', '<C-i>', function() split_term(vim.api.nvim_list_uis()[1], 'reasonix') end, { noremap = true } }, { 'n', '<C-i>', function() split_term('reasonix') end, { noremap = true } },
}) })
end end