Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- --Main "packet" table DO NOT CHANGE
- --Haupt "Paket" table NICHT VER壟F�83?0壟F�NDERN
- info = {}
- info.func = {}
- info.pages = {}
- function info:addPage(text)
- self.pages[self.func.maxPage + 1] = text
- self.func.maxPage = self.func.maxPage + 1
- self.func.minPage = 1
- self.func.currPage = self.func.minPage
- end
- function info.func:getBackPos()
- return {x=1, y=1}
- end
- function info.func:getFrontPos()
- w, h = term.getSize()
- return {x=w, y=1}
- end
- --File loading function
- --Datei lade funktion
- function info.func:setPages(path)
- if(path ~= nil and fs.isDir(path)) then
- files = fs.list(path)
- for k, v in ipairs(files) do
- --Parameters for the file, you can add more
- --Parameter f壟F�83壟F�BCr die datei, du kannst mehr einf壟F�83壟F�BCgen
- if(v ~= nil and not fs.isDir(v)) then
- f = fs.open(path.."/"..v, "r")
- cont = {}
- i = 1
- while(true) do
- local l = f.readLine()
- if(l == nil) then break end
- cont[i] = l
- i = i + 1
- end
- cont.minScroll = 1
- cont.maxScroll = i - 17
- if cont.maxScroll < 1 then
- cont.maxScroll = 0
- end
- info:addPage(cont)
- f.close()
- end
- end
- end
- end
- --Main function a lot of hardcoding
- --Hauptfunktion viel hardgecodetes
- function info.func:redraw()
- w, h = term.getSize()
- bp = self:getBackPos()
- fp = self:getFrontPos()
- term.clear()
- term.setCursorPos(bp.x, bp.y)
- term.write("<")
- toWrite = self.currPage.."/"..self.maxPage
- term.setCursorPos((w / 2) - (string.len(toWrite) / 2), 1)
- term.write(toWrite)
- term.setCursorPos(fp.x, fp.y)
- term.write(">")
- term.setCursorPos(1, 2)
- term.write("^")
- term.setCursorPos(w, 2)
- term.write("v")
- term.setCursorPos(1, 3)
- local page = info.pages[self.currPage]
- rLine = 3
- count = self.pageScroll
- toPrint = #page
- if toPrint > 17 then
- toPrint = 17
- end
- for i=1,toPrint do
- term.setCursorPos(1, rLine)
- term.write(page[count])
- rLine = rLine + 1
- count = count + 1
- end
- event, i, x, y = os.pullEvent()
- if event == "mouse_scroll" then
- if(page.maxScroll > 0) then
- self.pageScroll = self.pageScroll + i
- if(self.pageScroll < page.minScroll) then
- self.pageScroll = page.minScroll
- end
- if self.pageScroll > page.maxScroll then
- self.pageScroll = page.maxScroll
- end
- end
- elseif event == "monitor_touch" or event == "mouse_click" then
- if x == bp.x and y == bp.y then
- self.currPage = self.currPage - 1
- if self.currPage < self.minPage then
- self.currPage = self.maxPage
- end
- elseif x == fp.x and y == fp.y then
- self.currPage = self.currPage + 1
- if self.currPage > self.maxPage then
- self.currPage = self.minPage
- end
- elseif x == 1 and y == 2 then
- if(page.maxScroll > 0) then
- self.pageScroll = self.pageScroll - 1
- if(self.pageScroll < 1) then
- self.pageScroll = 1
- end
- end
- elseif x == w and y == 2 then
- if(page.maxScroll > 0) then
- self.pageScroll = self.pageScroll + 1
- if self.pageScroll > page.maxScroll then
- self.pageScroll = page.maxScroll
- end
- end
- end
- end
- end
- --Base parameters DO NOT CHANGE
- --Grund Parameter NICHT VER壟F�83?0壟F�NDERN
- info.func.minPage = 0
- info.func.maxPage = 0
- info.func.currPage = info.func.minPage;
- info.func.pageScroll = 1
- --The path to the folder with the informational files
- --Der pfad zum Verzeichnis mit den Dateien die gezeigt werden sollen
- toSearchPath = "disk/info"
- info.func:setPages(toSearchPath)
- --You can add other stuff to the loop
- --In diesem loop kann man auch andere dinge tun
- while(true) do
- info.func:redraw()
- end
Advertisement
Add Comment
Please, Sign In to add comment