-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.go
More file actions
98 lines (85 loc) · 3.15 KB
/
Copy pathrender.go
File metadata and controls
98 lines (85 loc) · 3.15 KB
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
package main
import (
"fmt"
"strings"
)
// getBlockSymbol returns color blocks based on levels
func getBlockSymbol(count int) string {
const reset = "\033[0m"
switch {
case count == 0:
return "\033[38;2;45;51;59m████" + reset
case count <= 2:
return "\033[38;2;14;68;41m████" + reset
case count <= 5:
return "\033[38;2;0;109;50m████" + reset
case count <= 10:
return "\033[38;2;38;166;65m████" + reset
default:
return "\033[38;2;57;211;83m████" + reset
}
}
// RenderDashboard prints formatted ASCII components and metrics inside a quiet terminal UI frame
func RenderDashboard(days []Day, stats Stats) {
if len(days) == 0 {
fmt.Println("No activity data to render.")
return
}
startDate := days[0].Date[5:]
endDate := days[len(days)-1].Date[5:]
totalGraphChars := (len(days) * 5) - 1
paddingLength := totalGraphChars - len(startDate) - len(endDate)
if paddingLength < 2 {
paddingLength = 2
}
middlePadding := strings.Repeat(" ", paddingLength)
fmt.Println()
fmt.Printf("📊 GitHub Activity (%d Days Log)\n", stats.TargetDays)
fmt.Println(strings.Repeat("─", totalGraphChars+13))
fmt.Printf("📅 Timeline: %s%s%s\n", startDate, middlePadding, endDate)
fmt.Print("🟩 Activity: ")
for i, day := range days {
fmt.Print(getBlockSymbol(day.Count))
if i < len(days)-1 {
fmt.Print(" ")
}
}
fmt.Println()
fmt.Println(strings.Repeat("─", totalGraphChars+13))
fmt.Printf("🔥 Current Streak: %d Days | 🏆 Longest: %d Days | 📦 Today: %d Commits\n",
stats.CurrentStreak, stats.LongestStreak, stats.TodayCommits)
fmt.Printf("📈 Avg Commit/Day: %.2f\n\n", stats.AveragePerDay)
}
// RenderWeeklyDashboard prints a vertical bar graph of the week's activity
func RenderWeeklyDashboard(stats WeeklyStats) {
const reset = "\033[0m"
const activeGreen = "\033[38;2;57;211;83m"
const highlightGold = "\033[38;2;227;179;65m"
const gray = "\033[38;2;100;100;100m"
const maxBarLength = 30 // Maximum length of the visual ASCII bar
fmt.Println("\n📊 Weekly Activity Graph")
fmt.Println("──────────────────────────────────────────────────")
for _, day := range stats.Days {
barLength := 0
if stats.Max > 0 {
// Calculate proportional scaling
barLength = (day.Count * maxBarLength) / stats.Max
}
// Prepare the visual representation bar
var bar string
if day.Count == 0 {
bar = gray + "·" + reset // Subtle single dot for zero commit days
} else {
bar = activeGreen + strings.Repeat("█", barLength) + reset
}
// Check if this day is the best performing day
bestIndicator := ""
if day.Count > 0 && day.Weekday == stats.BestDay {
bestIndicator = highlightGold + " ⭐ Best" + reset
}
// Print layout line
fmt.Printf("%s %-30s %3d commits%s\n", day.Weekday, bar, day.Count, bestIndicator)
}
fmt.Println("──────────────────────────────────────────────────")
fmt.Printf("📦 Weekly Total: %d commits | 🏆 Top Activity: %s\n\n", stats.Total, stats.BestDay)
}