Advertisement
SGunner2014

Untitled

Jan 31st, 2015
213
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. -- >> Variables << --
  2. DNSF = false
  3. mainOpts = { -- Will be replaced in future version
  4.     "Options",
  5.     "",
  6.     "Settings",
  7.     "Close",
  8. }
  9. run = true -- Sets main loop dependancy to true
  10. local dir = shell.dir().."/"
  11. local settings = {}
  12. local build = 160
  13. if not fs.exists("/loc/browser/userSet") then
  14.   local file = fs.open("/loc/browser/userSet","w")
  15.   local dat = {
  16.     btnColor = colors.gray,
  17.     bgColor = colors.lightGray,
  18.     mainColor = colors.white,
  19.     textColor = colors.white
  20.   }
  21.   file.write(textutils.serialize(dat))
  22.   file.close()
  23. end
  24.  
  25. local file = fs.open("/loc/browser/userSet","r")
  26. userSet = textutils.unserialize(file.readAll())
  27. file.close()
  28.  
  29. -- >> Functions << --
  30.  
  31. -- center
  32. function center(text,y,col)
  33.   if col~=nil then
  34.     term.setTextColor(userSet.textColor)
  35.   end
  36.     local w,h = term.getSize()
  37.     local x = ((w/2)-(#text/2))+1
  38.     term.setCursorPos(x,y)
  39.     write(text)
  40. end
  41.  
  42. -- click
  43. function click()
  44.   event, xB, xX, xY = os.pullEvent("mouse_click")
  45. end
  46.  
  47. -- keyPress
  48. function keyPress()
  49.   event, keyB = os.pullEvent("key_press")
  50. end
  51.  
  52. -- settings
  53. function settings()
  54.   setRun = true
  55.   repeat
  56.     term.setBackgroundColor(userSet.bgColor)
  57.     term.setTextColor(userSet.textColor)
  58.     term.clear()
  59.     center("Inzernet Browser Settings",1)
  60.     paintutils.drawPixel(51,1,colors.red)
  61.     term.setCursorPos(51,1)
  62.     write("X")
  63.     term.setBackgroundColor(userSet.bgColor)
  64.     center("Change main background color",3)
  65.     center("Change main button color",5)
  66.     center("Change secondary background color",7)
  67.     local event, button, x, y = os.pullEvent("mouse_click")
  68.     if button == 1 and x==51 and y==1 then
  69.       setRun = false
  70.     elseif button == 1 and y==3 then
  71.       local colSel = colorSel()
  72.       userSet.bgColor = colSel
  73.       upSet()
  74.     elseif button == 1 and y==5 then
  75.       local colSel = colorSel()
  76.       userSet[btnColor] = colSel
  77.       upSet()
  78.     elseif button == 1 and y==7 then
  79.       local colSel = colorSel()
  80.       userSet[mainColor] = colSel
  81.       upSet()
  82.     end
  83.   until setRun ~= true
  84. end
  85.  
  86. -- upSet
  87. function upSet()
  88.   local h = fs.open("/loc/browser/userSet","w")
  89.   h.write(textutils.serialize(userSet))
  90.   h.close()
  91. end
  92.  
  93. -- drawMain
  94. function drawMain()
  95.   term.setBackgroundColor(userSet.mainColor)
  96.   term.clear()
  97.   paintutils.drawLine(1,1,51,1,userSet.bgColor)
  98.   term.setCursorPos(1,1)
  99.   write("[^]")
  100.   paintutils.drawLine(4,1,50,1,userSet.btnColor)
  101.   term.setCursorPos(4,1)
  102.   write("Click here to browse...")
  103.   term.setBackgroundColor(colors.red)
  104.   term.setCursorPos(51,1)
  105.   write("X")
  106. end
  107.  
  108. -- drawWebsite
  109. function drawWebsite(var1)
  110.   local rawIP = inzernet.lookup(var1)
  111.   if rawIP ~= false then
  112.   term.setTextColor(colors.black)
  113.   print(rawIP)
  114.     local page = inzernet.GET(rawIP, "index")
  115.     print("debug again")
  116.     if page ~= false then
  117.       inzernet.write(page,var1)
  118.       inzernet.display(1,var1)
  119.     else
  120.       print("nope!")
  121.       sleep(2)
  122.     end
  123.   end
  124.   term.setTextColor(userSet.textColor)
  125. end
  126.  
  127. -- urlBar()
  128. function urlBar()
  129.   paintutils.drawLine(4,1,50,1,userSet.btnColor)
  130.   term.setCursorPos(4,1)
  131.   term.setTextColor(userSet.textColor)
  132.   local var = read()
  133.   return var
  134. end
  135.  
  136. -- colorSel
  137. function colorSel()
  138.   colSelRun = true
  139.   while true do
  140.     term.setBackgroundColor(userSet.bgColor)
  141.     term.clear()
  142.     center("Select a color",1)
  143.     center("Black",3,colors.black)
  144.     center("Gray",4,colors.gray)
  145.     center("Light Gray",5,colors.lightGray)
  146.     center("Red",6,colors.red)
  147.     center("Blue",7,colors.blue)
  148.     center("Pink",8,colors.pink)
  149.     center("Purple",9,colors.purple)
  150.     local event, button, x, y = os.pullEvent("mouse_click")
  151.     if button == 1 and y==3 then
  152.       return colors.black
  153.     elseif button == 1 and y==4 then
  154.       return colors.gray
  155.     elseif button == 1 and y==5 then
  156.       return colors.lightGray
  157.     elseif button == 1 and y==6 then
  158.       return colors.red
  159.     elseif button == 1 and y==7 then
  160.       return colors.blue
  161.     elseif button == 1 and y==8 then
  162.       return colors.pink
  163.     elseif button == 1 and y==9 then
  164.       return colors.purple
  165.     end
  166.   end
  167. end
  168.  
  169. -- mainFunc
  170. function mainFunc()
  171.   click()
  172.   if xB == 1 and xX>=1 and xX<=3 and xY == 1 then
  173.     local opSel = dropMenu(1,2,mainOpts)
  174.     if opSel == 3 then
  175.       settings()
  176.     end
  177.   elseif xB == 1 and xX>=4 and xX<=50 and xY == 1 then
  178.     local url = urlBar()
  179.     drawWebsite(url)
  180.   elseif xB == 1 and xX==51 and xY==1 then
  181.     run = false
  182.   end
  183. end
  184.  
  185. -- dropMenu
  186. function dropMenu(x,y,opts)
  187.   for yD=y,(y+#opts)-1 do
  188.     paintutils.drawLine(x,yD,x+10,yD,userSet.bgColor)
  189.   end
  190.   for k,v in pairs(opts) do
  191.     term.setCursorPos(x,y+k-1)
  192.     write(v)
  193.   end
  194.   local event, button, xPos, yPos = os.pullEvent("mouse_click")
  195.   if xPos>=x and xPos<=x+10 and yPos>=y and yPos<=y+#opts then
  196.     return (yPos-y)+1
  197.   end
  198. end
  199.  
  200. -- >> Startup << --
  201.  
  202. -- Loads inzernet API for program
  203. os.loadAPI("/loc/browser/includes/inzernet")
  204.  
  205. -- Startup InZernet API
  206. inzernet.startup()
  207.  
  208. -- Creates webDis
  209. webDis = window.create(term.native(),1,2,51,18)
  210.  
  211. -- >> Main Loop << --
  212. repeat
  213.   drawMain()
  214.   term.setBackgroundColor(colors.black)
  215.   mainFunc()
  216. until run ~= true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement