Advertisement
Le_JuiceBOX

[App] billboard.lua

Apr 1st, 2024 (edited)
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.84 KB | None | 0 0
  1. local termMod = require("/terminal")
  2. local Terminal = termMod.new()
  3. local Monitor = termMod.new()
  4.  
  5. local msgLocation = "/OS/temp/displayScreenMessage.txt"
  6. function Main()
  7.     local p = peripheral.find("monitor")
  8.     Monitor:setOutput(p)
  9.     updateDisplay(false)
  10.     term.setCursorBlink(false)
  11.     Terminal:reset()
  12.     while true do
  13.         print("Displaying message to the screen.")
  14.         print()
  15.         local menu = {
  16.             "Edit",
  17.             "Update",
  18.             "Auto Update",
  19.             "Preview",
  20.             "Clear",
  21.             "Exit"
  22.         }
  23.         local menuName, menuIndex = Terminal:promptOptions("What would you like to do?",false,menu)
  24.         if menuIndex == 1 then ---------------------- edit
  25.             shell.run("edit "..msgLocation)
  26.         elseif menuIndex == 2 then ------------------ update
  27.             updateDisplay(true)
  28.         elseif menuIndex == 3 then ------------------ auto update
  29.             while true do
  30.                 updateDisplay(false)
  31.                 Terminal:reset()
  32.                 print("Updating every 5 seconds, terminate to stop.")
  33.                 os.sleep(5)
  34.             end
  35.         elseif menuIndex == 4 then ------------------ preview
  36.             Terminal:reset()
  37.             local lines = getMsg()
  38.             for i = 1, #lines do
  39.                 Terminal:writeLine(i,lines[i])
  40.             end
  41.             term.setCursorPos(1,Terminal.size.y-1)
  42.             Terminal:pressAnyKeyToContinue()
  43.         elseif menuIndex == 5 then ------------------ clear
  44.             Monitor:reset()
  45.         elseif menuIndex == #menu then --exit
  46.             return
  47.         end
  48.     end
  49. end
  50.  
  51. function getMsg()
  52.     if fs.exists(msgLocation) == false then return {} end
  53.     local file_lines = {} --#create a blank table
  54.     local file = fs.open( msgLocation, "r" ) --#open the file in read mode
  55.     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
  56.         file_lines[ #file_lines + 1 ] = line --#set file_lines[ the number of items in file_lines + 1 ] equal to the current line
  57.     end
  58.     print("Got message of "..#file_lines.." lines...")
  59.     return file_lines
  60. end
  61.  
  62. function updateDisplay(doPrint)
  63.     if Monitor == nil then
  64.         Terminal:reset()
  65.         print("Cant find a monitor.")
  66.         print(p)
  67.         os.sleep(1.5)
  68.     else
  69.         Monitor:reset()
  70.         local lines = getMsg()
  71.         if #lines == 0 then
  72.             print("\nGo to 'Edit' and create a message first!")
  73.             os.sleep(1)
  74.         else
  75.             for i = 1, #lines do
  76.                 Monitor:writeLine(i,lines[i])
  77.             end
  78.             Terminal:reset()
  79.             if doPrint then
  80.                 print("Display updated!")
  81.                 os.sleep(0.75)
  82.             end
  83.         end
  84.     end
  85. end
  86.  
  87.  
  88. Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement