-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
62 lines (51 loc) · 1.46 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright Josh Komoroske. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE.txt file.
package main
import (
"flag"
"fmt"
"strings"
"github.com/JoelOtter/termloop"
"github.com/joshdk/tty-qlock/qlock"
)
// version contains the version string, replaced at build-time with ldflags.
var version = "development"
func main() {
var offColorFlag string
flag.StringVar(&offColorFlag, "off-color", "black", "color for disabled letters")
var onColorFlag string
flag.StringVar(&onColorFlag, "on-color", "blue", "color for enabled letters")
var versionFlag bool
flag.BoolVar(&versionFlag, "version", false, "print version and exit")
flag.Parse()
// If the -version flag was given, print the version and exit.
if versionFlag {
fmt.Println(version)
return
}
game := termloop.NewGame()
game.Screen().SetFps(5)
game.Screen().AddEntity(qlock.New(
color(onColorFlag),
color(offColorFlag),
))
game.Start()
}
func color(spec string) (attr termloop.Attr) {
if strings.HasSuffix(spec, "+bold") {
attr = termloop.AttrBold
}
spec = strings.TrimSuffix(spec, "+bold")
colors := map[string]termloop.Attr{
"black": termloop.ColorBlack,
"red": termloop.ColorRed,
"green": termloop.ColorGreen,
"yellow": termloop.ColorYellow,
"blue": termloop.ColorBlue,
"magenta": termloop.ColorMagenta,
"cyan": termloop.ColorCyan,
"white": termloop.ColorWhite,
}
return colors[spec] | attr
}