Junegunn Choi 12 лет назад
Родитель
Сommit
d37c7a47d7
1 измененных файлов с 17 добавлено и 12 удалено
  1. 17 12
      plug.vim

+ 17 - 12
plug.vim

@@ -179,11 +179,13 @@ function! s:syntax()
   syntax region plug2 start=/\%2l/ end=/\%3l/ contains=ALL
   syntax region plug2 start=/\%2l/ end=/\%3l/ contains=ALL
   syn match plugNumber /[0-9]\+[0-9.]*/ containedin=plug1 contained
   syn match plugNumber /[0-9]\+[0-9.]*/ containedin=plug1 contained
   syn match plugBracket /[[\]]/ containedin=plug2 contained
   syn match plugBracket /[[\]]/ containedin=plug2 contained
+  syn match plugX /x/ containedin=plug2 contained
   syn match plugDash /^-/
   syn match plugDash /^-/
   syn match plugName /\(^- \)\@<=[^:]*/
   syn match plugName /\(^- \)\@<=[^:]*/
   syn match plugError /^- [^:]\+: (x).*/
   syn match plugError /^- [^:]\+: (x).*/
   hi def link plug1       Title
   hi def link plug1       Title
   hi def link plug2       Repeat
   hi def link plug2       Repeat
+  hi def link plugX       Exception
   hi def link plugBracket Structure
   hi def link plugBracket Structure
   hi def link plugNumber  Number
   hi def link plugNumber  Number
   hi def link plugDash    Special
   hi def link plugDash    Special
@@ -229,13 +231,12 @@ function! s:assign_name()
 endfunction
 endfunction
 
 
 function! s:finish()
 function! s:finish()
-  call append(line('$'), '')
-  call append(line('$'), 'Finishing ... ')
+  call append(3, '- Finishing ... ')
   redraw
   redraw
   call s:apply()
   call s:apply()
   call s:syntax()
   call s:syntax()
-  call setline(line('$'), getline(line('$')) . 'Done!')
-  normal! G
+  call setline(4, getline(4) . 'Done!')
+  normal! gg
 endfunction
 endfunction
 
 
 function! s:update_impl(pull, args)
 function! s:update_impl(pull, args)
@@ -271,10 +272,10 @@ function! s:extend(names)
   return filter(copy(g:plugs), '!has_key(prev, v:key)')
   return filter(copy(g:plugs), '!has_key(prev, v:key)')
 endfunction
 endfunction
 
 
-function! s:update_progress(pull, cnt, total)
+function! s:update_progress(pull, cnt, bar, total)
   call setline(1, (a:pull ? 'Updating' : 'Installing').
   call setline(1, (a:pull ? 'Updating' : 'Installing').
         \ " plugins (".a:cnt."/".a:total.")")
         \ " plugins (".a:cnt."/".a:total.")")
-  call s:progress_bar(2, a:cnt, a:total)
+  call s:progress_bar(2, a:bar, a:total)
   normal! 2G
   normal! 2G
   redraw
   redraw
 endfunction
 endfunction
@@ -285,6 +286,7 @@ function! s:update_serial(pull)
   let todo  = copy(g:plugs)
   let todo  = copy(g:plugs)
   let total = len(todo)
   let total = len(todo)
   let done  = {}
   let done  = {}
+  let bar   = ''
 
 
   while !empty(todo)
   while !empty(todo)
     for [name, spec] in items(todo)
     for [name, spec] in items(todo)
@@ -317,14 +319,15 @@ function! s:update_serial(pull)
       if error
       if error
         let result = '(x) ' . result
         let result = '(x) ' . result
       endif
       endif
+      let bar .= error ? 'x' : '='
       call append(3, '- ' . name . ': ' . result)
       call append(3, '- ' . name . ': ' . result)
-      call s:update_progress(a:pull, len(done), total)
+      call s:update_progress(a:pull, len(done), bar, total)
     endfor
     endfor
 
 
     if !empty(s:extend(keys(todo)))
     if !empty(s:extend(keys(todo)))
       let todo = filter(copy(g:plugs), '!has_key(done, v:key)')
       let todo = filter(copy(g:plugs), '!has_key(done, v:key)')
       let total += len(todo)
       let total += len(todo)
-      call s:update_progress(a:pull, len(done), total)
+      call s:update_progress(a:pull, len(done), bar, total)
     else
     else
       break
       break
     endif
     endif
@@ -349,6 +352,7 @@ function! s:update_parallel(pull, threads)
   cd    = iswin ? 'cd /d' : 'cd'
   cd    = iswin ? 'cd /d' : 'cd'
   done  = {}
   done  = {}
   tot   = 0
   tot   = 0
+  bar   = ''
   skip  = 'Already installed'
   skip  = 'Already installed'
   mtx   = Mutex.new
   mtx   = Mutex.new
   take1 = proc { mtx.synchronize { running && all.shift } }
   take1 = proc { mtx.synchronize { running && all.shift } }
@@ -356,12 +360,13 @@ function! s:update_parallel(pull, threads)
     cnt = done.length
     cnt = done.length
     tot = VIM::evaluate('len(g:plugs)') || tot
     tot = VIM::evaluate('len(g:plugs)') || tot
     $curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
     $curbuf[1] = "#{pull ? 'Updating' : 'Installing'} plugins (#{cnt}/#{tot})"
-    $curbuf[2] = '[' + ('=' * cnt).ljust(tot) + ']'
+    $curbuf[2] = '[' + bar.ljust(tot) + ']'
     VIM::command('normal! 2G')
     VIM::command('normal! 2G')
     VIM::command('redraw') unless iswin
     VIM::command('redraw') unless iswin
   }
   }
   log = proc { |name, result, ok|
   log = proc { |name, result, ok|
     mtx.synchronize do
     mtx.synchronize do
+      bar += ok ? '=' : 'x'
       done[name] = true
       done[name] = true
       result = '(x) ' + result unless ok
       result = '(x) ' + result unless ok
       result = "- #{name}: #{result}"
       result = "- #{name}: #{result}"
@@ -479,8 +484,8 @@ function! s:glob_dir(path)
   return map(filter(split(globpath(a:path, '**'), '\n'), 'isdirectory(v:val)'), 's:dirpath(v:val)')
   return map(filter(split(globpath(a:path, '**'), '\n'), 'isdirectory(v:val)'), 's:dirpath(v:val)')
 endfunction
 endfunction
 
 
-function! s:progress_bar(line, cnt, total)
-  call setline(a:line, '[' . s:lpad(repeat('=', a:cnt), a:total) . ']')
+function! s:progress_bar(line, bar, total)
+  call setline(a:line, '[' . s:lpad(a:bar, a:total) . ']')
 endfunction
 endfunction
 
 
 function! s:git_valid(spec, cd)
 function! s:git_valid(spec, cd)
@@ -524,7 +529,7 @@ function! s:clean(force)
       call add(dirs, spec.dir)
       call add(dirs, spec.dir)
     endif
     endif
     let cnt += 1
     let cnt += 1
-    call s:progress_bar(2, cnt, total)
+    call s:progress_bar(2, repeat('=', cnt), total)
     redraw
     redraw
   endfor
   endfor