1
0
mirror of https://github.com/SpaceVim/SpaceVim.git synced 2025-01-24 05:30:07 +08:00
This commit is contained in:
wsdjeg 2017-10-05 21:26:24 +08:00
parent eb7d940de8
commit c5aee19c89

View File

@ -8,6 +8,7 @@
let s:JOB = SpaceVim#api#import('job')
let s:BUFFER = SpaceVim#api#import('vim#buffer')
let s:STRING = SpaceVim#api#import('data#string')
let s:runners = {}
@ -22,7 +23,7 @@ function! s:open_win() abort
exe 'resize ' . lines
setlocal buftype=nofile bufhidden=wipe nobuflisted nolist noswapfile nowrap cursorline nospell nonu norelativenumber
set filetype=SpaceVimRunner
nnoremap <silent><buffer> q :bd<cr>
nnoremap <silent><buffer> q :call SpaceVim#plugins#runner#close()<cr>
let s:bufnr = bufnr('%')
wincmd p
endfunction
@ -30,7 +31,8 @@ endfunction
function! s:async_run(runner) abort
let cmd = printf(a:runner, bufname('%'))
call s:JOB.start(cmd,{
let s:start_time = reltime()
let s:job_id = s:JOB.start(cmd,{
\ 'on_stdout' : function('s:on_stdout'),
\ 'on_stderr' : function('s:on_stderr'),
\ 'on_exit' : function('s:on_exit'),
@ -42,11 +44,11 @@ function! s:update_statusline() abort
redrawstatus!
endfunction
function! SpaceVim#plugins#runner#reg_runner(ft, runner)
function! SpaceVim#plugins#runner#reg_runner(ft, runner) abort
let s:runners[a:ft] = a:runner
endfunction
function! SpaceVim#plugins#runner#open()
function! SpaceVim#plugins#runner#open() abort
let s:lines = 0
let s:status = {
\ 'is_running' : 0,
@ -62,6 +64,9 @@ function! SpaceVim#plugins#runner#open()
endif
endfunction
" @vimlint(EVL103, 1, a:job_id)
" @vimlint(EVL103, 1, a:data)
" @vimlint(EVL103, 1, a:event)
function! s:on_stdout(job_id, data, event) abort
call s:BUFFER.buf_set_lines(s:bufnr, s:lines , s:lines + 1, 0, a:data)
let s:lines += len(a:data)
@ -76,21 +81,33 @@ function! s:on_stderr(job_id, data, event) abort
endfunction
function! s:on_exit(job_id, data, event) abort
let s:end_time = reltime(s:start_time)
let s:status.is_exit = 1
let s:status.exit_code = a:data
call s:update_statusline()
endfunction
" @vimlint(EVL103, 0, a:job_id)
" @vimlint(EVL103, 0, a:data)
" @vimlint(EVL103, 0, a:event)
function! s:debug_info() abort
return []
endfunction
function! SpaceVim#plugins#runner#status()
function! SpaceVim#plugins#runner#status() abort
if s:status.is_running == 1
elseif s:status.is_exit == 1
return 'exit code : ' . s:status.exit_code
return 'exit code : ' . s:status.exit_code
\ . ' time: ' . s:STRING.trim(reltimestr(s:end_time))
endif
return ''
endfunction
function! SpaceVim#plugins#runner#close() abort
if s:status.is_exit == 0
call s:JOB.close(s:job_id)
endif
exe 'bd' s:bufnr
endfunction