aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--init.lua22
1 files changed, 20 insertions, 2 deletions
diff --git a/init.lua b/init.lua
index 48eddb2..7a815d8 100644
--- a/init.lua
+++ b/init.lua
@@ -29,6 +29,11 @@ local function get_lock_dir()
return M.directory
end
+local function prompt_backend_whiptail(msg, menu)
+ local cmd = 'whiptail </dev/tty 2>&1 >/dev/tty --title "vis-lockfiles" --nocancel'
+ return vis:pipe(cmd .. ' --menu \'' .. msg .. '\n\' 0 0 0 ' .. menu, true)
+end
+
local function prompt_backend_vis_menu(msg, menu, choices)
local cmd1 = 'printf >/dev/tty %s \'' .. msg .. '\n\''
local cmd2 = 'printf %s \'' .. choices .. '\''
@@ -36,11 +41,24 @@ local function prompt_backend_vis_menu(msg, menu, choices)
return vis:pipe(cmd1 .. ';' .. cmd2 .. '|' .. cmd3, true)
end
-local function prompt_backend(path, lfile_path, pid)
+local function prompt_backend(path, lfile_path, pid, preferred_backend)
local msg = 'File is locked: ' .. path .. '\n lock: ' .. lfile_path ..
'\n owned by process ID: ' .. pid
local status, output
- status, output = prompt_backend_vis_menu(msg, '(E)dit anyway, (Q)uit, [A]bort', 'a\ne\nq')
+
+ if preferred_backend == 'whiptail' then
+ local p = io.popen('command -v whiptail 2>/dev/null || :', 'r')
+ output = assert(p:read('*a'))
+ p:close()
+ preferred_backend = (output ~= '') and preferred_backend
+ end
+
+ if preferred_backend == 'whiptail' then
+ local menu = 'abort "operation (a)" edit "anyway (e)" quit "vis (q)"'
+ status, output = prompt_backend_whiptail(msg, menu)
+ else
+ status, output = prompt_backend_vis_menu(msg, '(E)dit anyway, (Q)uit, [A]bort', 'a\ne\nq')
+ end
vis:redraw()
return (status == 0) and output:sub(1, 1)