Skip to content

Commit 3f9a9e8

Browse files
committed
🎨 tabs -> spaces
1 parent ad625f2 commit 3f9a9e8

File tree

6 files changed

+166
-166
lines changed

6 files changed

+166
-166
lines changed

‎app.go

Lines changed: 106 additions & 106 deletions
Original file line numberDiff line numberDiff line change
@@ -1,186 +1,186 @@
11
package main
22

33
import (
4-
"fmt"
5-
"os"
6-
"strconv"
7-
"time"
8-
9-
"github.com/ctcpip/notifize"
10-
"github.com/kardianos/osext"
11-
"github.com/nsf/termbox-go"
4+
"fmt"
5+
"os"
6+
"strconv"
7+
"time"
8+
9+
"github.com/ctcpip/notifize"
10+
"github.com/kardianos/osext"
11+
"github.com/nsf/termbox-go"
1212
)
1313

1414
type app struct{}
1515

1616
func (a *app) init() {
1717

18-
var k keyboard
18+
var k keyboard
1919

20-
booContinue := true
20+
booContinue := true
2121

22-
if len(os.Args) > 1 {
22+
if len(os.Args) > 1 {
2323

24-
if a, err := strconv.ParseFloat(os.Args[1], 64); err == nil {
25-
duration = time.Millisecond * time.Duration(a*60000)
26-
} else {
27-
printHelp(os.Args[1])
28-
booContinue = false
29-
}
24+
if a, err := strconv.ParseFloat(os.Args[1], 64); err == nil {
25+
duration = time.Millisecond * time.Duration(a*60000)
26+
} else {
27+
printHelp(os.Args[1])
28+
booContinue = false
29+
}
3030

31-
}
31+
}
3232

33-
if booContinue {
33+
if booContinue {
3434

35-
if duration == 0 {
36-
duration = time.Minute * 25
37-
}
35+
if duration == 0 {
36+
duration = time.Minute * 25
37+
}
3838

39-
duration += time.Second * 1
39+
duration += time.Second * 1
4040

41-
timer = time.NewTimer(duration)
42-
abort := make(chan bool, 1)
41+
timer = time.NewTimer(duration)
42+
abort := make(chan bool, 1)
4343

44-
scr.init()
44+
scr.init()
4545

46-
go countdown(duration, abort)
46+
go countdown(duration, abort)
4747

48-
go func() {
49-
<-timer.C
50-
abort <- false
51-
go alertBell()
52-
go alertVisual()
53-
alertNotification()
54-
}()
48+
go func() {
49+
<-timer.C
50+
abort <- false
51+
go alertBell()
52+
go alertVisual()
53+
alertNotification()
54+
}()
5555

56-
k.init()
56+
k.init()
5757

58-
}
58+
}
5959

6060
}
6161

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

64-
var toggle bool
65-
t := time.NewTicker(time.Millisecond * 500)
66-
endTime := time.Now().Add(d)
64+
var toggle bool
65+
t := time.NewTicker(time.Millisecond * 500)
66+
endTime := time.Now().Add(d)
6767

68-
drawTime(endTime)
68+
drawTime(endTime)
6969

70-
for {
70+
for {
7171

72-
select {
72+
select {
7373

74-
case <-t.C:
74+
case <-t.C:
7575

76-
if !timerPaused {
77-
clearTime()
78-
drawTime(endTime)
79-
} else {
76+
if !timerPaused {
77+
clearTime()
78+
drawTime(endTime)
79+
} else {
8080

81-
if toggle {
82-
clearPauseDisplay()
83-
} else {
84-
scr.drawColoredText("PAUSED", 3, 5, termbox.ColorWhite, termbox.ColorRed)
85-
termbox.Flush()
86-
}
81+
if toggle {
82+
clearPauseDisplay()
83+
} else {
84+
scr.drawColoredText("PAUSED", 3, 5, termbox.ColorWhite, termbox.ColorRed)
85+
termbox.Flush()
86+
}
8787

88-
toggle = !toggle
88+
toggle = !toggle
8989

90-
}
90+
}
9191

92-
case <-pause:
92+
case <-pause:
9393

94-
timerPaused = !timerPaused
94+
timerPaused = !timerPaused
9595

96-
if timerPaused {
97-
timer.Stop()
98-
d = endTime.Sub(time.Now())
99-
} else {
100-
timer.Reset(d)
101-
endTime = time.Now().Add(d)
102-
clearPauseDisplay()
103-
toggle = false
104-
}
96+
if timerPaused {
97+
timer.Stop()
98+
d = endTime.Sub(time.Now())
99+
} else {
100+
timer.Reset(d)
101+
endTime = time.Now().Add(d)
102+
clearPauseDisplay()
103+
toggle = false
104+
}
105105

106-
case <-abort:
107-
return
108-
}
106+
case <-abort:
107+
return
108+
}
109109

110-
}
110+
}
111111

