angulardart.lua (2106B)
1 --- Trun module handler for `pub run build_runner serve` 2 -- NOTE: This does not work for `webdev server` 3 -- 4 -- Status number i use for semaphor in WM status bar. 5 -- viz->tools/trun-fmt.lua 6 -- 7 -- Last output is inside tmpfile so i can load errors to quickfix list 8 -- inside vim. 9 -- viz->examples/handler_temp_output_file.lua -> for caching last output 10 -- viz->tools/trun_to_neovim_quickfix.lua -> for load qf-list 11 -- 12 -- 13 local s_map = {['running'] = 0, ['success'] = 1, ['severe'] = -1} 14 15 local notify = function() 16 -- Notify system, neovim, etc... 17 end 18 19 -- Output types: 20 -- [SEVERE] Failed after 11.4s 21 -- [INFO] Succeeded after 9.8s with 304 outputs (8 actions) 22 -- 23 -- Sometimes build is not ending with these lines. There may be couple of empty 24 -- lines after. 25 26 local succeeded = function(line) 27 if line:match('%[INFO%] Succeeded') then 28 return true 29 elseif line:match('Serving') then 30 return true 31 end 32 end 33 34 local last_status 35 local get_status = function(line) 36 if last_status and #line == 0 then 37 return last_status 38 end 39 if (succeeded(line)) then 40 return s_map.success 41 end 42 43 local line_type = line:match('^%[(.*)%] .*'); 44 if not line_type then 45 return s_map.running 46 end 47 48 if (line_type == 'SEVERE') then 49 return s_map.severe 50 end 51 52 return s_map.running 53 end 54 55 return { 56 57 -- on_start(userdata): before start reading 58 on_start = function(data) 59 data.tmpfile = '/tmp/' .. data.name .. '.trun' 60 os.execute('rm -f ' .. data.tmpfile .. ' 2>/dev/null') 61 end, 62 63 -- handle(userdata, line): return status 64 handle = function(data, line) 65 local tmpfile = io.open(data.tmpfile, 'a') 66 tmpfile:write(line, '\n') 67 tmpfile:close() 68 local status = get_status(line) 69 last_status = status 70 return {status, data.tmpfile} 71 end, 72 73 -- on_update(userdata, line, status): when status changed 74 on_update = function(data, _, status) 75 if status[1] == s_map.success then 76 io.open(data.tmpfile, 'w'):close() 77 end 78 notify() 79 end, 80 81 -- on_end(userdata): after reading end 82 on_end = function(data) 83 notify() 84 os.execute('rm -f ' .. data.tmpfile) 85 end, 86 }