Browse files

Improve printing and formatting

  • Loading branch information...
1 parent 177959d commit 39868489ad01eaf856a00357e7d50d815062930c @RStankov RStankov committed Feb 7, 2012
Showing with 17 additions and 14 deletions.
  1. +13 −4 lib/commands.js
  2. +4 −10 test/commands.test.js
View
17 lib/commands.js
@@ -20,7 +20,18 @@ commands.todos = require('./todos').init(commands.storage);
*
* @api private
*/
-commands.print = console.log;
+commands.print = function(value) {
+ console.log(value);
+};
+
+/**
+ * Format items for print.
+ *
+ * @api private
+ */
+commands.format = function(items) {
+ return "\n" + items.map(format).join("\n") + "\n"
+};
/**
* The application.
@@ -56,10 +67,8 @@ commands.version = function() {
* @api public
*/
commands.list = function() {
- commands.print('');
- items.map(format).map(commands.print);
- commands.print('');
commands.todos[app.argv.all ? 'all' : 'undone'](function(items) {
+ commands.print(commands.format(items));
});
};
View
14 test/commands.test.js
@@ -30,16 +30,10 @@ describe('commands', function() {
it('print list items', function(done) {
storage.items = [{text: 'Foo', done: false}];
- var left = 3,
- out = '';
-
- sinon.stub(commands, 'print', function(text) {
- out += text;
- if (--left == 0) {
- out.should.eql(' #1 \u001b[31m✖\u001b[39m Foo');
- commands.print.restore();
- done();
- }
+ sinon.stub(console, 'log', function(text) {
+ text.should.eql("\n" + ' #1 \u001b[31m✖\u001b[39m Foo' + "\n");
+ console.log.restore();
+ done();
});
commands.list();

0 comments on commit 3986848

Please sign in to comment.