summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCasey Robinson <casey.robinson@distilnetworks.com>2014-12-18 20:47:03 -0500
committerCasey Robinson <casey.robinson@distilnetworks.com>2014-12-18 20:47:03 -0500
commit2b934309a920df5cfdae47c923bf2222d926b442 (patch)
tree5c41c3fffc1f2659d848f56e24cffdd74051dddb
parentb86980e5641f9568b3abc29423241c7c09b8e2cf (diff)
downloadonetime-2b934309a920df5cfdae47c923bf2222d926b442.tar.gz
onetime-2b934309a920df5cfdae47c923bf2222d926b442.tar.bz2
onetime-2b934309a920df5cfdae47c923bf2222d926b442.zip
teach display how to run
-rw-r--r--main.go29
1 files changed, 20 insertions, 9 deletions
diff --git a/main.go b/main.go
index 7d0c583..cbc7912 100644
--- a/main.go
+++ b/main.go
@@ -41,19 +41,13 @@ func main() {
d.format.prefix = "%-"
d.format.suffix = "s %s (%ds) "
d.format.line = d.format.prefix + strconv.Itoa(namelen) + d.format.suffix + "\n"
- d.lines = make([][]byte, namelen + len(d.format.prefix) + len(d.format.suffix))
})
sigChan := make(chan os.Signal, 1)
signal.Notify(sigChan, syscall.SIGINT, syscall.SIGTERM)
- go func() {
- for {
- disp.update()
- time.Sleep(500 * time.Millisecond)
- disp.clear()
- }
- }()
+ disp.run()
+
for {
select {
@@ -106,7 +100,6 @@ func parseStdin() ([]provider, int) {
type display struct {
ps []provider
- lines [][]byte
format struct {
prefix string
suffix string
@@ -137,3 +130,21 @@ func (d *display) clear() {
os.Stdout.Write(up)
}
}
+
+func (d *display) fullRender() {
+ for _, p := range d.ps {
+ c, t := Code(p.secret)
+ fmt.Fprintf(os.Stdout, d.format.line, p.name, c, t)
+ }
+}
+
+func (d *display) run() {
+ d.fullRender()
+ go func() {
+ for {
+ time.Sleep(500 * time.Millisecond)
+ d.clear()
+ d.update()
+ }
+ }()
+}