diff --git a/autoload/tui/core/plug.vim b/autoload/tui/core/plug.vim index 50a8425..293c53e 100644 --- a/autoload/tui/core/plug.vim +++ b/autoload/tui/core/plug.vim @@ -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.enabled', []) tui#core#cached#Set('tui.plug.disabled', []) + + command! -nargs=0 -bar TuiPlug call tui#core#plug#Install() endif enddef @@ -135,6 +137,64 @@ def Parse(plug_id: string, plug_options: dict = {}): dict return plug_info 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() var tui_plug_registed = tui#core#cached#Get('tui.plug.registed', {}) var tui_plug_enabled = tui#core#cached#Get('tui.plug.enabled', []) diff --git a/layers/plug/init.vim b/layers/plug/init.vim index 83f5759..4aa7e73 100644 --- a/layers/plug/init.vim +++ b/layers/plug/init.vim @@ -4,3 +4,5 @@ TuiLayer plug.colorscheme TuiLayer plug.nerdtree +TuiLayer plug.poplar + diff --git a/layers/plug/poplar.vim b/layers/plug/poplar.vim new file mode 100644 index 0000000..333ff04 --- /dev/null +++ b/layers/plug/poplar.vim @@ -0,0 +1,4 @@ +vim9script + +tui#core#plug#Regist('ycm/poplar.vim') +