Allow command predicates to manage parameters passed to the commands

When a command is performed with parameters, those are now passed to the
predicate.
The predicate can then return, after the validity boolean, any other
value that will then be passed to the actual command.
If the predicate only returns the validity boolean, the original
parameters are passed through to the actual command.

This allows predicates to manipulate the received parameters, and allows
them to pass the result of an expensive computation to the actual
command, which won't have to recalculate it.

String and table predicates will now also return `core.active_view`.
This commit is contained in:
Guldoman
2022-08-16 22:13:16 +02:00
parent 6ccc5f6dde
commit cf29a6a45f
13 changed files with 223 additions and 233 deletions
+10 -10
View File
@@ -2,23 +2,23 @@ local core = require "core"
local command = require "core.command"
command.add("core.commandview", {
["command:submit"] = function()
core.active_view:submit()
["command:submit"] = function(active_view)
active_view:submit()
end,
["command:complete"] = function()
core.active_view:complete()
["command:complete"] = function(active_view)
active_view:complete()
end,
["command:escape"] = function()
core.active_view:exit()
["command:escape"] = function(active_view)
active_view:exit()
end,
["command:select-previous"] = function()
core.active_view:move_suggestion_idx(1)
["command:select-previous"] = function(active_view)
active_view:move_suggestion_idx(1)
end,
["command:select-next"] = function()
core.active_view:move_suggestion_idx(-1)
["command:select-next"] = function(active_view)
active_view:move_suggestion_idx(-1)
end,
})