Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local termMod = require("/terminal")
- local Terminal = termMod.new()
- local Monitor = termMod.new()
- local msgLocation = "/OS/temp/displayScreenMessage.txt"
- function Main()
- local p = peripheral.find("monitor")
- Monitor:setOutput(p)
- updateDisplay(false)
- term.setCursorBlink(false)
- Terminal:reset()
- while true do
- print("Displaying message to the screen.")
- print()
- local menu = {
- "Edit",
- "Update",
- "Auto Update",
- "Preview",
- "Clear",
- "Exit"
- }
- local menuName, menuIndex = Terminal:promptOptions("What would you like to do?",false,menu)
- if menuIndex == 1 then ---------------------- edit
- shell.run("edit "..msgLocation)
- elseif menuIndex == 2 then ------------------ update
- updateDisplay(true)
- elseif menuIndex == 3 then ------------------ auto update
- while true do
- updateDisplay(false)
- Terminal:reset()
- print("Updating every 5 seconds, terminate to stop.")
- os.sleep(5)
- end
- elseif menuIndex == 4 then ------------------ preview
- Terminal:reset()
- local lines = getMsg()
- for i = 1, #lines do
- Terminal:writeLine(i,lines[i])
- end
- term.setCursorPos(1,Terminal.size.y-1)
- Terminal:pressAnyKeyToContinue()
- elseif menuIndex == 5 then ------------------ clear
- Monitor:reset()
- elseif menuIndex == #menu then --exit
- return
- end
- end
- end
- function getMsg()
- if fs.exists(msgLocation) == false then return {} end
- local file_lines = {} --#create a blank table
- local file = fs.open( msgLocation, "r" ) --#open the file in read mode
- for line in file.readLine do --#file.readLine is a function which acts similar to pairs or ipairs, and therefor can be used like this
- file_lines[ #file_lines + 1 ] = line --#set file_lines[ the number of items in file_lines + 1 ] equal to the current line
- end
- print("Got message of "..#file_lines.." lines...")
- return file_lines
- end
- function updateDisplay(doPrint)
- if Monitor == nil then
- Terminal:reset()
- print("Cant find a monitor.")
- print(p)
- os.sleep(1.5)
- else
- Monitor:reset()
- local lines = getMsg()
- if #lines == 0 then
- print("\nGo to 'Edit' and create a message first!")
- os.sleep(1)
- else
- for i = 1, #lines do
- Monitor:writeLine(i,lines[i])
- end
- Terminal:reset()
- if doPrint then
- print("Display updated!")
- os.sleep(0.75)
- end
- end
- end
- end
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement