Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local parentShell = shell
- local bExit = false
- local sDir = (parentShell and parentShell.dir()) or ""
- local sPath = (parentShell and parentShell.path()) or ".:/rom/programs"
- local tAliases = (parentShell and parentShell.aliases()) or {}
- local tProgramStack = {}
- local w,h = term.getSize()
- local version = "0.8"
- local shell = {}
- local tCommands = {
- ["disk"] = function() if fs.exists("/disk") and fs.isDir("/disk") then sDir = "/disk" else print("Disk not found") end end,
- ["appstore"] = function() if term.isColor then launchAppStore() else print("Adv. Computer needed") end end,
- ["version"] = function() print(version) end,
- ["about"] = function() print("SkySHELL was made by AutoLocK") end,
- ["msg"] = function() write("Message> ") local msg = read() write("ID> ") local id = tonumber(read()) write("Modem Side> ") local side = read() rednet.open(side) rednet.send(id,msg) end,
- ["broadcast"] = function() write("Message> ") local msg = read() write("Modem Side> ") local side = read() rednet.open(side) rednet.broadcast(msg) end,
- ["list"] = function() print("/disk - Goes to Disk's directory") print("/appstore - Runs the Appstore") print("/version - Prints version") print("/about - About SkySHELL") print("/msg - Sends a message to an ID") print("/broadcast - Broadcasts a message") print("/list - Lists all commands") end,
- }
- local appCodes = {
- ["FileManager"] = { code = "pnzdr8FB" },
- ["NPaintPro"] = { code = "udDhEHeV" },
- ["LuaIDE"] = { code = "vyAZc6tJ" },
- ["SavviAnimation"] = { code = "ePY9eCDH" },
- ["LightShot"] = { code = "g0nVKvgr" },
- ["FireWolf"] = { code = "bY8YDUJ1" },
- ["Thunderhawk"] = { code = "R9Eb4XuG" },
- ["RPGame"] = { code = "COMING" }
- }
- local tEnv = {
- ["shell"] = shell,
- }
- -- GUI Colors
- if term.isColor() then
- promptColor = colors.lime
- textColor = colors.lime
- bgColor = colors.black
- tBarTCol = colors.white
- tBarBCol = colors.lime
- highlightColour = colours.white
- keywordColour = colours.lime
- commentColour = colours.magenta
- stringColour = colours.orange
- else
- promptColor = colors.white
- textColor = colors.white
- bgColor = colors.black
- tBarTCol = colors.black
- tBarBCol = colors.white
- highlightColour = colours.white
- keywordColour = colours.white
- commentColour = colours.white
- stringColour = colours.white
- end
- -- Neutral Functions
- local function run( _sCommand, ... )
- local sPath = shell.resolveProgram( _sCommand )
- if sPath ~= nil then
- tProgramStack[#tProgramStack + 1] = sPath
- local result = os.run( tEnv, sPath, ... )
- tProgramStack[#tProgramStack] = nil
- return result
- else
- printError( "No such program" )
- return false
- end
- end
- local function runLine( _sLine )
- local tWords = {}
- for match in string.gmatch( _sLine, "[^ \t]+" ) do
- table.insert( tWords, match )
- end
- local sCommand = tWords[1]
- if sCommand then
- return run( sCommand, unpack( tWords, 2 ) )
- end
- return false
- end
- function shell.run( ... )
- return runLine( table.concat( { ... }, " " ) )
- end
- function shell.exit()
- bExit = true
- end
- function shell.dir()
- return sDir
- end
- function shell.setDir( _sDir )
- sDir = _sDir
- end
- function shell.path()
- return sPath
- end
- function shell.setPath( _sPath )
- sPath = _sPath
- end
- function shell.resolve( _sPath )
- local sStartChar = string.sub( _sPath, 1, 1 )
- if sStartChar == "/" or sStartChar == "\\" then
- return fs.combine( "", _sPath )
- else
- return fs.combine( sDir, _sPath )
- end
- end
- function shell.resolveProgram( _sCommand )
- if tAliases[ _sCommand ] ~= nil then
- _sCommand = tAliases[ _sCommand ]
- end
- local sStartChar = string.sub( _sCommand, 1, 1 )
- if sStartChar == "/" or sStartChar == "\\" then
- local sPath = fs.combine( "", _sCommand )
- if fs.exists( sPath ) and not fs.isDir( sPath ) then
- return sPath
- end
- return nil
- end
- for sPath in string.gmatch(sPath, "[^:]+") do
- sPath = fs.combine( shell.resolve( sPath ), _sCommand )
- if fs.exists( sPath ) and not fs.isDir( sPath ) then
- return sPath
- end
- end
- return nil
- end
- function shell.programs( _bIncludeHidden )
- local tItems = {}
- for sPath in string.gmatch(sPath, "[^:]+") do
- sPath = shell.resolve( sPath )
- if fs.isDir( sPath ) then
- local tList = fs.list( sPath )
- for n,sFile in pairs( tList ) do
- if not fs.isDir( fs.combine( sPath, sFile ) ) and
- (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= ".") then
- tItems[ sFile ] = true
- end
- end
- end
- end
- -- Sort and return
- local tItemList = {}
- for sItem, b in pairs( tItems ) do
- table.insert( tItemList, sItem )
- end
- table.sort( tItemList )
- return tItemList
- end
- function shell.getRunningProgram()
- if #tProgramStack > 0 then
- return tProgramStack[#tProgramStack]
- end
- return nil
- end
- function shell.setAlias( _sCommand, _sProgram )
- tAliases[ _sCommand ] = _sProgram
- end
- function shell.clearAlias( _sCommand )
- tAliases[ _sCommand ] = nil
- end
- function shell.aliases()
- local tCopy = {}
- for sAlias, sCommand in pairs( tAliases ) do
- tCopy[sAlias] = sCommand
- end
- return tCopy
- end
- function draw_tBar()
- term.setTextColor(tBarTCol)
- term.setBackgroundColor(tBarBCol)
- term.setCursorPos(1,1)
- term.clearLine()
- term.setCursorPos(1,1)
- print("SkySHELL "..version)
- term.setTextColor(tBarTCol)
- term.setBackgroundColor(tBarBCol)
- term.setCursorPos(51-#sDir,1)
- print(sDir)
- end
- function as_drawBox(X,Y,W,H,title,color1,color2,bClosable)
- moveY = Y+1
- term.setCursorPos(X,Y)
- term.setBackgroundColor(color1)
- term.setTextColor(color2)
- print(string.rep(" ",W))
- term.setCursorPos(X,Y)
- print(title)
- term.setCursorPos(X,Y+1)
- term.setBackgroundColor(color2)
- for i=1,H-1 do
- term.setCursorPos(X,moveY)
- print(string.rep(" ",W))
- moveY = moveY + 1
- end
- if bClosable == true then
- term.setCursorPos(X+W-1,Y)
- term.setTextColor(colors.red)
- term.setBackgroundColor(color1)
- print("X")
- end
- end
- function as_addApp(guiname,name,code,x,y,color1,color2)
- as_drawBox(x,y,10,7,guiname,color1,color2,false)
- term.setCursorPos(x+1,y+2)
- term.setTextColor(textColor)
- print("Code:")
- term.setCursorPos(x+1,y+3)
- print(code)
- term.setTextColor(color2)
- term.setBackgroundColor(color1)
- if fs.exists("/Skyrom/Apps/"..name) then
- term.setCursorPos(x+1,y+5)
- print(" Launch ")
- else
- term.setCursorPos(x,y+5)
- print(" Download ")
- end
- end
- function as_downloadApp(name,code)
- local appFile = http.get("http://pastebin.com/raw.php?i="..textutils.urlEncode(code))
- local appCont = appFile.readAll()
- appFile.close()
- local file = fs.open("/Skyrom/Apps/"..name,"w")
- file.write(appCont)
- file.close()
- return true
- end
- function as_drawGUI()
- term.setBackgroundColor(bgColor)
- term.clear()
- as_addApp("FileManag.","FileManager",appCodes["FileManager"].code,2,2,colors.red,colors.white)
- as_addApp("NPaintPro","NPaintPro",appCodes["NPaintPro"].code,2,10,colors.green,colors.white)
- as_addApp("LuaIDE","LuaIDE",appCodes["LuaIDE"].code,15,2,colors.blue,colors.white)
- as_addApp("SavviAnim.","SavviAnimation",appCodes["SavviAnimation"].code,15,10,colors.orange,colors.white)
- as_addApp("LightShot","LightShot",appCodes["LightShot"].code,28,2,colors.blue,colors.white)
- as_addApp("FireWolf","FireWolf",appCodes["FireWolf"].code,28,10,colors.blue,colors.white)
- as_addApp("Thunderha.","Thunderhawk",appCodes["Thunderhawk"].code,41,2,colors.blue,colors.white)
- as_addApp("RPGame","RPGame",appCodes["RPGame"].code,41,10,colors.orange,colors.white)
- term.setCursorPos(16,18)
- term.setBackgroundColor(bgColor)
- term.setTextColor(promptColor)
- print("Press 'Enter' to Exit")
- end
- function launchAppStore()
- as_drawGUI()
- while true do
- local event,button,X,Y = os.pullEvent()
- if event == "mouse_click" then
- if X >= 2 and X <= 12 and Y == 7 and button == 1 then
- if fs.exists("/Skyrom/Apps/FileManager") then
- shell.run("/Skyrom/Apps/FileManager")
- sleep(.1)
- else
- local status = as_downloadApp("FileManager",appCodes["FileManager"].code)
- if status == true then
- term.setCursorPos(4,6)
- term.setBackgroundColor(colors.black)
- term.setTextColor(Colors.red)
- print("Complete!")
- sleep(1)
- as_drawGUI()
- else
- term.setCursorPos(4,6)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.red)
- print("Failure!")
- sleep(1)
- as_drawGUI()
- end
- end
- elseif X >= 2 and X <= 12 and Y == 15 and button == 1 then
- if fs.exists("/Skyrom/Apps/NPaintPro") then
- shell.run("/Skyrom/Apps/NPaintPro")
- sleep(.1)
- else
- local status = as_downloadApp("NPaintPro",appCodes["NPaintPro"].code)
- if status == true then
- term.setCursorPos(4,12)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lime)
- print("Complete!")
- sleep(1)
- as_drawGUI()
- else
- term.setCursorPos(4,12)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lime)
- print("Failure!")
- sleep(1)
- as_drawGUI()
- end
- end
- elseif X >= 15 and X <= 25 and Y == 7 and button == 1 then
- if fs.exists("/Skyrom/Apps/LuaIDE") then
- shell.run("/Skyrom/Apps/LuaIDE")
- sleep(.1)
- else
- local status = as_downloadApp("LuaIDE",appCodes["LuaIDE"].code)
- if status == true then
- term.setCursorPos(15,7)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- print("Complete!")
- sleep(1)
- as_drawGUI()
- else
- term.setCursorPos(15,12)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- sleep(1)
- as_drawGUI()
- end
- end
- elseif X >= 15 and X <= 25 and Y == 15 and button == 1 then
- if fs.exists("/Skyrom/Apps/SavviAnimation") then
- shell.run("/Skyrom/Apps/SavviAnimation")
- sleep(.1)
- else
- local status = as_downloadApp("SavviAnimation",appCodes["SavviAnimation"].code)
- if status == true then
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.orange)
- print("Complete!")
- sleep(1)
- as_drawGUI()
- else
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.orange)
- print("Failure!")
- sleep(1)
- as_drawGUI()
- end
- end
- elseif X >= 28 and X <= 38 and Y == 7 and button == 1 then
- if fs.exists("/Skyrom/Apps/LightShot") then
- shell.run("/Skyrom/Apps/LightShot")
- sleep(.1)
- else
- local status = as_downloadApp("LightShot",appCodes["LightShot"].code)
- if status == true then
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- print("Complete!")
- sleep(1)
- as_drawGUI()
- else
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- print("Failure!")
- sleep(1)
- as_drawGUI()
- end
- end
- elseif X >= 28 and X <= 38 and Y == 15 and button == 1 then
- if fs.exists("/Skyrom/Apps/FireWolf") then
- shell.run("/Skyrom/Apps/FireWolf")
- sleep(.1)
- else
- local status = as_downloadApp("FireWolf",appCodes["FireWolf"].code)
- if status == true then
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- print("Complete!")
- sleep(1)
- as_drawGUI()
- else
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- print("Failure!")
- sleep(1)
- as_drawGUI()
- end
- end
- elseif X >= 40 and X <= 50 and Y == 7 and button == 1 then
- if fs.exists("/Skyrom/Apps/Thunderhawk") then
- shell.run("/Skyrom/Apps/Thunderhawk")
- sleep(.1)
- else
- local status = as_downloadApp("Thunderhawk",appCodes["Thunderhawk"].code)
- if status == true then
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- print("Complete!")
- sleep(1)
- as_drawGUI()
- else
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.blue)
- print("Failure!")
- sleep(1)
- as_drawGUI()
- end
- end
- elseif X >= 40 and X <= 50 and Y == 15 and button == 1 then
- if fs.exists("/Skyrom/Apps/RPGame") then
- shell.run("/Skyrom/Apps/RPGame")
- sleep(.1)
- else
- local status = as_downloadApp("RPGame",appCodes["RPGame"].code)
- if status == true then
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.orange)
- print("Complete!")
- sleep(1)
- as_drawGUI()
- else
- term.setCursorPos(15,15)
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.orange)
- print("Failure!")
- sleep(1)
- as_drawGUI()
- end
- end
- else
- as_drawGUI()
- end
- elseif event == "key" then
- if button == keys.enter then
- term.setBackgroundColor(bgColor)
- term.clear()
- draw_tBar()
- break
- else
- as_drawGUI()
- end
- end
- end
- end
- term.clear()
- draw_tBar()
- term.setTextColor(textColor)
- term.setBackgroundColor(bgColor)
- if not fs.exists("/Skyrom") and not fs.isDir("/Skyrom") then
- fs.makeDir("/Skyrom")
- fs.makeDir("/Skyrom/Apps")
- elseif fs.exists("/Skyrom") and not fs.isDir("/Skyrom") then
- fs.move("/Skyrom","/OLD.Skyrom")
- fs.makeDir("/Skyrom")
- fs.makeDir("/Skyrom/Apps")
- end
- -- Run DISK Startup
- local sDiskStartup = shell.resolveProgram( "/disk/startup" )
- if sDiskStartup then
- print("Launch disk?")
- term.setTextColor( promptColor )
- write("> ")
- term.setTextColor( textColor )
- local answer = string.lower(read())
- if answer == "yes" then
- shell.run("/disk/startup")
- sleep(1)
- term.clear()
- draw_tBar()
- elseif answer == "y" then
- shell.run("/disk/startup")
- sleep(1)
- term.clear()
- draw_tBar()
- elseif answer == "no" then
- print("Ignored.")
- sleep(1)
- term.clear()
- draw_tBar()
- elseif answer == "n" then
- print("Ignored.")
- sleep(1)
- term.clear()
- draw_tBar()
- else
- if sUserStartup then
- shell.run( sUserStartup )
- sleep(1)
- term.clear()
- draw_tBar()
- else
- term.clear()
- draw_tBar()
- end
- end
- -- If not DISK Startup then run USER Startup
- elseif sUserStartup then
- shell.run( sUserStartup )
- sleep(1)
- term.clear()
- draw_tBar()
- end
- -- Reads commands and runs them
- local tCommandHistory = {}
- draw_tBar()
- while not bExit do
- term.setBackgroundColor( bgColor )
- term.setTextColor( promptColor )
- write("> ")
- term.setTextColor(textColor)
- local sLine = read(nil,tCommandHistory)
- table.insert(tCommandHistory,sLine)
- if string.lower(sLine) == "clear" then
- runLine(sLine)
- draw_tBar()
- elseif string.lower(sLine:sub(1,1)) == "/" then
- if tCommands[sLine:sub(2,#sLine)] then
- tCommands[sLine:sub(2,#sLine)]()
- else
- printError("Command unknown")
- end
- elseif string.lower(sLine:sub(1,4)) == "edit" then
- runLine(sLine)
- draw_tBar()
- else
- runLine(sLine)
- local x,y = term.getCursorPos()
- draw_tBar()
- term.setCursorPos(x,y)
- end
- end
- if parentShell == nil then
- if shell.resolveProgram( "shutdown" ) then
- shell.run( "shutdown" )
- end
- os.shutdown()
- end
Advertisement
Add Comment
Please, Sign In to add comment