Skip to content

Add minimal announcements CLI option and functionality #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion bin/pomojs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ cli
.option('-d, --duration [mins]', 'shortcut for -w <mins> -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:');
Expand All @@ -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);

Expand All @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions lib/runner.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions lib/timer.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

/**
Expand All @@ -53,7 +54,7 @@ Timer.prototype.now = function() {

/**
* Starts a timer, making periodic updates.
*
*
* timer.start().then(function() { ... });
*/

Expand Down Expand Up @@ -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!"
Expand Down
8 changes: 7 additions & 1 deletion test/timer_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 });

Expand Down Expand Up @@ -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;
Expand Down