Created
October 8, 2012 00:08
-
-
Save obfusk/3850045 to your computer and use it in GitHub Desktop.
js term test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*~ | |
*.swp | |
/lib/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#wrap1 { text-align: center; } | |
#wrap2 { display: inline-block; text-align: left; } | |
#term_div { display: block; } | |
.terminal { | |
font-family : "ubuntu mono", monospace, fixed; | |
font-size : 13pt; | |
line-height : 14pt; | |
color : #fff; | |
background-color : #000; | |
} | |
.terminal .cmd span.inverted { | |
background-color: #fff; color: #000; | |
} | |
.terminal div::-moz-selection, .terminal span::-moz-selection { | |
background-color: #fff; color: #000; | |
} | |
.terminal div::selection, .terminal span::selection { | |
background-color: #fff; color: #000; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>...</title> | |
<link rel="stylesheet" type="text/css" href="lib/jquery.terminal.css"/> | |
<link rel="stylesheet" type="text/css" href="term.css"/> | |
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script> | |
<script type="text/javascript" src="lib/jquery.terminal.js"></script> | |
<script type="text/javascript" src="term.js"></script> | |
</head> | |
<body> | |
<div id="wrap1"> | |
<div id="wrap2"> | |
<div id="term_div"></div> | |
</div> | |
</div> | |
</body> | |
</html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
jQuery (function () { | |
$.terminal.format = $.terminal.encode; | |
var __eval__ = function (code, cons) { | |
var res; | |
window.console_ = window.console; | |
window.console = cons; | |
try { | |
res = window.eval (code); // indirect call | |
} finally { | |
window.console = window.console_; | |
delete window.console_; | |
} | |
return res; | |
}; | |
var cons = function (term) { | |
return { | |
log: function () { | |
var line = ""; | |
for (var i = 0; i < arguments.length; ++i) { | |
if (i > 0) { line += " "; } | |
line += arguments[i]; | |
} | |
term.echo (line); | |
} | |
}; | |
}; | |
var term_handler = function (cmd, term) { | |
if (cmd === ".clear" || cmd === ".c") { | |
term.clear (); | |
} else { | |
try { | |
var res = __eval__ (cmd, cons (term)); | |
term.echo ("" + res); // TODO: pr-str | |
} catch (e) { | |
var f = typeof e.fileName === 'string' | |
? e.fileName + ": " : ""; | |
term.echo ("Error: " + f + e); | |
if (e.stack) { | |
term.echo (e.stack); | |
} | |
} | |
} | |
}; | |
var term_opts = { | |
height: 700, width: 1200, exit: false, clear: false, | |
greetings: "js term test -- repl\nglobal scope!", | |
prompt: ">>> " | |
}; | |
jQuery ('#term_div').terminal (term_handler, term_opts); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment