-
Notifications
You must be signed in to change notification settings - Fork 3
/
members.go
142 lines (127 loc) · 3.95 KB
/
members.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package main
import (
"fmt"
"sort"
"strings"
"time"
"github.com/charmbracelet/lipgloss"
)
type MemberTime struct {
Member string
Time time.Time
Location string
Offset int // in seconds
Display string
Abbreviation string
Type string // person, city, country
}
type MemberMap map[int][]MemberTime
func PrintMembers(am MemberMap, short bool, p *Palette) {
offsets := []int{}
for offset := range am {
offsets = append(offsets, offset)
}
sort.Ints(offsets)
Logger.Println(len(offsets))
for _, offset := range offsets {
PrintMembersLine(p, am[offset])
if !short {
PrintHours(p, am[offset][0].Time, am[offsets[0]][0].Time)
fmt.Println()
}
}
}
func PrintMembersLine(p *Palette, att []MemberTime) {
// map[abbreviation] = display
displayLineCountries := map[string][]string{}
displayLineCities := map[string][]string{}
displayLinePeople := map[string][]string{}
for _, at := range att {
switch at.Type {
case "country":
if _, ok := displayLineCountries[at.Abbreviation]; !ok {
displayLineCountries[at.Abbreviation] = []string{at.Display}
} else {
displayLineCountries[at.Abbreviation] = append(displayLineCountries[at.Abbreviation], at.Display)
// TODO: who cares about the repeated sorting right?
sort.Strings(displayLineCountries[at.Abbreviation])
}
case "city":
if _, ok := displayLineCities[at.Abbreviation]; !ok {
displayLineCities[at.Abbreviation] = []string{at.Display}
} else {
displayLineCities[at.Abbreviation] = append(displayLineCities[at.Abbreviation], at.Display)
// TODO: who cares about the repeated sorting right?
sort.Strings(displayLineCities[at.Abbreviation])
}
case "person":
if _, ok := displayLinePeople[at.Abbreviation]; !ok {
displayLinePeople[at.Abbreviation] = []string{at.Display}
} else {
displayLinePeople[at.Abbreviation] = append(displayLinePeople[at.Abbreviation], at.Display)
// TODO: who cares about the repeated sorting right?
sort.Strings(displayLinePeople[at.Abbreviation])
}
}
}
t := att[0].Time
// Line length is 141
fmt.Print(
p.Style(t.Hour()).Render(ClockEmoji[t.Hour()]+" "),
p.Style(t.Hour()).Render(t.Format("02 "+HourMinuteFormat+" -07")),
p.Style(t.Hour()).Render(" "),
)
str := ""
for abb, list := range displayLineCountries {
str += p.Style(t.Hour()).Render(fmt.Sprintf(" %s ", abb))
// for _, d := range list {
// str += fmt.Sprint(p.LipglossPalette.Member.Render(fmt.Sprintf("%s", d)))
// str += p.Style(t.Hour()).Render(" ")
// }
str += p.LipglossPalette.Member.Render(fmt.Sprintf(" %s ", strings.Join(list, " ")))
}
for abb, list := range displayLineCities {
str += p.Style(t.Hour()).Render(fmt.Sprintf(" %s ", abb))
str += p.LipglossPalette.Member.Render(fmt.Sprintf(" %s ", strings.Join(list, " ")))
}
for abb, list := range displayLinePeople {
str += p.Style(t.Hour()).Render(fmt.Sprintf(" %s ", abb))
str += p.LipglossPalette.Member.Render(fmt.Sprintf(" %s ", strings.Join(list, " ")))
}
// fmt.Println(lipgloss.PlaceHorizontal(132, lipgloss.Left, str, lipgloss.WithWhitespaceBackground(p.LipglossPalette.Noon.GetBackground())))
fmt.Println(lipgloss.PlaceHorizontal(126, lipgloss.Left, str, lipgloss.WithWhitespaceBackground(p.Style(t.Hour()).GetBackground())))
// 🕕 06:56 .
// fmt.Println(str)
}
func PrintHours(p *Palette, t, base time.Time) {
x := t.Hour()
h := t.Hour()
h -= 12
for i := 0; i < 24; i++ {
if h >= 24 {
h = h - 24
}
if h < 0 {
h = 24 + h
}
if h == x {
PrintBlock(t.Format("15:04"), p.Style(h), h == x, p.LipglossPalette.Highlight)
} else {
PrintBlock(fmt.Sprintf("%02d", h), p.Style(h), h == x, p.LipglossPalette.Highlight)
}
h++
}
fmt.Println()
}
func PrintBlock(hour string, style lipgloss.Style, highlight bool, hStyle lipgloss.Style) {
normal := style.Copy()
normal.
PaddingLeft(2).
PaddingRight(2)
if highlight {
hour = hStyle.Render(hour)
} else {
hour = normal.Render(hour)
}
fmt.Printf("%s", hour)
}