Advertisement
Guest User

browser

a guest
Jan 31st, 2015
236
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.63 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/userSettings") then
  14.   local file = fs.open("/loc/browser/userSettings","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/userSettings","r")
  25. userSet = textutils.unserialize(file.readAll())
  26. file.close()
  27.  
  28. -- >> Functions << --
  29.  
  30. -- click
  31. function click()
  32.   event, xB, xX, xY = os.pullEvent("mouse_click")
  33. end
  34.  
  35. -- keyPress
  36. function keyPress()
  37.   event, keyB = os.pullEvent("key_press")
  38. end
  39.  
  40. -- drawMain
  41. function drawMain()
  42.   term.setBackgroundColor(userSet.mainColor)
  43.   term.clear()
  44.   paintutils.drawLine(1,1,51,1,userSet.bgColor)
  45.   term.setCursorPos(1,1)
  46.   write("[^]")
  47.   paintutils.drawLine(4,1,50,1,userSet.btnColor)
  48.   term.setCursorPos(4,1)
  49.   write("Click here to browse...")
  50.   term.setBackgroundColor(colors.red)
  51.   term.setCursorPos(51,1)
  52.   write("X")
  53. end
  54.  
  55. -- drawWebsite
  56. function drawWebsite(var1)
  57.   local rawIP = inzernet.lookup(var1)
  58.   if var1 ~= DNSF then
  59.     local fIP = inzernet.parse(rawIP)
  60.     local page = inzernet.GET(fIP,"index")
  61.     inzernet.write(page)
  62.   end
  63. end
  64.  
  65. -- urlBar()
  66. function urlBar()
  67.   paintutils.drawLine(4,1,50,1,userSet.btnColor)
  68.   term.setCursorPos(4,1)
  69.   term.setTextColor(colors.white)
  70.   local var = read()
  71.   return var
  72. end
  73.  
  74. -- mainFunc
  75. function mainFunc()
  76.   click()
  77.   if xB == 1 and xX>=1 and xX<=3 and xY == 1 then
  78.     dropMenu(1,2,mainOpts)
  79.   elseif xB == 1 and xX>=4 and xX<=50 and xY == 1 then
  80.     local url = urlBar()
  81.     drawWebsite(url)
  82.   elseif xB == 1 and xX==51 and xY==1 then
  83.     run = false
  84.   end
  85. end
  86.  
  87. -- dropMenu
  88. function dropMenu(x,y,opts)
  89.   for yD=y,(y+#opts)-1 do
  90.     paintutils.drawLine(x,yD,x+10,yD,userSet.bgColor)
  91.   end
  92.   for k,v in pairs(opts) do
  93.     term.setCursorPos(x,y+k-1)
  94.     write(v)
  95.   end
  96.   local event, button, xPos, yPos = os.pullEvent("mouse_click")
  97.   if xPos>=x and xPos<=x+10 and yPos>=y and yPos<=y+#opts then
  98.     return (yPos-y)+1
  99.   end
  100. end
  101.  
  102. -- >> Startup << --
  103.  
  104. -- Loads inzernet API for program
  105. os.loadAPI("/loc/browser/includes/inzernet")
  106.  
  107. -- Startup InZernet API
  108. inzernet.startup()
  109.  
  110. -- Creates webDis
  111. webDis = window.create(term.native(),1,2,51,18)
  112.  
  113. -- >> Main Loop << --
  114. repeat
  115.   drawMain()
  116.   term.setBackgroundColor(colors.black)
  117.   mainFunc()
  118. until run ~= true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement