Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArg = {...}
- local w, h = term.getSize()
- local Title
- local Background = colors.white
- local Pages = {}
- local SelectedPage = 1
- function LoadPage()
- paintutils.drawFilledBox(1,2,w, h -1, colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.lightGray)
- term.write(Title)
- term.setBackgroundColor(Background)
- for i = 1, #Pages[SelectedPage] do
- if Pages[SelectedPage][i][2] == "text" then
- term.setCursorPos(1,i + 1)
- term.clearLine()
- term.write(Pages[SelectedPage][i][1])
- elseif Pages[SelectedPage][i][2] == "button" then
- term.setCursorPos(1,i + 1)
- term.clearLine()
- paintutils.drawBox(1,i + 1, string.len(Pages[SelectedPage][i][1]), i + 1, colors.lightBlue)
- term.setBackgroundColor(Background)
- term.write(Pages[SelectedPage][i][1])
- end
- end
- Interaction()
- end
- function Interaction()
- local n = 0
- while true do
- local a, b, c, d = os.pullEvent("mouse_click")
- if d > 1 and d < h then
- for i = 1, #Pages[SelectedPage] do
- if d == i and Pages[SelectedPage][i][2] == "button" then n = i end
- end
- else
- n = 100
- end
- if n > 0 then break end
- end
- if n == 100 then
- else
- if string.find(Pages[SelectedPage][n][3],"page_") then
- SelectedPage = string.sub(Pages[SelectedPage][n][3], string.find(Pages[SelectedPage][n][3],"page_") + 1,string.len(Pages[SelectedPage][n][3]))
- LoadPage()
- else
- shell.run(Pages[SelectedPage][n][3])
- LoadPage()
- end
- end
- end
- local i = 1
- local File = fs.open(tArg[1],"r")
- local content = "n"
- repeat
- content = File.readLine()
- print(content)
- if string.find(content,"<") then
- if string.find(content,"<newPage>") then Pages[#Pages + 1] = {} i = 1 end
- if string.find(content,"<title:") then Title = string.sub(content,8,(string.len(content) - 1)) end
- if string.find(content,"<text:") then Pages[#Pages][i] = {string.sub(content,7,(string.len(content) - 1)),"text"} i = i + 1 end
- if string.find(content,"<button:") then Pages[#Pages][i] = {string.sub(content,9,string.len("<button:")),"button",string.sub(content,string.len(content) - string.sub(content,9,string.len("<button:")), -1)} i = i + 1 end
- end
- until content == "<end>"
- File.close()
- LoadPage()
Add Comment
Please, Sign In to add comment