Posted 17 May 2012 - 03:59 AM
This is my command prompt program, its supposed to simulate CMD/Batch (currently can't run batch files). This is the code:
Click here for Formatted/Pastebin version
DO NOT run "execute" or the program will error.
These are the basic commands:
I'm trying to make this be exactly like cmd (or do all the commands you can do)
Known bugs:
Spoiler
local bExit = false
function eDecode(test)
local tCommandHistory = {}
test = io.open(test, "r")
for sLine in test:lines() do
table.insert( tCommandHistory, sLine )
local tWords = {}
for match in string.gmatch(sLine, "[^ t]+") do
table.insert( tWords, match )
end
eBatch(tWords, false, sLine)
end
test.close()
end
function eBatch(tWords, test, full)
local sCommand = tWords[1]
if sCommand == "echo" then
if tWords[2] then
print(string.sub(full, 6, string.len(full)))
if test == false then
print()
end
else
if test == false then
print("ECHO is on.")
end
end
elseif sCommand == "exit" then
bExit = true
elseif sCommand == "cmd" then
print("NeXuS Windows [Version 1.1.0001]")
print("Copyright (c) NeXuS Corporation. All rights reserved.n")
elseif sCommand == "pause" then
print("Press any key to continue.")
os.pullEvent("key")
sleep(0)
elseif sCommand == "cls" then
term.clear()
term.setCursorPos(1,1)
elseif sCommand == "dir" then
shell.run("rom/programs/list")
elseif sCommand == "del" then
if tWords[2] then
if fs.exists(tWords[2]) then
if fs.isReadOnly(tWords[2]) then
print("Could Not Find C:UsersAdmin" ..tWords[2].. "n")
else
fs.delete( tWords[2] )
end
else
print("Could Not Find C:UsersAdmin" ..tWords[2].. "n")
end
else
print("Could Not Find C:AppDataEarthUsersYouBrain.exen")
end
elseif sCommand == "execute" then --just made this one up, might not exist
if tWords[2] then
if fs.exists(tWords[2]) then
eDecode(tWords[2])
else
print("Could Not Find C:UsersAdmin" ..tWords[2])
end
end
elseif sCommand == "title" then
return tWords[2] --Title is pretty much useless here, so i'll just return what they typed for other's programs.
else
print("'"..sCommand.."' is not recognized as a internal or external command, operable program or batch file. n")
end
end
print("NeXuS Windows [Version 1.1.0001]")
print("Copyright (c) NeXuS Corporation. All rights reserved.n")
local tCommandHistory = {}
while not bExit do
write( "C:UsersAdmin> " )
local sLine = read( nil, tCommandHistory )
table.insert( tCommandHistory, sLine )
local tWords = {}
for match in string.gmatch(sLine, "[^ t]+") do
table.insert( tWords, match )
end
eBatch(tWords, false, sLine)
end
Click here for Formatted/Pastebin version
These are the basic commands:
echo --Prints whatever you type
exit --Exits the prompt
cmd --Opens a new prompt
pause --Pauses until you press a key
cls --Clears the screen
dir --Lists all the files
del --Deletes the file (easter egg inside)
execute --Runs the files as a .bat (the program will error on .io in line 3 after you run it. this is a bug)
title --Changes the title of the prompt, doesn't do anything yet but return what u typed
I'm trying to make this be exactly like cmd (or do all the commands you can do)
Copyright (c) NeXuS Corporation. All rights reserved.
Is just to make it look more realistic since the real CMD has this.Known bugs:
Echo doesn't support spaces, so this code won't work:Fixed.
, it will just echo HELLOecho HELLO EVERYONE
- The application crashes after you execute a .batch