Show HelpMenu in intermediate modes

Also, use xplr.util api in xplr.fn.builtin.try_complete_path
pull/551/head
Arijit Basu 1 year ago
parent d719700122
commit 57492b84c0
No known key found for this signature in database
GPG Key ID: 0F8EF5258DC38077

@ -1405,6 +1405,7 @@ xplr.config.modes.builtin.go_to_path = {
-- Type: [Mode](https://xplr.dev/en/mode) -- Type: [Mode](https://xplr.dev/en/mode)
xplr.config.modes.builtin.selection_ops = { xplr.config.modes.builtin.selection_ops = {
name = "selection ops", name = "selection ops",
layout = "HelpMenu",
key_bindings = { key_bindings = {
on_key = { on_key = {
["c"] = { ["c"] = {
@ -1464,6 +1465,7 @@ xplr.config.modes.builtin.selection_ops = {
-- Type: [Mode](https://xplr.dev/en/mode) -- Type: [Mode](https://xplr.dev/en/mode)
xplr.config.modes.builtin.create = { xplr.config.modes.builtin.create = {
name = "create", name = "create",
layout = "HelpMenu",
key_bindings = { key_bindings = {
on_key = { on_key = {
["d"] = { ["d"] = {
@ -1627,6 +1629,7 @@ xplr.config.modes.builtin.number.key_bindings.on_key["k"] =
-- Type: [Mode](https://xplr.dev/en/mode) -- Type: [Mode](https://xplr.dev/en/mode)
xplr.config.modes.builtin.go_to = { xplr.config.modes.builtin.go_to = {
name = "go to", name = "go to",
layout = "HelpMenu",
key_bindings = { key_bindings = {
on_key = { on_key = {
["f"] = { ["f"] = {
@ -1783,6 +1786,7 @@ xplr.config.modes.builtin.duplicate_as = {
-- Type: [Mode](https://xplr.dev/en/mode) -- Type: [Mode](https://xplr.dev/en/mode)
xplr.config.modes.builtin.delete = { xplr.config.modes.builtin.delete = {
name = "delete", name = "delete",
layout = "HelpMenu",
key_bindings = { key_bindings = {
on_key = { on_key = {
["D"] = { ["D"] = {
@ -1842,6 +1846,7 @@ xplr.config.modes.builtin.delete = {
-- Type: [Mode](https://xplr.dev/en/mode) -- Type: [Mode](https://xplr.dev/en/mode)
xplr.config.modes.builtin.action = { xplr.config.modes.builtin.action = {
name = "action to", name = "action to",
layout = "HelpMenu",
key_bindings = { key_bindings = {
on_key = { on_key = {
["!"] = { ["!"] = {
@ -1927,6 +1932,7 @@ xplr.config.modes.builtin.action = {
-- Type: [Mode](https://xplr.dev/en/mode) -- Type: [Mode](https://xplr.dev/en/mode)
xplr.config.modes.builtin.quit = { xplr.config.modes.builtin.quit = {
name = "quit", name = "quit",
layout = "HelpMenu",
key_bindings = { key_bindings = {
on_key = { on_key = {
["enter"] = { ["enter"] = {
@ -2306,6 +2312,7 @@ xplr.config.modes.builtin.sort = {
-- Type: [Mode](https://xplr.dev/en/mode) -- Type: [Mode](https://xplr.dev/en/mode)
xplr.config.modes.builtin.switch_layout = { xplr.config.modes.builtin.switch_layout = {
name = "switch layout", name = "switch layout",
layout = "HelpMenu",
key_bindings = { key_bindings = {
on_key = { on_key = {
["1"] = { ["1"] = {
@ -2345,6 +2352,7 @@ xplr.config.modes.builtin.switch_layout = {
-- Type: [Mode](https://xplr.dev/en/mode) -- Type: [Mode](https://xplr.dev/en/mode)
xplr.config.modes.builtin.vroot = { xplr.config.modes.builtin.vroot = {
name = "vroot", name = "vroot",
layout = "HelpMenu",
key_bindings = { key_bindings = {
on_key = { on_key = {
["v"] = { ["v"] = {
@ -2446,17 +2454,9 @@ xplr.fn.builtin.try_complete_path = function(m)
return return
end end
local function splitlines(str) local function matches_all(str, paths)
local res = {} for _, path in ipairs(paths) do
for s in str:gmatch("[^\r\n]+") do if string.sub(path, 1, #str) ~= str then
table.insert(res, s)
end
return res
end
local function matches_all(str, files)
for _, p in ipairs(files) do
if string.sub(p, 1, #str) ~= str then
return false return false
end end
end end
@ -2464,12 +2464,23 @@ xplr.fn.builtin.try_complete_path = function(m)
end end
local path = m.input_buffer local path = m.input_buffer
local explorer_config = {
filters = {
{ filter = "RelativePathDoesStartWith", input = xplr.util.basename(path) },
},
}
local parent = xplr.util.dirname(path)
if not parent or parent == "" then
parent = "./"
elseif parent ~= "/" then
parent = parent .. "/"
end
local p = assert(io.popen(string.format("ls -d %q* 2>/dev/null", path))) local nodes = xplr.util.explore(parent, explorer_config)
local out = p:read("*all") local found = {}
p:close() for _, node in ipairs(nodes) do
table.insert(found, parent .. node.relative_path)
local found = splitlines(out) end
local count = #found local count = #found
if count == 0 then if count == 0 then
@ -2481,7 +2492,7 @@ xplr.fn.builtin.try_complete_path = function(m)
else else
local first = found[1] local first = found[1]
while #first > #path and matches_all(path, found) do while #first > #path and matches_all(path, found) do
path = string.sub(found[1], 1, #path + 1) path = string.sub(first, 1, #path + 1)
end end
if matches_all(path, found) then if matches_all(path, found) then

@ -763,10 +763,12 @@ fn draw_help_menu<B: Backend>(
_: &Lua, _: &Lua,
) { ) {
let panel_config = &app.config.general.panel_ui; let panel_config = &app.config.general.panel_ui;
let config = panel_config let config = panel_config
.default .default
.to_owned() .to_owned()
.extend(&panel_config.help_menu); .extend(&panel_config.help_menu);
let help_menu_rows = app let help_menu_rows = app
.mode .mode
.help_menu() .help_menu()

Loading…
Cancel
Save