Created
April 2, 2018 23:12
-
-
Save lepinekong/034aff9e317d3e8ce575c74d778318cb to your computer and use it in GitHub Desktop.
buggy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Tutorials: [ | |
https://dev.to/lepinekong/red-for-hopeless-programmers---part-i-3g0 | |
https://dev.to/lepinekong/red-for-hopeless-programmers---part-ii-258 | |
] | |
Demo-Instruction: { | |
can be pasted directly in Redlang Console (1 Mb download https://www.red-lang.org/p/download.html) | |
if you just want to see demo without downloading, type in Red console: | |
do read https://gist.githubusercontent.com/lepinekong/08021f2b8ecdd3e0dc09685ef0b0c03f/raw/c7b41adc9a3815f77c4bca815af35b598f920bc1/.system.user.apps.countdown.red | |
Countdown 00:25:00 Pomodoro | |
} | |
Compile-Instruction: { | |
Note that you can just run in interpreted mode (See Demo-Instruction) but if you want an exe: | |
1°) you must use latest build red-30mar18-be7ff3a9.exe on https://www.red-lang.org/p/download.html | |
2°) you must remove /no-wait refinement for view | |
3°) for Windows you must use DOS Commandline and type: | |
c:\your.red.folder\red.exe -r -e -t Windows "c:\your.project.folder\.system.user.apps.countdown.red" | |
} | |
Url: https://gist.github.com/lepinekong/08021f2b8ecdd3e0dc09685ef0b0c03f | |
SHA256: #{ | |
07463B7EDE742EAA1A88D73E197B36FA41EF6B53CA7C6F068D684BC09767BD32 | |
} | |
Red [ | |
Title: ".system.user.apps.countdown.red" | |
Description: "Countdown with Voice alert on Windows (to adapt for Linux and MacOS)" | |
History: { | |
- [x][1.0]. Countdown with optional duration parameter (default is one minute) | |
- [x][1.1]. Countdown with optional title (see Pomodoro Usage example below) | |
- [x][1.2]. Don't need to remove /no-wait manually any more for compiled version | |
- [ ][1.x]. More features coming depending... on my moods :) (autostart, pre-register frequent timers,...) | |
} | |
Usage: { | |
Countdown ; 1 min countdown by default | |
Countdown 0:03:00 ; 3 min perfect boiled egg | |
Countdown 0:25:00 Pomodoro; Pomodoro title (use "" if any space) | |
} | |
Needs: 'View ; not needed for interpreter in Red console (only for compiler) | |
] | |
if not value? '.speak [ | |
.speak: function[message [string!]][ | |
Command: rejoin [{(New-Object –ComObject SAPI.SPVoice).Speak("} message {")}] | |
replace/all Command {"} {\"} | |
call cmd: rejoin ["powershell -command " {"} Command {"}] | |
] | |
] | |
Countdown: function['.duration [time! unset!] '.title [word! string! unset!]][ | |
<=default-duration: 0:01 ; 1 min duration by default | |
switch/default type?/word get/any '.duration [ | |
time! [ | |
<=duration: .duration ; I use <= prefix convention to tag external variables inputs | |
] | |
][ | |
<=duration: <=default-duration | |
] | |
<=refresh-rate: 10 | |
switch/default type?/word get/any '.title [ | |
unset! [ | |
<=title: "Countdown" | |
] | |
word! string! [ | |
<=title: form .title | |
] | |
][ | |
throw error 'script 'expect-arg .title | |
] | |
clock: Make object! [ | |
; below is just my very own convention | |
; in case you believe it's some Redlang special idioms | |
; local variables <= external variables | |
duration: <=duration | |
refresh-rate: <=refresh-rate | |
title: <=title | |
text-duration: to-string duration | |
text-duration-to-speak: copy "" | |
either (duration/minute > 0) [ | |
text-duration-to-speak: rejoin [duration/minute " minutes "] | |
either (duration/second > 0) [ | |
text-duration-to-speak: rejoin [text-duration-to-speak " and " duration/second " seconds elapsed"] | |
][ | |
text-duration-to-speak: rejoin [text-duration-to-speak " elapsed"] | |
] | |
][ | |
text-duration-to-speak: rejoin [duration/second " seconds elapsed"] | |
] | |
t: start-time: diff: rest: minutes: seconds: pause-time: pause-duration: 0 | |
b1: b2: none ; for buttons start/stop pause/continue | |
window: compose [ ; compose will evaluate expressions in () | |
title (title) | |
; example t: text "00:25:00" | |
t: text (text-duration) on-time [ | |
diff: difference now start-time | |
rest: (duration) - diff | |
minutes: pad/left/with (rest/minute) 2 #"0" | |
seconds: pad/left/with (round/to rest/second 1) 2 #"0" | |
t/text: rejoin [minutes ":" seconds] | |
if (rest < 0:0:0) [ | |
t/rate: none t/text: "00:00" b1/text: "Start" | |
.speak (text-duration-to-speak) | |
] | |
] | |
b1: button "start" [ | |
either b1/text = "Start" [ | |
b1/text: "Stop" t/rate: (refresh-rate) start-time: now | |
][ | |
b1/text: "Start" t/rate: none t/text: (text-duration) | |
] | |
] | |
b2: button "pause" [ | |
either (b2/text = "Pause") [ | |
b2/text: "Continue" t/rate: none | |
pause-time: now | |
][ | |
pause-duration: difference now pause-time | |
start-time: start-time + pause-duration | |
b2/text: "Pause" t/rate: (refresh-rate) | |
] | |
] | |
] | |
either (system/console = none) [ | |
view window | |
][ | |
view/no-wait window | |
] | |
print rejoin ["Running Countdown..."] | |
] | |
] | |
Countdown 00:25:00 "Pomodoro"; | |
;Countdown 00:03:00 ; for perfect boiled egg :) | |
;Countdown ; if you're lazy (coming default duration configuration) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment