Advertisement
Guest User

browser

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