MOS
Micro Operating System
by fordcars
HTML
<body id="bodyId">
<h1>MOS: Micro Operating System</h1>
<canvas id="canId" width="300" height="300">Doh! You're browser doesn't support the canvas tag, sorry!</canvas>
<br/>
<input type="text" id="inputId"/>
<br/>
<input type="button" id="butId" value="Enter"/>
</body>
CSS
canvas {background-color:#000000;}
JavaScript
var butNode;
var inputNode;
var eventClick;
var canNode;
var can;
var lineArray;
var inProgram;
var rootArray;
var curArray;
window.onload = boot();
function boot()
{
lineArray = [];
inProgram = "commandLine";
rootArray = ["root","dir"];
curArray = rootArray;
butNode = document.getElementById("butId");
inputNode = document.getElementById("inputId");
canNode = document.getElementById("canId");
can = canNode.getContext("2d");
can.font = "20px Courier New";
can.fillStyle = "lime";
eventClick = butNode.addEventListener("click",enterPressed,false);
newLine("Initialised variables",false,"yellow");
}
function newLine(lineString,withSymbol,colorArg)
{
can.font = "20px Courier New";
can.fillStyle = "lime";
can.clearRect(0,0,300,300);
var lineObj = {};
lineObj.xLoc = 300;
if(withSymbol===true)
{
lineObj.text = "$" + lineString;
}
else
{
lineObj.text = lineString;
}
if(colorArg!=="" || colorArg!==undefined)
{
lineObj.txtColor = colorArg;
}
if(colorArg===undefined || colorArg==="")
{
lineObj.txtColor="lime"; //If no color specified, change color to lime
}
lineArray.push(lineObj);
for(i=0;i<lineArray.length;i++)
{
lineArray[i].xLoc = lineArray[i].xLoc - 20;
if(lineArray[i].xLoc < 15)
{
lineArray.splice(i,1);
i = i - 1;
}
else
{
can.fillStyle = lineArray[i].txtColor;
can.fillText(lineArray[i].text,0,lineArray[i].xLoc);
}
}
}
function enterPressed()
{
var inputValue = inputNode.value;
if(inProgram==="commandLine")
{
inputNode.value = "";
newLine(inputValue,true);
checkCommand(inputValue);
return;
}
if(inProgram==="nd")
{
for(i=2;i<curArray.length;i++) //i=2 since first and second array cells are directory...