Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if OneOS then
- OneOS.ToolBarColour = colours.lightGrey
- end
- --Credits:
- --Developers:
- --Hithere
- --APIs
- --Special thanks to:
- --oeed, for OneOS, the OS Sapphari was
- --designed for
- --DEVELOPER CONFIG
- local waitForMessage = false
- --------------------------------------------------
- sapphariVersionString = "0.1"
- sapphariVersionNumber = 0
- sapphariSites = {}
- sapphariBlacklist = {}
- --The script sets the news, then sets the url vars
- shell.run("pastebin run Jg8D7mLi")
- --print("--------------------------------------------------")
- --It would seem I don't need to kill any functions as OneOS handles that for me :D
- --Internal functions
- local sapphInt = {}
- function sapphInt.redrawUI()
- local termX, termY = term.getSize()
- for i=1,2 do
- paintutils.drawLine(1,i,termX,i,colors.lightGray)
- end
- paintutils.drawLine(2,1,termX/3,1,colors.white)
- paintutils.drawLine(termX/3+2,1,termX/3+4,1,colors.green)
- term.setCursorPos(termX/3+2,1)
- term.write("GO!")
- end
- --this function will get the data for a site,
- --however, will not run it.
- function sapphInt.getSite(pasteID)
- local responce = http.get("http://pastebin.com/raw.php?i="..pasteID)
- if responce then
- return loadstring(responce.readAll())
- else
- return false
- end
- end
- function sapphInt.handleMenu(typeClick, clickX, clickY)
- --handle the user clicking the menu
- local termX,termY=term.getSize()
- if typeClick == 1 then
- --okay, it's a left click, passes first one'
- if clickX>1 then --okay, in somewhere special
- if clickX<termX/3+1 then
- --okay, the user wants to change the url.
- term.setCursorPos(2,1)
- print("calling")
- input = read()
- print"dun"
- --we will return the input which will
- --be returned until the program must
- --end, then it will be a temporary
- --global variable and read by safari
- --again. Complicated? True.
- return input
- end
- end
- end
- end
- function sapphInt.decodeHumanReadableURL(HRURL)
- --this is where we attempt to decode a
- --human readable url. If fails, will tell
- --calling function to attempt to use the
- --plain url instead.
- if sapphariSites[HRURL] then
- --this must be an HRURL, so we'll give them'
- --the pasteID
- return sapphariSites[HRURL]
- else
- return HRURL
- --this must be a PasteID then
- end
- end
- --WEBSITE FUNCTON
- --sapphutils, MUST be global!!!
- sapphUtils = {}
- function sapphUtils.pullEvent(filter)
- sapphInt.redrawUI()
- while true do do
- event, p1, p2, p3, p4, p5, p6, p7 = oldPullEvent()
- if event == "mouse_click" and p3==1 then
- print"handling"
- local newSiteq = sapphInt.handleMenu(p1, p2, p3)
- if newSiteq then
- newSite = newSiteq
- sapphInt.handleSapphari()
- error("Returned to bad pullEvent")
- end
- end
- if filter then
- if event == filter then
- return event, p1, p2, p3, p4, p5, p6, p7
- end
- else
- return event, p1, p2, p3, p4, p5, p6, p7
- end
- --if they changed sites, we'll never get here.
- end
- end end
- --fix os.pullEvent
- oldPullEvent = os.pullEvent
- os.pullEvent = sapphInt.pullEvent
- function sapphUtils.read(startx, starty, endx, endy)
- print("started")
- local endy = starty
- --a function for text boxes, that, in short,
- --has a text wrapping feature
- --~ to quit
- local writenString = ""
- local cursorPos = 0
- while true do
- local evt, charcode = oldPullEvent("key")
- term.setCursorPos(5,5)
- if evt == "key" then
- print"okay"
- else
- print"FUUUUUUUUUUUUUUU"
- end
- charcode = tonumber(charcode)
- print(charcode)
- if charcode == 41 then
- return false
- elseif charcode == 203 then
- --move left
- elseif charcode == 205 then
- --move right
- elseif charcode == 14 then
- --delete a cha+r with string.sub
- elseif charcode == 28 then
- term.setCursorPos(5,5)
- print("returning")
- return writenString
- elseif charcode>58 and charcode<80 then
- --Now, now, no need to do anything here!
- --This just prevents these from trying
- --to be added to the string :)
- --REJECTED keys:
- elseif charcode == 88 then
- elseif charcode == 183 then
- elseif charcode == 70 then
- elseif charcode == 197 then
- elseif charcode == 210 then
- elseif charcode == 199 then
- elseif charcode == 201 then
- elseif charcode == 211 then
- elseif charcode == 207 then
- elseif charcode == 209 then
- elseif charcode == 29 then
- elseif charcode == 219 then
- elseif charcode == 56 then
- elseif charcode == 184 then
- elseif charcode == 220 then
- elseif charcode == 221 then
- elseif charcode == 157 then
- elseif charcode == 42 then
- elseif charcode == 54 then
- elseif charcode == 58 then
- else
- local keyString = keys.getName(charcode)
- if keyString == nil then
- keyString = "There was an error. Tell Hithere it was this sapphInt.read() and that it failed hard"
- end
- writenString = writenString..keyString
- term.setCursorPos(8,6)
- print("test")
- print(writenString)
- --do the key thing here
- end
- end
- end
- --this must get the pasteid, not the human
- --redable url
- t = 0
- function sapphInt.handleWebsite(url)
- term.setCursorPos(7,4)
- t=t+1
- print("got to handle"..t)
- --need help on how to run a string as a function
- --this will work for now
- local rurl = sapphInt.decodeHumanReadableURL(url)
- local site = sapphInt.getSite(rurl)
- if site then
- --local ok, error = pcall(site())
- setfenv(site, getfenv())
- local ok, error = pcall(site())
- end
- --term.setCursorPos(1,1)
- --term.clear()
- --cool people do it backwards
- end
- function sapphInt.handleSapphari()
- --the mother function
- --the main mother loop. If the site crashes
- --it will go to homepage, will go to homepa
- --ge if first run too.
- --we'll need a loop
- while true do
- if newSite then
- gotoNewSite = newSite
- newSite = nil
- term.setCursorPos(1,3)
- term.setBackgroundColor(colors.black)
- term.clear()
- --cool people do it backwards
- sapphInt.handleWebsite(gotoNewSite)
- else
- sapphInt.handleWebsite("F99c7Fmi")
- end
- end
- end
- ---------------------------------------------------
- --yes = true
- --sapphInt.handleNews()
- sapphInt.handleSapphari()
Advertisement
Add Comment
Please, Sign In to add comment