Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function convertList(html)
- local tmp = fs.open("tmp", "w")
- tmp.write(html)
- tmp.close()
- local trends = {}
- while #html > 0 do
- local _, st = html:find("<paste_key>")
- local en = html:find("</paste_key>")
- local key = html:sub(st + 1, en - 1)
- local _, st = html:find("<paste_title>")
- local en = html:find("</paste_title>")
- local title = html:sub(st + 1, en - 1)
- if not title or title == "" then
- title = "Untitled"
- end
- local _, st = html:find("<paste_size>")
- local en = html:find("</paste_size>")
- local size = html:sub(st + 1, en - 1)
- local _, st = html:find("<paste_hits>")
- local en = html:find("</paste_hits>")
- local hits = html:sub(st + 1, en - 1)
- trends[#trends + 1] = {title, key, size, hits}
- _, en = html:find("</paste>")
- html = html:sub(en + 1)
- end
- return trends --trends[n] = {title, key, size, hits}
- end
- function uWords(string, x, y, txtcol, bakcol)
- local w, h = term.getSize()
- string = string or ""
- txtcol = txtcol or colors.white
- bakcol = bakcol or colors.black
- if not tonumber(x) then
- x = x:gsub(" ", "")
- if x:sub(1, 1) == "l" then
- if x:find("+") then
- offset = tonumber(x:sub(x:find("+") + 1))
- term.setCursorPos(1 + offset, y)
- else
- term.setCursorPos(1, y)
- end
- elseif x:sub(1, 1) == "c" then
- if x:find("+") then
- offset = tonumber(x:sub(x:find("+") + 1))
- term.setCursorPos(w/2 - #string/2 + 1 + offset, y)
- elseif x:find("-") then
- offset = tonumber(x:sub(x:find("-") + 1))
- term.setCursorPos(w/2 - #string/2 + 1 - offset, y)
- else
- term.setCursorPos(w/2 - #string/2 + 1, y)
- end
- elseif x:sub(1, 1) == "r" then
- if x:find("-") then
- offset = tonumber(x:sub(x:find("-") + 1))
- term.setCursorPos(w - #string + 1 - offset, y)
- else
- term.setCursorPos(w - #string + 1, y)
- end
- end
- else
- term.setCursorPos(x, y)
- end
- term.setBackgroundColor(bakcol)
- term.setTextColor(txtcol)
- term.write(string)
- end
- function displayTrends(trends)
- local w, h = term.getSize()
- local yPos = 1
- local selected
- while true do
- term.setBackgroundColor(colors.black)
- term.clear()
- paintutils.drawFilledBox(1, 1, w, 2, colors.gray)
- uWords("Trending Pastes", "c", 1, colors.white, colors.lightGray)
- uWords("Back", "r", 1, colors.white, colors.red)
- uWords("Title", 1, 2, colors.orange, colors.gray)
- uWords("|Size", "r - 6", 2, colors.orange, colors.gray)
- uWords("|Hits", "r", 2, colors.orange, colors.gray)
- for i = yPos, h + yPos - 3 do
- local text = colors.lightBlue
- local back = colors.black
- if selected == i then
- text = colors.blue
- back = colors.lightBlue
- term.setBackgroundColor(colors.lightBlue)
- term.setCursorPos(1, i - yPos + 3)
- term.clearLine()
- end
- uWords(trends[i][1], 1, i - yPos + 3, text, back)
- uWords(" ", w - 10, i - yPos + 3, text, back)
- uWords("|" .. tostring(trends[i][3]), w - 10, i - yPos + 3, text, back)
- uWords("|" .. tostring(trends[i][4]), w - 4, i - yPos + 3, text, back)
- end
- local events = {coroutine.yield()}
- if events[1] == "key" then
- if events[2] == keys.up then
- yPos = yPos - 1
- elseif events[2] == keys.down then
- yPos = yPos + 1
- end
- elseif events[1] == "mouse_scroll" then
- yPos = yPos + events[2]
- end
- if yPos + h - 3 > #trends then
- yPos = yPos - 1
- elseif yPos < 1 then
- yPos = 1
- end
- if events[1] == "mouse_click" and events[2] == 1 then
- if events[3] >= w - 4 and events[4] == 1 then
- uWords("Back", "r", 1, colors.white, colors.orange)
- sleep(.2)
- break
- end
- if selected and events[4] + yPos - 3 == selected then
- return trends[selected][2]
- elseif events[4] > 2 then
- selected = events[4] + yPos - 3
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement