Skip to content

Commit

Permalink
docs(nvim-plug): update default ui
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdjeg committed Feb 6, 2025
1 parent 5d7b6aa commit 42cc99b
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 26 deletions.
16 changes: 12 additions & 4 deletions bundle/nvim-plug/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`
Expand All @@ -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

Expand All @@ -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.
Expand Down
46 changes: 25 additions & 21 deletions bundle/nvim-plug/lua/plug/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 .. ')',
'',
Expand All @@ -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

Expand All @@ -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:
Expand All @@ -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
Expand Down
8 changes: 7 additions & 1 deletion bundle/nvim-plug/test/ui.lua
Original file line number Diff line number Diff line change
@@ -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,
})

0 comments on commit 42cc99b

Please sign in to comment.