Skip to content

Instantly share code, notes, and snippets.

@eli-oat
Last active October 7, 2022 17:22
Show Gist options
  • Save eli-oat/4a516f9d1527d5c7cc1b1b181a509828 to your computer and use it in GitHub Desktop.
Save eli-oat/4a516f9d1527d5c7cc1b1b181a509828 to your computer and use it in GitHub Desktop.
Pomodoro Timer in Forth
( POMO POMO POMO )
VARIABLE POMO-TIME
1500000 POMO-TIME !
VARIABLE REST-TIME
600000 REST-TIME !
( TODO: Consider using VALUE instead of VARIABLE )
: 1SEC 1000 MS ;
: 30SEC 30000 MS ;
: 60SEC 60000 MS ;
: PRETTY-TIME
1000 /
60 /
;
( DECREMENTS POMO-TIME if it is greater than 0 )
: CHECK-POMO-TIME?
0> IF
POMO-TIME @ 1000 - POMO-TIME ! ." 🍅" SPACE POMO-TIME @ PRETTY-TIME . ." minutes" CR
." ....." SPACE POMO-TIME ? CR
ELSE
REST-TIME @ 1000 - REST-TIME ! ." 😴" SPACE REST-TIME @ PRETTY-TIME . ." minutes" CR
." ....." SPACE REST-TIME ? CR
THEN
;
( POMO-LOOP exits when POMO-TIME reaches 0 )
( FIXME: reset POMO-TIME and REST-TIME once they've reached 0 )
: POMO-LOOP
BEGIN
PAGE
POMO-TIME @ CHECK-POMO-TIME? 1SEC
PAGE
POMO-TIME @ REST-TIME @ + 0=
UNTIL
;
POMO-LOOP
BYE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment