11import { useState } from "react" ;
22
3- function echo_foo ( ) {
4- return "echo foo" ;
5- }
6-
7- function echo_bar ( ) {
8- return "echo bar" ;
9- }
10-
11- function echo_baz ( ) {
12- return "echo baz" ;
13- }
14-
15- function echo_$0 ( ) {
16- return "echo $0" ;
17- }
18-
19- function echo_$ROOT_$USER ( ) {
20- return "echo $ROOT/$USER" ;
21- }
22-
23- function export_USER_WebAssembly ( ) {
24- return "export USER=WebAssembly" ;
25- }
26-
27- function export_USER_Tophe ( ) {
28- return "export USER=Tophe" ;
29- }
30-
31- function greet_USER ( ) {
32- return "greet $USER" ;
33- }
34-
35- function azertyuiop ( ) {
36- return "azertyuiop" ;
37- }
38-
39- function echo_$question_mark ( ) {
40- return "echo $?" ;
41- }
42-
43- function help ( ) {
44- return "help" ;
45- }
46-
47- function man_weather ( ) {
48- return "man weather" ;
49- }
50-
513function ls ( path ?: string ) {
524 if ( path ) {
535 return `ls ${ path } ` ;
@@ -62,48 +14,39 @@ function cat(path?: string) {
6214 return "cat" ;
6315}
6416
65- function weather_Paris ( ) {
66- return "weather Paris" ;
67- }
68-
69- function export_DATE ( ) {
70- return `export DATE=${ new Date ( ) . toISOString ( ) } ` ;
71- }
72-
73- function echo_DATE ( ) {
74- return `echo $DATE` ;
75- }
76-
7717const commands = [
78- echo_foo ,
79- echo_bar ,
80- echo_baz ,
81- echo_$0 ,
82- echo_$ROOT_ $USER,
83- greet_USER ,
84- echo_$0 ,
85- export_USER_WebAssembly ,
86- echo_$ROOT_ $USER,
87- echo_$0 ,
88- echo_$question_mark ,
89- azertyuiop ,
90- echo_$question_mark ,
91- echo_$question_mark ,
92- export_DATE ,
93- echo_DATE ,
94- export_USER_Tophe ,
95- echo_$ROOT_ $USER,
96- ls ,
18+ "echo foo" ,
19+ "echo bar" ,
20+ "echo baz" ,
21+ "echo $0" ,
22+ "echo $ROOT/ $USER" ,
23+ "greet $USER" ,
24+ "echo $0" ,
25+ "export USER=WebAssembly" ,
26+ "echo $ROOT/ $USER" ,
27+ "echo $0" ,
28+ "echo $?" ,
29+ " azertyuiop" ,
30+ "echo $?" ,
31+ "echo $?" ,
32+ ( ) => `export DATE= ${ new Date ( ) . toISOString ( ) } ` ,
33+ "echo $DATE" ,
34+ "export USER=Tophe" ,
35+ "echo $ROOT/ $USER" ,
36+ ( ) => ls ( ) ,
9737 ( ) => cat ( "README.md" ) ,
98- ls ,
38+ ( ) => ls ( ) ,
9939 ( ) => ls ( "data" ) ,
10040 ( ) => ls ( "data/processed" ) ,
10141 ( ) => ls ( "data/processed/2024" ) ,
10242 ( ) => ls ( "documents" ) ,
10343 ( ) => cat ( "documents/config.json" ) ,
104- weather_Paris ,
105- man_weather ,
106- help ,
44+ "weather Paris" ,
45+ "man weather" ,
46+ "help" ,
47+ "echoc This is the same as `echo`, implemented in C" ,
48+ "echoc try `man echo` vs `man echoc`" ,
49+ "echoc qux" ,
10750] ;
10851
10952export function useGetExampleCommand ( ) {
@@ -118,7 +61,8 @@ export function useGetExampleCommand() {
11861 setDone ( true ) ;
11962 setIndex ( 0 ) ;
12063 }
121- const output = commands [ index ] ( ) ;
64+ const command = commands [ index ] ;
65+ const output = typeof command === "function" ? command ( ) : command ;
12266 setCommand ( output ) ;
12367 setRemaining ( ( left ) => left - 1 ) ;
12468 setIndex ( ( index ) => index + 1 ) ;
0 commit comments