基础插件管理界面与命令

This commit is contained in:
2025-07-15 13:54:48 +08:00
parent 446b801c05
commit dbb3f1db68
3 changed files with 66 additions and 0 deletions

View File

@ -26,6 +26,8 @@ export def Init(plug_home: string = v:none)
tui#core#cached#Set('tui.plug.registed', {}) tui#core#cached#Set('tui.plug.registed', {})
tui#core#cached#Set('tui.plug.enabled', []) tui#core#cached#Set('tui.plug.enabled', [])
tui#core#cached#Set('tui.plug.disabled', []) tui#core#cached#Set('tui.plug.disabled', [])
command! -nargs=0 -bar TuiPlug call tui#core#plug#Install()
endif endif
enddef enddef
@ -135,6 +137,64 @@ def Parse(plug_id: string, plug_options: dict<any> = {}): dict<any>
return plug_info return plug_info
enddef enddef
export def Install()
var tui_plug_registed = tui#core#cached#Get('tui.plug.registed', {})
var tui_plugs = []
var tui_plug_ids = keys(tui_plug_registed)
if !empty(tui_plug_registed)
var index = 1
for plug_id in tui_plug_ids
var item = '' .. index .. ' '
var plug_info = tui_plug_registed[plug_id]
var plug_state = ' '
if isdirectory(plug_info['path'])
plug_state = 'D'
if plug_info['enabled']
plug_state = 'E'
endif
endif
item = item .. '[' .. plug_state .. '] '
item = item .. split(plug_id, '/')[-1]
add(tui_plugs, item)
index += 1
endfor
endif
var minwidth = 60
popup_menu(tui_plugs, {
title: 'Plugins - ' .. tui#core#cached#Get('tui.plug.home'),
minwidth: minwidth,
callback: (_, index) => {
echo index
if index > 0
var plug_id = tui_plug_ids[index - 1]
var plug_info = tui_plug_registed[plug_id]
if !isdirectory(plug_info['path'])
var cmds = 'git clone https://github.com/' .. plug_id .. ' ' .. plug_info['path']
echo "executing " .. cmds
system(cmds)
echo "install success"
else
echo 'plug: ' .. plug_id .. ' already install.'
endif
endif
},
filter: (id, key) => {
if key == ' '
return false
elseif key == 'i' || key == 'I'
return popup_filter_menu(id, ' ')
else
return popup_filter_menu(id, key)
endif
}
})
enddef
export def Hook() export def Hook()
var tui_plug_registed = tui#core#cached#Get('tui.plug.registed', {}) var tui_plug_registed = tui#core#cached#Get('tui.plug.registed', {})
var tui_plug_enabled = tui#core#cached#Get('tui.plug.enabled', []) var tui_plug_enabled = tui#core#cached#Get('tui.plug.enabled', [])

View File

@ -4,3 +4,5 @@ TuiLayer plug.colorscheme
TuiLayer plug.nerdtree TuiLayer plug.nerdtree
TuiLayer plug.poplar

4
layers/plug/poplar.vim Normal file
View File

@ -0,0 +1,4 @@
vim9script
tui#core#plug#Regist('ycm/poplar.vim')