Skip to content

Commit 7c96609

Browse files
committed
fix: align sessions column
1 parent b85ccf2 commit 7c96609

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

lua/codeme/ui/renderer.lua

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,11 +318,13 @@ end
318318
---@param max_val number?
319319
---@param height number? Max 1 currently supported for sparklines
320320
---@param hl_group string?
321+
---@param spacing number? Number of spaces after each bar (default 1)
321322
---@return table[] Segments
322-
function M.histogram(data, max_val, height, hl_group)
323+
function M.histogram(data, max_val, height, hl_group, spacing)
323324
local blocks = { " ", " ", "", "", "", "", "", "", "" }
324325
local max = tonumber(max_val) or 0
325326
local data_list = type(data) == "table" and data or {}
327+
local bar_spacing = math.max(0, tonumber(spacing) or 1)
326328

327329
if max == 0 then
328330
for _, v in ipairs(data_list) do
@@ -343,7 +345,7 @@ function M.histogram(data, max_val, height, hl_group)
343345
level = 2
344346
end
345347
level = math.min(9, math.max(1, level))
346-
table.insert(segs, { blocks[level] .. " ", hl_group or "exgreen" })
348+
table.insert(segs, { blocks[level] .. string.rep(" ", bar_spacing), hl_group or "exgreen" })
347349
end
348350
return segs
349351
end

lua/codeme/ui/tabs/activity.lua

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@ function M.render(stats, width, height)
4343
end
4444

4545
local hist_line = { { " ", "commentfg" } }
46-
for _, s in ipairs(renderer.histogram(hourly_raw, 0, 1, "exblue")) do
46+
for _, s in ipairs(renderer.histogram(hourly_raw, 0, 1, "exblue", 2)) do
4747
table.insert(hist_line, s)
4848
end
4949
table.insert(lines, hist_line)
5050

5151
local label_line = { { " ", "commentfg" } }
5252
for h = 0, 23 do
53-
local display_h = (h + 2) % 24
54-
table.insert(label_line, { string.format("%02d", display_h) .. " ", "commentfg" })
53+
local display_h = h % 24
54+
table.insert(label_line, { string.format("%02d ", display_h), "commentfg" })
5555
end
5656
table.insert(lines, label_line)
5757

@@ -207,15 +207,19 @@ function M.render(stats, width, height)
207207
meta = "[" .. lang_str .. "]"
208208
end
209209

210-
-- Session line
210+
local time_col = time_range .. string.rep(" ", math.max(0, 11 - #time_range))
211+
local dur_str = util.format_duration(dur)
212+
local dur_col = dur_str .. string.rep(" ", math.max(0, 6 - #dur_str))
213+
local star_col = is_peak and "" or " "
214+
211215
local sess_line = {
212216
{ " " .. connector .. " ", "commentfg" },
213-
{ time_range, "commentfg" },
214-
{ " ", "normal" },
215-
{ util.format_duration(dur), is_peak and "exyellow" or "normal" },
216-
{ is_peak and "" or " ", "exyellow" },
217+
{ time_col, "commentfg" },
217218
{ " ", "normal" },
219+
{ dur_col, is_peak and "exyellow" or "normal" },
220+
{ " " .. star_col .. " ", "exyellow" },
218221
}
222+
219223
-- Mini bar
220224
local filled = math.floor(pct / 100 * bar_w)
221225
table.insert(sess_line, { string.rep("", filled), bar_hl })
@@ -226,7 +230,7 @@ function M.render(stats, width, height)
226230
end
227231
table.insert(lines, sess_line)
228232

229-
-- Break gap between sessions (only show if meaningful > 5 min)
233+
-- Break gap
230234
if not is_last then
231235
local break_sec = session.break_after or 0
232236
if break_sec >= 300 then
@@ -241,7 +245,6 @@ function M.render(stats, width, height)
241245
end
242246
end
243247
end
244-
table.insert(lines, {})
245248

246249
-- ── Summary bar (total confirmed) ─────────────────────────────────
247250
table.insert(lines, {

lua/codeme/ui/tabs/overview.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ function M.render(stats, width)
164164
end
165165
table.insert(lines, vol_line)
166166

167-
local label_line = { { " ", "commentfg" } }
167+
local label_line = { { " ", "commentfg" } }
168168
for _, label in ipairs({ "M", "T", "W", "T", "F", "S", "S" }) do
169169
table.insert(label_line, { label .. " ", "commentfg" })
170170
end

lua/codeme/ui/tabs/search.lua

Lines changed: 36 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,34 @@ function M.render(stats, width, height)
158158
table.insert(lines, {})
159159

160160
-- Hourly activity
161-
local hourly = data.hourly_activity or {}
161+
local hourly_raw = {}
162+
for i = 1, 24 do
163+
hourly_raw[i] = 0
164+
end
165+
166+
-- Handle both formats: array of numbers OR array of {hour, duration} objects
167+
local hourly_data = data.hourly_activity or {}
168+
if #hourly_data > 0 then
169+
local first = hourly_data[1]
170+
if type(first) == "table" and first.hour ~= nil then
171+
-- Format: [{hour: 0, duration: 123}, ...]
172+
for _, item in ipairs(hourly_data) do
173+
if item.hour and item.hour >= 0 and item.hour < 24 then
174+
hourly_raw[item.hour + 1] = item.duration or 0
175+
end
176+
end
177+
else
178+
-- Format: [0, 123, 456, ...] (direct 24-element array)
179+
for i, v in ipairs(hourly_data) do
180+
if i <= 24 then
181+
hourly_raw[i] = tonumber(v) or 0
182+
end
183+
end
184+
end
185+
end
186+
162187
local has_hourly = false
163-
for _, v in ipairs(hourly) do
188+
for _, v in ipairs(hourly_raw) do
164189
if v > 0 then
165190
has_hourly = true
166191
break
@@ -170,13 +195,18 @@ function M.render(stats, width, height)
170195
if has_hourly then
171196
table.insert(lines, { { " ⏰ Hourly Distribution", "exgreen" } })
172197
table.insert(lines, {})
173-
local hist_line = { { " ", "normal" } }
174-
local hist_segs = renderer.histogram(hourly, 0, 1, "exblue")
175-
for _, s in ipairs(hist_segs) do
198+
199+
local hist_line = { { " ", "commentfg" } }
200+
for _, s in ipairs(renderer.histogram(hourly_raw, 0, 1, "exblue", 2)) do
176201
table.insert(hist_line, s)
177202
end
178203
table.insert(lines, hist_line)
179-
table.insert(lines, { { " 00 02 04 06 08 10 12 14 16 18 20 22", "commentfg" } })
204+
205+
local label_line = { { " ", "commentfg" } }
206+
for h = 0, 23 do
207+
table.insert(label_line, { string.format("%02d ", h), "commentfg" })
208+
end
209+
table.insert(lines, label_line)
180210
table.insert(lines, {})
181211
end
182212

0 commit comments

Comments
 (0)