diff options
| author | Alin Mr <almr.oss@outlook.com> | 2024-05-06 06:17:50 +0000 |
|---|---|---|
| committer | Alin Mr <almr.oss@outlook.com> | 2024-05-06 06:17:50 +0000 |
| commit | 0f8d04d2e27e4fa8d76627fd717ac8d85090e74f (patch) | |
| tree | dcb24245e80f5e77a26123f48415d5ea4e5a9e5a | |
| parent | 5cc1d08393c3d92e32b99b74c3dd95863aa65d51 (diff) | |
| download | vis-lockfiles-0f8d04d2e27e4fa8d76627fd717ac8d85090e74f.tar.gz vis-lockfiles-0f8d04d2e27e4fa8d76627fd717ac8d85090e74f.zip | |
init.lua: prompt backend: +whiptail
| -rw-r--r-- | init.lua | 22 |
1 files changed, 20 insertions, 2 deletions
@@ -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) |
