Permalink
Browse files

better button label matching

  • Loading branch information...
1 parent eeee01f commit 97e49e0cb69bb2d49ca103aeaddb7cbb9c6c31a5 @jessetane committed Nov 28, 2012
Showing with 38 additions and 8 deletions.
  1. +1 −1 lib/cui.js
  2. +9 −6 lib/util.js
  3. +1 −1 package.json
  4. +27 −0 test/exactButtonMatch.js
View
@@ -51,7 +51,7 @@ function findPackageJSON (dir, cb) {
var packageJSON = path.normalize(dir + "/package");
cb(null, require(packageJSON), dir);
} catch (err) {
- if (dir !== "/" && err.code === "MODULE_NOT_FOUND" && err.message.search("/package") > -1) {
+ if (dir !== "/" && err.code === "MODULE_NOT_FOUND" && err.message.indexOf("/package") > -1) {
findPackageJSON(path.normalize(dir + "/.."), cb);
} else {
cb(err);
View
@@ -37,14 +37,17 @@ function selectButton (buttons, props, selection) {
if (isNaN(n)) {
var temp = null;
for (var b in buttonsArray) {
- var label = generateButtonLabel(buttonsArray[b], props).toLowerCase();
- if (label.search(selection.toLowerCase()) > -1) {
- temp = buttonsArray[b];
- if (buttons !== buttonsArray) temp = buttons[temp];
- break;
+ var label = generateButtonLabel(buttonsArray[b], props);
+ if (label.toLowerCase().indexOf(selection.toLowerCase()) === 0) {
+ if (label.length === selection.length) {
+ temp = buttonsArray[b];
+ break;
+ } else if (temp === null) {
+ temp = buttonsArray[b];
+ }
}
}
- selection = temp;
+ selection = (buttons !== buttonsArray) ? buttons[temp] : temp;
} else if (n > 0 && n <= buttonsArray.length) {
selection = buttonsArray[Math.floor(n)-1];
if (buttons !== buttonsArray) selection = buttons[selection];
View
@@ -1,7 +1,7 @@
{
"name": "cui",
"description": "GUIs for the command line.",
- "version": "0.0.4",
+ "version": "0.0.5",
"main": "lib/cui.js",
"author": "Jesse Tane <jesse.tane@gmail.com>",
"dependencies": {
View
@@ -0,0 +1,27 @@
+#!/usr/bin/env node
+
+/*
+ * exactButtonMatch.js
+ *
+ */
+
+
+var cui = require("../lib/cui");
+var assert = require("assert");
+
+cui.push({
+ title: "Exact button label matching",
+ type: "buttons",
+ data: [
+ "Ones",
+ "One.a-b-c-d",
+ "One.a-b-c",
+ "One.a-b",
+ "One.a",
+ "One"
+ ],
+ action: function (cb) {
+ console.log("Result:", cui.last(1));
+ cb();
+ }
+});

0 comments on commit 97e49e0

Please sign in to comment.