Elffuss BraidHub

kikocis/continue public

1d0255b31268 · 2.0 KiBRawPermalink
1import { Box, Text } from "ink";
2import React from "react";
3
4interface ChecklistDisplayProps {
5 content: string;
6}
7
8/**
9 * Renders checklist content with styled checkboxes
10 */
11export 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={isCompleted ? "gray" : isFirstIncomplete ? "cyan" : "white"}
50 strikethrough={isCompleted}
51 bold={isFirstIncomplete}
52 >
53 {taskText}
54 </Text>
55 </Box>
56 );
57 } else if (line.trim()) {
58 // Non-checkbox lines (headers, etc.)
59 return (
60 <Box key={index}>
61 <Text color="white">{line}</Text>
62 </Box>
63 );
64 } else {
65 // Empty lines
66 return <Box key={index} height={1} />;
67 }
68 })}
69 </Box>
70 );
71};