@name PotatOS
@inputs Scr:wirelink In
@persist Line CurCMD:string App Appv:array LastCMD:string
@persist ChatLast:string
@outputs Reset
#backpace 127
#enter 13
interval(500)
AppChat=gTable("AppChat")
if (first()) {#defineshit
        function out(S:string) {
        Scr:writeString(S,0,Line)
        if (Line>17) {Scr:writeString(" ":repeat(30*20),0,0) Scr:writeString("Potatos 1.0",0,0) Line=1}
        Line++
    }
    function clear() {
        Scr:writeString(" ":repeat(30*20),0,0)
        Line=0
        CurCMD=""
        out("Potatos 1.0")
    }
    
    function sendCommand() {
        LastCMD=CurCMD
        CurCMD=CurCMD:lower()
        Scr:writeString(">",0,Line)
        Line++
        if (Line>17) {clear() Line=1}
        
        
        
        if (App==0) {#main system commands
        if (CurCMD:lower():matchFirst("help")) {
            out("Why should I help you?")
        } elseif (CurCMD:lower():matchFirst("/0")) {
            out("Error: Cannot divide by zero")
            out("!!CRITICAL ERROR!!")
            error("banana problem")
        } elseif (CurCMD:lower():matchFirst("porn")) {
            out("8==D~~~ 0")
    }
}


if (App==0) {#defineapps
    if (CurCMD:lower()=="chat") {App=1}
    
}

if (App==1) {#chat

    #appvars[1] - inchat
    #appvars[2] - channel
    if (changed(App)) {
        out("Welcome to iChat!")
        out("Please type a command.")
        out("close | enter [id]")
}
    if (!Appv[1,number]) {
    if(CurCMD:sub(1,5)=="enter") {
        Appv[2,number]=CurCMD:sub(7):toNumber()
        Appv[1,number]=1
        out("Entered iCHAT"+Appv[2,number])
    }
    
    } else {
        if (CurCMD!="close") {
            AppChat[Appv[2,number],string]=LastCMD
    }
    
}
}





if (CurCMD:lower()=="close") {
    App=0
    out("!!Closed all applications")
}



        CurCMD=""
    }
    clear()
}
if (In) {
    if (In==127) {
        CurCMD=CurCMD:sub(1,CurCMD:length()-1)
    } elseif
    (In==13) {
        sendCommand()
} elseif (CurCMD:length()<29 & In!=154) {CurCMD=CurCMD+toChar(In)}
}
Scr:writeString("["+CurCMD+" ":repeat(30-CurCMD:length()),0,Line)

if (changed(Scr) & !first()) {reset()}

if (App==1 & Appv[1,number] & AppChat[1,string]!=LastCMD:lower() & changed(ChatLast)) {#ichatauto
            out("/"+AppChat[1,string])
            ChatLast=AppChat[1,string]
    }
