From 2d3eaa3e981742afa5b9ecba54a5deb96427fe70 Mon Sep 17 00:00:00 2001 From: Matt Hulse Date: Wed, 15 Oct 2014 23:12:13 -0600 Subject: [PATCH] Colorize task names --- bin/ti | 33 ++++++++++++++++++++++++--------- requirements.txt | 1 + test/fin.t | 12 ++++++------ test/format.t | 14 +++++++------- test/interrupt.t | 12 ++++++------ test/note.t | 6 +++--- test/on.t | 8 ++++---- test/status.t | 8 ++++---- test/tag.t | 2 +- 9 files changed, 56 insertions(+), 40 deletions(-) diff --git a/bin/ti b/bin/ti index 0e81059..e3fa090 100755 --- a/bin/ti +++ b/bin/ti @@ -37,6 +37,8 @@ import os, subprocess, tempfile from os import path import sys +from colorama import * + class JsonStore(object): def __init__(self, filename): @@ -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] @@ -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) @@ -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): @@ -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): @@ -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): @@ -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): @@ -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() diff --git a/requirements.txt b/requirements.txt index 40e4b7a..d0c3677 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,3 +2,4 @@ cram pygreen ghp-import pyyaml +colorama diff --git a/test/fin.t b/test/fin.t index 5dae820..202eb43 100644 --- a/test/fin.t +++ b/test/fin.t @@ -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 diff --git a/test/format.t b/test/format.t index 988d1d4..f7b5669 100644 --- a/test/format.t +++ b/test/format.t @@ -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) diff --git a/test/interrupt.t b/test/interrupt.t index 9f4f89a..23aa34b 100644 --- a/test/interrupt.t +++ b/test/interrupt.t @@ -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) diff --git a/test/note.t b/test/note.t index 6b181c9..4055974 100644 --- a/test/note.t +++ b/test/note.t @@ -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 diff --git a/test/on.t b/test/on.t index bcfe5bb..5268d85 100644 --- a/test/on.t +++ b/test/on.t @@ -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] diff --git a/test/status.t b/test/status.t index 20cba43..1366384 100644 --- a/test/status.t +++ b/test/status.t @@ -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. diff --git a/test/tag.t b/test/tag.t index 84e2ac4..552020e 100644 --- a/test/tag.t +++ b/test/tag.t @@ -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.