Skip to content

Commit 0890d3a

Browse files
committed
chore: rename domain to util
1 parent 70592f0 commit 0890d3a

File tree

7 files changed

+62
-61
lines changed

7 files changed

+62
-61
lines changed

lua/codeme/ui/dashboard.lua

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ local M = {}
33
local stats = require("codeme.stats")
44
local renderer = require("codeme.ui.renderer")
55
local backend = require("codeme.backend")
6-
local domain = require("codeme.domain")
6+
local util = require("codeme.util")
77

88
-- Tab definitions
99
local TABS = {
@@ -38,7 +38,7 @@ end
3838
---@param stat_data table
3939
local function render_dashboard(stat_data)
4040
-- Strip every vim.NIL from the backend payload once here.
41-
stat_data = domain.sanitize(stat_data) or {}
41+
stat_data = util.sanitize(stat_data) or {}
4242

4343
local buf = stats.get_buf()
4444
local win = stats.get_win()

lua/codeme/ui/tabs/activity.lua

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local domain = require("codeme.domain")
1+
local util = require("codeme.util")
22
local renderer = require("codeme.ui.renderer")
33

44
local M = {}
@@ -17,7 +17,7 @@ function M.render(stats)
1717
table.insert(lines, {
1818
{ " ☀️ Today's Activity", "exgreen" },
1919
{ string.rep(" ", 35), "commentfg" },
20-
{ domain.format_duration(total_time), "exgreen" },
20+
{ util.format_duration(total_time), "exgreen" },
2121
{ "", "commentfg" },
2222
{ today_date, "exyellow" },
2323
})
@@ -118,14 +118,14 @@ function M.render(stats)
118118
for i, session in ipairs(today_sessions) do
119119
if session.start_time then
120120
local time_str = session.start_time:sub(12, 16)
121-
local duration_str = domain.format_duration(session.duration or 0)
121+
local duration_str = util.format_duration(session.duration or 0)
122122

123123
if i == peak_index and #today_sessions > 1 then
124124
duration_str = duration_str .. ""
125125
end
126126

127-
local projects = domain.top_items(session.projects or {}, 2)
128-
local languages = domain.top_items(session.languages or {}, 5)
127+
local projects = util.top_items(session.projects or {}, 2)
128+
local languages = util.top_items(session.languages or {}, 5)
129129

130130
tbl[#tbl + 1] = {
131131
time_str,
@@ -138,7 +138,7 @@ function M.render(stats)
138138
local icon = session.break_after < 1800 and "" or "🍽️"
139139
tbl[#tbl + 1] = {
140140
"",
141-
icon .. " " .. domain.format_duration(session.break_after),
141+
icon .. " " .. util.format_duration(session.break_after),
142142
"-",
143143
"",
144144
}
@@ -154,14 +154,15 @@ function M.render(stats)
154154
-- Time by Language
155155
local languages = today.languages or {}
156156
if #languages > 0 then
157-
table.insert(lines, { { "Time by Language", "exgreen" } })
157+
table.insert(lines, { { " ⏰ Language activity", "exgreen" } })
158158
table.insert(lines, {})
159159

160-
local tblLang = { { "Language", "Time" } }
160+
local tblLang = { { "Language", "Time", "Lines" } }
161161
for _, lang in ipairs(languages) do
162162
table.insert(tblLang, {
163163
lang.name,
164-
domain.format_duration(lang.time),
164+
util.format_duration(lang.time),
165+
util.format_number(lang.lines),
165166
})
166167
end
167168

@@ -174,7 +175,7 @@ function M.render(stats)
174175
-- Quick Stats
175176
table.insert(lines, {
176177
{ " 📊 ", "exgreen" },
177-
{ domain.format_duration(total_time), "exgreen" },
178+
{ util.format_duration(total_time), "exgreen" },
178179
{ " total • ", "commentfg" },
179180
{ string.format("Focus %d%%", focus_score), focus_score >= 70 and "exgreen" or "exyellow" },
180181
})

lua/codeme/ui/tabs/overview.lua

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local domain = require("codeme.domain")
1+
local util = require("codeme.util")
22
local renderer = require("codeme.ui.renderer")
33

44
local M = {}
@@ -48,7 +48,7 @@ function M.render(stats)
4848
local focus_str = focus_score > 0 and tostring(focus_score) .. "/100" or ""
4949
local metrics_tbl = {
5050
{ "⏰ Time", "📝 Lines", "🎯 Focus" },
51-
{ domain.format_duration(today_time), domain.format_number(today_lines), focus_str },
51+
{ util.format_duration(today_time), util.format_number(today_lines), focus_str },
5252
}
5353

5454
for _, l in ipairs(renderer.table(metrics_tbl, 120)) do
@@ -72,7 +72,7 @@ function M.render(stats)
7272
end
7373
table.insert(time_goal_line, { string.format(" %d%%", time_pct), goal_hl })
7474
table.insert(time_goal_line, {
75-
string.format(" %s / %s", domain.format_duration(today_time), domain.format_duration(daily_goal_time)),
75+
string.format(" %s / %s", util.format_duration(today_time), util.format_duration(daily_goal_time)),
7676
"commentfg",
7777
})
7878
table.insert(lines, time_goal_line)
@@ -89,7 +89,7 @@ function M.render(stats)
8989
end
9090
table.insert(lines_goal_line, { string.format(" %d%%", lines_pct), lines_hl })
9191
table.insert(lines_goal_line, {
92-
string.format(" %s / %s", domain.format_number(today_lines), domain.format_number(daily_goal_lines)),
92+
string.format(" %s / %s", util.format_number(today_lines), util.format_number(daily_goal_lines)),
9393
"commentfg",
9494
})
9595
table.insert(lines, lines_goal_line)
@@ -107,9 +107,9 @@ function M.render(stats)
107107
status_msg = "💪 Halfway there - keep the momentum"
108108
elseif goal_pct > 0 then
109109
local remaining = daily_goal_time - today_time
110-
status_msg = "🚀 Great start - " .. domain.format_duration(remaining) .. " to go"
110+
status_msg = "🚀 Great start - " .. util.format_duration(remaining) .. " to go"
111111
else
112-
status_msg = "💡 Goal: " .. domain.format_duration(daily_goal_time) .. " - Let's begin!"
112+
status_msg = "💡 Goal: " .. util.format_duration(daily_goal_time) .. " - Let's begin!"
113113
end
114114

115115
table.insert(lines, {})
@@ -207,8 +207,8 @@ function M.render(stats)
207207
if yesterday_time == 0 then
208208
table.insert(comparison_data, {
209209
"vs Yesterday",
210-
domain.format_duration(today_time),
211-
domain.format_duration(0),
210+
util.format_duration(today_time),
211+
util.format_duration(0),
212212
"↑ New",
213213
})
214214
else
@@ -217,8 +217,8 @@ function M.render(stats)
217217
local status = diff >= 0 and "" or ""
218218
table.insert(comparison_data, {
219219
"vs Yesterday",
220-
domain.format_duration(today_time),
221-
domain.format_duration(yesterday_time),
220+
util.format_duration(today_time),
221+
util.format_duration(yesterday_time),
222222
string.format("%s %d%%", status, diff_pct),
223223
})
224224
end
@@ -228,8 +228,8 @@ function M.render(stats)
228228
if last_week_time == 0 then
229229
table.insert(comparison_data, {
230230
"vs Last Week",
231-
domain.format_duration(week_time),
232-
domain.format_duration(0),
231+
util.format_duration(week_time),
232+
util.format_duration(0),
233233
"↑ New",
234234
})
235235
else
@@ -238,8 +238,8 @@ function M.render(stats)
238238
local status = diff >= 0 and "" or ""
239239
table.insert(comparison_data, {
240240
"vs Last Week",
241-
domain.format_duration(week_time),
242-
domain.format_duration(last_week_time),
241+
util.format_duration(week_time),
242+
util.format_duration(last_week_time),
243243
string.format("%s %d%%", status, diff_pct),
244244
})
245245
end

lua/codeme/ui/tabs/records.lua

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local domain = require("codeme.domain")
1+
local util = require("codeme.util")
22
local renderer = require("codeme.ui.renderer")
33

44
local M = {}
@@ -23,26 +23,26 @@ function M.render(stats)
2323
{ "Period", "Time", "Lines", "Files" },
2424
{
2525
"Today",
26-
domain.format_duration(today.total_time or 0),
27-
domain.format_number(today.total_lines or 0),
26+
util.format_duration(today.total_time or 0),
27+
util.format_number(today.total_lines or 0),
2828
tostring(today.total_files or 0),
2929
},
3030
{
3131
"This Week",
32-
domain.format_duration(this_week.total_time or 0),
33-
domain.format_number(this_week.total_lines or 0),
32+
util.format_duration(this_week.total_time or 0),
33+
util.format_number(this_week.total_lines or 0),
3434
tostring(this_week.total_files or 0),
3535
},
3636
{
3737
"This Month",
38-
domain.format_duration(this_month.total_time or 0),
39-
domain.format_number(this_month.total_lines or 0),
38+
util.format_duration(this_month.total_time or 0),
39+
util.format_number(this_month.total_lines or 0),
4040
tostring(this_month.total_files or 0),
4141
},
4242
{
4343
"All Time",
44-
domain.format_duration(all_time.total_time or 0),
45-
domain.format_number(all_time.total_lines or 0),
44+
util.format_duration(all_time.total_time or 0),
45+
util.format_number(all_time.total_lines or 0),
4646
tostring(all_time.total_files or 0),
4747
},
4848
}
@@ -132,9 +132,9 @@ function M.render(stats)
132132
table.insert(record_list, {
133133
icon = "🏆",
134134
title = "Best Day",
135-
value = domain.format_duration(most_productive_day.time),
136-
detail = most_productive_day.date and domain.format_date(most_productive_day.date) or "",
137-
extra = most_productive_day.lines and domain.format_number(most_productive_day.lines) .. " lines" or "",
135+
value = util.format_duration(most_productive_day.time),
136+
detail = most_productive_day.date and util.format_date(most_productive_day.date) or "",
137+
extra = most_productive_day.lines and util.format_number(most_productive_day.lines) .. " lines" or "",
138138
})
139139
end
140140

@@ -148,8 +148,8 @@ function M.render(stats)
148148
table.insert(record_list, {
149149
icon = "⏱️",
150150
title = "Longest Session",
151-
value = domain.format_duration(longest_session.duration),
152-
detail = longest_session.date and domain.format_date(longest_session.date) or "",
151+
value = util.format_duration(longest_session.duration),
152+
detail = longest_session.date and util.format_date(longest_session.date) or "",
153153
extra = time_range,
154154
})
155155
end
@@ -159,15 +159,15 @@ function M.render(stats)
159159
table.insert(record_list, {
160160
icon = "📝",
161161
title = "Most Lines",
162-
value = domain.format_number(highest_daily_output.lines) .. " lines",
163-
detail = highest_daily_output.date and domain.format_date(highest_daily_output.date) or "",
162+
value = util.format_number(highest_daily_output.lines) .. " lines",
163+
detail = highest_daily_output.date and util.format_date(highest_daily_output.date) or "",
164164
extra = highest_daily_output.session_count and highest_daily_output.session_count .. " sessions" or "",
165165
})
166166
end
167167

168168
local best_streak = records.best_streak or {}
169169
if best_streak.day_count and best_streak.day_count > 0 then
170-
local streak_icon, _ = domain.get_streak_display(best_streak.day_count)
170+
local streak_icon, _ = util.get_streak_display(best_streak.day_count)
171171
local date_range = ""
172172
if best_streak.start_date and best_streak.end_date then
173173
date_range = best_streak.start_date:sub(6, 10) .. " - " .. best_streak.end_date:sub(6, 10)
@@ -178,7 +178,7 @@ function M.render(stats)
178178
title = "Best Streak",
179179
value = best_streak.day_count .. " days " .. streak_icon,
180180
detail = date_range,
181-
extra = best_streak.total_time and domain.format_duration(best_streak.total_time) .. " total" or "",
181+
extra = best_streak.total_time and util.format_duration(best_streak.total_time) .. " total" or "",
182182
})
183183
end
184184

@@ -230,7 +230,7 @@ function M.render(stats)
230230
end
231231

232232
if most_languages_day and most_languages_day.date and most_languages_day.date ~= "" then
233-
local languages_count = domain.safe_length(most_languages_day.languages)
233+
local languages_count = util.safe_length(most_languages_day.languages)
234234
if languages_count > 0 then
235235
table.insert(lines, {
236236
{ " 🌍 ", "normal" },
@@ -307,7 +307,7 @@ function M.render(stats)
307307
if gap > 0 and today_time > 0 then
308308
table.insert(challenges, {
309309
icon = "🎯",
310-
text = domain.format_duration(gap) .. " more to beat your best day",
310+
text = util.format_duration(gap) .. " more to beat your best day",
311311
color = gap < 3600 and "exgreen" or "exyellow",
312312
})
313313
end
@@ -333,7 +333,7 @@ function M.render(stats)
333333
if longest_session.duration then
334334
table.insert(challenges, {
335335
icon = "",
336-
text = "Can you beat " .. domain.format_duration(longest_session.duration) .. " in one session?",
336+
text = "Can you beat " .. util.format_duration(longest_session.duration) .. " in one session?",
337337
color = "exyellow",
338338
})
339339
end

lua/codeme/ui/tabs/weekly.lua

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local domain = require("codeme.domain")
1+
local util = require("codeme.util")
22
local renderer = require("codeme.ui.renderer")
33

44
local M = {}
@@ -58,17 +58,17 @@ function M.render(stats)
5858
local last_week_time = last_week.total_time or 0
5959
local week_lines = this_week.total_lines or 0
6060

61-
local t_trend, t_hl = domain.get_trend(week_time, last_week_time)
61+
local t_trend, t_hl = util.get_trend(week_time, last_week_time)
6262

6363
-- Header
6464
table.insert(lines, {})
6565
table.insert(lines, {
6666
{ " 📅 Weekly Summary ", "exgreen" },
6767
{ "⏱️ ", "commentfg" },
68-
{ domain.format_duration(week_time), "exgreen" },
68+
{ util.format_duration(week_time), "exgreen" },
6969
{ t_trend, t_hl },
7070
{ " │ 📝 ", "commentfg" },
71-
{ domain.format_number(week_lines), "exyellow" },
71+
{ util.format_number(week_lines), "exyellow" },
7272
})
7373
table.insert(lines, {})
7474

@@ -108,8 +108,8 @@ function M.render(stats)
108108
tbl[#tbl + 1] = {
109109
label,
110110
date:sub(6, 10),
111-
t > 0 and domain.format_duration(t) or "-",
112-
l > 0 and domain.format_number(l) or "-",
111+
t > 0 and util.format_duration(t) or "-",
112+
l > 0 and util.format_number(l) or "-",
113113
s > 0 and tostring(s) or "-",
114114
t > 0 and "" or "-",
115115
}
@@ -139,7 +139,7 @@ function M.render(stats)
139139
local daily_avg = week_time > 0 and math.floor(week_time / 7) or 0
140140
table.insert(lines, {
141141
{ " Daily Average: ", "commentfg" },
142-
{ domain.format_duration(daily_avg), "exgreen" },
142+
{ util.format_duration(daily_avg), "exgreen" },
143143
})
144144

145145
local days_coded = count_week_coding_days(daily_activity)
@@ -155,7 +155,7 @@ function M.render(stats)
155155
table.insert(lines, {
156156
{ " Vs Last Week: ", "commentfg" },
157157
{ arrow, hl },
158-
{ " " .. domain.format_duration(math.abs(diff)), hl },
158+
{ " " .. util.format_duration(math.abs(diff)), hl },
159159
})
160160
end
161161
local weekday_time, weekend_time = 0, 0

lua/codeme/ui/tabs/work.lua

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
local domain = require("codeme.domain")
1+
local util = require("codeme.util")
22
local renderer = require("codeme.ui.renderer")
33

44
local M = {}
@@ -42,8 +42,8 @@ function M.render(stats)
4242
local it = items[i]
4343
tbl[#tbl + 1] = {
4444
it.name,
45-
domain.format_duration(it.time),
46-
domain.format_number(it.lines),
45+
util.format_duration(it.time),
46+
util.format_number(it.lines),
4747
it.main_lang ~= "" and it.main_lang or "Mixed",
4848
}
4949
end
@@ -100,7 +100,7 @@ function M.render(stats)
100100

101101
tbl[#tbl + 1] = {
102102
it.name,
103-
domain.format_duration(it.time),
103+
util.format_duration(it.time),
104104
it.lines,
105105
it.proficiency,
106106
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,11 @@ end
8181
---@return string
8282
function M.format_date(date_str)
8383
if not date_str then
84-
return "Unknown"
84+
return "_"
8585
end
8686
local year, month, day = date_str:match("(%d+)-(%d+)-(%d+)")
8787
if not year then
88-
return "Unknown"
88+
return "_"
8989
end
9090

9191
local timestamp = os.time({ year = year, month = month, day = day, hour = 12 })

0 commit comments

Comments
 (0)