From 4f9d77b7659824ebd9e88e3eb30745108542c978 Mon Sep 17 00:00:00 2001 From: Taylor McGann Date: Tue, 27 Sep 2016 10:37:01 -0600 Subject: [PATCH] Add minimal announcements CLI option and functionality --- bin/pomojs | 4 +++- lib/runner.js | 4 ++-- lib/timer.js | 5 +++-- test/timer_test.js | 8 +++++++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/bin/pomojs b/bin/pomojs index adab9dd..d7fbe02 100755 --- a/bin/pomojs +++ b/bin/pomojs @@ -23,6 +23,7 @@ cli .option('-d, --duration [mins]', 'shortcut for -w -b 0', null) .option('-t, --tmux', 'enable tmux reporting') .option('-l, --log [file]', 'log to this file') + .option('-m, --minimal-announcements', 'only announce start and completion of work and break cycles') .option('-q, --quiet', 'no sounds') .on('--help', function() { console.log(' examples:'); @@ -31,6 +32,7 @@ cli console.log(' $ pomojs "Fix stuff" # with reason'); console.log(' $ pomojs -w 10 # 10-minute pomodoro'); console.log(' $ pomojs -d 5 "Tea" # Simple tea timer (no break)'); + console.log(' $ pomojs -m # Default timers w/ minimal announcements'); }) .parse(process.argv); @@ -44,7 +46,7 @@ if (cli.args[0] && +cli.args[0] > 0 && _(cli.rawArgs).intersection(['--work','-w } } -var pomo = new Runner(cli.work, cli.break, { reason: cli.args.join(' ') || 'work' }); +var pomo = new Runner(cli.work, cli.break, { reason: cli.args.join(' ') || 'work', minimalAnnouncements: cli.minimalAnnouncements }); // Activate reporters if (cli.log) Logger.extend(pomo, cli.log); diff --git a/lib/runner.js b/lib/runner.js index fd6079c..3ed3ea5 100644 --- a/lib/runner.js +++ b/lib/runner.js @@ -33,8 +33,8 @@ var Timer = require('./timer'); var Runner = module.exports = function(work, snack, options) { // Timers - this.work = new Timer(work, {mode: 'work'}); - this.snack = snack > 0 ? new Timer(snack, {mode: 'snack'}) : null; + this.work = new Timer(work, {mode: 'work', minimalAnnouncements: options.minimalAnnouncements}); + this.snack = snack > 0 ? new Timer(snack, {mode: 'snack', minimalAnnouncements: options.minimalAnnouncements}) : null; // Start and end times this.start = null; this.end = null; diff --git a/lib/timer.js b/lib/timer.js index 86cddac..f960f97 100644 --- a/lib/timer.js +++ b/lib/timer.js @@ -31,6 +31,7 @@ var Timer = module.exports = function(mins, options) { this.speed = options.speed || 1000; this.duration = moment.duration(mins * 60000); this.startDate = null; + this.minimalAnnouncements = !!options.minimalAnnouncements; }; /** @@ -53,7 +54,7 @@ Timer.prototype.now = function() { /** * Starts a timer, making periodic updates. - * + * * timer.start().then(function() { ... }); */ @@ -116,7 +117,7 @@ Timer.prototype.getMessage = function() { var int = parseInt; // If too early, don't say anything - if (lapsed < 2000) + if (lapsed < 2000 || this.minimalAnnouncements) return; // "5 minutes in!" diff --git a/test/timer_test.js b/test/timer_test.js index 57f27f1..5b0829f 100644 --- a/test/timer_test.js +++ b/test/timer_test.js @@ -100,6 +100,12 @@ describe('Timer', function() { assert.isUndefined(timer.getMessage()); }); + it("minimal announcements", function() { + timer = makeTimer({ mins: 1.1, elapsed: 6*secs, minimalAnnouncements: true }); + + assert.isUndefined(timer.getMessage()); + }); + it("1 minute to go", function() { timer = makeTimer({ mins: 1.1, elapsed: 6*secs }); @@ -130,7 +136,7 @@ describe('Timer', function() { */ function makeTimer(options) { - var timer = new Timer(options.mins); + var timer = new Timer(options.mins, options); var start = moment('jan 10 2011, 01:00 am').toDate(); timer.startDate = start;