| 1 | import { Box, Text } from "ink"; |
| 2 | import React from "react"; |
| 3 | |
| 4 | interface ChecklistDisplayProps { |
| 5 | content: string; |
| 6 | } |
| 7 | |
| 8 | /** |
| 9 | * Renders checklist content with styled checkboxes |
| 10 | */ |
| 11 | export const ChecklistDisplay: React.FC<ChecklistDisplayProps> = ({ |
| 12 | content, |
| 13 | }) => { |
| 14 | const lines = content.split("\n"); |
| 15 | |
| 16 | // Find the index of the first incomplete checkbox item |
| 17 | let firstIncompleteIndex = -1; |
| 18 | for (let i = 0; i < lines.length; i++) { |
| 19 | const line = lines[i]; |
| 20 | const checkboxMatch = line.match(/^(\s*)-\s*\[([ x])\]\s*(.*)$/); |
| 21 | if (checkboxMatch && checkboxMatch[2] === " ") { |
| 22 | firstIncompleteIndex = i; |
| 23 | break; |
| 24 | } |
| 25 | } |
| 26 | |
| 27 | return ( |
| 28 | <Box flexDirection="column" paddingLeft={2}> |
| 29 | {lines.map((line, index) => { |
| 30 | if (line.startsWith("Task list")) { |
| 31 | return null; |
| 32 | } |
| 33 | // Match both completed [x] and incomplete [ ] checkboxes |
| 34 | const checkboxMatch = line.match(/^(\s*)-\s*\[([ x])\]\s*(.*)$/); |
| 35 | |
| 36 | if (checkboxMatch) { |
| 37 | const [, indent, status, taskText] = checkboxMatch; |
| 38 | const isCompleted = status === "x"; |
| 39 | const isFirstIncomplete = index === firstIncompleteIndex; |
| 40 | |
| 41 | return ( |
| 42 | <Box key={index}> |
| 43 | <Text>{indent}</Text> |
| 44 | <Text color={isCompleted ? "green" : "yellow"}> |
| 45 | {isCompleted ? "✓" : "○"} |
| 46 | </Text> |
| 47 | <Text> </Text> |
| 48 | <Text |
| 49 | color={ |
| 50 | isCompleted ? "gray" : isFirstIncomplete ? "cyan" : "white" |
| 51 | } |
| 52 | strikethrough={isCompleted} |
| 53 | bold={isFirstIncomplete} |
| 54 | > |
| 55 | {taskText} |
| 56 | </Text> |
| 57 | </Box> |
| 58 | ); |
| 59 | } else if (line.trim()) { |
| 60 | // Non-checkbox lines (headers, etc.) |
| 61 | return ( |
| 62 | <Box key={index}> |
| 63 | <Text color="white">{line}</Text> |
| 64 | </Box> |
| 65 | ); |
| 66 | } else { |
| 67 | // Empty lines |
| 68 | return <Box key={index} height={1} />; |
| 69 | } |
| 70 | })} |
| 71 | </Box> |
| 72 | ); |
| 73 | }; |