Skip to content

Commit

Permalink
🎨 tabs -> spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
ctcpip committed Feb 4, 2023
1 parent ad625f2 commit 3f9a9e8
Show file tree
Hide file tree
Showing 6 changed files with 166 additions and 166 deletions.
212 changes: 106 additions & 106 deletions app.go
Original file line number Diff line number Diff line change
@@ -1,186 +1,186 @@
package main

import (
"fmt"
"os"
"strconv"
"time"

"github.com/ctcpip/notifize"
"github.com/kardianos/osext"
"github.com/nsf/termbox-go"
"fmt"
"os"
"strconv"
"time"

"github.com/ctcpip/notifize"
"github.com/kardianos/osext"
"github.com/nsf/termbox-go"
)

type app struct{}

func (a *app) init() {

var k keyboard
var k keyboard

booContinue := true
booContinue := true

if len(os.Args) > 1 {
if len(os.Args) > 1 {

if a, err := strconv.ParseFloat(os.Args[1], 64); err == nil {
duration = time.Millisecond * time.Duration(a*60000)
} else {
printHelp(os.Args[1])
booContinue = false
}
if a, err := strconv.ParseFloat(os.Args[1], 64); err == nil {
duration = time.Millisecond * time.Duration(a*60000)
} else {
printHelp(os.Args[1])
booContinue = false
}

}
}

if booContinue {
if booContinue {

if duration == 0 {
duration = time.Minute * 25
}
if duration == 0 {
duration = time.Minute * 25
}

duration += time.Second * 1
duration += time.Second * 1

timer = time.NewTimer(duration)
abort := make(chan bool, 1)
timer = time.NewTimer(duration)
abort := make(chan bool, 1)

scr.init()
scr.init()

go countdown(duration, abort)
go countdown(duration, abort)

go func() {
<-timer.C
abort <- false
go alertBell()
go alertVisual()
alertNotification()
}()
go func() {
<-timer.C
abort <- false
go alertBell()
go alertVisual()
alertNotification()
}()

k.init()
k.init()

}
}

}

func countdown(d time.Duration, abort chan bool) {

var toggle bool
t := time.NewTicker(time.Millisecond * 500)
endTime := time.Now().Add(d)
var toggle bool
t := time.NewTicker(time.Millisecond * 500)
endTime := time.Now().Add(d)

drawTime(endTime)
drawTime(endTime)

for {
for {

select {
select {

case <-t.C:
case <-t.C:

if !timerPaused {
clearTime()
drawTime(endTime)
} else {
if !timerPaused {
clearTime()
drawTime(endTime)
} else {

if toggle {
clearPauseDisplay()
} else {
scr.drawColoredText("PAUSED", 3, 5, termbox.ColorWhite, termbox.ColorRed)
termbox.Flush()
}
if toggle {
clearPauseDisplay()
} else {
scr.drawColoredText("PAUSED", 3, 5, termbox.ColorWhite, termbox.ColorRed)
termbox.Flush()
}

toggle = !toggle
toggle = !toggle

}
}

case <-pause:
case <-pause:

timerPaused = !timerPaused
timerPaused = !timerPaused

if timerPaused {
timer.Stop()
d = endTime.Sub(time.Now())
} else {
timer.Reset(d)
endTime = time.Now().Add(d)
clearPauseDisplay()
toggle = false
}
if timerPaused {
timer.Stop()
d = endTime.Sub(time.Now())
} else {
timer.Reset(d)
endTime = time.Now().Add(d)
clearPauseDisplay()
toggle = false
}

case <-abort:
return
}
case <-abort:
return
}

}
}

}

func clearPauseDisplay() {
scr.drawText(" ", 3, 5)
termbox.Flush()
scr.drawText(" ", 3, 5)
termbox.Flush()
}

func clearTime() {
for x := 0; x < 80; x++ {
termbox.SetCell(x, 3, ' ', termbox.ColorDefault, termbox.ColorDefault)
}
for x := 0; x < 80; x++ {
termbox.SetCell(x, 3, ' ', termbox.ColorDefault, termbox.ColorDefault)
}
}

func drawTime(endTime time.Time) {
remainingTime := endTime.Sub(time.Now())
scr.drawText(getTimeString(remainingTime), 3, 3)
termbox.Flush()
remainingTime := endTime.Sub(time.Now())
scr.drawText(getTimeString(remainingTime), 3, 3)
termbox.Flush()
}

func alertNotification() {

appPath, err := osext.ExecutableFolder()
if err != nil {
panic(err)
}
appPath, err := osext.ExecutableFolder()
if err != nil {
panic(err)
}

notifize.Display("timezilla", "time is up!", true, appPath+"/clock.png")
notifize.Display("timezilla", "time is up!", true, appPath+"/clock.png")

}

func alertBell() {

// ring the terminal bell
// ring the terminal bell

fmt.Print("\a")
fmt.Print("\a")

t := time.NewTicker(time.Second * 30)
t := time.NewTicker(time.Second * 30)

for _ = range t.C {
fmt.Print("\a")
}
for _ = range t.C {
fmt.Print("\a")
}

}

func alertVisual() {

var b bool
var c termbox.Attribute
var b bool
var c termbox.Attribute

t := time.NewTicker(time.Second * 1)
t := time.NewTicker(time.Second * 1)

for _ = range t.C {
for _ = range t.C {

if b {
c = termbox.ColorBlack
} else {
c = termbox.ColorRed
}
if b {
c = termbox.ColorBlack
} else {
c = termbox.ColorRed
}

for y := 2; y < 24; y++ {
for y := 2; y < 24; y++ {

for x := 0; x < 80; x++ {
termbox.SetCell(x, y, ' ', c, c)
}
for x := 0; x < 80; x++ {
termbox.SetCell(x, y, ' ', c, c)
}

}
}

termbox.Flush()
termbox.Flush()

b = !b
b = !b

}
}

}

Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ module github.com/ctcpip/timezilla
go 1.20

require (
github.com/ctcpip/notifize v1.0.1
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/nsf/termbox-go v1.1.1
github.com/ctcpip/notifize v1.0.1
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
github.com/nsf/termbox-go v1.1.1
)

require github.com/mattn/go-runewidth v0.0.9 // indirect
26 changes: 13 additions & 13 deletions keyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ func (k *keyboard) init() { k.read() }
func (k *keyboard) read() {

loopyMcLoopface:
for {
for {

switch e := termbox.PollEvent(); e.Type {
switch e := termbox.PollEvent(); e.Type {

case termbox.EventKey:
case termbox.EventKey:

switch {
case e.Key == termbox.KeyCtrlC:
break loopyMcLoopface
case e.Ch == 'p', e.Ch == 'P':
pause <- true
}
switch {
case e.Key == termbox.KeyCtrlC:
break loopyMcLoopface
case e.Ch == 'p', e.Ch == 'P':
pause <- true
}

case termbox.EventError:
panic(e.Err)
}
case termbox.EventError:
panic(e.Err)
}

}
}

}
Loading

0 comments on commit 3f9a9e8

Please sign in to comment.