Skip to content

Commit

Permalink
Merge pull request #2 from blakek/go-rewrite
Browse files Browse the repository at this point in the history
✨ Rewrite project in Go
  • Loading branch information
blakek authored Dec 17, 2020
2 parents fbc5868 + 43a6f54 commit ed6969d
Show file tree
Hide file tree
Showing 9 changed files with 138 additions and 185 deletions.
6 changes: 0 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,2 @@
*.dSYM
.vrepl*
*.exe
*.o
.*.c
*.obj
*.pdb
pomodoro
37 changes: 37 additions & 0 deletions Info.plist
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleExecutable</key>
<string>pomodoro</string>
<key>CFBundleIconFile</key>
<string>Terminal</string>
<key>CFBundleIdentifier</key>
<string>blakek.pomodoro</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>2.0</string>
<key>CFBundleName</key>
<string>pomodoro</string>
<key>CFBundlePackageType</key>
<string>APPL</string>
<key>CFBundleShortVersionString</key>
<string>2.0.0</string>
<key>CFBundleSignature</key>
<string>????</string>
<key>CFBundleVersion</key>
<string>2</string>
<key>LSMinimumSystemVersion</key>
<string>10.9.0</string>
<key>LSUIElement</key>
<true/>
<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
<true/>
</dict>
<key>NSHumanReadableCopyright</key>
<string>Copyright © 2020 Blake Knight</string>
<key>NSUserNotificationAlertStyle</key>
<string>alert</string>
</dict>
</plist>
22 changes: 0 additions & 22 deletions Makefile

This file was deleted.

42 changes: 15 additions & 27 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@ 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:
Expand All @@ -36,7 +31,13 @@ pomodoro -l
**Start a 3 minute timer for tea:**

```bash
pomodoro -c 3
pomodoro -c 3m
```

**Start a 1 hour, 2 minute, 3 second timer:**

```bash
pomodoro -c 1h2m3s
```

If you want to see more details, here's all options at the time of writing:
Expand All @@ -63,36 +64,23 @@ brew tap blakek/blakek && brew install blakek/blakek/pomodoro

### Build from Source

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).
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:
Then, in a terminal open to this project's directory, build with Go:

```
$ 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
$ go build
```

## Updating

If you installed using Homebrew, you can use the normal `brew upgrade` process.

The easiest way to update from a source build is to re-run the install
directions. If you keep the repository, you can occasionally run
`git pull && make install` to build using the latest changes.

## See Also

- [`vlang/v`](https://github.com/vlang/v) - The language this project is written
in.
The easiest way to update from a source build is to pull the latest changes
(e.g. `git pull`) and re-run the install directions. If you keep the
repository, you can occasionally run `git pull && go build` to build using the
latest changes.

## License

Expand Down
8 changes: 8 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module github.com/blakek/pomodoro

go 1.14

require (
github.com/blakek/go-notifier v0.1.0
github.com/jessevdk/go-flags v1.4.0
)
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
github.com/blakek/go-notifier v0.1.0 h1:ZhB7OVgbfXWL9m919xvqCfwoSsoen4oFzVUr+m1Ozec=
github.com/blakek/go-notifier v0.1.0/go.mod h1:vRLSkYnhnPiXD1kgtpBh6JpZDkFfVDdcn1dz7/rQObM=
github.com/jessevdk/go-flags v1.4.0 h1:4IU2WS7AumrZ/40jfhf4QVDMsQwqA7VEHozFRrGARJA=
github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI=
15 changes: 0 additions & 15 deletions notifier_mac/notifier_mac.v

This file was deleted.

74 changes: 74 additions & 0 deletions pomodoro.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package main

import (
"fmt"
"os"
"time"

"github.com/blakek/go-notifier"
"github.com/jessevdk/go-flags"
)

var arguments struct {
CustomTimer string `long:"custom" short:"c" description:"start a custom timer for given number of minutes" default:"25m"`
RunShortTimer bool `long:"short" short:"s" description:"starts a timer for 5 minutes"`
RunLongTimer bool `long:"long" short:"l" description:"starts a timer for 20 minutes"`
}

func clearCurrentLine() {
fmt.Print("\033[2K\r")
}

func printTime(timeRemaining time.Duration) {
clearCurrentLine()

if timeRemaining <= 0 {
fmt.Printf("Timer finished at %s\n", time.Now().Format(time.Kitchen))
} else {
fmt.Printf("%s remaining", timeRemaining.String())
}
}

func main() {
var duration time.Duration
flags.Parse(&arguments)

if arguments.RunLongTimer {
duration = 20 * time.Minute
} else if arguments.RunShortTimer {
duration = 5 * time.Minute
} else {
var parseError error
duration, parseError = time.ParseDuration(arguments.CustomTimer)

if parseError != nil {
fmt.Fprintln(os.Stderr, parseError)
os.Exit(2)
}

}

ticker := time.NewTicker(time.Second)
timeRemaining := duration

for range ticker.C {
timeRemaining = (timeRemaining - time.Second).Round(time.Second)
printTime(timeRemaining)

if timeRemaining <= 0 {
break
}
}

notification := notifier.Notification{
Title: "Timer Finished",
Message: fmt.Sprintf("Finished %s timer", duration.String()),
Timeout: 15,
}

systemNotifier, _ := notifier.NewNotifier()
systemNotifier.DeliverNotification(notification)

// HACK: tries to deliver notification before exiting
time.Sleep(time.Second)
}
115 changes: 0 additions & 115 deletions pomodoro.v

This file was deleted.

0 comments on commit ed6969d

Please sign in to comment.