Skip to content

Commit 362dc1c

Browse files
author
Balazs Nadasdi
committed
Add flag to display AM/PM state.
It was already on the board, but was never used, it was a filler, but it can be useful and if it's already on the board, why not make it visible with a flag?
1 parent 5954614 commit 362dc1c

File tree

4 files changed

+22
-5
lines changed

4 files changed

+22
-5
lines changed

main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ import (
1717
var version = "development"
1818

1919
func main() {
20+
var showAMPMFlag bool
21+
flag.BoolVar(&showAMPMFlag, "show-am-pm", false, "visualize AM/PM")
22+
2023
var compactFlag bool
2124
flag.BoolVar(&compactFlag, "compact", false, "compact format")
2225

@@ -29,6 +32,7 @@ func main() {
2932
var versionFlag bool
3033
flag.BoolVar(&versionFlag, "version", false, "print version and exit")
3134

35+
3236
flag.Parse()
3337

3438
// If the -version flag was given, print the version and exit.
@@ -43,6 +47,7 @@ func main() {
4347
color(onColorFlag),
4448
color(offColorFlag),
4549
compactFlag,
50+
showAMPMFlag,
4651
))
4752
game.Start()
4853
}

qlock/board.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const (
1515
quarter = "QUARTER"
1616
twenty = "TWENTY"
1717
half = "HALF"
18+
am = "AM"
19+
pm = "PM"
1820

1921
one = "ONE"
2022
two = "TWO"
@@ -31,7 +33,7 @@ const (
3133

3234
dot = "●"
3335
f1 = "L"
34-
f2 = "ASAMPM"
36+
f2 = "AS"
3537
f3 = "C"
3638
f4 = "DC"
3739
f5 = "X"

qlock/rules.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ func quickAbs(value int) int {
2121
return value * ((value*2 + 1) % 2)
2222
}
2323

24-
func entries(hour int, minute int) [][]entry {
24+
func entries(hour int, minute int, ampm bool) [][]entry {
2525
board := [][]entry{
26-
{e(it, true), e(f1, false), e(is, true), e(f2, false)},
26+
{e(it, true), e(f1, false), e(is, true), e(f2, false), e(am, false), e(pm, false)},
2727
{e(a, false), e(f3, false), e(quarter, false), e(f4, false)},
2828
{e(twenty, false), e(five, false), e(f5, false)},
2929
{e(half, false), e(f6, false), e(ten, false), e(f7, false), e(to, false)},
@@ -37,6 +37,14 @@ func entries(hour int, minute int) [][]entry {
3737

3838
minSection := minute - minute%5
3939

40+
if ampm {
41+
if hour < 12 {
42+
activate(board, 0, 4)
43+
} else {
44+
activate(board, 0, 5)
45+
}
46+
}
47+
4048
if minSection > 30 {
4149
// Set: to.
4250
activate(board, 3, 4)

qlock/widget.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,15 @@ type clock struct {
1515
colorOn termloop.Attr
1616
colorOff termloop.Attr
1717
compact bool
18+
showAMPM bool
1819
}
1920

20-
func New(colorOn, colorOff termloop.Attr, compact bool) termloop.Drawable {
21+
func New(colorOn, colorOff termloop.Attr, compact, ampm bool) termloop.Drawable {
2122
return &clock{
2223
colorOn: colorOn,
2324
colorOff: colorOff,
2425
compact: compact,
26+
showAMPM: ampm,
2527
}
2628
}
2729

@@ -63,7 +65,7 @@ func (c *clock) Draw(s *termloop.Screen) {
6365
originY = 0
6466
}
6567

66-
board := entries(hour, minute)
68+
board := entries(hour, minute, c.showAMPM)
6769

6870
minuteMarker := minute % 5
6971

0 commit comments

Comments
 (0)