Skip to content

Instantly share code, notes, and snippets.

@obfusk
Created October 8, 2012 00:08
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save obfusk/3850045 to your computer and use it in GitHub Desktop.
Save obfusk/3850045 to your computer and use it in GitHub Desktop.
js term test
*~
*.swp
/lib/
#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;
}
<!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>
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