rendered paste body<html>
<head>
<title>ssh</title>
<script type="text/javascript">
var stack = new Array();
function load()
{
document.getElementById('ssh').value = 'Starting connection to joel.io..\nConnection Established\n\nAvailable commands are: \'ls\' and \'cat\'\n\n[guest@joel.io /]$ ';
document.term.ssh.focus();
}
function process(event)
{
if (event.keyCode)
{
charCode = event.keyCode;
}
else if (event.which)
{
charCode = event.which;
}
//alert(charCode);
if (charCode == 13)
{
var ssh = document.getElementById('ssh');
if (stack[0] == '108' && stack[1] == '115')
{
// do ls
ssh.value = ssh.value + '\naboutme\nmotd\n[guest@joel.io /]$ ';
}
else if (stack[0] == '99' && stack[1] == '97' && stack[2] == '116')
{
// now we need to check the next set of files to know what to print
ssh.value = ssh.value + '\nWorking on it\n[guest@joel.io /]$ ';
}
else
{
ssh.value = ssh.value + '\n-bash: ';
for (var i = 0; i < stack.length; i++)
{
ssh.value = ssh.value + stack[i];
}
ssh.value = ssh.value + ': command not found\n[guest@joel.io /]$ ';
document.term.ssh.focus();
}
ssh.value = ssh.value.replace(/\r\n$/g, '');
document.term.ssh.focus();
// We should probably destory the stack too
stack = new Array();
}
else
{
stack.push(charCode);
}
}
</script>
</head>
<body
style="align: center; text-align: center;"
onLoad="load()"
>
<form name=term>
<textarea
name=ssh
id=ssh
rows=35
cols=95
onKeypress="process(event);"
>
</textarea>
</form>
</body>
</html>