forked from aantthony/javascript-cas
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.js
More file actions
executable file
·48 lines (44 loc) · 1015 Bytes
/
console.js
File metadata and controls
executable file
·48 lines (44 loc) · 1015 Bytes
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
47
48
#!/usr/bin/env node
var M=require("./build/math.js");
(function (){
function con(){
global.console.log=function(){};
function color(str){
return '\x1b[1m' + (str || "") + '\x1b[22m';
}
var stdin = process.openStdin(),
stdio = process.binding("stdio"),
stderr= process.stderr,
stdout= process.stdout;
var line = "";
stderr.write("Javascript-cas (http://aantthony.github.com/javascript-cas/)\n");
stderr.write(">> ");
stdin.on("data", function (c) {
c = c + ""
line+=c;
switch (line[line.length-1]) {
case "\n": case "\r": case "\u0004":
line=line.trim();
if(line=="exit"){
stdout.write("\n");
process.exit()
}else if(line==="clear"){
stdout.write("\x1b[H\x1b[2J");
}else if(line){
try{
var expr = M(line).simplify()
stdout.write(expr.toString()+"\n");
}catch(ex){
stderr.write(color(ex)+"\n");
}
}
stderr.write(">> ");
line="";
break;
default:
break
}
});
}
con();
}());