pomme/pomme/pomme.py

85 lines
1.7 KiB
Python

""" CLI timer for working with the pomodoro method """
import click
import toml
import os
import sched
import time
import click_completion
from blessed import Terminal # type: ignore
from pomme.timer import Timer
from pomme.hooks import Hooks
from pomme import __version__
file_path = os.path.dirname(__file__)
config = toml.load(os.path.join(file_path, "config.toml"))
database_location = config['database']['location']
timer = Timer(database_location)
term = Terminal()
@click.command()
def cancel() -> None:
""" stop timer """
timer.cancel()
@click.command()
@click.argument(
'duration'
)
def start(duration: str) -> None:
""" start timer
Format of the duration can be either hh:mm:ss, mm:ss or mm
:param duration: duration of the timer
"""
print("timer start")
timer.start(duration)
run_tui_timer()
def run_tui_timer() -> None:
s = sched.scheduler(time.time, time.sleep)
s.enter(1, 1, print_time, (s,))
s.run()
def print_time(s) -> None:
"""
:param s: sheduler
"""
hooks = Hooks()
print(term.home + term.clear)
if timer.running():
print(timer.remaining())
else:
print("timer finished")
hooks.after()
return
s.enter(1, 1, print_time, (s,))
@click.group(invoke_without_command=True)
@click.option('-v', '--version', is_flag=True)
def pomme(version) -> None:
""" Pomme timer management system """
context = click.get_current_context()
if version:
print("Pomme version {}".format(__version__))
return
elif not context.invoked_subcommand:
print(context.get_help())
pass
pomme.add_command(start)
pomme.add_command(cancel)
click_completion.init()