@@ -5,29 +5,43 @@ if exists('g:autoloaded_dispatch_screen')
55endif 
66let  g: autoloaded_dispatch_screen  =  1 
77
8+ let  s: waiting  =  {}
9+ 
810function !  dispatch#screen#handle (request) abort 
911  if  empty ($STY ) ||  ! executable (' screen'  )
1012    return  0 
1113  endif 
14+   let  aftercmd =  ' screen -X only; screen -X at $WINDOW kill' 
1215  if  a: request .action == # ' make' 
13-     if  ! get (a: request , ' background'  , 0 ) &&  empty (v: servername )
16+     if  ! get (a: request , ' background'  , 0 ) &&  empty (v: servername )  &&   ! empty ( s: waiting ) 
1417      return  0 
1518    endif 
16-     return  dispatch#screen#spawn (dispatch#prepare_make (a: request ), a: request )
19+     let  cmd =  dispatch#prepare_make (a: request , aftercmd)
20+     return  dispatch#screen#spawn (cmd, a: request )
1721  elseif  a: request .action == # ' start' 
18-     return  dispatch#screen#spawn (dispatch#prepare_start (a: request ), a: request )
22+     let  cmd =  dispatch#prepare_start (a: request , aftercmd)
23+     return  dispatch#screen#spawn (cmd, a: request )
1924  endif 
2025endfunction 
2126
2227function !  dispatch#screen#spawn (command , request) abort 
23-   let  command  =  ' screen -ln -fn -t '  .dispatch#shellescape (a: request .title )
28+   let  command  =  ' ' 
29+   if  ! get (a: request , ' background'  , 0 )
30+     silent  execute  " !screen -X eval 'split' 'focus down' 'resize 10'" 
31+   endif 
32+   let  command  .=  ' screen -ln -fn -t '  .dispatch#shellescape (a: request .title )
2433        \  . '  '   . &shell  . '  '   . &shellcmdflag  . '  ' 
2534        \  . shellescape (' exec '   . dispatch#isolate ([' STY'  , ' WINDOW'  ],
2635        \  dispatch#set_title (a: request ), a: command ))
2736  silent  execute  ' !'   . escape (command , ' !#%'  )
37+ 
2838  if  a: request .background 
2939    silent  ! screen - X other
40+   else 
41+     silent  ! screen - X focus up 
3042  endif 
43+ 
44+   let  s: waiting  =  a: request
3145  return  1 
3246endfunction 
3347
@@ -42,3 +56,19 @@ function! dispatch#screen#activate(pid) abort
4256    return  ! v: shell_error
4357  endif 
4458endfunction 
59+ 
60+ function !  dispatch#screen#poll () abort 
61+   if  empty (s: waiting )
62+     return 
63+   endif 
64+   let  request =  s: waiting
65+   if  ! dispatch#pid (request)
66+     let  s: waiting  =  {}
67+     call  dispatch#complete (request)
68+   endif 
69+ endfunction 
70+ 
71+ augroup  dispatch_screen 
72+   autocmd ! 
73+   autocmd  VimResized  *  if  ! has (' gui_running'  ) | call  dispatch#screen#poll () | endif 
74+ augroup  END 
0 commit comments