-
Notifications
You must be signed in to change notification settings - Fork 243
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
263 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |