Advertisement
Guest User

startup

a guest
Jun 4th, 2014
260
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 5.12 KB | None | 0 0
  1.  if OneOS then
  2.   if shell.getRunningProgram() == "startup" then
  3.     --to make sure they're not running this in shell
  4.     --because if they are it'll crash.
  5.     OneOS.ToolBarColour = colours.lightGrey
  6.   end
  7. end
  8. --Credits:
  9.  
  10. --Developers:
  11.  
  12. --Hithere
  13.  
  14.  
  15. --APIs
  16.  
  17.  
  18. --Special thanks to:
  19.  
  20. --oeed, for OneOS, the OS Sapphari was
  21. --designed for
  22.  
  23.  
  24.  
  25. --DEVELOPER CONFIG
  26. local waitForMessage =  false
  27.  
  28.  
  29. --------------------------------------------------
  30.   sapphariVersionString = "1.0"
  31.   sapphariVersionNumber = 1
  32.  
  33.   sapphariSites = {}
  34.   sapphariBlacklist = {}
  35. --TESTS:
  36. --might fix some crashes
  37. --+function error()
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.  
  45.  
  46.  
  47.  
  48.  
  49.  
  50.     --The script sets the news, then sets the url vars
  51. shell.run("rom/programs/http/pastebin run Jg8D7mLi")
  52. --print("--------------------------------------------------")
  53. --It would seem I don't need to kill any functions as OneOS handles that for me :D
  54. --Internal functions
  55. local sapphInt = {}
  56. function sapphInt.redrawUI()
  57.   term.setBackgroundColor(colors.white)
  58.   term.setTextColor(colors.black)
  59.   local termX, termY = term.getSize()
  60.   for i=1,2 do
  61.     paintutils.drawLine(1,i,termX,i,colors.lightGray)
  62.   end
  63.   paintutils.drawLine(2,1,termX/3,1,colors.white)
  64.   paintutils.drawLine(termX/3+2,1,termX/3+3,1,colors.green)
  65.   --this is the last thing getting drawn,
  66.   --we do not need to specify length.
  67.   --writing on it takes care of it
  68.   term.setCursorPos(termX/3+2,1)
  69.   term.write("Refresh")
  70.   --now it's the right length.
  71. end
  72. --this function will get the data for a site,
  73. --however, will not run it.
  74. function sapphInt.getSite(pasteID)
  75.   local responce = http.get("http://pastebin.com/raw.php?i="..pasteID)
  76.   if responce then
  77.     return loadstring(responce.readAll())
  78.   else
  79.     return false
  80.   end
  81. end
  82. function sapphInt.handleMenu(typeClick, clickX, clickY)
  83.   --handle the user   clicking the menu
  84.   print"cal1"
  85.   local termX,termY=term.getSize()
  86.   if typeClick == 1 then
  87.     --okay, it's a left click, passes first one'
  88.     if clickX>1 then --okay, in somewhere special
  89.       if clickX<termX/3+1 then
  90.         --okay, the user wants to change the url.
  91.         term.setCursorPos(2,1)
  92.         print"cal"
  93.         input = read()
  94.         print"dun"
  95.         --we will return the input which will
  96.         --be returned until the program must
  97.         --end, then it will be a temporary
  98.         --global variable and read by safari
  99.         --again. Complicated? True.
  100.         return input
  101.       end
  102.     end
  103.     if clickX>termX/3+1 then
  104.       if clickX<termX/3+8 then
  105.         --need to refresh page nao
  106.         return currentSite
  107.       end
  108.     end
  109.   end
  110. end
  111. function sapphInt.decodeHumanReadableURL(HRURL)
  112.   --this is where we attempt to decode a
  113.   --human readable url. If fails, will tell
  114.   --calling function to attempt to use the
  115.   --plain url instead.
  116.   if sapphariSites[HRURL] then
  117.     --this must be an HRURL, so we'll give them'
  118.     --the pasteID
  119.     currentSite = sapphariSites[HRURL]
  120.     return sapphariSites[HRURL]
  121.   else
  122.     currentSite = HRURL
  123.     return HRURL
  124.     --this must be a PasteID then
  125.   end
  126. end
  127. --WEBSITE FUNCTON
  128. --sapphutils, MUST be global!!!
  129. sapphUtils = {}
  130. function sapphUtils.pullEvent(filter)
  131.   print"f"
  132.   termX,termY=term.getSize()
  133.   print"redaw"
  134.   sapphInt.redrawUI()
  135.   while true do
  136.     local event, p1, p2, p3,  p4, p5, p6, p7 = os.pullEventRaw()
  137.     --note that pullEvent yields
  138.     --so we have to make sure we don't
  139.     --kill the routine while it's checking
  140.     --for events
  141.     if event == "mouse_click" and p3==1 then
  142.       print"handling"
  143.       if p1 == 1 and p3 == 1 then
  144.           if p2>1 and p2<termX/3+1 then
  145.             print"menu"
  146.             term.setCursorPos(5,5)
  147.             newSiteq=true
  148.             clickx=p2
  149.             clicky=p3
  150.             --okay, it'll be
  151.           elseif p2>termX/3+1 and p3<termX/3+8 then
  152.             newSiteq=true
  153.             clickx=p2
  154.             clicky=p3
  155.             --okay, it'll be Refresh then.
  156.           end
  157.       end
  158.       if newSiteq then
  159.         print"die"
  160.       coroutine.yeild()
  161.       end
  162.     end
  163.     if filter then
  164.       if event == filter then
  165.         return event, p1, p2, p3, p4, p5, p6, p7
  166.       end
  167.     else
  168.       return event, p1, p2, p3, p4, p5, p6, p7
  169.     end
  170.     --if they changed sites, we'll never get here.
  171.   end
  172. end
  173.    
  174. function sapphUtils.read(startx, starty, endx, endy)
  175.   while true do
  176.     evt, text = os.pullEvent()
  177.     if evt == "key" then
  178.  
  179.     end
  180.   end
  181. end
  182. --this must get  the pasteid, not the human
  183. --redable url
  184. function sapphInt.handleWebsite(url)
  185.   print"Aliv fn"
  186.  
  187.   local rurl = sapphInt.decodeHumanReadableURL(url)
  188.   print"stil"
  189.   local site = sapphInt.getSite(rurl)
  190.   print"loadin sit"
  191.   coSite = coroutine.create(site)
  192. end
  193.  
  194. function sapphInt.handleSapphari()
  195.   local site = sapphInt.handleWebsite("homepage")
  196.   --coSite = coroutine.create(site)
  197.   --handleWebsite does this
  198.   while coroutine.status(coSite) == "suspended" do
  199.     coroutine.resume(coSite)
  200.   end
  201.   print("it diedz")
  202.   print(coroutine.status(coSite))
  203. end
  204. ---------------------------------------------------
  205.  
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212. sapphInt.handleSapphari()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement