Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- VERSION = 7
- os.pullEvent = os.pullEventRaw
- --Install stuff if missing
- if(fs.exists("/CLI/API/cprint"))then
- os.loadAPI("/CLI/API/cprint")
- else
- shell.run("pastebin get QR1qTMtm CLI/API/cprint")
- os.reboot()
- end
- if(fs.exists("/CLI/Skins"))then
- else
- fs.makeDir("/CLI/Skins")
- end
- if(fs.exists("/CLI/Settings"))then
- else
- fs.makeDir("/CLI/Settings")
- end
- if(fs.exists("/CLI/Settings/skin"))then
- else
- defaultskin=fs.open("/CLI/Settings/skin","w")
- defaultskin.write("/CLI/Skins/default")
- defaultskin.close()
- end
- if(fs.exists("/CLI/Skins/default"))then
- else
- shell.run("pastebin get gVatgky8 /CLI/Skins/default")
- os.reboot()
- end
- print("Exiting CraftOS")
- sleep(1)
- term.clear()
- term.setCursorPos(1,1)
- print("Starting CLI")
- for i = 1, 100, 1 do
- term.setCursorPos(1,1)
- print("Starting CLI "..i.."% ")
- term.setCursorPos(1,2)
- if(i == 1)then
- print("Loading kernel ")
- elseif(i == 13)then
- print("Loading file system ")
- elseif(i == 26)then
- print("Loading APIs ")
- elseif(i == 43)then
- print("Locking you in ")
- elseif(i == 87)then
- print("Applying your settings ")
- end
- sleep(math.random()/8)
- end
- term.clear()
- term.setCursorPos(1,1)
- print("It works! This is the default web page for this server.")
- sleep(1)
- function helpprint(cmd, desc)
- term.setTextColor(s.textColor)
- write(cmd)
- term.setTextColor(s.textColorLight)
- print(" - "..desc)
- end
- function errorprint(desc)
- --term.setTextColor(s.errorColor)
- --write(s.errorText)
- --term.setTextColor(s.errorColorLight)
- --print(desc)
- cprint.cprint(string.gsub(s.text.errorFormat,"*s",desc))
- end
- function string.starts(String,Start)
- return string.sub(String,1,string.len(Start))==Start
- end
- function string.ends(String,End)
- return End=='' or string.sub(String,-string.len(End))==End
- end
- function loadSave()
- defaultskin=fs.open("/CLI/Settings/skin","r")
- dir = defaultskin.readAll()
- defaultskin.close()
- s={text={errorFormat = "&1Error: *s"}}
- dir = formatPath(dir,"","",true)
- if(dir == false)then
- loadSkin("/CLI/Skins/default")
- errorprint("Error loading your skin. Make sure it still exists. Type 'skin resetdefault' to reset the default skin")
- sleep(10)
- else
- loadSkin(dir)
- end
- s2 = {
- textColor = colors.white,
- textColorLight = colors.lightGray,
- bgColor = colors.black,
- lsFolder = colors.white,
- lsFile = colors.lightGray,
- text = {
- cmdFormat = "&0*p> ",
- errorFormat = "Error: *s"}}
- end
- function loadSkin(file)
- pt = formatPath(file,path,"",true)
- if(pt == false)then
- return(false)
- else
- skin = fs.open(formatPath(file,path,"",true),"r")
- end
- skn = skin.readAll()
- skin.close()
- s = textutils.unserialize(skn)
- end
- function saveSkin(file)
- skin=fs.open(formatPath(file,path,"",false),"w")
- skin.write(textutils.serialize(s))
- skin.close()
- end
- function formatPath(file,current,enchar,reqExist)
- local pathb = current
- local cpath = current
- local echar = enchar
- local allowerror = true
- if(enchar == "//")then
- allowerror = false
- echar = "/"
- end
- if(string.ends(file,enchar))then echar = "" end
- if(string.starts(file,"/"))then
- cpath = file..echar
- elseif(string.starts(file,"~"))then
- cpath = string.gsub (file, "~", home)..echar
- else
- cpath = cpath..file..echar
- end
- if(reqExist)then
- if(fs.exists(cpath))then
- if(fs.isDir(cpath))then
- if(enchar == "")then
- if allowerror then errorprint("File not found") end
- return(false)
- end
- else
- if(enchar == "/")then
- if allowerror then errorprint("Directory not found") end
- return(pathb)
- end
- end
- else
- if(enchar == "/")then
- if allowerror then errorprint("Directory not found") end
- return(pathb)
- else
- if allowerror then errorprint("File not found") end
- return(false)
- end
- return(pathb)
- end
- end
- return(cpath)
- end
- loadSave()
- if(tonumber((http.get("http://pastebin.com/raw.php?i=XE9Hbau4")).readAll()) > VERSION)then
- fs.delete("install")
- startup=fs.open("startup","w")
- startup.write('shell.run("update")')
- startup.close()
- os.reboot()
- else
- term.setBackgroundColor(s.bgColor)
- term.clear()
- term.setCursorPos(1,1)
- home = "/CLI/Usr"
- path = "/CLI/Usr/"
- user = "User"
- computerName = "CLI"
- while true do
- term.setBackgroundColor(s.bgColor)
- term.setTextColor(s.textColor)
- pathv = path
- pathv = string.gsub (pathv, home, "~")
- gsubbed = string.gsub (string.gsub (string.gsub (s.text.cmdFormat, "*u", user),"*c",computerName),"*p",pathv)
- cprint.cwrite(gsubbed)
- command = read()
- if(command == "help")then
- print("Help:")
- helpprint("help", "List commands")
- helpprint("shutdown", "Shut down the OS")
- helpprint("reboot", "Reboot the OS with no warning")
- helpprint("cd <directory>", "Switch directories")
- helpprint("ls", "List content of current directory")
- helpprint("pwd", "Display current directory")
- helpprint("skin", "Skin your CLI")
- helpprint("clear", "Clear the screen")
- helpprint("mkdir <path>","Creates a directory")
- helpprint("open <file>","Opens <file>")
- helpprint("edit <file>","Edits <file>")
- helpprint("rm <file>","Deletes <file>")
- elseif (command == "exit")then
- print("Do you really think I'd let you out that easily?")
- sleep(1)
- textutils.slowPrint("Don't exit don't exit don't exit don't exit")
- os.reboot()
- elseif (command == "shutdown")then
- os.shutdown()
- elseif (command == "reboot")then
- os.reboot()
- elseif (command=="")then
- elseif (command=="clear")then
- term.clear()
- term.setCursorPos(1,1)
- elseif (command=="ls")then
- local tArgs = { ... }
- local sDir = path
- local tAll = fs.list( sDir )
- local tFiles = {}
- local tDirs = {}
- for n, sItem in pairs( tAll ) do
- if string.sub( sItem, 1, 1 ) ~= "." then
- local sPath = fs.combine( sDir, sItem )
- if fs.isDir( sPath ) then
- table.insert( tDirs, sItem )
- else
- table.insert( tFiles, sItem )
- end
- end
- end
- table.sort( tDirs )
- table.sort( tFiles )
- textutils.pagedTabulate( s.lsFolder, tDirs, s.lsFile, tFiles )
- elseif (command=="pwd")then
- print(path)
- else
- words = {}
- for word in command:gmatch("%S+") do table.insert(words, word) end
- --print(table.concat(words,","))
- length = table.maxn(words)
- if(words[1] == "cd")then
- if(length == 2)then
- -- local pathb = path
- -- local echar = "/"
- -- if(string.ends(words[2],"/"))then echar = "" end
- -- if(string.starts(words[2],"/"))then
- -- path = words[2]..echar
- -- elseif(string.starts(words[2],"~"))then
- -- path = string.gsub (words[2], "~", home)..echar
- -- else
- -- path = path..words[2]..echar
- -- end
- -- if(fs.exists(path))then
- -- if(fs.isDir(path))then
- -- else
- -- errorprint("Directory not found")
- -- path = pathb
- -- end
- -- else
- -- errorprint("Directory not found")
- -- path = pathb
- -- end
- path = formatPath(words[2],path,"/",true)
- else
- helpprint("Usage", "cd <directory>")
- end
- elseif(words[1] == "yes")then
- print("You don't want to do that...")
- elseif(words[1] == "open")then
- if(length > 1)then
- local files = formatPath(words[2],path,"",true)
- local args = ""
- if(length > 2)then
- args = words
- table.remove(args, 1)
- table.remove(args, 1)
- args = table.concat(args," ")
- args = " "..args
- end
- if(not files == false)then
- shell.run("cd "..path)
- shell.run(files..args)
- end
- else
- helpprint("open <file>","Opens <file>")
- end
- elseif(words[1] == "edit")then
- if(length == 2)then
- shell.run('edit '..formatPath(words[2],path,"",false))
- else
- helpprint("edit <file>","Edits <file>")
- end
- elseif(words[1] == "mv" or words[1] == "cp")then
- if(length == 3)then
- olddir = formatPath(words[2],path,"//",true)
- if(olddir == false)then
- olddir = formatPath(words[2],path,"",true)
- end
- if(olddir == false)then
- else
- newdir = formatPath(words[3],path,"//",false)
- if(newdir == false)then
- newdir = formatPath(words[3],path,"",false)
- end
- if(newdir == false)then
- else
- if(fs.exists(newdir))then
- errorprint(words[3].." already exists")
- else
- if(words[1] == "mv")then
- fs.move(olddir,newdir)
- elseif(words[1] == "cp")then
- fs.copy(olddir,newdir)
- end
- end
- end
- end
- else
- helpprint("mv <oldlocation> <newlocation>","Moves oldlocation to newlocation")
- helpprint("cp <file> <newlocation>","Copies file and puts it at newlocation")
- end
- elseif(words[1] == "rm")then
- if(length == 2)then
- files = formatPath(words[2],path,"//",true)
- if(files == path)then
- files = formatPath(words[2],path,"",true)
- write("Are you sure y/n? ")
- if(read()=="y")then
- fs.delete(files)
- end
- else
- write("Are you sure y/n? ")
- if(read()=="y")then
- fs.delete(files)
- end
- end
- else
- helpprint("rm <file>","Deletes <file>")
- end
- elseif(words[1] == "mkdir")then
- if(length == 2)then
- fs.makeDir(formatPath(words[2],path,"/",false))
- else
- helpprint("mkdir <path>","Creates a directory")
- end
- elseif(words[1] == "skin")then
- if(length == 4)then
- if(words[2] == "download")then
- shell.run("pastebin get "..words[3].." "..formatPath(words[4],path,"",false))
- end
- elseif(length == 3)then
- if(words[2] == "save")then
- saveSkin(words[3])
- elseif(words[2] == "load")then
- loadSkin(words[3])
- elseif(words[2] == "setdefault")then
- defaultskin=fs.open("/CLI/Settings/skin","w")
- defaultskin.write(formatPath(words[3],path,"",true))
- defaultskin.close()
- elseif(words[2] == "resetdefault")then
- defaultskin=fs.open("/CLI/Settings/skin","w")
- defaultskin.write("/CLI/Skins/default")
- defaultskin.close()
- end
- elseif(length == 2)then
- if(words[2] == "edit")then
- term.clear()
- term.setCursorPos(1,1)
- local editing = true
- while editing do
- term.setBackgroundColor(s.bgColor)
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColor(s.textColor)
- print("Skin preview:")
- local gsubbed = string.gsub (string.gsub (string.gsub (s.text.cmdFormat, "*u", user),"*c",computerName),"*p",pathv)
- cprint.cprint(gsubbed.."help")
- term.setTextColor(s.textColor)
- helpprint("Light text", "Dark text")
- term.setTextColor(s.textColor)
- errorprint("File not found")
- term.setTextColor(s.textColor)
- term.setTextColor(s.lsFolder)
- write("Folder ")
- term.setTextColor(s.lsFile)
- print("File")
- term.setTextColor(s.textColor)
- local w, h = term.getSize()
- print("Commands:")
- helpprint("edit text","Edit the main text colors for CLI")
- helpprint("edit ls","Edit the colors for the ls command")
- helpprint("edit error","Complex: Change how error messages display")
- helpprint("edit shell","Complex: Edit your command prompt (~/> command)")
- helpprint("exit","Get me out of here")
- term.setCursorPos(1,h-2)
- term.clearLine()
- term.setCursorPos(1,h-1)
- term.clearLine()
- term.setCursorPos(1,h)
- write("> ")
- local cmd = read()
- if(cmd == "exit")then
- editing = false
- elseif(cmd == "edit text")then
- if(true)then -- Edit text
- term.setCursorPos(1,h-2)
- cprint.cwrite("&0Colors: &11&22&33&44&55&66&77&88&99&00&aa&bb&cc&dd&ee&ff")
- term.setCursorPos(1,h)
- term.setTextColor(s.textColor)
- write("Normal text color > ")
- local subcmd = read()
- if(subcmd == "")then
- else
- s.textColor = cprint.cCode(subcmd)
- end
- term.setCursorPos(1,h-2)
- cprint.cwrite("&0Colors: &11&22&33&44&55&66&77&88&99&00&aa&bb&cc&dd&ee&ff")
- term.setCursorPos(1,h)
- term.setTextColor(s.textColorLight)
- write("Light text color > ")
- local subcmd = read()
- if(subcmd == "")then
- else
- s.textColorLight = cprint.cCode(subcmd)
- end
- term.setCursorPos(1,h-2)
- cprint.cwrite("&0Colors: +11+22+33+44+55+66+77+88+99+00+aa+bb+cc+dd+ee+ff")
- term.setCursorPos(1,h)
- term.setTextColor(s.textColorLight)
- write("Background color > ")
- local subcmd = read()
- if(subcmd == "")then
- else
- s.bgColor = cprint.cCode(subcmd)
- end
- end
- elseif(cmd == "edit error")then
- term.setCursorPos(1,h-4)
- print("Use & then a color code for a color (EX: &2)")
- term.setCursorPos(1,h-3)
- cprint.cwrite("*s will be replaced with the error message")
- term.setCursorPos(1,h-2)
- cprint.cwrite("&0Colors: &11&22&33&44&55&66&77&88&99&00&aa&bb&cc&dd&ee&ff")
- term.setCursorPos(1,h-1)
- term.setTextColor(s.textColor)
- write("Example: &bError! *s")
- term.setCursorPos(1,h)
- term.setTextColor(s.textColor)
- write("Error text > ")
- local subcmd = read()
- if(subcmd == "")then
- else
- s.text.errorFormat = subcmd
- end
- elseif(cmd == "edit shell")then
- term.setCursorPos(1,h-4)
- print("Use & then a color code for a color (EX: &2)")
- term.setCursorPos(1,h-3)
- cprint.cwrite("*u for your user *c for your computername *p for your current directory ")
- term.setCursorPos(1,h-2)
- cprint.cwrite("&0Colors: &11&22&33&44&55&66&77&88&99&00&aa&bb&cc&dd&ee&ff")
- term.setCursorPos(1,h-1)
- term.setTextColor(s.textColor)
- write("Example: &1*p &3>")
- term.setCursorPos(1,h)
- term.setTextColor(s.textColor)
- write("Prompt text > ")
- local subcmd = read()
- if(subcmd == "")then
- else
- s.text.cmdFormat = subcmd
- end
- elseif(cmd == "edit ls")then
- term.setCursorPos(1,h-2)
- cprint.cwrite("&0Colors: &11&22&33&44&55&66&77&88&99&00&aa&bb&cc&dd&ee&ff")
- term.setCursorPos(1,h)
- term.setTextColor(s.lsFolder)
- write("Folder text color > ")
- local subcmd = read()
- if(subcmd == "")then
- else
- s.lsFolder = cprint.cCode(subcmd)
- end
- term.setCursorPos(1,h-2)
- cprint.cwrite("&0Colors: &11&22&33&44&55&66&77&88&99&00&aa&bb&cc&dd&ee&ff")
- term.setCursorPos(1,h)
- term.setTextColor(s.lsFile)
- write("File text color > ")
- local subcmd = read()
- if(subcmd == "")then
- else
- s.lsFile = cprint.cCode(subcmd)
- end
- end
- end
- end
- else
- helpprint("skin save <filename>", "Saves the current skin to <filename>")
- helpprint("skin load <filename>", "Loads the skin at <filename>")
- helpprint("skin setdefault <filename>", "Automaticly loads the skin at <filename> on startup")
- helpprint("skin edit", "Edit your current skin")
- helpprint("skin download <code> <name>", "Download a skin off pastebin")
- end
- else
- helpprint("help", "List commands")
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement