@@ -9,6 +9,7 @@ export const useTerminal = () => {
9
9
const [ tasks , dispatch ] = useReducer ( taskReducer , [ ] ) ;
10
10
11
11
const executeCommand = ( command : string ) => {
12
+ // "add" command
12
13
if ( command . startsWith ( "add" ) ) {
13
14
const task = command . match ( / " ( [ ^ " ] + ) " / ) ?. [ 1 ] ;
14
15
if ( ! task ) {
@@ -18,7 +19,7 @@ export const useTerminal = () => {
18
19
return `Task added: ${ task } ` ;
19
20
}
20
21
21
- if ( command . startsWith ( "mark " ) ) {
22
+ if ( command . startsWith ( "check " ) ) {
22
23
const match = command . match ( / # ( \d + ) / ) ;
23
24
if ( ! match ) {
24
25
return `Invalid command format. Use: check #taskId (e.g., check #1)` ;
@@ -38,6 +39,28 @@ export const useTerminal = () => {
38
39
return `Task marked as done: ${ task . name } ` ;
39
40
}
40
41
42
+ // "rm" command
43
+ if ( command . startsWith ( "rm" ) ) {
44
+ const match = command . match ( / # ( \d + ) / ) ;
45
+ if ( ! match ) {
46
+ return `Invalid command format. Use: rm #taskId (e.g., rm #1)` ;
47
+ }
48
+
49
+ const taskId = parseInt ( match [ 1 ] , 10 ) ;
50
+ if ( isNaN ( taskId ) ) {
51
+ return `Invalid task ID. Use a valid number with the format: rm #taskId (e.g., rm #1)` ;
52
+ }
53
+
54
+ const task = tasks . find ( ( task ) => task . id === taskId ) ;
55
+ if ( ! task ) {
56
+ return `Task with ID #${ taskId } not found.` ;
57
+ }
58
+
59
+ dispatch ( { type : "REMOVE_TASK" , payload : { id : taskId } } ) ;
60
+ return `Task removed: ${ task . name } ` ;
61
+ }
62
+
63
+ // "cat" command
41
64
if ( command . startsWith ( "cat" ) ) {
42
65
const match = command . match ( / # ( \d + ) / ) ;
43
66
if ( ! match ) {
@@ -64,15 +87,35 @@ export const useTerminal = () => {
64
87
` ;
65
88
}
66
89
90
+ // "ls" command
67
91
if ( command === "ls" ) {
68
- return tasks
92
+ const listedTasks = tasks
69
93
. map (
70
94
( task ) =>
71
95
`${ task . id } . [${ task . status === "done" ? "x" : " " } ] ${ task . name } `
72
96
)
73
97
. join ( "\n" ) ;
98
+
99
+ if ( ! listedTasks ) {
100
+ return "<empty list>" ;
101
+ }
102
+
103
+ return listedTasks ;
104
+ }
105
+
106
+ // "help" command
107
+ if ( command === "help" ) {
108
+ return `
109
+ add "task name" - Add a new task\n
110
+ rm #taskId - Remove a task\n
111
+ cat #taskId - Show info about a task\n
112
+ check #taskId - Mark the task as done\n
113
+ ls - List all the tasks\n
114
+ clear - Clear the terminal display\n
115
+ ` ;
74
116
}
75
117
118
+ // "clear" command
76
119
if ( command === "clear" ) {
77
120
setHistory ( [ ] ) ;
78
121
setCommand ( "" ) ;
0 commit comments