Skip to content

Commit 1249bb3

Browse files
committed
refactor: move emojis from TOML to Go constants
1 parent c07fc9c commit 1249bb3

12 files changed

Lines changed: 185 additions & 103 deletions

File tree

internal/presentation/styles/styles.go

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package styles
22

33
import (
44
"github.com/charmbracelet/lipgloss"
5+
6+
"github.com/ignavan39/mood-diary/internal/presentation/tui/constants"
57
)
68

79
var (
@@ -108,18 +110,6 @@ var (
108110
BorderForeground(PastelLavender).
109111
Padding(0, 1)
110112

111-
SuccessStyle = lipgloss.NewStyle().
112-
Foreground(TextDark).
113-
Background(SuccessGreen).
114-
Padding(0, 2).
115-
Bold(true)
116-
117-
ErrorStyle = lipgloss.NewStyle().
118-
Foreground(TextDark).
119-
Background(ErrorRed).
120-
Padding(0, 2).
121-
Bold(true)
122-
123113
InfoStyle = lipgloss.NewStyle().
124114
Foreground(TextDark).
125115
Background(InfoBlue).
@@ -147,6 +137,24 @@ var (
147137
Italic(true)
148138
)
149139

140+
func SuccessStyle(text string) string {
141+
return lipgloss.NewStyle().
142+
Foreground(TextDark).
143+
Background(SuccessGreen).
144+
Padding(0, 2).
145+
Bold(true).
146+
Render(constants.Emoji.Checkmark + " " + text)
147+
}
148+
149+
func ErrorStyle(text string) string {
150+
return lipgloss.NewStyle().
151+
Foreground(TextDark).
152+
Background(ErrorRed).
153+
Padding(0, 2).
154+
Bold(true).
155+
Render(constants.Emoji.Crossmark + " " + text)
156+
}
157+
150158
func GetMoodColor(level int) lipgloss.Color {
151159
if level < 0 {
152160
level = 0
@@ -229,4 +237,4 @@ func Sparkline(values []float64) string {
229237
Foreground(PastelLavender).
230238
Bold(true).
231239
Render(result)
232-
}
240+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package constants
2+
3+
var Emoji = struct {
4+
Checkmark string
5+
Crossmark string
6+
Warning string
7+
ArrowUp string
8+
ArrowDown string
9+
ArrowStable string
10+
Flower string
11+
MoodForm string
12+
Edit string
13+
Calendar string
14+
History string
15+
Stats string
16+
Settings string
17+
Heatmap string
18+
}{
19+
Checkmark: "✓",
20+
Crossmark: "✗",
21+
Warning: "⚠️",
22+
ArrowUp: "↑",
23+
ArrowDown: "↓",
24+
ArrowStable: "─",
25+
Flower: "🌸",
26+
MoodForm: "📝",
27+
Edit: "✏️",
28+
Calendar: "📅",
29+
History: "📜",
30+
Stats: "📊",
31+
Settings: "⚙️",
32+
Heatmap: "🗺️",
33+
}
Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
package constants
22

33
const (
4-
Checkmark = "✓"
5-
Crossmark = "✗"
64
ArrowRight = "→"
75
LoadingFrames = "⠋⠙⠹⠸⠼⠴⠦⠧⠇⠏"
86
EmptyDot = "○"
97
FilledDot = "●"
10-
WarningSign = "⚠"
11-
12-
HistoryIcon = "📜"
13-
SettingsIcon = "⚙️"
14-
CalendarIcon = "📅"
15-
MoodFormIcon = "📝"
16-
ExitIcon = "❌"
17-
DeleteIcon = "⚠️"
18-
EditIcon = "✏️"
19-
StatsIcon = "📊"
20-
)
8+
Checkmark = "✓"
9+
Crossmark = "✗"
10+
WarningSign = "⚠️"
11+
)

internal/presentation/tui/screens/calendar_screen.go

Lines changed: 58 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/ignavan39/mood-diary/internal/infrastructure/i18n"
1515
"github.com/ignavan39/mood-diary/internal/presentation/styles"
1616
"github.com/ignavan39/mood-diary/internal/presentation/tui/components"
17+
"github.com/ignavan39/mood-diary/internal/presentation/tui/constants"
1718
"github.com/ignavan39/mood-diary/internal/presentation/tui/formatters"
1819
"github.com/ignavan39/mood-diary/internal/presentation/tui/state"
1920
)
@@ -32,8 +33,17 @@ type CalendarScreen struct {
3233
cursorRow int
3334
cursorCol int
3435
confirmDlg *components.ConfirmationDialog
36+
37+
viewMode calendarViewMode
3538
}
3639

40+
type calendarViewMode string
41+
42+
const (
43+
viewEmoji calendarViewMode = "emoji"
44+
viewHeatmap calendarViewMode = "heatmap"
45+
)
46+
3747
func NewCalendarScreen(ctx context.Context, service *usecase.MoodService, translator i18n.Translator) *CalendarScreen {
3848
now := time.Now()
3949
return &CalendarScreen{
@@ -43,6 +53,7 @@ func NewCalendarScreen(ctx context.Context, service *usecase.MoodService, transl
4353
currentMonth: time.Date(now.Year(), now.Month(), 1, 0, 0, 0, 0, time.UTC),
4454
selectedDate: time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, time.UTC),
4555
moodData: make(map[time.Time]*entity.MoodEntry),
56+
viewMode: viewEmoji,
4657
}
4758
}
4859

@@ -123,6 +134,13 @@ func (s *CalendarScreen) handleKeyMsg(msg tea.KeyMsg) (state.Screen, tea.Cmd) {
123134
return s, nil
124135
}
125136

137+
case "m":
138+
if s.viewMode == viewEmoji {
139+
s.viewMode = viewHeatmap
140+
} else {
141+
s.viewMode = viewEmoji
142+
}
143+
126144
case "esc", "q":
127145
return s, state.NavigateBack()
128146
}
@@ -211,7 +229,7 @@ func (s *CalendarScreen) View() string {
211229
var b strings.Builder
212230

213231
monthName := s.t(fmt.Sprintf("date.month.%d", s.currentMonth.Month()))
214-
header := styles.HeaderStyle.Render(fmt.Sprintf("📅 %s %d", monthName, s.currentMonth.Year()))
232+
header := styles.HeaderStyle.Render(fmt.Sprintf("%s %s %d", constants.Emoji.Calendar, monthName, s.currentMonth.Year()))
215233
b.WriteString(header)
216234
b.WriteString("\n\n")
217235

@@ -221,7 +239,7 @@ func (s *CalendarScreen) View() string {
221239
}
222240

223241
if s.Error != nil {
224-
b.WriteString(styles.ErrorStyle.Render(s.t(i18n.CommonErrorPrefixKey) + s.Error.Error()))
242+
b.WriteString(styles.ErrorStyle(s.t(i18n.CommonErrorPrefixKey) + s.Error.Error()))
225243
b.WriteString("\n\n")
226244
}
227245

@@ -244,19 +262,25 @@ func (s *CalendarScreen) View() string {
244262
b.WriteString(strings.Repeat("─", 42) + "\n")
245263

246264
rows := s.buildCalendarGrid()
265+
if s.viewMode == viewHeatmap {
266+
rows = s.buildHeatmapGrid()
267+
}
247268
for i, row := range rows {
248269
var line strings.Builder
249270
for j, cell := range row {
250271
style := lipgloss.NewStyle().Width(6).Align(lipgloss.Center)
251272

252273
if i == s.cursorRow && j == s.cursorCol {
253274
style = style.Background(styles.PastelDarkSlateBlue).Foreground(styles.TextLight).Bold(true)
275+
} else if cell.bgColor != "" {
276+
style = style.Background(cell.bgColor)
277+
if cell.date.Month() != s.currentMonth.Month() {
278+
style = style.Foreground(styles.TextMuted)
279+
} else {
280+
style = style.Foreground(styles.TextLight)
281+
}
254282
} else if entry, ok := s.moodData[cell.date]; ok {
255-
256283
style = style.Foreground(styles.GetMoodColor(int(entry.Level)))
257-
} else if cell.date.Month() != s.currentMonth.Month() {
258-
259-
style = style.Foreground(styles.TextMuted)
260284
}
261285

262286
line.WriteString(style.Render(cell.text))
@@ -272,11 +296,20 @@ func (s *CalendarScreen) View() string {
272296
}
273297

274298
type calendarCell struct {
275-
date time.Time
276-
text string
299+
date time.Time
300+
text string
301+
bgColor lipgloss.Color
277302
}
278303

279304
func (s *CalendarScreen) buildCalendarGrid() [][]calendarCell {
305+
return s.buildGrid(viewEmoji)
306+
}
307+
308+
func (s *CalendarScreen) buildHeatmapGrid() [][]calendarCell {
309+
return s.buildGrid(viewHeatmap)
310+
}
311+
312+
func (s *CalendarScreen) buildGrid(mode calendarViewMode) [][]calendarCell {
280313
year, month := s.currentMonth.Year(), s.currentMonth.Month()
281314
firstDay := time.Date(year, month, 1, 0, 0, 0, 0, time.UTC)
282315

@@ -295,7 +328,17 @@ func (s *CalendarScreen) buildCalendarGrid() [][]calendarCell {
295328
cell := calendarCell{date: current}
296329

297330
if current.Month() != month {
298-
cell.text = lipgloss.NewStyle().Foreground(styles.TextMuted).Render(" ")
331+
cell.bgColor = lipgloss.Color("#F0F0F0")
332+
cell.text = " "
333+
} else if mode == viewHeatmap {
334+
entry, ok := s.moodData[current]
335+
if ok {
336+
cell.bgColor = styles.GetMoodColor(int(entry.Level))
337+
cell.text = fmt.Sprintf("%2d", current.Day())
338+
} else {
339+
cell.bgColor = styles.PastelGray
340+
cell.text = fmt.Sprintf("%2d", current.Day())
341+
}
299342
} else {
300343
dayNum := fmt.Sprintf("%2d", current.Day())
301344
if entry, ok := s.moodData[current]; ok {
@@ -313,9 +356,13 @@ func (s *CalendarScreen) buildCalendarGrid() [][]calendarCell {
313356

314357
func (s *CalendarScreen) renderFooter() string {
315358
dateStr := formatters.FormatDate(s.selectedDate)
359+
modeIcon := constants.Emoji.Calendar
360+
if s.viewMode == viewHeatmap {
361+
modeIcon = constants.Emoji.Heatmap
362+
}
316363
if entry, ok := s.moodData[s.selectedDate]; ok {
317364
note := formatters.TruncateNote(entry.Note, 25)
318-
return fmt.Sprintf("📍 %s | %s %d/10 | %s", dateStr, entry.Level.Emoji(), entry.Level.Int(), note)
365+
return fmt.Sprintf("%s %s | %s %d/10 | %s", modeIcon, dateStr, entry.Level.Emoji(), entry.Level.Int(), note)
319366
}
320-
return fmt.Sprintf("📍 %s | %s", dateStr, s.t(i18n.CalendarNoEntryKey))
367+
return fmt.Sprintf("%s %s | %s", modeIcon, dateStr, s.t(i18n.CalendarNoEntryKey))
321368
}

internal/presentation/tui/screens/history_screen.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"github.com/ignavan39/mood-diary/internal/infrastructure/i18n"
1313
"github.com/ignavan39/mood-diary/internal/presentation/styles"
1414
"github.com/ignavan39/mood-diary/internal/presentation/tui/components"
15+
"github.com/ignavan39/mood-diary/internal/presentation/tui/constants"
1516
"github.com/ignavan39/mood-diary/internal/presentation/tui/formatters"
1617
"github.com/ignavan39/mood-diary/internal/presentation/tui/state"
1718
)
@@ -177,7 +178,7 @@ func (s *HistoryScreen) View() string {
177178
Align(lipgloss.Center).
178179
Width(s.Width)
179180

180-
header := headerStyle.Render("📜 " + s.t(i18n.HistoryTitleKey))
181+
header := headerStyle.Render(constants.Emoji.History + " " + s.t(i18n.HistoryTitleKey))
181182

182183
if s.confirmDlg != nil {
183184
return lipgloss.JoinVertical(

internal/presentation/tui/screens/language_settings_screen.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -126,12 +126,12 @@ func (s *LanguageSettingsScreen) View() string {
126126
b.WriteString("\n\n")
127127

128128
if s.Error != nil {
129-
b.WriteString(styles.ErrorStyle.Render(s.t(i18n.CommonErrorPrefixKey) + s.Error.Error()))
129+
b.WriteString(styles.ErrorStyle(s.t(i18n.CommonErrorPrefixKey) + s.Error.Error()))
130130
b.WriteString("\n\n")
131131
}
132132

133133
if s.saved {
134-
b.WriteString(styles.SuccessStyle.Render(s.t(i18n.SettingsSuccessEditKey)))
134+
b.WriteString(styles.SuccessStyle(s.t(i18n.SettingsSuccessEditKey)))
135135
b.WriteString("\n\n")
136136
b.WriteString(styles.HelpStyle.Render(s.t(i18n.CommonReturningKey)))
137137
return lipgloss.NewStyle().Padding(2, 4).Render(b.String())
@@ -160,7 +160,7 @@ func (s *LanguageSettingsScreen) renderLanguageSelection() string {
160160
b.WriteString(constants.ArrowRight + " ")
161161
if isCurrent {
162162
b.WriteString(styles.SelectedListItemStyle.Render(
163-
fmt.Sprintf("%s %s %s", constants.FilledDot, label, constants.Checkmark)))
163+
fmt.Sprintf("%s %s %s", constants.FilledDot, label, constants.Emoji.Checkmark)))
164164
} else {
165165
b.WriteString(styles.SelectedListItemStyle.Render(
166166
fmt.Sprintf("%s %s", constants.FilledDot, label)))
@@ -169,7 +169,7 @@ func (s *LanguageSettingsScreen) renderLanguageSelection() string {
169169
b.WriteString(" ")
170170
if isCurrent {
171171
b.WriteString(styles.ListItemStyle.Render(
172-
fmt.Sprintf("%s %s %s", constants.EmptyDot, label, constants.Checkmark)))
172+
fmt.Sprintf("%s %s %s", constants.EmptyDot, label, constants.Emoji.Checkmark)))
173173
} else {
174174
b.WriteString(styles.ListItemStyle.Render(
175175
fmt.Sprintf("%s %s", constants.EmptyDot, label)))

internal/presentation/tui/screens/menu_screen.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,35 +44,35 @@ func NewMenuScreen(ctx context.Context, translator i18n.Translator) *MenuScreen
4444
screen: state.ScreenMoodForm,
4545
params: state.MoodFormParams{Date: time.Now(), Entry: nil},
4646
key: "r",
47-
icon: constants.EditIcon,
47+
icon: constants.Emoji.MoodForm,
4848
},
4949
{
5050
label: s.t(i18n.MenuCalendarKey),
5151
screen: state.ScreenCalendar,
5252
params: state.CalendarParams{InitialDate: time.Now()},
5353
key: "c",
54-
icon: constants.CalendarIcon,
54+
icon: constants.Emoji.Calendar,
5555
},
5656
{
5757
label: s.t(i18n.MenuHistoryKey),
5858
screen: state.ScreenHistory,
5959
params: nil,
6060
key: "h",
61-
icon: constants.HistoryIcon,
61+
icon: constants.Emoji.History,
6262
},
6363
{
6464
label: s.t(i18n.MenuStatsKey),
6565
screen: state.ScreenStats,
6666
params: state.StatsParams{Period: "month"},
6767
key: "s",
68-
icon: constants.StatsIcon,
68+
icon: constants.Emoji.Stats,
6969
},
7070
{
7171
label: s.t(i18n.MenuSettingsKey),
7272
screen: state.ScreenSettings,
7373
params: nil,
7474
key: "o",
75-
icon: constants.SettingsIcon,
75+
icon: constants.Emoji.Settings,
7676
},
7777
}
7878

0 commit comments

Comments
 (0)