@name KOSTER MINGE OS
@inputs S:wirelink K
@persist X Y Cmdbuf:string CmdExec Prefix:string True False

runOnTick(1)

#MingeOS
if(first()){
	True = 1
	False = 0
	S[2041] = True
	Prefix = ">:"

	S:writeString("minge os",X,Y)
	Y++
	S:writeString(Prefix,X,Y)
}


if(~K & K){
	if(K>32&K<127){
		S:writeString(toChar(K),X,Y)
		X++
		Cmdbuf += toChar(K)
	}
	if(K == 13){
		Y++
		CmdExec = True
		X = 0
	}
	if(K == 127){
		X--
		Cmdbuf = Cmdbuf:left(Cmdbuf:length()-1)
		S:writeString(" ",X,Y)
	}
}
if(CmdExec){
	Args = Cmdbuf:explode(" ")
	Cmdname = Args:remove(1)
	if(Cmdname == "hax"){
		S:writeString("I USE MINGE OS!",0,Y)
		Y++
	}elseif(Cmdname == "echo"){
		Str = Args:concat(" ")
		S:writeString("minge os says:"+Str,X,Y)
		Y++
	}elseif(Cmdname == "help"){
		S:writeString("hax",X,Y)
		Y++
		S:writeString("echo <str>",X,Y)
		Y++
		S:writeString("help",X,Y)
		Y++
	}
	
	if(Y>16){
		S[2041] = True
		Y = 0
		X = 0
	}	

	S:writeString(Prefix,X,Y)
	Cmdbuf = ""
	CmdExec = 0
}