aboutsummaryrefslogtreecommitdiff
path: root/init.lua
diff options
context:
space:
mode:
Diffstat (limited to 'init.lua')
-rw-r--r--init.lua39
1 files changed, 28 insertions, 11 deletions
diff --git a/init.lua b/init.lua
index 0769660..408d20c 100644
--- a/init.lua
+++ b/init.lua
@@ -31,21 +31,37 @@ end
-- get a user confirmation
-- return true if user selected yes, false otherwise
-local function confirm(path, pid)
- local choices = 'no\nyes'
- local prompt = path .. ' for PID '..pid .. ' exists. Edit anyway:'
- local cmd = 'printf %s \'' .. choices .. '\' | vis-menu -b -p \'' .. prompt .. '\''
+local function prompt(path, lfile_path, pid)
+ local choices = 'a\ne\nq'
+ local msg = 'Lock file found!\n\t lock file: "' .. lfile_path .. '"\n\tfile name: ' .. path ..
+ '\n\tprocess ID: ' .. pid
- -- local status, output = vis:pipe(nil, {start = 0, finish = 0}, cmd)
- local menu = assert(io.popen(cmd))
- local output = menu:read('*a')
- local _, _, status = menu:close()
+ vis:command('open')
+ local prompt_win = vis.win
+ prompt_win.file:insert(0, msg)
+ prompt_win.selection.pos = 0
+
+ vis:redraw()
+
+ local menu_prompt = '(E)dit anyway, (Q)uit, [A]bort'
+ local cmd = 'printf %s \'' .. choices .. '\' | vis-menu -b -p \'' .. menu_prompt .. '\''
+
+ local status, output = vis:pipe(prompt_win.file, {start = 0, finish = 0}, cmd)
vis:redraw()
+ local result = false
if status == 0 then
- return 'yes' == output:sub(1, 3)
+ if output:sub(1, 1) == 'e' then
+ result = true
+ elseif output:sub(1, 1) == 'q' then
+ vis:exit(1)
+ end
end
- return false
+
+ -- TODO: Auto close the prompt window
+ -- Currently it fails because it is last only open window
+ -- prompt_win:close(true)
+ return result
end
local created_locks = {}
@@ -59,7 +75,8 @@ vis.events.subscribe(vis.events.FILE_OPEN, function(file)
local lock_pid = lockfiles.create_lock_file(get_lock_dir(), lfile_path)
if lockfiles.vis_pid == lock_pid then
created_locks[file.path] = lfile_path
- elseif not confirm(lfile_path, lock_pid) then
+ elseif not prompt(file.path, lfile_path, lock_pid) then
+ -- TODO: abort
vis:exit(1)
end
end)