1
0
mirror of https://github.com/gryf/pentadactyl-pm.git synced 2026-01-04 05:24:12 +01:00

Usage command stuff.

This commit is contained in:
Kris Maglione
2011-05-22 15:56:25 -04:00
parent 9791cdb886
commit b4adf32663

View File

@@ -181,6 +181,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
},
addUsageCommand: function (params) {
function keys(item) (item.names || [item.name]).concat(item.description, item.columns || []);
let name = commands.add(params.name, params.description,
function (args) {
let results = array(params.iterate(args))
@@ -188,7 +190,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
let filters = args.map(function (arg) util.regexp("\\b" + util.regexp.escape(arg) + "\\b", "i"));
if (filters.length)
results = results.filter(function (item) filters.every(function (re) [item.name, item.description].concat(item.columns || []).some(re.closure.test)));
results = results.filter(function (item) filters.every(function (re) keys(item).some(re.closure.test)));
commandline.commandOutput(
template.usage(results, params.format));
@@ -199,7 +201,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
context.keys.text = util.identity;
context.keys.description = function () seen[this.text] + /*L*/" matching items";
let seen = {};
context.completions = array(item.description.toLowerCase().split(/[()\s]+/)
context.completions = array(keys(item).join(" ").toLowerCase().split(/[()\s]+/)
for (item in params.iterate(args)))
.flatten().filter(function (w) /^\w[\w-_']+$/.test(w))
.map(function (k) {