This commit is contained in:
Alexander Kiryukhin 2021-12-13 15:39:41 +03:00
parent 58160f5a65
commit cc47f2e556
No known key found for this signature in database
GPG key ID: 6DF7A2910D0699E9
5 changed files with 176 additions and 0 deletions

49
.goreleaser.yml Normal file
View file

@ -0,0 +1,49 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com
before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...
builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin
archives:
- replacements:
darwin: Darwin
linux: Linux
windows: Windows
386: i386
amd64: x86_64
checksum:
name_template: 'checksums.txt'
snapshot:
name_template: "{{ incpatch .Version }}-next"
changelog:
sort: asc
filters:
exclude:
- '^docs:'
- '^test:'
brews:
-
name: pomodoro
goarm: 6
tap:
owner: neonxp
name: homebrew-tap
branch: master
url_template: "http://github.com/neonxp/pomodoro/releases/download/{{ .Tag }}/{{ .ArtifactName }}"
commit_author:
name: NeonXP
email: i@neonxp.ru
commit_msg_template: "Brew formula update for {{ .ProjectName }} version {{ .Tag }}"
folder: Formula
homepage: "https://neonxp.ru/pomodoro/"
description: "Pomodoro timer for nerds"
license: "GPL-3.0-or-later"

View file

@ -1,2 +1,29 @@
# pomodoro # pomodoro
Pomodoro timer for nerds Pomodoro timer for nerds
## Installation
### Binaries
Grab binaries for different OS from https://github.com/neonxp/pomodoro/releases
### Homebrew
```
brew install neonxp/tap/pomodoro
```
### With golang
```
go install github.com/neonxp/pomodoro@latest
```
## Usage
Just run
```shell
pomodoro
```
to stop - press Ctrl+C or kill process

15
go.mod Normal file
View file

@ -0,0 +1,15 @@
module github.com/neonxp/pomodoro
go 1.17
require github.com/gen2brain/beeep v0.0.0-20210529141713-5586760f0cc1
require (
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 // indirect
github.com/godbus/dbus/v5 v5.0.3 // indirect
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c // indirect
github.com/gopherjs/gopherwasm v1.1.0 // indirect
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d // indirect
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af // indirect
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 // indirect
)

17
go.sum Normal file
View file

@ -0,0 +1,17 @@
github.com/gen2brain/beeep v0.0.0-20210529141713-5586760f0cc1 h1:Xh9mvwEmhbdXlRSsgn+N0zj/NqnKvpeqL08oKDHln2s=
github.com/gen2brain/beeep v0.0.0-20210529141713-5586760f0cc1/go.mod h1:ElSskYZe3oM8kThaHGJ+kiN2yyUMVXMZ7WxF9QqLDS8=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4 h1:qZNfIGkIANxGv/OqtnntR4DfOY2+BgwR60cAcu/i3SE=
github.com/go-toast/toast v0.0.0-20190211030409-01e6764cf0a4/go.mod h1:kW3HQ4UdaAyrUCSSDR4xUzBKW6O2iA4uHhk7AtyYp10=
github.com/godbus/dbus/v5 v5.0.3 h1:ZqHaoEF7TBzh4jzPmqVhE/5A1z9of6orkAe5uHoAeME=
github.com/godbus/dbus/v5 v5.0.3/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c h1:16eHWuMGvCjSfgRJKqIzapE78onvvTbdi1rMkU00lZw=
github.com/gopherjs/gopherjs v0.0.0-20180825215210-0210a2f0f73c/go.mod h1:wJfORRmW1u3UXTncJ5qlYoELFm8eSnnEO6hX4iZ3EWY=
github.com/gopherjs/gopherwasm v1.1.0 h1:fA2uLoctU5+T3OhOn2vYP0DVT6pxc7xhTlBB1paATqQ=
github.com/gopherjs/gopherwasm v1.1.0/go.mod h1:SkZ8z7CWBz5VXbhJel8TxCmAcsQqzgWGR/8nMhyhZSI=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d h1:VhgPp6v9qf9Agr/56bj7Y/xa04UccTW04VP0Qed4vnQ=
github.com/nu7hatch/gouuid v0.0.0-20131221200532-179d4d0c4d8d/go.mod h1:YUTz3bUH2ZwIWBy3CJBeOBEugqcmXREj14T+iG/4k4U=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af h1:6yITBqGTE2lEeTPG04SN9W+iWHCRyHqlVYILiSXziwk=
github.com/tadvi/systray v0.0.0-20190226123456-11a2b8fa57af/go.mod h1:4F09kP5F+am0jAwlQLddpoMDM+iewkxxt6nxUQ5nq5o=
golang.org/x/sys v0.0.0-20200302150141-5c8b2ff67527/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9 h1:YTzHMGlqJu67/uEo1lBv0n3wBXhXNeUbB1XfN2vmTm0=
golang.org/x/sys v0.0.0-20200515095857-1151b9dac4a9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

68
main.go Normal file
View file

@ -0,0 +1,68 @@
package main
import (
"fmt"
"time"
)
type state int
const (
Working state = iota
Break
LongBreak
)
var (
currentState = Working
currentDuration = 25 * 60
pomodoros = 1
)
func main() {
for {
clearline()
switch currentState {
case Working:
fmt.Printf("🍅 #%d Working (%s)", pomodoros, secondsToMinutes(currentDuration))
case Break:
fmt.Printf("☕️ #%d Break (%s)", pomodoros, secondsToMinutes(currentDuration))
case LongBreak:
fmt.Printf("☕️ #%d Long break (%s)", pomodoros, secondsToMinutes(currentDuration))
}
currentDuration--
if currentDuration < 0 {
switch currentState {
case Working:
if pomodoros%4 == 0 {
currentState = LongBreak
currentDuration = 15 * 60
} else {
currentState = Break
currentDuration = 5 * 60
}
case Break, LongBreak:
currentState = Working
currentDuration = 25 * 60
pomodoros++
}
bell()
}
<-time.After(1 * time.Second)
}
}
func bell() {
fmt.Print("\a")
}
func clearline() {
fmt.Print("\x1b[2K\r")
}
func secondsToMinutes(inSeconds int) string {
minutes := inSeconds / 60
seconds := inSeconds % 60
str := fmt.Sprintf("%02d:%02d", minutes, seconds)
return str
}