Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --]] CC-DOS Interface By: Redxone [[--
- -- IGN: trainerred2000
- -- BIOS: MultMine
- -- Project Leader: Gonow32 :)
- local _osver = "CS-DOS v3.5"
- local _DOS = {
- setpos = term.setCursorPos,
- setback = term.setBackgroundColor,
- settext = term.setTextColor,
- clear = function() term.clear() term.setCursorPos(1,1) end;
- inDir = "",
- input_history = {};
- isCmd = false,
- run = true,
- getScreenSize = term.getSize,
- runProg = shell.run,
- breakpath = function(inputstr, sep)
- i=1
- t={}
- s=""
- ki=0
- for str in string.gmatch(inputstr, "([^/]+)") do
- t[i] = str
- i = i + 1
- end
- for k, v in pairs(t) do
- ki=k
- end
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- for k, v in pairs(t) do
- if(k <= ki-1)then s = s..t[k].."/" end
- end
- return s
- end,
- getfiles = function(self,dir)
- self.settext(colors.white)
- dir=dir.."/"
- local dirs = {}
- local files = {}
- print("Directory of :"..dir..".")
- for k, v in pairs(fs.list(dir)) do
- if(fs.isDir(dir..v))then table.insert(dirs,v)
- else table.insert(files,v) end
- end
- textutils.tabulate(colors.orange, dirs, colors.white, files)
- end,
- cmds = {
- {name="cd",desc="Change directory",run=function(self,v)
- if(v=="" or v==" ")then print("The syntax of the command is incorrect. \n") return end
- if(fs.exists(shell.resolve(v)))then
- shell.setDir(shell.resolve(v))
- else
- self.settext(colors.red)
- print("Unknown directory: "..shell.resolve(v).."\n")
- self.settext(colors.white)
- end
- end};
- {name="reload",desc="Reload CS-DOS",run=function(self,v) self.run=false self.runProg(shell.getRunningProgram()) return end};
- {name="exit",desc="Exits shell",run = function(self, v) self.run = false return end};
- {name="error",desc="Test error message",run = function(self, v) error("Exception Caught!") end};
- {name="cls",desc="Clear screen",run = function(self, v) self.clear() end};
- {name="edit",desc="Edit a file",run = function(self, v) if(v=="" or v==" ")then print("The syntax of the command is incorrect. \n") end self.runProg("edit",v) end};
- {name="dir",desc="Lists files and directorys",run = function(self, v) self.getfiles(self,shell.resolve(v)) end};
- {name="help",desc="Lists all commands",run = function(self, v)
- write("CS-DOS Commands: \n")
- for i = 1, #self.cmds do
- write("<")
- self.settext(colors.blue)
- write(string.upper(self.cmds[i].name)..string.rep(" ",8 - #self.cmds[i].name))
- self.settext(colors.white)
- local w, h = self.getScreenSize()
- write(">")
- self.settext(colors.lightGray)
- write(self.cmds[i].desc.."\n")
- self.settext(colors.white)
- end
- end};
- };
- }
- local _logo = {
- " /---| /--| /--\ /-\ /--| ",
- " | | | | | | | ",
- " | | | | | | | ",
- " | \--\ | | | | |--\ ",
- " | | | | | | | ",
- " | | | | | | | ",
- " \--| |--/ \--/ \-/ |--/ ",
- }
- _DOS.clear()
- -- functions
- local _printlogo = function()
- _DOS.setback(colors.blue)
- for i = 1, #_logo do
- _DOS.settext(colors.green)
- print(_logo[i])
- _DOS.settext(colors.white)
- end
- print(string.rep(" ",_logo[1]:len()))
- print(_osver,string.rep(" ", (_logo[1]:len() - #_osver )))
- _DOS.setback(colors.black)
- end
- -- Manage
- _system = function()
- write(shell.dir().."> ")
- _inp = read(nil,_DOS.input_history)
- table.insert(_DOS.input_history,_inp)
- _DOS.isCmd = false
- -- Catch Potential Error --
- _proInp = _inp
- -- check command
- for i = 1, #_DOS.cmds do
- _proInp = _inp:sub(1,#_DOS.cmds[i].name)
- if(_proInp == _DOS.cmds[i].name)then
- _DOS.cmds[i].run(_DOS,_inp:sub(#_DOS.cmds[i].name+2,-1))
- _DOS.isCmd = true
- end
- end
- if(not _DOS.isCmd)then
- if(fs.exists(shell.resolve(_inp)))then
- shell.run(shell.resolve(_inp))
- else
- _DOS.settext(colors.gray)
- print("Bad command or file name: ".._inp..". \n")
- _DOS.settext(colors.white)
- end
- end
- end
- -- Commands
- -- Loop
- _OS = function()
- _printlogo()
- while _DOS.run do
- local _gud, _value = pcall(_system)
- if(not _gud)then
- _DOS.settext(colors.red)
- print("ERROR SEVERE: ".._value..". \n")
- _DOS.settext(colors.white)
- end
- end
- end
- _OS()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement