From 5c111e96f1cce6bc9be6f46af8bdd376e989f7ea Mon Sep 17 00:00:00 2001 From: "Chris (wolcen) Thompson" <chris@agaric.coop> Date: Mon, 18 Nov 2024 21:39:33 -0500 Subject: [PATCH 1/3] Add ability to use w/out GUI (via --no-gui) And ring the console bell w/--noisy --- pomodoroprompt.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/pomodoroprompt.py b/pomodoroprompt.py index 1cec777..ddb370b 100644 --- a/pomodoroprompt.py +++ b/pomodoroprompt.py @@ -15,6 +15,7 @@ SHORT_MIN = 5 # Minutes for a short break LONG_MIN = 15 # Minutes for a long break (NOT YET IMPLEMENTED) INTERRUPTED_MIN = 1 # Minimum minutes to ask to record an interrupted Pomodoro QUIET = True +GUI = True def pomodoro_prompt_plan(whatdid = ''): """ Ask about what task will be worked on (showing last thing worked on) @@ -22,7 +23,11 @@ def pomodoro_prompt_plan(whatdid = ''): text = "What're you gonna do?" # 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. - whatnext = prompt_window.prompt(prompt=text, task=whatdid) + if GUI: + whatnext = prompt_window.prompt(prompt=text, task=whatdid) + else: + print(f'\n{text}') + whatnext = (input(f'({whatdid}): ' if whatdid else '').strip() or whatdid) # Pressing cancel returns None, but we want to just treat it as an empty string. if whatnext is None: whatnext = '' @@ -32,7 +37,11 @@ def pomodoro_prompt_report(whatnext): """ Ask what task was completed, showing the last task claimed to be being worked on """ text = "What'd you do?" - whatdid = prompt_window.prompt(prompt=text, task=whatnext) + if GUI: + whatdid = prompt_window.prompt(prompt=text, task=whatnext) + else: + print(f'\n{text}') + whatdid = (input(f'({whatnext}): ' if whatnext else '').strip() or whatnext) # Pressing cancel returns None, but we want to just treat it as an empty string. if whatdid is None: whatdid = '' @@ -107,8 +116,22 @@ def prepare_file(utc_start, ext='csv', daily=False): timelog_path += '.' + ext 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(): whatdid = '' + global GUI, QUIET + if "--no-gui" in sys.argv: + GUI = False + if "--noisy" in sys.argv: + QUIET = False + while True: whatnext = pomodoro_prompt_plan(whatdid) @@ -119,8 +142,7 @@ def main(): print('Working on: ' + whatnext) countdown_to(end) if not QUIET: - from playsound import playsound - playsound('res/timesup.aac') + bing() whatdid = pomodoro_prompt_report(whatnext) record_task(whatnext, whatdid, start) log_step('Completed pomodoro: ' + whatdid, start, True) @@ -132,7 +154,7 @@ def main(): end = datetime.now(pytz.utc) + timedelta(minutes=SHORT_MIN) countdown_to(end) if not QUIET: - playsound('res/timesup.aac') + bing() continue except KeyboardInterrupt: if start is None: From f908389c4059da02806b87e0a69d4da5222d7dfa Mon Sep 17 00:00:00 2001 From: "Chris (wolcen) Thompson" <chris@agaric.coop> Date: Tue, 19 Nov 2024 10:59:14 -0500 Subject: [PATCH 2/3] Add text entry history/editing/auto-complete ...and import utc directly --- pomodoroprompt.py | 44 +++++++++++++++++++++++++++++--------------- shell.nix | 1 + 2 files changed, 30 insertions(+), 15 deletions(-) diff --git a/pomodoroprompt.py b/pomodoroprompt.py index ddb370b..0e4575c 100644 --- a/pomodoroprompt.py +++ b/pomodoroprompt.py @@ -6,9 +6,17 @@ import prompt_window import time from datetime import datetime, timedelta from pathlib import Path -from pytz import timezone +from pytz import timezone, utc +from prompt_toolkit import PromptSession +from prompt_toolkit.history import FileHistory +#from prompt_toolkit.auto_suggest import AutoSuggestFromHistory +from prompt_toolkit.completion import WordCompleter -import pytz +session = PromptSession(history=FileHistory(os.path.expanduser('~/.pomodoro_history'))) +# 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 SHORT_MIN = 5 # Minutes for a short break @@ -20,14 +28,17 @@ GUI = True def pomodoro_prompt_plan(whatdid = ''): """ Ask about what task will be worked on (showing last thing worked on) """ - 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 # 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) else: - print(f'\n{text}') - whatnext = (input(f'({whatdid}): ' if whatdid else '').strip() or whatdid) + whatnext = session.prompt(message = text, + 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. if whatnext is None: whatnext = '' @@ -36,12 +47,15 @@ def pomodoro_prompt_plan(whatdid = ''): def pomodoro_prompt_report(whatnext): """ 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) else: - print(f'\n{text}') - whatdid = (input(f'({whatnext}): ' if whatnext else '').strip() or whatnext) + whatdid = session.prompt(message = text, + 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. if whatdid is None: whatdid = '' @@ -73,7 +87,7 @@ def record_task(whatnext, whatdid, start, end=None): """ Record completed pomodoro to CSV """ if end is None: - end = datetime.now(pytz.utc) + end = datetime.now(utc) filepath = prepare_file(start) if not os.path.isfile(filepath): @@ -93,8 +107,8 @@ def str_minutes(time_diff): def countdown_to(until): """ Display a timer counting down to until """ - while datetime.now(pytz.utc) <= until: - to_go = until-datetime.now(pytz.utc) + while datetime.now(utc) <= until: + to_go = until-datetime.now(utc) print('\r', str_minutes(to_go), sep='', end='') time.sleep(1) @@ -135,11 +149,11 @@ def main(): while True: whatnext = pomodoro_prompt_plan(whatdid) - start = datetime.now(pytz.utc) + start = datetime.now(utc) end = start + timedelta(minutes=WORK_MIN) log_step('Start with plan: ' + whatnext, start) try: - print('Working on: ' + whatnext) + print('Working on: ' + (whatnext or "(...it must be a mystery)")) countdown_to(end) if not QUIET: bing() @@ -151,7 +165,7 @@ def main(): print('Break time!') # We're taking a break. Clear out task start/end times. start = None - end = datetime.now(pytz.utc) + timedelta(minutes=SHORT_MIN) + end = datetime.now(utc) + timedelta(minutes=SHORT_MIN) countdown_to(end) if not QUIET: bing() @@ -160,7 +174,7 @@ def main(): if start is None: quit_prompt() continue - time_spent = datetime.now(pytz.utc) - start + time_spent = datetime.now(utc) - start if time_spent < timedelta(minutes=INTERRUPTED_MIN): quit_prompt() continue diff --git a/shell.nix b/shell.nix index 484bf23..fff5e53 100644 --- a/shell.nix +++ b/shell.nix @@ -11,6 +11,7 @@ in pkgs.mkShell { pycairo pytz tzlocal + prompt-toolkit # for text entry history/auto complete # For Qt: # pyside6 # Using GTK: From e8f7adc3559b893ff33110e1842478c46ef29059 Mon Sep 17 00:00:00 2001 From: "Chris (wolcen) Thompson" <chris@agaric.coop> Date: Tue, 19 Nov 2024 13:31:34 -0500 Subject: [PATCH 3/3] Seems there are problems with prompt on the same line (sometimes) May well have to do with changes to my environment, but I'm not dealing w/that now --- pomodoroprompt.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pomodoroprompt.py b/pomodoroprompt.py index 0e4575c..7cb3456 100644 --- a/pomodoroprompt.py +++ b/pomodoroprompt.py @@ -34,7 +34,7 @@ def pomodoro_prompt_plan(whatdid = ''): if GUI: whatnext = prompt_window.prompt(prompt=text, task=whatdid) else: - whatnext = session.prompt(message = text, + whatnext = session.prompt(message = text + '\n', default = whatdid or '', vi_mode = True, completer = words, @@ -51,7 +51,7 @@ def pomodoro_prompt_report(whatnext): if GUI: whatdid = prompt_window.prompt(prompt=text, task=whatnext) else: - whatdid = session.prompt(message = text, + whatdid = session.prompt(message = text + '\n', default = whatnext or '', vi_mode = True, completer = words,