-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay.go
46 lines (39 loc) · 1.25 KB
/
display.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
package main
import (
"fmt"
"math"
"strings"
"github.com/antoineneff/kal/utils"
)
func printMonth() {
printHeaders()
printWeeks()
}
func printHeaders() {
fmt.Printf("┌%s┐\n", strings.Repeat("─", 34))
fmt.Printf("│ %v", currentYear)
fmt.Printf("%*s │\n", 28, currentMonth)
fmt.Println("├────┬────┬────┬────┬────┬────┬────┤")
fmt.Println("│ Su │ Mo │ Tu │ We │ Th │ Fr │ Sa │")
}
func printWeeks() {
firstDayIndex, numberOfDays := utils.MonthDetails(currentYear, currentMonth, now.Location())
numberOfWeeks := int(math.Ceil(float64(firstDayIndex+numberOfDays) / 7))
for i := 0; i < numberOfWeeks; i += 1 {
startIndex := -firstDayIndex + i*7
printWeek(startIndex, numberOfDays)
}
fmt.Println("└────┴────┴────┴────┴────┴────┴────┘")
}
func printWeek(startIndex, limit int) {
fmt.Println("├────┼────┼────┼────┼────┼────┼────┤")
fmt.Print("│")
for i := startIndex; i < startIndex+7; i++ {
if i >= 0 && i < limit {
fmt.Printf(" %02d │", i+1)
} else {
fmt.Print(" │")
}
}
fmt.Println("")
}