Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Hilfsfunktionen
- local function clear()
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.lightBlue)
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- Auto-Start Bildschirmanzeige (einmalig beim Programmstart)
- local function autoStartScreen()
- if not fs.exists("auto_start") then return end
- local file = fs.open("auto_start", "r")
- local screenFile = file.readLine()
- file.close()
- if not screenFile or screenFile == "" then return end
- local path = "screens/" .. screenFile
- if not fs.exists(path) then
- term.setTextColor(colors.red)
- print("Auto-Start Datei existiert nicht mehr: " .. screenFile)
- term.setTextColor(colors.lightBlue)
- sleep(2)
- return
- end
- local monitor = peripheral.wrap("left")
- if not monitor then
- term.setTextColor(colors.red)
- print("Kein Monitor für Auto-Start gefunden.")
- term.setTextColor(colors.lightBlue)
- sleep(2)
- return
- end
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- local file = fs.open(path, "r")
- while true do
- local line = file.readLine()
- if not line then break end
- local gap, lineNum, textColor, bgColor, text = line:match("([^,]+),([^,]+),([^,]+),([^,]+),(.+)")
- gap = tonumber(gap)
- lineNum = tonumber(lineNum)
- textColor = tonumber(textColor)
- bgColor = tonumber(bgColor)
- if gap and lineNum and textColor and bgColor and text then
- monitor.setCursorPos(gap, lineNum)
- monitor.setTextColor(textColor)
- monitor.setBackgroundColor(bgColor)
- monitor.write(text)
- end
- end
- file.close()
- end
- local function listScreens()
- if not fs.exists("screens") then fs.makeDir("screens") end
- local files = fs.list("screens")
- local screens = {}
- for _, f in ipairs(files) do
- if not fs.isDir("screens/" .. f) then
- table.insert(screens, f)
- end
- end
- return screens
- end
- local function waitEnter()
- term.setTextColor(colors.gray)
- print("\nDrücke [Enter], um fortzufahren...")
- term.setTextColor(colors.lightBlue)
- read()
- end
- -- [2] Neuen Bildschirm Konfigurieren
- local function screenConfig()
- shell.run("1")
- end
- -- [1] Gespeicherten Bildschirm anschauen
- local function promptScreenStart()
- clear()
- print("Gespeicherte Screens:\n")
- local screens = listScreens()
- for i, s in ipairs(screens) do
- print(i .. ") " .. s)
- end
- io.write("\nNummer eingeben zum Starten: ")
- local n = tonumber(read())
- if not (n and screens[n]) then
- term.setTextColor(colors.red)
- print("Ungültige Eingabe.")
- term.setTextColor(colors.lightBlue)
- waitEnter()
- return
- end
- -- Monitor suchen
- local monitor = peripheral.wrap("left")
- if not monitor then
- term.setTextColor(colors.red)
- print("Kein Monitor gefunden.")
- term.setTextColor(colors.lightBlue)
- waitEnter()
- return
- end
- monitor.setBackgroundColor(colors.black)
- monitor.setTextColor(colors.white)
- monitor.clear()
- monitor.setCursorPos(1, 1)
- -- Datei öffnen und lesen
- local path = "screens/" .. screens[n]
- local file = fs.open(path, "r")
- if not file then
- term.setTextColor(colors.red)
- print("Datei konnte nicht geöffnet werden.")
- term.setTextColor(colors.lightBlue)
- waitEnter()
- return
- end
- while true do
- local line = file.readLine()
- if not line then break end
- local gap, lineNum, textColor, bgColor, text = line:match("([^,]+),([^,]+),([^,]+),([^,]+),(.+)")
- gap = tonumber(gap)
- lineNum = tonumber(lineNum)
- textColor = tonumber(textColor)
- bgColor = tonumber(bgColor)
- if gap and lineNum and textColor and bgColor and text then
- monitor.setCursorPos(gap, lineNum)
- monitor.setTextColor(textColor)
- monitor.setBackgroundColor(bgColor)
- monitor.write(text)
- end
- end
- file.close()
- term.setTextColor(colors.green)
- print("\nBildschirm auf Monitor angezeigt.")
- term.setTextColor(colors.lightBlue)
- waitEnter()
- end
- -- [3] Auto-Start Bildschirm festlegen
- local function promptAutoStart()
- clear()
- print("Auto-Start Bildschirm festlegen:\n")
- local screens = listScreens()
- for i, s in ipairs(screens) do
- print(i .. ") " .. s)
- end
- io.write("\nNummer eingeben: ")
- local n = tonumber(read())
- if n and screens[n] then
- local file = fs.open("auto_start", "w")
- file.write(screens[n])
- file.close()
- term.setTextColor(colors.green)
- print("\nGespeichert! Beim nächsten Start wird dieser Bildschirm automatisch angezeigt.")
- term.setTextColor(colors.lightBlue)
- else
- term.setTextColor(colors.red)
- print("Ungültige Eingabe.")
- term.setTextColor(colors.lightBlue)
- end
- waitEnter()
- end
- -- [4] Gespeicherten Bildschirm löschen
- local function deleteScreen()
- clear()
- print("Screen löschen:\n")
- local screens = listScreens()
- for i, s in ipairs(screens) do
- print(i .. ") " .. s)
- end
- io.write("\nNummer eingeben: ")
- local n = tonumber(read())
- if n and screens[n] then
- fs.delete("screens/" .. screens[n])
- term.setTextColor(colors.green)
- print("\nBildschirm gelöscht.")
- term.setTextColor(colors.lightBlue)
- else
- term.setTextColor(colors.red)
- print("Ungültige Eingabe.")
- term.setTextColor(colors.lightBlue)
- end
- waitEnter()
- end
- -- Hauptmenü
- local function main()
- autoStartScreen() -- Bildschirm einmalig anzeigen (wenn vorhanden)
- while true do
- clear()
- print([[
- Willkommen im Bildschirm - Konfigurator
- Du kannst ohne Programmierkenntnisse folgendes tun:
- 1) Gespeicherten Bildschirm anschauen
- 2) Neuen Bildschirm konfigurieren
- 3) Auto-Start für Bildschirm festlegen
- 4) Gespeicherten Bildschirm löschen
- 5) Beenden
- ]])
- io.write("Bitte Zahl eingeben und [Enter] drücken: ")
- local input = read()
- if input == "1" then promptScreenStart() -- [1]
- elseif input == "2" then screenConfig() -- [2]
- elseif input == "3" then promptAutoStart() -- [3]
- elseif input == "4" then deleteScreen() -- [4]
- elseif input == "5" then -- [5]
- print("Beende Menü...")
- sleep(1)
- break
- else
- term.setTextColor(colors.red)
- print("Ungültige Eingabe.")
- term.setTextColor(colors.lightBlue)
- waitEnter()
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement