Compare commits
No commits in common. "cli-only" and "stable" have entirely different histories.
2 changed files with 16 additions and 53 deletions
|
@ -6,24 +6,15 @@ import prompt_window
|
||||||
import time
|
import time
|
||||||
from datetime import datetime, timedelta
|
from datetime import datetime, timedelta
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from pytz import timezone, utc
|
from pytz import timezone
|
||||||
from prompt_toolkit import PromptSession
|
|
||||||
from prompt_toolkit.history import FileHistory
|
|
||||||
#from prompt_toolkit.auto_suggest import AutoSuggestFromHistory
|
|
||||||
from prompt_toolkit.completion import WordCompleter
|
|
||||||
|
|
||||||
session = PromptSession(history=FileHistory(os.path.expanduser('~/.pomodoro_history')))
|
import pytz
|
||||||
# Move to a file:
|
|
||||||
words = WordCompleter(['NCHFA', 'PECE', 'Housing Works', 'Internal'])
|
|
||||||
#os.path.dirname(os.path.realpath(__file__))
|
|
||||||
#completion_list = WordCompleter(history=FileHistory(os.path.dirname(os.path.realpath(__file__)) + '.auto_complete'))
|
|
||||||
|
|
||||||
WORK_MIN = 25 # Minutes for a work session
|
WORK_MIN = 25 # Minutes for a work session
|
||||||
SHORT_MIN = 5 # Minutes for a short break
|
SHORT_MIN = 5 # Minutes for a short break
|
||||||
LONG_MIN = 15 # Minutes for a long break (NOT YET IMPLEMENTED)
|
LONG_MIN = 15 # Minutes for a long break (NOT YET IMPLEMENTED)
|
||||||
INTERRUPTED_MIN = 1 # Minimum minutes to ask to record an interrupted Pomodoro
|
INTERRUPTED_MIN = 1 # Minimum minutes to ask to record an interrupted Pomodoro
|
||||||
QUIET = True
|
QUIET = True
|
||||||
GUI = True
|
|
||||||
|
|
||||||
def pomodoro_prompt_plan(whatdid = ''):
|
def pomodoro_prompt_plan(whatdid = ''):
|
||||||
""" Ask about what task will be worked on (showing last thing worked on)
|
""" Ask about what task will be worked on (showing last thing worked on)
|
||||||
|
@ -31,14 +22,7 @@ def pomodoro_prompt_plan(whatdid = ''):
|
||||||
text = "What're you gonna do?"
|
text = "What're you gonna do?"
|
||||||
# NOTE: If we can do system notifications that when clicked will focus the terminal
|
# NOTE: If we can do system notifications that when clicked will focus the terminal
|
||||||
# running pomodoro prompt, that might be even better than the pop-up GUI text entry.
|
# running pomodoro prompt, that might be even better than the pop-up GUI text entry.
|
||||||
if GUI:
|
|
||||||
whatnext = prompt_window.prompt(prompt=text, task=whatdid)
|
whatnext = prompt_window.prompt(prompt=text, task=whatdid)
|
||||||
else:
|
|
||||||
whatnext = session.prompt(message = text + '\n',
|
|
||||||
default = whatdid or '',
|
|
||||||
vi_mode = True,
|
|
||||||
completer = words,
|
|
||||||
complete_while_typing = True).strip()
|
|
||||||
# Pressing cancel returns None, but we want to just treat it as an empty string.
|
# Pressing cancel returns None, but we want to just treat it as an empty string.
|
||||||
if whatnext is None:
|
if whatnext is None:
|
||||||
whatnext = ''
|
whatnext = ''
|
||||||
|
@ -48,14 +32,7 @@ def pomodoro_prompt_report(whatnext):
|
||||||
""" Ask what task was completed, showing the last task claimed to be being worked on
|
""" Ask what task was completed, showing the last task claimed to be being worked on
|
||||||
"""
|
"""
|
||||||
text = "What'd you do?"
|
text = "What'd you do?"
|
||||||
if GUI:
|
|
||||||
whatdid = prompt_window.prompt(prompt=text, task=whatnext)
|
whatdid = prompt_window.prompt(prompt=text, task=whatnext)
|
||||||
else:
|
|
||||||
whatdid = session.prompt(message = text + '\n',
|
|
||||||
default = whatnext or '',
|
|
||||||
vi_mode = True,
|
|
||||||
completer = words,
|
|
||||||
complete_while_typing = True).strip()
|
|
||||||
# Pressing cancel returns None, but we want to just treat it as an empty string.
|
# Pressing cancel returns None, but we want to just treat it as an empty string.
|
||||||
if whatdid is None:
|
if whatdid is None:
|
||||||
whatdid = ''
|
whatdid = ''
|
||||||
|
@ -87,7 +64,7 @@ def record_task(whatnext, whatdid, start, end=None):
|
||||||
""" Record completed pomodoro to CSV
|
""" Record completed pomodoro to CSV
|
||||||
"""
|
"""
|
||||||
if end is None:
|
if end is None:
|
||||||
end = datetime.now(utc)
|
end = datetime.now(pytz.utc)
|
||||||
|
|
||||||
filepath = prepare_file(start)
|
filepath = prepare_file(start)
|
||||||
if not os.path.isfile(filepath):
|
if not os.path.isfile(filepath):
|
||||||
|
@ -107,8 +84,8 @@ def str_minutes(time_diff):
|
||||||
def countdown_to(until):
|
def countdown_to(until):
|
||||||
""" Display a timer counting down to until
|
""" Display a timer counting down to until
|
||||||
"""
|
"""
|
||||||
while datetime.now(utc) <= until:
|
while datetime.now(pytz.utc) <= until:
|
||||||
to_go = until-datetime.now(utc)
|
to_go = until-datetime.now(pytz.utc)
|
||||||
print('\r', str_minutes(to_go), sep='', end='')
|
print('\r', str_minutes(to_go), sep='', end='')
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
@ -130,33 +107,20 @@ def prepare_file(utc_start, ext='csv', daily=False):
|
||||||
timelog_path += '.' + ext
|
timelog_path += '.' + ext
|
||||||
return timelog_path
|
return timelog_path
|
||||||
|
|
||||||
def bing():
|
|
||||||
if GUI:
|
|
||||||
from playsound import playsound
|
|
||||||
playsound('res/timesup.aac')
|
|
||||||
else:
|
|
||||||
sys.stdout.write('\a')
|
|
||||||
sys.stdout.flush()
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
whatdid = ''
|
whatdid = ''
|
||||||
global GUI, QUIET
|
|
||||||
if "--no-gui" in sys.argv:
|
|
||||||
GUI = False
|
|
||||||
if "--noisy" in sys.argv:
|
|
||||||
QUIET = False
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
whatnext = pomodoro_prompt_plan(whatdid)
|
whatnext = pomodoro_prompt_plan(whatdid)
|
||||||
|
|
||||||
start = datetime.now(utc)
|
start = datetime.now(pytz.utc)
|
||||||
end = start + timedelta(minutes=WORK_MIN)
|
end = start + timedelta(minutes=WORK_MIN)
|
||||||
log_step('Start with plan: ' + whatnext, start)
|
log_step('Start with plan: ' + whatnext, start)
|
||||||
try:
|
try:
|
||||||
print('Working on: ' + (whatnext or "(...it must be a mystery)"))
|
print('Working on: ' + whatnext)
|
||||||
countdown_to(end)
|
countdown_to(end)
|
||||||
if not QUIET:
|
if not QUIET:
|
||||||
bing()
|
from playsound import playsound
|
||||||
|
playsound('res/timesup.aac')
|
||||||
whatdid = pomodoro_prompt_report(whatnext)
|
whatdid = pomodoro_prompt_report(whatnext)
|
||||||
record_task(whatnext, whatdid, start)
|
record_task(whatnext, whatdid, start)
|
||||||
log_step('Completed pomodoro: ' + whatdid, start, True)
|
log_step('Completed pomodoro: ' + whatdid, start, True)
|
||||||
|
@ -165,16 +129,16 @@ def main():
|
||||||
print('Break time!')
|
print('Break time!')
|
||||||
# We're taking a break. Clear out task start/end times.
|
# We're taking a break. Clear out task start/end times.
|
||||||
start = None
|
start = None
|
||||||
end = datetime.now(utc) + timedelta(minutes=SHORT_MIN)
|
end = datetime.now(pytz.utc) + timedelta(minutes=SHORT_MIN)
|
||||||
countdown_to(end)
|
countdown_to(end)
|
||||||
if not QUIET:
|
if not QUIET:
|
||||||
bing()
|
playsound('res/timesup.aac')
|
||||||
continue
|
continue
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
if start is None:
|
if start is None:
|
||||||
quit_prompt()
|
quit_prompt()
|
||||||
continue
|
continue
|
||||||
time_spent = datetime.now(utc) - start
|
time_spent = datetime.now(pytz.utc) - start
|
||||||
if time_spent < timedelta(minutes=INTERRUPTED_MIN):
|
if time_spent < timedelta(minutes=INTERRUPTED_MIN):
|
||||||
quit_prompt()
|
quit_prompt()
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -11,7 +11,6 @@ in pkgs.mkShell {
|
||||||
pycairo
|
pycairo
|
||||||
pytz
|
pytz
|
||||||
tzlocal
|
tzlocal
|
||||||
prompt-toolkit # for text entry history/auto complete
|
|
||||||
# For Qt:
|
# For Qt:
|
||||||
# pyside6
|
# pyside6
|
||||||
# Using GTK:
|
# Using GTK:
|
||||||
|
|
Loading…
Reference in a new issue