Skip to content

Commit

Permalink
Add progress window
Browse files Browse the repository at this point in the history
  • Loading branch information
Shougo committed Oct 11, 2023
1 parent ef2a00b commit e8a8a1f
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 7 deletions.
58 changes: 58 additions & 0 deletions autoload/dpp/ext/installer.vim
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
function dpp#ext#installer#_print_progress_message(msg) abort
if !exists('s:progress_winid') || s:progress_winid <= 0
let s:progress_winid = s:new_progress_window()
endif

const bufnr = s:progress_winid->winbufnr()
if bufnr->getbufline(1) ==# ['']
call setbufline(bufnr, 1, a:msg)
else
call appendbufline(bufnr, '$', a:msg)
endif
call win_execute(s:progress_winid, "call cursor('$', 0) | redraw")
endfunction

function dpp#ext#installer#_close_progress_window() abort
if !exists('s:progress_winid') || s:progress_winid->winbufnr() < 0
return
endif

if has('nvim')
silent! call nvim_win_close(s:progress_winid, v:true)
else
silent! call popup_close(s:progress_winid)
endif

let s:progress_winid = -1
endfunction

function s:new_progress_window() abort
const winrow = 0
const wincol = &columns / 4
const winwidth = 80
const winheight = 20

if has('nvim')
const winid = nvim_open_win(nvim_create_buf(v:false, v:true), v:true, #{
\ relative: 'editor',
\ row: winrow,
\ col: wincol,
\ focusable: v:false,
\ noautocmd: v:true,
\ style: 'minimal',
\ width: winwidth,
\ height: winheight,
\})
else
const winid = popup_create([], #{
\ pos: 'topleft',
\ line: winrow + 1,
\ col: wincol + 1,
\ minwidth: winwidth,
\ minheight: winheight,
\ wrap: 0,
\ })
endif

return winid
endfunction
33 changes: 26 additions & 7 deletions denops/@dpp-exts/installer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ async function updatePlugins(args: {
}, plugins: Plugin[]) {
// NOTE: Skip local plugins
for (const plugin of plugins.filter((plugin) => !plugin.local)) {
console.log(plugin.name);
await args.denops.call(
"dpp#ext#installer#_print_progress_message",
plugin.name,
);

const protocol = args.protocols[plugin.protocol ?? ""];

Expand All @@ -115,7 +118,6 @@ async function updatePlugins(args: {

// Execute commands
for (const command of commands) {
console.log(command);
const proc = new Deno.Command(
command.command,
{
Expand All @@ -128,13 +130,30 @@ async function updatePlugins(args: {

const { stdout, stderr } = await proc.output();

const outLines = new TextDecoder().decode(stdout).split(/\r?\n/);
console.log(outLines);
for (
const line of new TextDecoder().decode(stdout).split(/\r?\n/).filter((
line,
) => line.length > 0)
) {
await args.denops.call(
"dpp#ext#installer#_print_progress_message",
line,
);
}

const errLines = new TextDecoder().decode(stderr).split(/\r?\n/);
console.log(errLines);
for (
const line of new TextDecoder().decode(stderr).split(/\r?\n/).filter((
line,
) => line.length > 0)
) {
await args.denops.call(
"dpp#ext#installer#_print_progress_message",
line,
);
}
}

}

console.log("Done");
await args.denops.call("dpp#ext#installer#_close_progress_window");
}
4 changes: 4 additions & 0 deletions doc/dpp-ext-installer.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Please install both "dpp.vim" and "denops.vim".
https://github.com/Shougo/dpp.vim
https://github.com/vim-denops/denops.vim

And you need to install protocol like "dpp-protocol-git".

https://github.com/Shougo/dpp-protocol-git


==============================================================================
EXAMPLES *dpp-ext-installer-examples*
Expand Down

0 comments on commit e8a8a1f

Please sign in to comment.