1- // =================
2- // Stripped down cowsayer CLI,
3- // no libraries or arguments
4- // https://nodejs.dev/learn/accept-input-from-the-command-line-in-nodejs
5- // =================
6-
7- // 1. Make a command line interface.
8-
9- // 2. Make supplies for our speech bubble
10-
11- // 3. Make a cow that takes a string
1+ const readline = require ( "readline" ) ;
2+ const rl = readline . createInterface ( {
3+ input : process . stdin ,
4+ output : process . stdout ,
5+ } ) ;
126
137const cow = ( saying ) => {
14- let line = "_" . repeat ( saying . length + 2 ) ;
15- let bottom = "-" . repeat ( saying . length + 2 ) ;
8+ let line = "_" . repeat ( saying . length + 2 ) ;
9+ let bottom = "-" . repeat ( saying . length + 2 ) ;
1610
17- console . log ( ` ${ line } ` ) ;
18- console . log ( `< ${ saying } >` ) ;
19- console . log ( ` ${ bottom } ` ) ;
20- console . log ( ` \\ ^__^` ) ;
21- console . log ( ` \\ (oo)\\_______` ) ;
22- console . log ( ` (__)\\ )\\/\\` ) ;
23- console . log ( ` ||----w |` ) ;
24- console . log ( ` || ||` ) ;
25-
11+ console . log ( ` ${ line } ` ) ;
12+ console . log ( `< ${ saying } >` ) ;
13+ console . log ( ` ${ bottom } ` ) ;
14+ console . log ( ` \\ ^__^` ) ;
15+ console . log ( ` \\ (oo)\\_______` ) ;
16+ console . log ( ` (__)\\ )\\/\\` ) ;
17+ console . log ( ` ||----w |` ) ;
18+ console . log ( ` || ||` ) ;
2619} ;
27- rl . question ( "What would you like the cow to say? " , function ( answer ) {
20+ rl . question ( "What would you like the cow to say? " , function ( answer ) {
2821 cow ( answer || "Mooooo" ) ;
2922 rl . close ( ) ;
3023} ) ;
31-
32- // 4. Use readline to get a string from the terminal
33- // (with a prompt so it's clearer what we want)
0 commit comments