-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 463f9f6
Showing
6 changed files
with
266 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
*.dSYM | ||
.vrepl* | ||
*.exe | ||
*.o | ||
.*.c | ||
*.obj | ||
*.pdb | ||
pomodoro |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2019 Blake Knight | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
PREFIX ?= /usr/local/bin | ||
V ?= v | ||
|
||
all: pomodoro | ||
|
||
clean: | ||
$(RM) -r .*.dSYM | ||
$(RM) .vrepl* | ||
$(RM) .*. | ||
|
||
# Moves the build binary to the installation prefix | ||
install: pomodoro | ||
mv -i `pwd`/pomodoro ${PREFIX}/pomodoro | ||
|
||
# Makes the pomodoro executable | ||
pomodoro: | ||
${V} -prod -o pomodoro pomodoro.v | ||
@echo "Successfully built pomodoro" | ||
|
||
# Alternate to install. Symlinks from this directory to the installation prefix | ||
symlink: pomodoro | ||
ln -is `pwd`/pomodoro ${PREFIX}/pomodoro |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
# pomodoro | ||
|
||
> A simple terminal-based pomodoro timer | ||
The point of pomodoro timers is to help you focus and save time. Unfortunately, | ||
I found myself wasting time with other tools. To fix that, I spent a few minutes | ||
making a simple timer for use in the terminal. | ||
|
||
⚠️ Right now, due to notifications, this is macOS-only. My plan is to work on a | ||
cross-platform notification system for [V](https://github.com/vlang/v). Once | ||
that's done, this project will be updated. Two lines can be commented out for a | ||
fully terminal-based system, but that's not what I want. | ||
|
||
## Usage | ||
|
||
Here are some common ways to use the timer: | ||
|
||
**Start a 25 minute timer:** | ||
|
||
```bash | ||
pomodoro | ||
``` | ||
|
||
**Start a short (5 minute) break:** | ||
|
||
```bash | ||
pomodoro -s | ||
``` | ||
|
||
**Start a short (20 minute) break:** | ||
|
||
```bash | ||
pomodoro -l | ||
``` | ||
|
||
**Start a 3 minute timer for tea:** | ||
|
||
```bash | ||
pomodoro -c 3 | ||
``` | ||
|
||
If you want to see more details, here's all options at the time of writing: | ||
|
||
- `-c time, --custom time`: start a custom timer (time in minutes) | ||
- `-h, --help`: show the help text | ||
- `-l, --long`: starts the timer for 20 minutes | ||
- `-s, --short`: starts the timer for 5 minutes | ||
|
||
**Remember:** you can always run `pomodoro --help` to get the latest list of | ||
options available. | ||
|
||
## Installing | ||
|
||
First, either [clone this | ||
repo](https://help.github.com/articles/cloning-a-repository/) or [download a zip | ||
file](https://github.com/blakek/pomodoro/archive/master.zip). | ||
|
||
Then, in a terminal open to this project's directory, run make: | ||
|
||
``` | ||
$ make install | ||
``` | ||
|
||
This will compile the binary and move it to a directory. The default install | ||
directory is `/usr/local/bin`. You can change this by setting the `PREFIX` | ||
variable: | ||
|
||
``` | ||
$ PREFIX=/custom/directory make install | ||
``` | ||
|
||
## Updating | ||
|
||
Right now, the easiest way to update is to re-run the install directions. If you | ||
keep the repository, you can occasionally run `git pull && make install` to use | ||
the latest. | ||
|
||
## See Also | ||
|
||
- [`vlang/v`](https://github.com/vlang/v) - The language this project is written | ||
in. | ||
|
||
## License | ||
|
||
MIT |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
module notifier_mac | ||
|
||
import os | ||
|
||
struct Options { | ||
sound_name string | ||
text string | ||
title string | ||
} | ||
|
||
pub fn show_notification(options Options) { | ||
command := 'osascript -e \'display notification "${options.text}" with title "${options.title}" sound name "${options.sound_name}"\'' | ||
|
||
os.system(command) | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,115 @@ | ||
import notifier_mac | ||
import os | ||
import time | ||
|
||
struct Arguments { | ||
minutes f32 | ||
show_help bool | ||
} | ||
|
||
fn print_time(time i64) { | ||
minutes := int(time / 60) | ||
seconds := time % 60 | ||
|
||
print('\e[2K\r${minutes}:${seconds:02d} remaining') | ||
|
||
// Don't optimize output timing; print immediately. | ||
C.fflush(stdout) | ||
} | ||
|
||
fn show_help() { | ||
println('Usage: pomodoro [options]') | ||
println('') | ||
println('Examples:') | ||
println(' Start a standard pomodoro timer for 25 minutes:') | ||
println(' pomodoro') | ||
println(' Start a short (5 minute) break:') | ||
println(' pomodoro -s') | ||
println(' Start a 3 minute timer for tea:') | ||
println(' pomodoro -c 3') | ||
println('') | ||
println('Options:') | ||
println(' -c time, --custom time start a custom timer (time in minutes)') | ||
println(' -h, --help show this help text') | ||
println(' -l, --long starts the timer for 20 minutes') | ||
println(' -s, --short starts the timer for 5 minutes') | ||
} | ||
|
||
fn parse_arguments(args []string, defaultValues Arguments) Arguments { | ||
if args.len == 0 { | ||
return defaultValues | ||
} | ||
|
||
arg := args[0] | ||
|
||
if arg in ['-c', '--custom'] { | ||
return parse_arguments( | ||
args.slice(2, args.len), | ||
{ defaultValues | minutes: args[1].f32() } | ||
) | ||
} | ||
|
||
if arg in ['-h', '--help'] { | ||
return parse_arguments( | ||
args.slice(1, args.len), | ||
{ defaultValues | show_help: true } | ||
) | ||
} | ||
|
||
if arg in ['-l', '--long'] { | ||
return parse_arguments( | ||
args.slice(1, args.len), | ||
{ defaultValues | minutes: 20 } | ||
) | ||
} | ||
|
||
if arg in ['-s', '--short'] { | ||
return parse_arguments( | ||
args.slice(1, args.len), | ||
{ defaultValues | minutes: 5 } | ||
) | ||
} | ||
|
||
println('Unknown argument ${arg}') | ||
exit(1) | ||
} | ||
|
||
fn main() { | ||
// Get arguments | ||
arguments := parse_arguments( | ||
os.args.slice(1, os.args.len), | ||
Arguments { | ||
minutes: 25 | ||
show_help: false | ||
} | ||
) | ||
|
||
// If help specified, show help and exit | ||
if arguments.show_help { | ||
show_help() | ||
exit(0) | ||
} | ||
|
||
// Take in minutes for easier typing, but use seconds so we know how much | ||
// time is left | ||
seconds := int(arguments.minutes * 60) | ||
|
||
for i := seconds; i > 0; i-- { | ||
print_time(i) | ||
time.sleep(1) | ||
} | ||
|
||
notification_minutes := seconds / 60 | ||
notification_seconds := seconds % 60 | ||
|
||
notification_options := notifier_mac.Options { | ||
sound_name: 'default', | ||
text: 'Finished ${notification_minutes}min ${notification_seconds:d}s timer' | ||
title: 'Pomodoro' | ||
} | ||
|
||
notifier_mac.show_notification(notification_options) | ||
|
||
// Print extra newline so next command is on a new line | ||
println('') | ||
} |