summaryrefslogtreecommitdiff
path: root/config/essentials/vis/build.lua
diff options
context:
space:
mode:
authorRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-22 02:05:44 +0200
committerRaymaekers Luca <raymaekers.luca@gmail.com>2024-06-22 02:05:44 +0200
commit36d2972c60ec86b873fa496d1f5ea95cf748cf49 (patch)
treea6d6750fa17c2964cd241afa8e963cac6106b390 /config/essentials/vis/build.lua
parent4914b43f642e2772a140a8f9b1f26b4e555ed88b (diff)
parent32256e087aaf7744348a5ba33e802d5c8d9d97dd (diff)
Merge branch 'main' of db:dotfiles
Diffstat (limited to 'config/essentials/vis/build.lua')
-rw-r--r--config/essentials/vis/build.lua66
1 files changed, 66 insertions, 0 deletions
diff --git a/config/essentials/vis/build.lua b/config/essentials/vis/build.lua
new file mode 100644
index 0000000..8a062cd
--- /dev/null
+++ b/config/essentials/vis/build.lua
@@ -0,0 +1,66 @@
+-- Copyright (c) 2024 Florian Fischer. All rights reserved.
+--
+-- vis-build is free software: you can redistribute it and/or modify it under
+-- the terms of the GNU General Public License as published by the Free Software
+-- Foundation, either version 3 of the License, or (at your option) any later
+-- version.
+--
+-- vis-build is distributed in the hope that it will be useful, but WITHOUT
+-- ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License along with
+-- vis-build found in the LICENSE file.
+-- If not, see <https://www.gnu.org/licenses/>.
+local M = {}
+M.get_default_build_cmd = function() return 'make' end
+
+local build_id = 0
+local builds = {}
+
+M.new_build = function(cmd)
+ build_id = build_id + 1
+ local build_name = 'build' .. build_id
+ local build_fd = vis:communicate(build_name, cmd)
+ local build = {fd = build_fd, out = '', err = '', cmd = cmd}
+ builds[build_name] = build
+end
+
+vis.events.subscribe(vis.events.PROCESS_RESPONSE,
+ function(name, event, code, msg)
+ local build = builds[name]
+ if not build then return end
+
+ if event == 'EXIT' or event == 'SIGNAL' then
+ if code ~= 0 then
+ vis:message('build: ' .. name .. ' cmd: ' .. build.cmd)
+ if event == 'EXIT' then
+ vis:message('failed with: ' .. code)
+ else
+ vis:message('got signal: ' .. code)
+ end
+ vis:message('stdout:\n' .. build.out)
+ vis:message('stderr:\n' .. build.err)
+ else
+ vis:message(name .. ':\n' .. build.out)
+ end
+ builds[name] = nil
+ end
+
+ if event == 'STDOUT' then
+ build.out = build.out .. msg
+ elseif event == 'STDERR' then
+ build.err = build.err .. msg
+ end
+end)
+
+vis:command_register('build', function(argv)
+ M.new_build(argv[1] or M.get_default_build_cmd())
+end, 'Asynchronously build the current file or project')
+
+vis:map(vis.modes.NORMAL, '<M-b>', function()
+ vis:command('build')
+ return 0
+end, 'Asynchronously build the current file or project')
+
+return M