diff options
| author | Alin Mr <almr.oss@outlook.com> | 2024-05-06 06:16:29 +0000 |
|---|---|---|
| committer | Alin Mr <almr.oss@outlook.com> | 2024-05-06 06:16:29 +0000 |
| commit | 5cc1d08393c3d92e32b99b74c3dd95863aa65d51 (patch) | |
| tree | 670c940366778e8542af39f68355916dda2a620b | |
| parent | 9cd4194528b2d73d83abd1364fecd9b334793444 (diff) | |
| download | vis-lockfiles-5cc1d08393c3d92e32b99b74c3dd95863aa65d51.tar.gz vis-lockfiles-5cc1d08393c3d92e32b99b74c3dd95863aa65d51.zip | |
init.lua: refactor prompt backend
| -rw-r--r-- | init.lua | 38 |
1 files changed, 21 insertions, 17 deletions
@@ -29,28 +29,32 @@ local function get_lock_dir() return M.directory end --- get a user confirmation --- return true if user wants to edit the locked file -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 menu_prompt = '(E)dit anyway, (Q)uit, [A]bort' +local function prompt_backend_vis_menu(msg, menu, choices) local cmd1 = 'printf >/dev/tty %s \'' .. msg .. '\n\'' local cmd2 = 'printf %s \'' .. choices .. '\'' - local cmd3 = 'vis-menu -b -p \'' .. menu_prompt .. '\'' - local cmd = cmd1 .. ';' .. cmd2 .. '|' .. cmd3 + local cmd3 = 'vis-menu -b -p \'' .. menu .. '\'' + return vis:pipe(cmd1 .. ';' .. cmd2 .. '|' .. cmd3, true) +end - local status, output = vis:pipe(cmd, true) +local function prompt_backend(path, lfile_path, pid) + 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') vis:redraw() - if status == 0 then - if output:sub(1, 1) == 'e' then - return true - elseif output:sub(1, 1) == 'q' then - vis:exit(1) - end + return (status == 0) and output:sub(1, 1) +end + +-- get a user confirmation +-- return true if user wants to edit the locked file +local function prompt(path, lfile_path, pid) + + local output = prompt_backend(path, lfile_path, pid) + if output == 'e' then + return true + elseif output == 'q' then + vis:exit(1) end -- else 'abort' or dialog canceled |
