Skip to content

Commit

Permalink
adding reset option and better docs
Browse files Browse the repository at this point in the history
  • Loading branch information
twood02 committed Jun 29, 2015
1 parent ce946a8 commit a5478ab
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@

A package for **Atom** to measure how many keys you type each day.

Atometer tracks how many **letters**, **arrow keys**, **symbols**, and **new lines** you type and displays them in a handy odometer at the bottom right of your window (hover for more detailed data). Statistics are tracked independently for each Atom project window you open and are saved on exit.

*How far have you typed today?*

![Atometer](https://raw.githubusercontent.com/twood02/scratchCode/master/misc/atometer.gif)

## Usage:
* Install at: https://atom.io/packages/atometer
* Press keys on keyboard.
* Look at bottom right of window. Hover for more details.
* Reset stats for window by invoking the *Atometer: Reset* action from the Command Palette.

## Todo:
* Report arrow key distance traveled in feet/miles/light years, rather than button presses.
* Make tooltip less blue.
31 changes: 23 additions & 8 deletions lib/atometer-tracker.coffee
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
module.exports =
class AtometerTracker

CURRENT_STATS_VERSION: 1
stats: null

constructor: (state, @atometerView) ->
# probably should just listen within editor, but this is OK
workspaceView = atom.views.getView(atom.workspace)
workspaceView.addEventListener 'keydown', => @track(event)
if state
@stats = state
this.load(state)
else
@stats =
letters: 0
moves: 0
symbols: 0
lines: 0
@atometerView.update(@stats.letters)
this.reset()
# Create a tooltip and fill it with some mess
@tooltip = atom.tooltips.add(@atometerView.element, title: =>
"<center><strong>Atometer</strong></center>
Expand All @@ -25,7 +23,24 @@ class AtometerTracker
</div>
"
)
console.log @atometerView.element

reset: ->
@stats =
letters: 0
moves: 0
symbols: 0
lines: 0
version: @CURRENT_STATS_VERSION
@atometerView.update(@stats.letters)

load: (oldstats) ->
@stats =
letters: oldstats.letters ? 0
moves: oldstats.moves ? 0
symbols: oldstats.symbols ? 0
lines: oldstats.lines ? 0
version: @CURRENT_STATS_VERSION
@atometerView.update(@stats.letters)

# Save the stats measured thus far on exit
serialize: ->
Expand Down
19 changes: 12 additions & 7 deletions lib/atometer.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,23 @@ AtometerTracker = require './atometer-tracker'
module.exports = Atometer =
atometerView: null
stats: null
subscriptions: null

activate: (state) ->
@atometerView = new AtometerView()
@stats = new AtometerTracker(state.stats, @atometerView)
@subscriptions = new CompositeDisposable
@atometerView = new AtometerView()
@stats = new AtometerTracker(state.stats, @atometerView)
@subscriptions.add atom.commands.add 'atom-workspace',
'atometer:reset': => @stats.reset()

consumeStatusBar: (statusBar) ->
@statusBarTile = statusBar.addRightTile(item: @atometerView.element, priority: 0)
@statusBarTile = statusBar.addRightTile(item: @atometerView.element, priority: 0)

deactivate: ->
@atometerView.destroy()
@statusBarTile?.destroy()
@statusBarTile = null
@atometerView.destroy()
@statusBarTile?.destroy()
@statusBarTile = null
@subscriptions.dispose()

serialize: ->
stats: @stats.serialize()
stats: @stats.serialize()

0 comments on commit a5478ab

Please sign in to comment.