Skip to content

Commit

Permalink
Merge branch 'master' into gitlog
Browse files Browse the repository at this point in the history
  • Loading branch information
mojoaxel authored May 7, 2017
2 parents 86caaa0 + c19e53c commit 7d6ed23
Show file tree
Hide file tree
Showing 5 changed files with 263 additions and 6 deletions.
16 changes: 10 additions & 6 deletions .github/ISSUE_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
Follow the template below to ensure a more accurate response to your issue.
Just as a sanity check, did you run `npm install -g git-standup`? A lot of the installation
problems we're seeing is because that step was skipped.

**Node Version**: `node --version`
**tiny-core-terminal version**: `npm info tiny-care-terminal | grep version:`
**Shell**: `bash, zsh, fish, something else?`
**Terminal Program**: `tmux, iterm, terminator, cmd, something else?`
**Operating System**: `Mac, Windows, Linux, BSD, Really, something else?`
If you _did_ run it and you're still having problems, follow the template below to ensure a more accurate response to your issue.


- **Node Version**: `node --version`
- **tiny-core-terminal version**: `npm info tiny-care-terminal | grep version:`
- **Shell**: `bash, zsh, fish, something else?`
- **Terminal Program**: `tmux, iterm, terminator, cmd, something else?`
- **Operating System**: `Mac, Windows, Linux, BSD, Really, something else?`

Thank you!
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,22 @@ tiny-care-terminal
You can exit the dashboard by pressing `esc` or `q`. You can refresh it
manually by pressing `r`.


## 🍅 Pomodoro Mode

You can press 'p' to switch parrot box to pomodoro mode.

Other commands while in pomodoro mode:

```
s - start/pause/resume pomodoro
e - stop pomodoro
u - update pomodoro duration
b - update break time
```


## 🆘 Halp I don't see my commits

There's a couple of reasons why this might happen:
Expand Down
104 changes: 104 additions & 0 deletions care.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
var config = require(__dirname + '/config.js');
var twitterbot = require(__dirname + '/twitterbot.js');
var gitbot = require(__dirname + '/gitbot.js');
var notifier = require('node-notifier');
var pomodoro = require(__dirname + '/pomodoro.js');

var spawn = require('child_process').spawn;
var blessed = require('blessed');
Expand All @@ -11,6 +13,8 @@ var parrotSay = require('parrotsay-api');
var bunnySay = require('sign-bunny');
var weather = require('weather-js');

var inPomodoroMode = false;

var screen = blessed.screen(
{fullUnicode: true, // emoji or bust
smartCSR: true,
Expand All @@ -28,6 +32,53 @@ screen.key(['r', 'C-r'], function(ch, key) {
tick();
});

screen.key(['s', 'C-s'], function(ch, key) {
if (!inPomodoroMode) {
return;
} else if (pomodoroObject.isStopped()) {
pomodoroObject.start();
} else if (pomodoroObject.isPaused()) {
pomodoroObject.resume();
} else {
pomodoroObject.pause();
pomodoroHandlers.onTick();
}
});

screen.key(['e', 'C-e'], function(ch, key) {
if (inPomodoroMode) {
pomodoroObject.stop();
pomodoroHandlers.onTick();
}
});

screen.key(['u', 'C-u'], function(ch, key) {
if (inPomodoroMode) {
pomodoroObject.updateRunningDuration();
pomodoroHandlers.onTick();
}
});

screen.key(['b', 'C-b'], function(ch, key) {
if (inPomodoroMode) {
pomodoroObject.updateBreakDuration();
pomodoroHandlers.onTick()
}
});

screen.key(['p', 'C-p'], function(ch, key) {
if (inPomodoroMode) {
pomodoroObject.stop();
inPomodoroMode = false;
doTheTweets();
parrotBox.removeLabel('');
} else {
parrotBox.setLabel(' 🍅 ');
inPomodoroMode = true;
pomodoroHandlers.onTick()
}
});

var grid = new contrib.grid({rows: 12, cols: 12, screen: screen});

// grid.set(row, col, rowSpan, colSpan, obj, opts)
Expand Down Expand Up @@ -77,6 +128,9 @@ function doTheTweets() {
for (var which in config.twitter) {
// Gigantor hack: first twitter account gets spoken by the party parrot.
if (which == 0) {
if (inPomodoroMode) {
return;
}
twitterbot.getTweet(config.twitter[which]).then(function(tweet) {
if (config.say === 'bunny') {
parrotBox.content = bunnySay(tweet.text);
Expand Down Expand Up @@ -268,3 +322,53 @@ function catSay(text) {
      ∪`
;
}


var pomodoroHandlers = {
onTick: function() {
if (!inPomodoroMode) return;
var remainingTime = pomodoroObject.getRemainingTime();

var statusText = '';
if (pomodoroObject.isInBreak()) {
statusText = ' (Break Started) ';
} else if (pomodoroObject.isStopped()) {
statusText = ' (Press "s" to start) ';
} else if (pomodoroObject.isPaused()) {
statusText = ' (Press "s" to resume) ';
}

var content = `In Pomodoro Mode: ${remainingTime} ${statusText}`;
var metaData = `Duration: ${pomodoroObject.getRunningDuration()} Minutes, Break Time: ${pomodoroObject.getBreakDuration()} Minutes\n`;
metaData += 'commands: \n s - start/pause/resume \n e - stop \n u - update duration \n b - update break time';

parrotSay(content).then(function(text) {
parrotBox.content = text + metaData;
screen.render();
});
},

onBreakStarts: function() {
if (inPomodoroMode) {
notifier.notify({
title: 'Pomodoro Alert',
message: 'Break Time!',
sound: true,
timeout: 30,
});
}
},

onBreakEnds: function() {
if (inPomodoroMode) {
notifier.notify({
title: 'Pomodoro Alert',
message: 'Break Time Ends!',
sound: true,
timeout: 30,
});
}
},
}

var pomodoroObject = pomodoro(pomodoroHandlers);
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"git-user-name": "^1.2.0",
"gitlog": "^2.4.0",
"is-git": "0.0.1",
"node-notifier": "^5.1.2",
"parrotsay-api": "^0.1.1",
"resolve-dir": "^1.0.0",
"scraperjs": "^1.2.0",
Expand Down
132 changes: 132 additions & 0 deletions pomodoro.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,132 @@

var States = {
RUNNING: 'running',
STOPPED: 'stopped',
IN_BREAK: 'in_break',
PAUSED: 'paused',
};


// options (object)
// options.onTick (function) - Runs on every tick
// options.onBreakStarts (function) - Runs when break starts
// options.onBreakEnds (function) - Runs when break ends
var pomodoro = function(options) {
var _setIntervalId = null;
var _runningDuration = 20; // Default pomodoro duration: 20 Min
var _breakDuration = 5; // Default break duration: 5 Min
var _runningDurationRemaining = 0; // In seconds
var _breakDurationRemaining = 0; // In seconds
var _currentState = States.STOPPED;

var _onTick = function() {
switch (_currentState) {
case States.RUNNING: _handleTickOnRunning(); break;
case States.IN_BREAK: _handleTickOnBreak(); break;
case States.STOPPED: _handleTickOnStopped(); break;
case States.PAUSED: return;
}
}

var _handleTickOnRunning = function() {
if (_runningDurationRemaining < 1) {
_runningDurationRemaining = 0;
_breakDurationRemaining = _breakDuration * 60;
_currentState = States.IN_BREAK
options.onBreakStarts && options.onBreakStarts();
} else {
_runningDurationRemaining -= 1;
if (options.onTick) options.onTick()
}
};

var _handleTickOnBreak = function() {
if (_breakDurationRemaining < 1) {
_breakDurationRemaining = 0;
_runningDurationRemaining = _runningDuration * 60;
_currentState = States.RUNNING
options.onBreakEnds && options.onBreakEnds();
} else {
_breakDurationRemaining -= 1;
if (options.onTick) options.onTick()
}
};

var _handleTickOnStopped = function() {
clearInterval(_setIntervalId)
_runningDurationRemaining = 0;
_breakDurationRemaining = 0;
_setIntervalId = null;
};

var exports = {
start: function() {
if (_setIntervalId !== null) clearInterval(_setIntervalId);
_runningDurationRemaining = _runningDuration * 60;
_setIntervalId = setInterval(_onTick, 1000);
_currentState = States.RUNNING;
},

stop: function() {
_currentState = States.STOPPED;
},

pause: function() {
_currentState = States.PAUSED;
},

resume: function() {
_currentState = _breakDurationRemaining ? States.IN_BREAK : States.RUNNING;
},

updateRunningDuration() {
if (_runningDuration >= 60) _runningDuration = 1;
else _runningDuration += 1;
},

updateBreakDuration() {
if (_breakDuration >= 60) _breakDuration = 1;
else _breakDuration += 1;
},

getRunningDuration() {
return _runningDuration;
},

getBreakDuration() {
return _breakDuration;
},

getRemainingTime() {
var remainingTime;
switch (_currentState) {
case States.RUNNING: remainingTime = _runningDurationRemaining; break;
case States.IN_BREAK: remainingTime = _breakDurationRemaining; break;
case States.STOPPED: remainingTime = _runningDuration * 60; break;
case States.PAUSED: remainingTime = _runningDurationRemaining || _breakDurationRemaining;
}
return ('0' + Math.floor(remainingTime/60)).slice(-2) + ':' + ('0' + remainingTime % 60).slice(-2);
},

isRunning() {
return _currentState === States.RUNNING;
},

isInBreak() {
return _currentState === States.IN_BREAK;
},

isPaused() {
return _currentState === States.PAUSED;
},

isStopped() {
return _currentState === States.STOPPED;
},
}

return exports;
}


module.exports = pomodoro;

0 comments on commit 7d6ed23

Please sign in to comment.