handler.lua (1426B)
1 --- Trun test handler 2 -- 3 -- interface 4 -- - handle(userdata, line): return status 5 -- - (optional) on_start(userdata): call once before start reading 6 -- - (optional) on_update(userdata, line, status): calls every time when status changed 7 -- - (optional) on_end(userdata): calls once after reading end 8 -- 9 local status_map = {['running'] = 0, ['success'] = 1, ['error'] = -1} 10 11 -- send nvim_cmd to all neovim instances 12 local nvim_cmd = function(nvim_cmd) 13 local servers = io.popen('nvr --serverlist') 14 for socket in servers:lines() do 15 local cmd = string.format('nvr --servername "%s" -cc "%s" --nostart -s &', 16 socket, nvim_cmd) 17 os.execute(cmd) 18 end 19 servers:close() 20 end 21 22 return { 23 -- handle(userdata, line): return status 24 handle = function(_, line) 25 if line:find('success') then 26 return status_map.success 27 elseif line:find('normal') then 28 return status_map.running 29 else 30 return status_map.error 31 end 32 end, 33 34 -- on_update(userdata, line, status): calls every time when status changed 35 on_update = function(data, _, status) 36 if status == status_map.success or status == status_map.error then 37 local type_map = {[1] = 'info', [-1] = 'error'} 38 local cmd = string.format( 39 'lua require(\'notify\')(\'%s\', \'%s\', {title=\'%s\'})', 40 data.name, type_map[status], 'Build') 41 nvim_cmd(cmd) 42 end 43 end, 44 }