diff --git a/autoload/dispatch/screen.vim b/autoload/dispatch/screen.vim index 2e9702b..146f2ed 100644 --- a/autoload/dispatch/screen.vim +++ b/autoload/dispatch/screen.vim @@ -5,13 +5,17 @@ if exists('g:autoloaded_dispatch_screen') endif let g:autoloaded_dispatch_screen = 1 +let s:waiting = {} + function! dispatch#screen#handle(request) abort if empty($STY) || !executable('screen') return 0 endif + call dispatch#screen#poll() + if a:request.action ==# 'make' - if !get(a:request, 'background', 0) && empty(v:servername) - return 0 + if !get(a:request, 'background', 0) && empty(v:servername) && !empty(s:waiting) + return 0 endif return dispatch#screen#spawn(dispatch#prepare_make(a:request), a:request) elseif a:request.action ==# 'start' @@ -20,14 +24,23 @@ function! dispatch#screen#handle(request) abort endfunction function! dispatch#screen#spawn(command, request) abort + let teardown = 'screen -X eval "focus bottom" "remove"' + if a:request.background + let teardown = '' + endif let command = 'screen -ln -fn -t '.dispatch#shellescape(a:request.title) \ . ' ' . &shell . ' ' . &shellcmdflag . ' ' \ . shellescape('exec ' . dispatch#isolate(['STY', 'WINDOW'], - \ dispatch#set_title(a:request), a:command)) - silent execute '!' . escape(command, '!#%') + \ dispatch#set_title(a:request), a:command, teardown)) + if a:request.background - silent !screen -X other + call system(command) + else + let command = 'screen -X eval "split" "focus down" "resize 10" "' . escape(command, '"') . '" "focus up"' + call system(command) + let s:waiting = a:request endif + return 1 endfunction @@ -42,3 +55,20 @@ function! dispatch#screen#activate(pid) abort return !v:shell_error endif endfunction + +function! dispatch#screen#poll() abort + if empty(s:waiting) + return + endif + + if !dispatch#pid(s:waiting) + let request = s:waiting + let s:waiting = {} + call dispatch#complete(request) + endif +endfunction + +augroup dispatch_screen + autocmd! + autocmd VimResized * if !has('gui_running') | call dispatch#screen#poll() | endif +augroup END