112112
}
113113

114114
func clearPauseDisplay() {
115-
scr.drawText(" ", 3, 5)
116-
termbox.Flush()
115+
scr.drawText(" ", 3, 5)
116+
termbox.Flush()
117117
}
118118

119119
func clearTime() {
120-
for x := 0; x < 80; x++ {
121-
termbox.SetCell(x, 3, ' ', termbox.ColorDefault, termbox.ColorDefault)
122-
}
120+
for x := 0; x < 80; x++ {
121+
termbox.SetCell(x, 3, ' ', termbox.ColorDefault, termbox.ColorDefault)
122+
}
123123
}
124124

125125
func drawTime(endTime time.Time) {
126-
remainingTime := endTime.Sub(time.Now())
127-
scr.drawText(getTimeString(remainingTime), 3, 3)
128-
termbox.Flush()
126+
remainingTime := endTime.Sub(time.Now())
127+
scr.drawText(getTimeString(remainingTime), 3, 3)
128+
termbox.Flush()
129129
}
130130

131131
func alertNotification() {
132132

133-
appPath, err := osext.ExecutableFolder()
134-
if err != nil {
135-
panic(err)
136-
}
133+
appPath, err := osext.ExecutableFolder()
134+
if err != nil {
135+
panic(err)
136+
}
137137

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

140140
}
141141

142142
func alertBell() {
143143

144-
// ring the terminal bell
144+
// ring the terminal bell
145145

146-
fmt.Print("\a")
146+
fmt.Print("\a")
147147

148-
t := time.NewTicker(time.Second * 30)
148+
t := time.NewTicker(time.Second * 30)
149149

150-
for _ = range t.C {
151-
fmt.Print("\a")
152-
}
150+
for _ = range t.C {
151+
fmt.Print("\a")
152+
}
153153

154154
}
155155

156156
func alertVisual() {
157157

158-
var b bool
159-
var c termbox.Attribute
158+
var b bool
159+
var c termbox.Attribute
160160

161-
t := time.NewTicker(time.Second * 1)
161+
t := time.NewTicker(time.Second * 1)
162162

163-
for _ = range t.C {
163+
for _ = range t.C {
164164

165-
if b {
166-
c = termbox.ColorBlack
167-
} else {
168-
c = termbox.ColorRed
169-
}
165+
if b {
166+
c = termbox.ColorBlack
167+
} else {
168+
c = termbox.ColorRed
169+
}
170170

171-
for y := 2; y < 24; y++ {
171+
for y := 2; y < 24; y++ {
172172

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

177-
}
177+
}
178178

179-
termbox.Flush()
179+
termbox.Flush()
180180

181-
b = !b
181+
b = !b
182182

183-
}
183+
}
184184

185185
}
186186

‎go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ module github.com/ctcpip/timezilla
33
go 1.20
44

55
require (
6-
github.com/ctcpip/notifize v1.0.1
7-
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
8-
github.com/nsf/termbox-go v1.1.1
6+
github.com/ctcpip/notifize v1.0.1
7+
github.com/kardianos/osext v0.0.0-20190222173326-2bc1f35cddc0
8+
github.com/nsf/termbox-go v1.1.1
99
)
1010

1111
require github.com/mattn/go-runewidth v0.0.9 // indirect

‎keyboard.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ func (k *keyboard) init() { k.read() }
99
func (k *keyboard) read() {
1010

1111
loopyMcLoopface:
12-
for {
12+
for {
1313

14-
switch e := termbox.PollEvent(); e.Type {
14+
switch e := termbox.PollEvent(); e.Type {
1515

16-
case termbox.EventKey:
16+
case termbox.EventKey:
1717

18-
switch {
19-
case e.Key == termbox.KeyCtrlC:
20-
break loopyMcLoopface
21-
case e.Ch == 'p', e.Ch == 'P':
22-
pause <- true
23-
}
18+
switch {
19+
case e.Key == termbox.KeyCtrlC:
20+
break loopyMcLoopface
21+
case e.Ch == 'p', e.Ch == 'P':
22+
pause <- true
23+
}
2424

25-
case termbox.EventError:
26-
panic(e.Err)
27-
}
25+
case termbox.EventError:
26+
panic(e.Err)
27+
}
2828

29-
}
29+
}
3030

3131
}

0 commit comments

Comments
 (0)