提交 bf089b0d 编写于 作者: C Cosmin Popescu

version 7.1

上级 f2e1a253
......@@ -6,7 +6,7 @@ let s:channels = {}
function! sw#background#run(profile, cmd, handler)
let channel = sw#server#start_sqlwb('sw#background#message_handler', 1)
let s:channels[channel] = {'profile': a:profile, 'txt': '', 'handler': a:handler}
call ch_setoptions(channel, {'close_cb': 'sw#background#close'})
""call ch_setoptions(channel, {'close_cb': 'sw#background#close'})
if a:profile != ''
let command = sw#get_connect_command(a:profile)
call sw#server#execute_sql(command, channel)
......@@ -21,11 +21,13 @@ function! sw#background#message_handler(channel, message)
endif
endfunction
function! sw#background#close(channel)
let channel = sw#find_channel(s:channels, a:channel)
function! sw#background#close(args)
let channel = sw#find_channel(s:channels, a:args.channel)
if channel != ''
let Func = function(s:channels[channel].handler)
call Func(s:channels[channel].profile, s:channels[channel].txt)
endif
endfunction
call sw#server#add_event('exit', 'sw#background#close')
......@@ -68,7 +68,7 @@ endfunction
function! s:log_channel(channel, txt)
if g:sw_log_to_file
let file = s:channel_handlers[a:channel].log
let mode = filereadable(file) ? 'ab' : 'wb'
let mode = filereadable(file) || s:nvim ? 'ab' : 'wb'
call writefile(split(a:txt, "\n"), file, mode)
else
let s:channel_handlers[a:channel].log .= a:txt
......@@ -259,7 +259,8 @@ function! sw#server#execute_sql(sql, ...)
endfunction
function s:trigger_event(channel, event, args)
if s:channel_handlers[a:channel].background
let key = sw#find_channel(s:channel_handlers, a:channel)
if key != '' && s:channel_handlers[key].background && a:event != 'exit'
return
endif
if has_key(s:events, a:event)
......@@ -302,13 +303,14 @@ function! sw#server#disconnect_buffer(...)
endif
let key = substitute(channel, '\v^channel ([0-9]+).*$', 'channel \1 open', 'g')
if has_key(s:channel_handlers, key)
call s:trigger_event(channel, 'exit', {'channel': key})
unlet s:channel_handlers[key]
endif
call s:init_timer()
if exists('g:sw_airline_support') && g:sw_airline_support == 1
call airline#update_statusline()
endif
""if exists('g:sw_airline_support') && g:sw_airline_support == 1
"" call airline#update_statusline()
""endif
endfunction
function! sw#server#kill_statement(...)
......
......@@ -35,3 +35,10 @@ function! airline#extensions#sw#apply(...)
let g:airline_section_c = s:airline_section_c
endif
endfunction
function! airline#extensions#sw#on_exit(channel)
call airline#update_statusline()
endfunction
call sw#server#add_event('exit', 'airline#extensions#sw#on_exit')
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册