Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use as an incremental timer #85

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@ Options:
only, use: --exec-cmd "if [ '{0}' == '5' ];
then say -v Alex {1}; fi"

-i, --increment TEXT Increment to add to countdown when resetting

--no-figlet Don't use ASCII art for display
--no-figlet-y-offset INTEGER Vertical offset within the terminal (only for
--no-figlet)
Expand Down
18 changes: 15 additions & 3 deletions termdown.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,6 @@ def parse_timestr(timestr):

if timedelta_secs:
target = datetime.now() + timedelta(seconds=timedelta_secs)
elif timestr.isdigit():
target = datetime.now() + timedelta(seconds=int(timestr))
else:
try:
target = parse(timestr)
Expand Down Expand Up @@ -248,6 +246,9 @@ def parse_timedelta(deltastr):
matches = TIMEDELTA_REGEX.match(deltastr)
if not matches:
return None
if deltastr.isdigit():
return int(deltastr)

components = {}
for name, value in matches.groupdict().items():
if value:
Expand Down Expand Up @@ -298,6 +299,7 @@ def countdown(
no_figlet=False,
no_figlet_y_offset=-1,
no_window_title=False,
increment=None,
time=False,
time_format=None,
date_format=None,
Expand All @@ -323,6 +325,8 @@ def countdown(
if voice or exec_cmd:
voice_prefix = voice_prefix or ""

resets = 0

input_thread = Thread(
args=(stdscr, input_queue, quit_event, curses_lock),
target=input_thread_body,
Expand Down Expand Up @@ -404,7 +408,7 @@ def countdown(

# If sync_start has microsecond=0, it might happen that we
# need to skip one frame (the very first one). This occurs
# when the program has been startet at, say,
# when the program has been started at, say,
# "2014-05-29 20:27:57.930651". Now suppose rendering the
# frame took about 0.2 seconds. The real time now is
# "2014-05-29 20:27:58.130000" and sleep_target is
Expand Down Expand Up @@ -443,6 +447,8 @@ def countdown(
continue
elif input_action == INPUT_RESET:
sync_start, target = parse_timestr(timespec)
if increment:
target += timedelta(seconds=(parse_timedelta(increment) * resets))
seconds_left = int(ceil((target - datetime.now()).total_seconds()))
continue
elif input_action == INPUT_PLUS:
Expand Down Expand Up @@ -519,7 +525,11 @@ def countdown(
return
elif input_action == INPUT_RESET:
sync_start, target = parse_timestr(timespec)
if increment:
resets += 1
target += timedelta(seconds=(parse_timedelta(increment) * resets))
seconds_left = int(ceil((target - datetime.now()).total_seconds()))

blink_reset = True
break
slept += (sleep_end - sleep_start).total_seconds()
Expand Down Expand Up @@ -755,6 +765,8 @@ def input_thread_body(stdscr, input_queue, quit_event, curses_lock):
"remaining/elapsed number of seconds and a more sparse annunciation as in "
"--voice, respectively. For example, to get a callout at five seconds only, "
"use: --exec-cmd \"if [ '{0}' == '5' ]; then say -v Alex {1}; fi\"")
@click.option("-i", "--increment", default=None,
help="Increment to add to countdown when resetting")
@click.option("--no-figlet", default=False, is_flag=True,
help="Don't use ASCII art for display")
@click.option("--no-figlet-y-offset", default=-1,
Expand Down