Skip to content

Commit

Permalink
bump version to 0.0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
jessetane committed Dec 5, 2012
1 parent 64e1ef6 commit 9e7f54b
Show file tree
Hide file tree
Showing 14 changed files with 306 additions and 305 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -10,7 +10,7 @@ _/ ___\| | \ |
GUIs for the command line.

## Why
Command line tools are fast, but they can be hard to use. cui allows you to create optional (and potentially dynamic) views for each parameter your tool requires.
Command line tools are fast, but they can be hard to learn/use. cui allows you to create optional (and potentially dynamic) views for each parameter your tool requires.

## How
Views are pushed to a sequence, and can display either buttons or fields. After each view collects input, the results are stored and the sequence advances. Views can include an action that executes after the results are stored, but before the sequence advances. Usually a tool's primary "work" is performed in the last view's action.
Expand All @@ -24,7 +24,7 @@ The examples are all executable scripts - try cd'ing into the example folder and
## Usage
This code below is essentially the same as in example/basic:
```javascript
var cui = require("cui");
var cui = require("cui")
cui.push({
title: "This is a very basic example.",
type: "buttons",
Expand All @@ -34,9 +34,9 @@ cui.push({
"Three"
],
action: function () {
console.log("You could do something now with: \"" + cui.results[0] + "\"");
console.log("You could do something now with: \"" + cui.results[0] + "\"")
}
});
})
```

## License
Expand Down
32 changes: 16 additions & 16 deletions example/advanced
Expand Up @@ -6,19 +6,19 @@
*/


var fs = require("fs");
var cui = require("../lib/cui");
var fs = require("fs")
var cui = require("../lib/cui")


cui.push({
title: "This is a contrived example to demonstrate a branching view tree. Pick a file:",
type: "buttons",
data: function (cb) {
fs.readdir(process.cwd(), function (err, filenames) {
cb(err, filenames);
});
cb(err, filenames)
})
}
});
})

cui.push({
title: "Pick an action:",
Expand All @@ -30,28 +30,28 @@ cui.push({
action: function (cb) {
var last = cui.results.slice(-1)[0]
if (last === "Stat") {
statAction();
statAction()
} else {
cui.push(renameView);
cui.push(renameView)
}
cb();
cb()
}
});
})

var statAction = function () {
fs.stat(cui.results[0], function (err, data) {
console.log(data || err);
});
};
console.log(data || err)
})
}

var renameView = {
type: "fields",
data: function (cb) {
cb(null, "Type a new name for " + cui.results[0] + ": ");
cb(null, "Type a new name for " + cui.results[0] + ": ")
},
action: function () {
fs.rename(cui.results[0], cui.results[2], function (err) {
console.log((err) ? err : cui.results[0] + " successfully renamed as " + cui.results[2]);
});
console.log((err) ? err : cui.results[0] + " successfully renamed as " + cui.results[2])
})
}
};
}
22 changes: 11 additions & 11 deletions example/all
Expand Up @@ -6,24 +6,24 @@
*/


var fs = require("fs");
var cui = require("../lib/cui");
var fs = require("fs")
var cui = require("../lib/cui")


cui.push({
title: "Try an example:",
type: "buttons",
data: function (cb) {
fs.readdir(__dirname, function (err, examples) {
filtered = [];
examples.forEach(function (filename) { if (filename !== "all") filtered.push(filename) });
cb(err, filtered);
});
filtered = []
examples.forEach(function (filename) { if (filename !== "all") filtered.push(filename) })
cb(err, filtered)
})
},
action: function (cb) {
var example = __dirname + "/" + cui.results[0];
cui.results = []; // reset for the new cuifile
require(example);
cb();
var example = __dirname + "/" + cui.results[0]
cui.results = [] // reset for the new cuifile
require(example)
cb()
}
});
})
6 changes: 3 additions & 3 deletions example/basic
Expand Up @@ -6,7 +6,7 @@
*/


var cui = require("../lib/cui");
var cui = require("../lib/cui")


cui.push({
Expand All @@ -18,6 +18,6 @@ cui.push({
"Three"
],
action: function () {
console.log("You could do something now with: \"" + cui.results[0] + "\"");
console.log("You could do something now with: \"" + cui.results[0] + "\"")
}
});
})
16 changes: 8 additions & 8 deletions example/intermediate
Expand Up @@ -6,7 +6,7 @@
*/


var cui = require("../lib/cui");
var cui = require("../lib/cui")


cui.push({
Expand All @@ -18,14 +18,14 @@ cui.push({
"Year [YYYY]: "
],
action: function (cb) {
var parts = cui.results.slice(-3);
var str = parts[0] + "/" + parts[1] + "/" + parts[2];
var birthday = new Date(str);
var parts = cui.results.slice(-3)
var str = parts[0] + "/" + parts[1] + "/" + parts[2]
var birthday = new Date(str)
if (birthday === "Invalid Date") {
console.log(str + " is not a valid date.");
console.log(str + " is not a valid date.")
} else {
console.log("You were born on a " + birthday.toLocaleDateString().split(",")[0] + ".");
console.log("You were born on a " + birthday.toLocaleDateString().split(",")[0] + ".")
}
cb();
cb()
}
});
})
22 changes: 11 additions & 11 deletions example/say
Expand Up @@ -6,28 +6,28 @@
*/


var exec = require("child_process").exec;
var cui = require("../lib/cui");
var exec = require("child_process").exec
var cui = require("../lib/cui")


cui.push({
title: "Choose a voice:",
type: "buttons",
data: function (cb) {
var s = exec("say -v ?", function (err, voices) {
voices = voices.split("\n").slice(0, -1);
voices = voices.map(function (v) { return v.split(" ")[0] });
cb(null, voices);
});
voices = voices.split("\n").slice(0, -1)
voices = voices.map(function (v) { return v.split(" ")[0] })
cb(null, voices)
})
}
});
})

cui.push({
type: "fields",
data: "Type a message: ",
action: function () {
var voice = cui.results[0];
var message = cui.results[1];
exec("say -v \"" + voice + "\" \"" + message + "\"");
var voice = cui.results[0]
var message = cui.results[1]
exec("say -v \"" + voice + "\" \"" + message + "\"")
}
});
})

0 comments on commit 9e7f54b

Please sign in to comment.