Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Lua: API to wait customview final selection / usage like generic selector #1103

@PRESFIL

Description

@PRESFIL

Decription

Recently I tried to write a plugin for rclone, which able to select rclone remote
from list, mount and go into it. It is more convenient than to create mount-files
for each new remote.

But it didn't work. Pressing Enter on selected entry causes open it
like regular path:

Image

Current selection, as far as I understand, is empty and collected before press.

rclone.lua
local function rclone(info)
   local remotes = {}

   -- 1. get list of rclone remotes
   local job = vifm.startjob {
         cmd = "rclone listremotes",
   }

   local out = job:stdout():read('*all')

   for item in string.gmatch(out, "([^,\n]+)") do
      table.insert(remotes, item)
   end

   -- 2. show prompt and get selection
   vifm.menus.loadcustom({
         title = 'rclone remotes',
         items = remotes,
         withnavigation = true,
   })

   local curview = vifm.currview()

   local selected = curview:selected()

   for item in selected do
      print(item)
   end
   -- 3. mount select

   -- 4. cd into it
end

-- this does NOT overwrite pre-existing user command
local added = vifm.cmds.add {
    name = "Rclone",
    description = "Select and jump into rclone remote",
    handler = rclone,
    minargs = 0,
    maxargs = 0,
}
if not added then
    vifm.sb.error("Failed to register :Rclone")
end

return {}

At the moment it is not possible to get final selection or wait for Enter
to be pressed on the current selection, or override action. Or it is not documented.

Maybe I have a false idea about what is custom view (very custom view), can it
contain not only files and be used as generic selector like dmenu or fzf? It
would be very useful in terms of writing interactive Lua plugins.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions