this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

refactor: merge print_task_details and print_task_full_details into single print_task function

bnjox 0e39a238 9ca5ef3c

+75 -80
+75 -80
src/core/task.zig
··· 205 205 if (pending.items.len > 0) { 206 206 std.debug.print("{s}Pending{s} ({d})\n", .{ color(.cyan), color(.reset), pending.items.len }); 207 207 for (pending.items) |task| { 208 - try print_task_details(task); 208 + try print_task(task, false); 209 209 } 210 210 std.debug.print("\n", .{}); 211 211 } ··· 213 213 if (in_progress.items.len > 0) { 214 214 std.debug.print("{s}In Progress{s} ({d})\n", .{ color(.cyan), color(.reset), in_progress.items.len }); 215 215 for (in_progress.items) |task| { 216 - try print_task_details(task); 216 + try print_task(task, false); 217 217 } 218 218 std.debug.print("\n", .{}); 219 219 } ··· 221 221 if (completed.items.len > 0) { 222 222 std.debug.print("{s}Completed{s} ({d})\n", .{ color(.green), color(.reset), completed.items.len }); 223 223 for (completed.items) |task| { 224 - try print_task_details(task); 224 + try print_task(task, false); 225 225 } 226 226 } 227 227 } 228 228 229 - fn print_task_details(task: models.Task) !void { 229 + fn print_task(task: models.Task, detailed: bool) !void { 230 230 const c_status = status_color(task.status); 231 231 const c_reset = color(.reset); 232 + const compact_id = if (task.id.len > 8) task.id[0..8] else task.id; 232 233 233 - const compact_id = if (task.id.len > 8) task.id[0..8] else task.id; 234 + if (detailed) { 235 + std.debug.print("{s}=== Task Details ==={s}\n\n", .{ color(.cyan), c_reset }); 236 + std.debug.print("ID: {s}\n", .{task.id}); 237 + std.debug.print("Title: {s}\n", .{task.title}); 238 + 239 + if (task.description) |desc| { 240 + std.debug.print("Description: {s}\n", .{desc}); 241 + } else { 242 + std.debug.print("Description: -\n", .{}); 243 + } 244 + 245 + std.debug.print("Status: {s}{s}{s}\n", .{ color(c_status), status_icon(task.status), c_reset }); 246 + 247 + if (task.priority) |p| { 248 + std.debug.print("Priority: {s}{s}{s}\n", .{ color(priority_color(task.priority)), priority_label(p), c_reset }); 249 + } else { 250 + std.debug.print("Priority: -\n", .{}); 251 + } 234 252 235 - std.debug.print(" {s}{s}{s} ", .{ color(c_status), status_icon(task.status), c_reset }); 236 - if (task.priority) |p| { 237 - std.debug.print("{s} ", .{priority_label(p)}); 238 - } 239 - std.debug.print("{s}\n", .{task.title}); 253 + if (task.due_date) |due| { 254 + const now = std.time.timestamp(); 255 + if (due < now) { 256 + std.debug.print("Due Date: {d} (overdue)\n", .{due}); 257 + } else { 258 + std.debug.print("Due Date: {d}\n", .{due}); 259 + } 260 + } else { 261 + std.debug.print("Due Date: -\n", .{}); 262 + } 263 + 264 + if (task.assigned_to) |assigned| { 265 + std.debug.print("Assigned To: {s}\n", .{assigned}); 266 + } else { 267 + std.debug.print("Assigned To: -\n", .{}); 268 + } 240 269 241 - if (task.description) |desc| { 242 - std.debug.print(" {s}📝{s} {s}\n", .{ color(.yellow), c_reset, desc }); 243 - } 270 + std.debug.print("\n", .{}); 271 + std.debug.print("Created: {d}\n", .{task.created_at}); 244 272 245 - if (task.due_date) |due| { 246 - const now = std.time.timestamp(); 247 - if (due < now) { 248 - std.debug.print(" {s}📅 Due: {d} (overdue){s}\n", .{ color(.red), due, c_reset }); 273 + if (task.updated_at) |updated| { 274 + std.debug.print("Updated: {d}\n", .{updated}); 249 275 } else { 250 - std.debug.print(" {s}📅 Due: {d}{s}\n", .{ color(.yellow), due, c_reset }); 276 + std.debug.print("Updated: -\n", .{}); 251 277 } 252 - } 253 278 254 - if (task.status == .completed) { 255 279 if (task.completed_at) |completed| { 256 - std.debug.print(" {s}✓ Completed: {d}{s}\n", .{ color(.green), completed, c_reset }); 280 + std.debug.print("Completed: {d}\n", .{completed}); 281 + } else { 282 + std.debug.print("Completed: -\n", .{}); 257 283 } 258 - } 284 + } else { 285 + std.debug.print(" {s}{s}{s} ", .{ color(c_status), status_icon(task.status), c_reset }); 286 + if (task.priority) |p| { 287 + std.debug.print("{s} ", .{priority_label(p)}); 288 + } 289 + std.debug.print("{s}\n", .{task.title}); 259 290 260 - std.debug.print(" {s}ID: {s}{s}\n", .{ color(.yellow), compact_id, c_reset }); 291 + if (task.description) |desc| { 292 + std.debug.print(" {s}📝{s} {s}\n", .{ color(.yellow), c_reset, desc }); 293 + } 294 + 295 + if (task.due_date) |due| { 296 + const now = std.time.timestamp(); 297 + if (due < now) { 298 + std.debug.print(" {s}📅 Due: {d} (overdue){s}\n", .{ color(.red), due, c_reset }); 299 + } else { 300 + std.debug.print(" {s}📅 Due: {d}{s}\n", .{ color(.yellow), due, c_reset }); 301 + } 302 + } 303 + 304 + if (task.status == .completed) { 305 + if (task.completed_at) |completed| { 306 + std.debug.print(" {s}✓ Completed: {d}{s}\n", .{ color(.green), completed, c_reset }); 307 + } 308 + } 309 + 310 + std.debug.print(" {s}ID: {s}{s}\n", .{ color(.yellow), compact_id, c_reset }); 311 + } 261 312 } 262 313 263 314 /// Marks the task matching `task_id` as completed. Returns `error.InvalidItem` ··· 375 426 } 376 427 377 428 const task = tasks[found_indices.items[0]]; 378 - try print_task_full_details(task); 379 - } 380 - 381 - fn print_task_full_details(task: models.Task) !void { 382 - const c_status = status_color(task.status); 383 - const c_reset = color(.reset); 384 - 385 - std.debug.print("{s}=== Task Details ==={s}\n\n", .{ color(.cyan), c_reset }); 386 - 387 - std.debug.print("ID: {s}\n", .{task.id}); 388 - std.debug.print("Title: {s}\n", .{task.title}); 389 - 390 - if (task.description) |desc| { 391 - std.debug.print("Description: {s}\n", .{desc}); 392 - } else { 393 - std.debug.print("Description: -\n", .{}); 394 - } 395 - 396 - std.debug.print("Status: {s}{s}{s}\n", .{ color(c_status), status_icon(task.status), c_reset }); 397 - 398 - if (task.priority) |p| { 399 - std.debug.print("Priority: {s}{s}{s}\n", .{ color(priority_color(task.priority)), priority_label(p), c_reset }); 400 - } else { 401 - std.debug.print("Priority: -\n", .{}); 402 - } 403 - 404 - if (task.due_date) |due| { 405 - const now = std.time.timestamp(); 406 - if (due < now) { 407 - std.debug.print("Due Date: {d} (overdue)\n", .{due}); 408 - } else { 409 - std.debug.print("Due Date: {d}\n", .{due}); 410 - } 411 - } else { 412 - std.debug.print("Due Date: -\n", .{}); 413 - } 414 - 415 - if (task.assigned_to) |assigned| { 416 - std.debug.print("Assigned To: {s}\n", .{assigned}); 417 - } else { 418 - std.debug.print("Assigned To: -\n", .{}); 419 - } 420 - 421 - std.debug.print("\n", .{}); 422 - std.debug.print("Created: {d}\n", .{task.created_at}); 423 - 424 - if (task.updated_at) |updated| { 425 - std.debug.print("Updated: {d}\n", .{updated}); 426 - } else { 427 - std.debug.print("Updated: -\n", .{}); 428 - } 429 - 430 - if (task.completed_at) |completed| { 431 - std.debug.print("Completed: {d}\n", .{completed}); 432 - } else { 433 - std.debug.print("Completed: -\n", .{}); 434 - } 429 + try print_task(task, true); 435 430 } 436 431 437 432 test "add and list tasks" {