-
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.
Merge pull request #2 from blakek/go-rewrite
✨ Rewrite project in Go
- Loading branch information
Showing
9 changed files
with
138 additions
and
185 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 |
---|---|---|
@@ -1,8 +1,2 @@ | ||
*.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,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> |
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
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 @@ | ||
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 | ||
) |
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,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= |
This file was deleted.
Oops, something went wrong.
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,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) | ||
} |
This file was deleted.
Oops, something went wrong.