Ads

New Domain

Blog has been moved to new domain: www.it-googled.com Enjoy!

Monday 1 August 2011

Flex emulating sh terminal

private function keyHandler(event:KeyboardEvent):void
{
if(event.keyCode == Keyboard.ENTER){
// variable to hold user input
var command:String = userInput.text;
// variable to read from output and keep history
var history:String = console.text;
// variables to create shell like enviroment
var root:String = "root@LB:~# ";
var rootchanged:String = "root@LB:";
var i:int = 0;
// cd command (for instance cd /home)
if (command.charAt(0) == "c" && command.charAt(1) == "d"){
var words:Array = command.split(" ");
var changedcurrent:String = words[1];
console.text = history + rootchanged + changedcurrent + "#" + "\n"}
else{
//arrays that holds possbile commands and output
known.push("pwd","ls","arp","help");
answer.push("/root" ,"filezilla3","192.168.25.254 either 00:50:56:f0:87:d2 eth1","pwd, ls, arp, help");
hint.push("help");
// loop through known commands
for (i=0; i if(userInput.text == known[i]){
//displaying output
console.text = history + root + userInput.text + "\n"+ answer[i] + "\n"
}}}}}

Primitive type is to be replaced by more object-oriented approach.

No comments:

Post a Comment