-
Notifications
You must be signed in to change notification settings - Fork 1
/
bash.js
48 lines (35 loc) · 870 Bytes
/
bash.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
//Output a prompt
const pwd = require('./pwd.js');
const ls = require('./ls.js');
const cat = require('./cat.js');
const date = require('./date.js');
process.stdout.write('prompt > ');
const path = require('path');
//import { cwd } from 'node:process';
// The stdin 'data' event fires after a user types in a line
const done = (output) => {
// show the output
process.stdout.write(output);
process.stdout.write("\nprompt > ");
};
//const promptName = () =>{
process.stdin.on('data', (data) =>{
const entry = data.toString().trim();
const [cmd, arg] = entry.split(" ");
switch (cmd){
case "ls":
ls(done);
break;
case "pwd":
pwd(done);
break;l
case "cat":
cat(done, arg);
break;
case "date":
date(done);
break;
}
//process.stdout.write("\nprompt > ");
});
//promptName();