Skip to content

Commit

Permalink
feat(nvim-plug): default ui
Browse files Browse the repository at this point in the history
  • Loading branch information
wsdjeg committed Feb 7, 2025
1 parent 42cc99b commit 53ccf0f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
26 changes: 26 additions & 0 deletions bundle/nvim-plug/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,32 @@

**Alpha version. Any changes, including backward incompatible changes, are applied without announcements.**

![Image](https://github.com/user-attachments/assets/93b04c48-4f41-46aa-b7f7-6390ee9622c7)

<!-- vim-markdown-toc GFM -->

- [Intro](#intro)
- [Features](#features)
- [Usage](#usage)
- [Plugin Spec](#plugin-spec)
- [Commands](#commands)
- [Default UI](#default-ui)
- [Custom Plugin UI](#custom-plugin-ui)
- [Feedback](#feedback)

<!-- vim-markdown-toc -->

## Intro

nvim-plug is anasynchronous Neovim plugin manager written in Lua.

## Features

- **faster:** written in lua.
- **async:** downloading and building via job.
- **lazy loading:** lazy load plugin based on events, comamnd, mapping, etc..
- **custom UI:** provide custom UI API.

## Usage

```lua
Expand Down
8 changes: 4 additions & 4 deletions bundle/nvim-plug/lua/plug/installer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ local function install_plugin(plugSpec)
return
elseif vim.fn.isdirectory(plugSpec.path) == 1 then
-- if the directory exists, skip installation
on_uidate(plugSpec.name, { downloaded = true })
on_uidate(plugSpec.name, { clone_done = true })
return
end
local cmd = { 'git', 'clone', '--depth', '1', '--progress' }
Expand All @@ -85,7 +85,7 @@ local function install_plugin(plugSpec)

table.insert(cmd, plugSpec.url)
table.insert(cmd, plugSpec.path)
on_uidate(plugSpec.name, { downloaded = false, download_process = 0 })
on_uidate(plugSpec.name, { clone_process = 0 })
local jobid = job.start(cmd, {
on_stdout = function(id, data)
for _, v in ipairs(data) do
Expand All @@ -102,12 +102,12 @@ local function install_plugin(plugSpec)
end,
on_exit = function(id, data, single)
if data == 0 and single == 0 then
on_uidate(plugSpec.name, { downloaded = true, download_process = 100 })
on_uidate(plugSpec.name, { clone_done = true, download_process = 100 })
if plugSpec.build then
build(plugSpec)
end
else
on_uidate(plugSpec.name, { downloaded = false, download_process = 0 })
on_uidate(plugSpec.name, { clone_done = false, download_process = 0 })
end
processes = processes - 1
if #installation_queue > 0 then
Expand Down
16 changes: 12 additions & 4 deletions bundle/nvim-plug/lua/plug/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local base = function()
done = count_done(plugin_status)
weight = vim.api.nvim_win_get_width(winid) - 10
return {
'plugins:(' .. done .. '/' .. total .. ')',
'Plugins:(' .. done .. '/' .. total .. ')',
'',
'[' .. string.rep('=', math.floor(done / total * weight)) .. string.rep(
' ',
Expand All @@ -43,9 +43,11 @@ local function build_context()

for k, plug in pairs(plugin_status) do
if plug.clone_done then
table.insert(b, '+ ' .. k .. ' downloaded')
table.insert(b, '' .. k .. ' installed')
elseif plug.clone_done == false then
table.insert(b, '× ' .. k .. ' failed to install')
else
table.insert(b, '- ' .. k .. string.format(' (%s%%)', plug.clone_process))
table.insert(b, '- ' .. k .. string.format(' cloning: %s', plug.clone_process))
end
end

Expand All @@ -67,8 +69,14 @@ M.open = function()
--- 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.cmd('hi def link PlugDone Type')
vim.cmd('hi def link PlugFailed WarningMsg')
vim.cmd('hi def link PlugDoing Number')
vim.fn.matchadd('PlugTitle', '^Plugins.*', 2, -1, { window = winid })
vim.fn.matchadd('PlugProcess', '^\\[\\zs=*', 2, -1, { window = winid })
vim.fn.matchadd('PlugDone', '^√.*', 2, -1, { window = winid })
vim.fn.matchadd('PlugFailed', '^×.*', 2, -1, { window = winid })
vim.fn.matchadd('PlugDoing', '^-.*', 2, -1, { window = winid })
end

--- @class PlugUiData
Expand Down
5 changes: 4 additions & 1 deletion bundle/nvim-plug/test/ui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ ui.on_update('test.vim', {
clone_done = true,
})
ui.on_update('test2.vim', {
clone_process = '67',
clone_process = '16% (160/1000)',
})
ui.on_update('test3.vim', {
clone_done = true,
})
ui.on_update('test4.vim', {
clone_done = false,
})

0 comments on commit 53ccf0f

Please sign in to comment.