Skip to content

[wip] Added support to screen foreground, fixes #83 #84

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 35 additions & 5 deletions autoload/dispatch/screen.vim
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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

Expand All @@ -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