Skip to content

Commit

Permalink
feat: Custom Emoji Width Settings
Browse files Browse the repository at this point in the history
  • Loading branch information
AccursedGalaxy committed Nov 4, 2024
1 parent fe0390c commit 14375ec
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
24 changes: 17 additions & 7 deletions cmd/stats.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ type repoInfo struct {
lastCommit time.Time
}

// TODO: I think emojis are casuing the table to might get dispalyed wrongly on different devices/terminals - since emoji width might be different.
// TODO: emojis are casuing the table to get dispalyed wrongly on different devices/terminals - since emoji width might be different.

// DisplayStats - Displays stats for all active repositories in a more compact format
func DisplayStats() {
Expand Down Expand Up @@ -211,11 +211,11 @@ func buildProjectsSection() string {
changesStr := fmt.Sprintf("+%d/-%d", weeklyAdditions, weeklyDeletions)

table.Append([]string{
fmt.Sprintf("%s %s", activity, repo.name),
padWithEmoji(activity, repo.name),
fmt.Sprintf("%d↑", meta.WeeklyCommits),
streakStr,
changesStr,
activityStr,
streakStr,
changesStr,
activityStr,
})
}

Expand Down Expand Up @@ -313,8 +313,11 @@ func buildInsightsSection() string {

// Only add configured insight rows
if insights.ShowWeeklySummary {
table.Append([]string{"📈", "Weekly Summary:", fmt.Sprintf("%d commits, +%d/-%d lines",
totalWeeklyCommits, totalAdditions, totalDeletions)})
table.Append([]string{
"📈", // No padding needed for single-column emojis
"Weekly Summary:",
fmt.Sprintf("%d commits, +%d/-%d lines",
totalWeeklyCommits, totalAdditions, totalDeletions)})
}

if insights.ShowDailyAverage {
Expand Down Expand Up @@ -373,3 +376,10 @@ func getAlignment(alignment string) int {
return tablewriter.ALIGN_CENTER
}
}

// Add these new helper functions
func padWithEmoji(emoji, text string) string {
// Use zero-width spaces to ensure consistent width
paddedEmoji := emoji + "\u200B" // Add zero-width space after emoji
return fmt.Sprintf("%s %s", paddedEmoji, text)
}
5 changes: 5 additions & 0 deletions cmd/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,16 @@ func TestDisplayStats(t *testing.T) {
StreakRecord: "🏆",
ActiveStreak: "🔥",
},
UseFixedEmojiWidth: bool `mapstructure:"use_fixed_emoji_width"`,
FixedEmojiWidth: int `mapstructure:"fixed_emoji_width"`,
Thresholds: struct {
HighActivity int `mapstructure:"high_activity"`
}{
HighActivity: 10,
},
{
HighActivity: 10,
},
InsightSettings: struct {
TopLanguagesCount int `mapstructure:"top_languages_count"`
ShowDailyAverage bool `mapstructure:"show_daily_average"`
Expand Down
2 changes: 2 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ type Config struct {
StreakRecord string `mapstructure:"streak_record"` // 🏆
ActiveStreak string `mapstructure:"active_streak"` // 🔥
} `mapstructure:"activity_indicators"`
UseFixedEmojiWidth bool `mapstructure:"use_fixed_emoji_widht"`
FixedEmojiWidth int `mapstructure:"fixed_emoji_width"`
Thresholds struct {
HighActivity int `mapstructure:"high_activity"` // commits > 10 for high activity
} `mapstructure:"thresholds"`
Expand Down

0 comments on commit 14375ec

Please sign in to comment.