Skip to content

Commit

Permalink
Colorize task names
Browse files Browse the repository at this point in the history
  • Loading branch information
MattHulse committed Oct 16, 2014
1 parent 64869ba commit 2d3eaa3
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 40 deletions.
33 changes: 24 additions & 9 deletions bin/ti
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ import os, subprocess, tempfile
from os import path
import sys

from colorama import *

class JsonStore(object):

def __init__(self, filename):
Expand All @@ -58,6 +60,20 @@ class JsonStore(object):
json.dump(data, f, separators=(',', ': '), indent=2)


def red(str):
return Fore.RED + str + Fore.RESET

def green(str):
return Fore.GREEN + str + Fore.RESET

def yellow(str):
return Fore.YELLOW + str + Fore.RESET

def blue(str):
return Fore.BLUE + str + Fore.RESET



def get_current(data):
return (data['interrupt_stack'] or data['work'])[-1]

Expand All @@ -67,7 +83,7 @@ def action_on(name, time):
work = data['work']

if work and 'end' not in work[-1]:
print('You are already working on ' + work[-1]['name'] +
print('You are already working on ' + yellow(work[-1]['name']) +
'. Stop it or use a different sheet.', file=sys.stderr)
raise SystemExit(1)

Expand All @@ -79,7 +95,7 @@ def action_on(name, time):
work.append(entry)
store.dump(data)

print('Start working on ' + name + '.')
print('Start working on ' + green(name) + '.')


def action_fin(time):
Expand All @@ -99,9 +115,9 @@ def action_fin(time):
store.dump(data)

if interrupted is not None:
print('%s is done, you\'re back to working on %s.' % (current['name'], interrupted['name']))
print('%s is done, you\'re back to working on %s.' % (red(current['name']), green(interrupted['name'])))
else:
print('So you stopped working on ' + current['name'] + '.')
print('So you stopped working on ' + red(current['name']) + '.')


def action_interrupt(name, time):
Expand All @@ -124,7 +140,7 @@ def action_interrupt(name, time):
current = data['work'][-1]

print('Interrupting %s with %s. You are now %d deep in interrupts.' %
(interrupted['name'], entry['name'], len(interrupt_stack)))
(red(interrupted['name']), green(entry['name']), len(interrupt_stack)))


def action_note(content):
Expand All @@ -140,7 +156,7 @@ def action_note(content):

store.dump(data)

print('Yep, noted to `' + current['name'] + '`.')
print('Yep, noted to ' + yellow(current['name']) + '.')


def action_tag(tags):
Expand Down Expand Up @@ -172,9 +188,8 @@ def action_status():
start_time = parse_isotime(current['start'])
diff = timegap(start_time, datetime.utcnow())

print('You have been working on `{0[name]}` for {1}.'
.format(current, diff))

print('You have been working on {0} for {1}.'
.format(green(current['name']), diff))

def action_log(period):
data = store.load()
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ cram
pygreen
ghp-import
pyyaml
colorama
12 changes: 6 additions & 6 deletions test/fin.t
Original file line number Diff line number Diff line change
Expand Up @@ -18,24 +18,24 @@ Incorrectly running it (above) shouldn't create any file
Start a task and then fin

$ ti on testing-my-foot
Start working on testing-my-foot.
Start working on \x1b[32mtesting-my-foot\x1b[39m. (esc)
$ ti fin
So you stopped working on testing-my-foot.
So you stopped working on \x1b[31mtesting-my-foot\x1b[39m. (esc)
$ test -f $SHEET_FILE

Fin a tagged activity

$ ti on tagged-one
Start working on tagged-one.
Start working on \x1b[32mtagged-one\x1b[39m. (esc)
$ ti tag woohoo
Okay, tagged current work with 1 tags.
$ ti fin
So you stopped working on tagged-one.
So you stopped working on \x1b[31mtagged-one\x1b[39m. (esc)

Check the current file existence

$ ti on awesomeness
Start working on awesomeness.
Start working on \x1b[32mawesomeness\x1b[39m. (esc)
$ ti fin
So you stopped working on awesomeness.
So you stopped working on \x1b[31mawesomeness\x1b[39m. (esc)
$ test -f $SHEET_FILE
14 changes: 7 additions & 7 deletions test/format.t
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ Confirm no sheet file
Start a project, add content to current file

$ ti on a-project
Start working on a-project.
Start working on \x1b[32ma-project\x1b[39m. (esc)

End a project, add content to sheet file

$ ti fin
So you stopped working on a-project.
So you stopped working on \x1b[31ma-project\x1b[39m. (esc)

Another one, with notes

$ ti on another-project
Start working on another-project.
Start working on \x1b[32manother-project\x1b[39m. (esc)
$ ti note a simple note
Yep, noted to `another-project`.
Yep, noted to \x1b[33manother-project\x1b[39m. (esc)

End and check

$ ti fin
So you stopped working on another-project.
So you stopped working on \x1b[31manother-project\x1b[39m. (esc)

Another one, with tags

$ ti on yet-another-project
Start working on yet-another-project.
Start working on \x1b[32myet-another-project\x1b[39m. (esc)
$ ti tag hella
Okay, tagged current work with 1 tags.
$ ti fin
So you stopped working on yet-another-project.
So you stopped working on \x1b[31myet-another-project\x1b[39m. (esc)
12 changes: 6 additions & 6 deletions test/interrupt.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ Setup
Go two deep in interrupts

$ ti o task
Start working on task.
Start working on \x1b[32mtask\x1b[39m. (esc)
$ ti i interrupt1
Interrupting task with interrupt: interrupt1. You are now 1 deep in interrupts.
Interrupting \x1b[31mtask\x1b[39m with \x1b[32minterrupt: interrupt1\x1b[39m. You are now 1 deep in interrupts. (esc)
$ ti i interrupt2
Interrupting interrupt: interrupt1 with interrupt: interrupt2. You are now 2 deep in interrupts.
Interrupting \x1b[31minterrupt: interrupt1\x1b[39m with \x1b[32minterrupt: interrupt2\x1b[39m. You are now 2 deep in interrupts. (esc)
$ ti f
interrupt: interrupt2 is done, you're back to working on interrupt: interrupt1.
\x1b[31minterrupt: interrupt2\x1b[39m is done, you're back to working on \x1b[32minterrupt: interrupt1\x1b[39m. (esc)
$ ti f
interrupt: interrupt1 is done, you're back to working on task.
\x1b[31minterrupt: interrupt1\x1b[39m is done, you're back to working on \x1b[32mtask\x1b[39m. (esc)
$ ti f
So you stopped working on task.
So you stopped working on \x1b[31mtask\x1b[39m. (esc)
6 changes: 3 additions & 3 deletions test/note.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ Note when not working
Start working and then note

$ ti on donkey-music
Start working on donkey-music.
Start working on \x1b[32mdonkey-music\x1b[39m. (esc)
$ ti note hee-haw
Yep, noted to `donkey-music`.
Yep, noted to \x1b[33mdonkey-music\x1b[39m. (esc)

Add another longer note

$ ti note holla hoy with a longer musical? note
Yep, noted to `donkey-music`.
Yep, noted to \x1b[33mdonkey-music\x1b[39m. (esc)

Note with external editor
FIXME: Need a better EDITOR to test with
Expand Down
8 changes: 4 additions & 4 deletions test/on.t
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ Setup
Start working

$ ti on my-project
Start working on my-project.
Start working on \x1b[32mmy-project\x1b[39m. (esc)
$ test -f $SHEET_FILE
$ ti fin
So you stopped working on my-project.
So you stopped working on \x1b[31mmy-project\x1b[39m. (esc)

Start working while working

$ ti on project1
Start working on project1.
Start working on \x1b[32mproject1\x1b[39m. (esc)
$ ti on project2
You are already working on project1. Stop it or use a different sheet.
You are already working on \x1b[33mproject1\x1b[39m. Stop it or use a different sheet. (esc)
[1]
8 changes: 4 additions & 4 deletions test/status.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ Status when not working
Status after on-ing a task

$ ti on conqering-the-world
Start working on conqering-the-world.
Start working on \x1b[32mconqering-the-world\x1b[39m. (esc)
$ ti status
You have been working on `conqering-the-world` for less than a minute.
You have been working on \x1b[32mconqering-the-world\x1b[39m for less than a minute. (esc)

After adding tags

$ ti tag awesome
Okay, tagged current work with 1 tags.
$ ti status
You have been working on `conqering-the-world` for less than a minute.
You have been working on \x1b[32mconqering-the-world\x1b[39m for less than a minute. (esc)

Status after fin-ing it

$ ti fin
So you stopped working on conqering-the-world.
So you stopped working on \x1b[31mconqering-the-world\x1b[39m. (esc)
$ ti status
For all I know, you aren't working on anything. I don't know what to do.
See `ti -h` to know how to start working.
Expand Down
2 changes: 1 addition & 1 deletion test/tag.t
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ When not working
Not giving a tag to add

$ ti on something
Start working on something.
Start working on \x1b[32msomething\x1b[39m. (esc)
$ ti tag
Please provide at least one tag to add.

0 comments on commit 2d3eaa3

Please sign in to comment.