display.go (687B)
1 package main 2 3 import ( 4 "fmt" 5 "time" 6 ) 7 8 const ( 9 title = "TOP TEN ZIP CODES BY HIGHEST CURRENT TEMPERATURE" 10 ) 11 12 func display(ztchan chan []*ZipTemp, done chan struct{}) { 13 for { 14 locations, more := <-ztchan 15 if !more { 16 done <- struct{}{} 17 return 18 } 19 20 // Clear the screen. 21 print("\033[H\033[2J") 22 23 // Print the title and top ten. 24 fmt.Println(title) 25 fmt.Printf( 26 "Last update: %s.\n\n", 27 time.Now().Format(time.RFC1123), 28 ) 29 30 for i, zt := range locations { 31 if zt == nil { 32 fmt.Printf("%d. No data\n", i+1) 33 34 continue 35 } 36 37 fmt.Printf( 38 "%d. %.02f°F %s (%s, %s)\n", 39 i+1, 40 zt.Temperature, 41 zt.ZipCode, 42 zt.City, 43 zt.State, 44 ) 45 } 46 } 47 }