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 timer #81

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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: 1 addition & 1 deletion flomo/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def start(tag: str, name: str):
db.create_table()
session_id = db.create_session(tag, name, datetime.datetime.now())
db.conn.close()
ui.main(tag, name, session_id)
ui.main(tag, name, session_id, timer=True)
except (
errors.DBFileNotFoundError,
errors.NoConfigError,
Expand Down
72 changes: 50 additions & 22 deletions flomo/ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@

class UI:
def __init__(
self, status: int, tag: str, name: str, chilling_time: int | None = None
self, status: int, tag: str, name: str, chilling_time: int, timer_time: int | None = None
):
self.tag = f"#{tag}"
self.tag_color = helpers.tag_color(self.tag)
self.name = name
self.status = status

self.chilling_time = round(chilling_time) if chilling_time else None
self.timer_time = round(timer_time) if timer else None

self.stopwatch = 0
self.close_live_panel = False

Expand All @@ -34,7 +36,7 @@ def __init__(
def generate_panel(self):
# TODO: Fix UI resize issue?
stuff = f"{self.name}\n[{self.tag_color}]{self.tag}[/{self.tag_color}]\n\n{helpers.format_time(
self.stopwatch if (self.status == 0) else self.chilling_time or 0)}\n\n\\[q] - {'break' if self.status == 0 else 'skip?'} [Ctrl+C] - quit"
self.stopwatch if (self.status == 0) else (self.chilling_time or 0 if (self.status == 1) else self.timer_time or 0)) }\n\n\\[q] - {'break' if self.status == 0 else 'skip?'} [Ctrl+C] - quit"
content = Text.from_markup(stuff, justify="center", style="yellow")
return Align.center(
Panel(
Expand All @@ -59,39 +61,65 @@ def show_live_panel(self):
if not (self.chilling_time > 1):
break
self.chilling_time -= 1
elif self.status == 2 and self.timer_time:
if not (self.timer_time > 1):
break
self.timer_time -=1
_live.update(self.generate_panel())

def get_input(self):
with self.terminal.cbreak(), self.terminal.hidden_cursor():
return self.terminal.inkey(timeout=0.1).lower()


def main(tag: str, name: str, session_id: str):
def main(tag: str, name: str, session_id: str, timer=False):
# TODO: Do something with the Terminal close issue
try:
while True:
play_sound_thread = threading.Thread(target=helpers.play_sound, daemon=True)
play_sound_thread.start()

flowing_ui = UI(0, tag, name)
flowing_panel_thread = threading.Thread(
target=flowing_ui.show_live_panel, daemon=True
)
flowing_panel_thread.start()

inp = ""
while flowing_ui.stopwatch == 0 or not (
flowing_ui.stopwatch != 0 and inp == "q"
):
inp = flowing_ui.get_input()

chilling_time = flowing_ui.stopwatch / 5

flowing_ui.close_live_panel = True
flowing_panel_thread.join()
play_sound_thread.join()

del flowing_ui
if timer:
print("bruh")
timer_ui = UI(2, tag, name, timer_time=6000, chilling_time=60)
timer_panel_thread = threading.Thread(
target=timer_ui.show_live_panel, daemon=True
)
timer_panel_thread.start()

inp = ""
while timer_ui.timer_time == 0 or not (
timer_ui.timer_time != 0 and inp == "q"
):
inp = timer_ui.get_input()

chilling_time = timer_ui.timer_time / 5

timer_ui.close_live_panel = True
timer_panel_thread.join()
play_sound_thread.join()

del timer_ui
else:
flowing_ui = UI(0, tag, name)
flowing_panel_thread = threading.Thread(
target=flowing_ui.show_live_panel, daemon=True
)
flowing_panel_thread.start()

inp = ""
while flowing_ui.stopwatch == 0 or not (
flowing_ui.stopwatch != 0 and inp == "q"
):
inp = flowing_ui.get_input()

chilling_time = flowing_ui.stopwatch / 5

flowing_ui.close_live_panel = True
flowing_panel_thread.join()
play_sound_thread.join()

del flowing_ui

chilling_ui = UI(1, tag, name, int(chilling_time))

Expand Down
Loading