mirror of
https://github.com/gryf/pentadactyl-pm.git
synced 2026-03-16 23:23:31 +01:00
Usage command stuff.
This commit is contained in:
@@ -181,6 +181,8 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
},
|
},
|
||||||
|
|
||||||
addUsageCommand: function (params) {
|
addUsageCommand: function (params) {
|
||||||
|
function keys(item) (item.names || [item.name]).concat(item.description, item.columns || []);
|
||||||
|
|
||||||
let name = commands.add(params.name, params.description,
|
let name = commands.add(params.name, params.description,
|
||||||
function (args) {
|
function (args) {
|
||||||
let results = array(params.iterate(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"));
|
let filters = args.map(function (arg) util.regexp("\\b" + util.regexp.escape(arg) + "\\b", "i"));
|
||||||
if (filters.length)
|
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(
|
commandline.commandOutput(
|
||||||
template.usage(results, params.format));
|
template.usage(results, params.format));
|
||||||
@@ -199,7 +201,7 @@ var Dactyl = Module("dactyl", XPCOM(Ci.nsISupportsWeakReference, ModuleBase), {
|
|||||||
context.keys.text = util.identity;
|
context.keys.text = util.identity;
|
||||||
context.keys.description = function () seen[this.text] + /*L*/" matching items";
|
context.keys.description = function () seen[this.text] + /*L*/" matching items";
|
||||||
let seen = {};
|
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)))
|
for (item in params.iterate(args)))
|
||||||
.flatten().filter(function (w) /^\w[\w-_']+$/.test(w))
|
.flatten().filter(function (w) /^\w[\w-_']+$/.test(w))
|
||||||
.map(function (k) {
|
.map(function (k) {
|
||||||
|
|||||||
Reference in New Issue
Block a user