Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function clearScreen()
- term.clear()
- term.setCursorPos(1,1)
- end
- local tArgs = {...}
- local command = tArgs[1]
- if command == "help" then
- print("availiable commands are:")
- print(" create-makes a new ballot.")
- print(" delete-deletes a ballot.")
- print(" info-displays info on a given ballot.")
- print(" list-displays a list of all currect ballots.")
- end
- if command == "list" then
- ballots = fs.list("disk")
- for i = 1,1000 do
- if ballots[i] == nil then break end
- if ballots[i] ~= "idlists" then
- if ballots[i] ~= "results" then
- print(ballots[i])
- end
- end
- end
- end
- if command == "info" then
- print("What ballot would you like information on?")
- ballot = read()
- hrBallot = fs.open("disk/"..ballot,"r")
- print("Information on "..ballot)
- print(nil)
- print(hrBallot.readLine())
- print(nil)
- print("Press any key to continue.")
- os.pullEvent("key")
- hrBallot.close()
- end
- if command == "create" then
- clearScreen()
- print("What would you like to name your ballot?")
- name = read()
- ballot = fs.open("disk/"..name,"w")
- clearScreen()
- print("Please explain the ballot for the voters:")
- desc = read()
- ballot.write(desc)
- ballot.close()
- hResults = fs.open("disk/results/"..name,"w")
- tResults = {0,0}
- hResults.writeLine(textutils.serialize(tResults))
- hResults.close()
- error()
- end
- if command == "delete" then
- term.clear()
- term.setCursorPos(1,1)
- print("enter name of ballot to delete:")
- local ballot = read()
- while true do
- term.clear()
- term.setCursorPos(1,1)
- print("Are you sure you want to delete ballot '"..ballot.."'? This cannot be undone. (type yes or no.)")
- local choice = read()
- if choice == "yes" then
- fs.delete("disk/"..ballot)
- fs.delete("disk/idlists/"..ballot)
- print("Ballot '"..ballot.."' deleted.")
- break
- else
- if choice == "no" then
- break
- else
- term.clear()
- term.setCursorPos(1,1)
- print("'"..choice.."' is not a valid option. Please type yes or no.")
- sleep(2)
- end
- end
- end
- error()
- end
Advertisement
Add Comment
Please, Sign In to add comment