mirror of
https://github.com/SpaceVim/SpaceVim.git
synced 2025-02-15 23:39:27 +08:00
docs(nvim-plug): update default ui
This commit is contained in:
parent
5d7b6aa055
commit
42cc99b36a
16
bundle/nvim-plug/README.md
vendored
16
bundle/nvim-plug/README.md
vendored
@ -60,10 +60,20 @@ require('plug').add({
|
||||
|
||||
- `:PlugInstall`: install specific plugin
|
||||
|
||||
## Default UI
|
||||
|
||||
The default is ui is inspired by [vundle](https://github.com/VundleVim/Vundle.vim)
|
||||
|
||||
The default highlight group.
|
||||
|
||||
| highlight group name | description |
|
||||
| -------------------- | ------------------------------- |
|
||||
| `PlugTitle` | the first line of plugin window |
|
||||
| `PlugProcess` | the process of downloading |
|
||||
|
||||
## Custom Plugin UI
|
||||
|
||||
The default is ui is inspired by [vundle](https://github.com/VundleVim/Vundle.vim), to setup custom UI,
|
||||
you need to creat a on_update function, this function is called with two arges:
|
||||
To setup custom UI, you need to creat a on_update function, this function is called with two arges:
|
||||
|
||||
- name: `string`
|
||||
- date: `PlugUiData`
|
||||
@ -72,7 +82,6 @@ you need to creat a on_update function, this function is called with two arges:
|
||||
| ------------ | ---------------------------------------- |
|
||||
| `clone_done` | boolead, is true when clone successfully |
|
||||
|
||||
|
||||
```lua
|
||||
--- your custom UI
|
||||
|
||||
@ -89,7 +98,6 @@ require('plug').setup({
|
||||
})
|
||||
```
|
||||
|
||||
|
||||
## Feedback
|
||||
|
||||
The development of this plugin is in [`SpaceVim/bundle/nvim-plug`](https://github.com/SpaceVim/SpaceVim/tree/master/bundle/nvim-plug) directory.
|
||||
|
46
bundle/nvim-plug/lua/plug/ui.lua
vendored
46
bundle/nvim-plug/lua/plug/ui.lua
vendored
@ -11,9 +11,22 @@ local bufnr = -1
|
||||
local winid = -1
|
||||
local done = 0
|
||||
local total = -1
|
||||
local weight = math.floor(vim.o.columns / 2)
|
||||
local weight = 100
|
||||
local plugin_status = {}
|
||||
|
||||
local function count_done(p)
|
||||
done = 0
|
||||
for _, v in pairs(p) do
|
||||
if v.clone_done then
|
||||
done = done + 1
|
||||
end
|
||||
end
|
||||
return done
|
||||
end
|
||||
local base = function()
|
||||
weight = math.floor(vim.o.columns / 2)
|
||||
total = #vim.tbl_keys(plugin_status)
|
||||
done = count_done(plugin_status)
|
||||
weight = vim.api.nvim_win_get_width(winid) - 10
|
||||
return {
|
||||
'plugins:(' .. done .. '/' .. total .. ')',
|
||||
'',
|
||||
@ -25,21 +38,14 @@ local base = function()
|
||||
}
|
||||
end
|
||||
|
||||
--- @clase PluginStatus
|
||||
--- @filed downloaded boolean
|
||||
--- @filed download_process number 0 - 100
|
||||
|
||||
local plugin_status = {}
|
||||
|
||||
local function build_context()
|
||||
total = #plugin_status
|
||||
local b = base()
|
||||
|
||||
for _, plug in ipairs(plugin_status) do
|
||||
if type(plug.downloaded) == 'boolean' and plug.downloaded then
|
||||
table.insert(b, '+ ' .. plug.name .. ' downloaded')
|
||||
for k, plug in pairs(plugin_status) do
|
||||
if plug.clone_done then
|
||||
table.insert(b, '+ ' .. k .. ' downloaded')
|
||||
else
|
||||
table.insert(b, '- ' .. plug.name .. string.format(' (%s%%)', plug.download_process))
|
||||
table.insert(b, '- ' .. k .. string.format(' (%s%%)', plug.clone_process))
|
||||
end
|
||||
end
|
||||
|
||||
@ -58,9 +64,13 @@ M.open = function()
|
||||
if vim.api.nvim_buf_is_valid(bufnr) then
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, build_context())
|
||||
end
|
||||
--- setup highlight
|
||||
vim.cmd('hi def link PlugTitle TODO')
|
||||
vim.cmd('hi def link PlugProcess Repeat')
|
||||
vim.fn.matchadd('PlugTitle', '', 2, -1, { window = winid })
|
||||
vim.fn.matchadd('PlugProcess', '^\\[\\zs=*', 2, -1, { window = winid })
|
||||
end
|
||||
|
||||
|
||||
--- @class PlugUiData
|
||||
--- Job 的消息推送到 UI manager
|
||||
--- install:
|
||||
@ -73,13 +83,7 @@ end
|
||||
--- @param name string
|
||||
--- @param data PlugUiData
|
||||
M.on_update = function(name, data)
|
||||
if not plugin_status[name] then
|
||||
plugin_status[name] = {
|
||||
downloaded = data.downloaded or false,
|
||||
download_process = data.download_process or 0,
|
||||
}
|
||||
else
|
||||
end
|
||||
plugin_status[name] = vim.tbl_deep_extend('force', plugin_status[name] or {}, data)
|
||||
if vim.api.nvim_buf_is_valid(bufnr) then
|
||||
vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, build_context())
|
||||
end
|
||||
|
8
bundle/nvim-plug/test/ui.lua
vendored
8
bundle/nvim-plug/test/ui.lua
vendored
@ -1,5 +1,11 @@
|
||||
local ui = require('plug.ui')
|
||||
ui.open()
|
||||
ui.on_update('test.vim', {
|
||||
downdloaded = true,
|
||||
clone_done = true,
|
||||
})
|
||||
ui.on_update('test2.vim', {
|
||||
clone_process = '67',
|
||||
})
|
||||
ui.on_update('test3.vim', {
|
||||
clone_done = true,
|
||||
})
|
||||
|
Loading…
Reference in New Issue
Block a user