Guest User

test

a guest
May 20th, 2015
614
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.72 KB | None | 0 0
  1. args = {...}
  2.  
  3. --Main "packet" table DO NOT CHANGE
  4. --Haupt "Paket" table NICHT VER壟F�83?0壟F�NDERN
  5. info = {}
  6. info.func = {}
  7. info.pages = {}
  8.  
  9. function info:addPage(text)
  10.  
  11.     self.pages[self.func.maxPage + 1] = text
  12.     self.func.maxPage = self.func.maxPage + 1
  13.     self.func.minPage = 1
  14.     self.func.currPage = self.func.minPage
  15.  
  16. end
  17.  
  18.  
  19.  
  20. function info.func:getBackPos()
  21. return {x=1, y=1}
  22. end
  23.  
  24. function info.func:getFrontPos()
  25. w, h = term.getSize()
  26. return {x=w, y=1}
  27. end
  28.  
  29. --File loading function
  30. --Datei lade funktion
  31. function info.func:setPages(path)
  32.  
  33.     if(path ~= nil and fs.isDir(path)) then
  34.  
  35.         files = fs.list(path)
  36.  
  37.         for k, v in ipairs(files) do
  38.  
  39.             --Parameters for the file, you can add more
  40.             --Parameter f壟F�83壟F�BCr die datei, du kannst mehr einf壟F�83壟F�BCgen
  41.             if(v ~= nil and not fs.isDir(v)) then
  42.  
  43.                     f = fs.open(path.."/"..v, "r")
  44.  
  45.                     cont = {}
  46.  
  47.                     i = 1
  48.  
  49.                     while(true) do
  50.  
  51.                         local l = f.readLine()
  52.  
  53.                         if(l == nil) then break end
  54.  
  55.                         cont[i] = l
  56.  
  57.                         i = i + 1
  58.  
  59.                     end
  60.  
  61.                     cont.minScroll = 1
  62.  
  63.                     cont.maxScroll = i - 17
  64.                     if cont.maxScroll < 1 then
  65.                         cont.maxScroll = 0
  66.                     end
  67.  
  68.                     info:addPage(cont)
  69.  
  70.                     f.close()
  71.             end
  72.         end
  73.  
  74.        
  75.  
  76.     end
  77.  
  78. end
  79.  
  80. --Main function a lot of hardcoding
  81. --Hauptfunktion viel hardgecodetes
  82. function info.func:redraw()
  83.  
  84.     w, h = term.getSize()
  85.  
  86.     bp = self:getBackPos()
  87.     fp = self:getFrontPos()
  88.  
  89.     term.clear()
  90.  
  91.     term.setCursorPos(bp.x, bp.y)
  92.     term.write("<")
  93.  
  94.     toWrite = self.currPage.."/"..self.maxPage
  95.     term.setCursorPos((w / 2) - (string.len(toWrite) / 2), 1)
  96.     term.write(toWrite)
  97.  
  98.     term.setCursorPos(fp.x, fp.y)
  99.     term.write(">")
  100.  
  101.     term.setCursorPos(1, 2)
  102.     term.write("^")
  103.  
  104.     term.setCursorPos(w, 2)
  105.     term.write("v")
  106.    
  107.     term.setCursorPos(1, 3)
  108.  
  109.     local page = info.pages[self.currPage]
  110.  
  111.     rLine = 3
  112.  
  113.     count = self.pageScroll
  114.  
  115.     toPrint = #page
  116.  
  117.     if toPrint > 17 then
  118.         toPrint = 17
  119.     end
  120.  
  121.     for i=1,toPrint do
  122.  
  123.         term.setCursorPos(1, rLine)
  124.         term.write(page[count])
  125.         rLine = rLine + 1
  126.         count = count + 1
  127.  
  128.     end
  129.  
  130.     event, i, x, y = os.pullEvent()
  131.  
  132.     if event == "mouse_scroll" then
  133.  
  134.         if(page.maxScroll > 0) then
  135.  
  136.             self.pageScroll = self.pageScroll + i
  137.  
  138.             if(self.pageScroll < page.minScroll) then
  139.                 self.pageScroll = page.minScroll
  140.             end
  141.  
  142.             if self.pageScroll > page.maxScroll then
  143.                 self.pageScroll = page.maxScroll
  144.             end
  145.  
  146.         end
  147.  
  148.     elseif event == "monitor_touch" or event == "mouse_click" then
  149.  
  150.         if x == bp.x and y == bp.y then
  151.  
  152.             self.currPage = self.currPage - 1
  153.  
  154.             if self.currPage < self.minPage then
  155.                 self.currPage = self.maxPage
  156.             end
  157.  
  158.         elseif x == fp.x and y == fp.y then
  159.  
  160.             self.currPage = self.currPage + 1
  161.  
  162.             if self.currPage > self.maxPage then
  163.                 self.currPage = self.minPage
  164.             end
  165.  
  166.         elseif x == 1 and y == 2 then
  167.  
  168.             if(page.maxScroll > 0) then
  169.  
  170.                 self.pageScroll = self.pageScroll - 1
  171.  
  172.                 if(self.pageScroll < 1) then
  173.                     self.pageScroll = 1
  174.                 end
  175.  
  176.             end
  177.  
  178.         elseif x == w and y == 2 then
  179.  
  180.             if(page.maxScroll > 0) then
  181.  
  182.                 self.pageScroll = self.pageScroll + 1
  183.  
  184.                 if self.pageScroll > page.maxScroll then
  185.                     self.pageScroll = page.maxScroll
  186.                 end
  187.  
  188.             end
  189.  
  190.         end
  191.  
  192.     end
  193.  
  194. end
  195.  
  196. --Base parameters DO NOT CHANGE
  197. --Grund Parameter NICHT VER壟F�83?0壟F�NDERN
  198. info.func.minPage = 0
  199. info.func.maxPage = 0
  200. info.func.currPage = info.func.minPage;
  201. info.func.pageScroll = 1
  202.  
  203. --The path to the folder with the informational files
  204. --Der pfad zum Verzeichnis mit den Dateien die gezeigt werden sollen
  205. toSearchPath = "disk/info"
  206.  
  207. info.func:setPages(toSearchPath)
  208.  
  209. --You can add other stuff to the loop
  210. --In diesem loop kann man auch andere dinge tun
  211. while(true) do
  212. info.func:redraw()
  213. end
Advertisement
Add Comment
Please, Sign In to add comment