Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- >> Variables << --
- DNSF = false
- mainOpts = { -- Will be replaced in future version
- "Options",
- "",
- "Settings",
- "Close",
- }
- run = true -- Sets main loop dependancy to true
- local dir = shell.dir().."/"
- local settings = {}
- local build = 160
- if not fs.exists("/loc/browser/userSet") then
- local file = fs.open("/loc/browser/userSet","w")
- local dat = {
- btnColor = colors.gray,
- bgColor = colors.lightGray,
- mainColor = colors.white,
- textColor = colors.white
- }
- file.write(textutils.serialize(dat))
- file.close()
- end
- local file = fs.open("/loc/browser/userSet","r")
- userSet = textutils.unserialize(file.readAll())
- file.close()
- -- >> Functions << --
- -- center
- function center(text,y,col)
- if col~=nil then
- term.setTextColor(userSet.textColor)
- end
- local w,h = term.getSize()
- local x = ((w/2)-(#text/2))+1
- term.setCursorPos(x,y)
- write(text)
- end
- -- click
- function click()
- event, xB, xX, xY = os.pullEvent("mouse_click")
- end
- -- keyPress
- function keyPress()
- event, keyB = os.pullEvent("key_press")
- end
- -- settings
- function settings()
- setRun = true
- repeat
- term.setBackgroundColor(userSet.bgColor)
- term.setTextColor(userSet.textColor)
- term.clear()
- center("Inzernet Browser Settings",1)
- paintutils.drawPixel(51,1,colors.red)
- term.setCursorPos(51,1)
- write("X")
- term.setBackgroundColor(userSet.bgColor)
- center("Change main background color",3)
- center("Change main button color",5)
- center("Change secondary background color",7)
- local event, button, x, y = os.pullEvent("mouse_click")
- if button == 1 and x==51 and y==1 then
- setRun = false
- elseif button == 1 and y==3 then
- local colSel = colorSel()
- userSet.bgColor = colSel
- upSet()
- elseif button == 1 and y==5 then
- local colSel = colorSel()
- userSet[btnColor] = colSel
- upSet()
- elseif button == 1 and y==7 then
- local colSel = colorSel()
- userSet[mainColor] = colSel
- upSet()
- end
- until setRun ~= true
- end
- -- upSet
- function upSet()
- local h = fs.open("/loc/browser/userSet","w")
- h.write(textutils.serialize(userSet))
- h.close()
- end
- -- drawMain
- function drawMain()
- term.setBackgroundColor(userSet.mainColor)
- term.clear()
- paintutils.drawLine(1,1,51,1,userSet.bgColor)
- term.setCursorPos(1,1)
- write("[^]")
- paintutils.drawLine(4,1,50,1,userSet.btnColor)
- term.setCursorPos(4,1)
- write("Click here to browse...")
- term.setBackgroundColor(colors.red)
- term.setCursorPos(51,1)
- write("X")
- end
- -- drawWebsite
- function drawWebsite(var1)
- local rawIP = inzernet.lookup(var1)
- if rawIP ~= false then
- term.setTextColor(colors.black)
- print(rawIP)
- local page = inzernet.GET(rawIP, "index")
- print("debug again")
- if page ~= false then
- inzernet.write(page,var1)
- inzernet.display(1,var1)
- else
- print("nope!")
- sleep(2)
- end
- end
- term.setTextColor(userSet.textColor)
- end
- -- urlBar()
- function urlBar()
- paintutils.drawLine(4,1,50,1,userSet.btnColor)
- term.setCursorPos(4,1)
- term.setTextColor(userSet.textColor)
- local var = read()
- return var
- end
- -- colorSel
- function colorSel()
- colSelRun = true
- while true do
- term.setBackgroundColor(userSet.bgColor)
- term.clear()
- center("Select a color",1)
- center("Black",3,colors.black)
- center("Gray",4,colors.gray)
- center("Light Gray",5,colors.lightGray)
- center("Red",6,colors.red)
- center("Blue",7,colors.blue)
- center("Pink",8,colors.pink)
- center("Purple",9,colors.purple)
- local event, button, x, y = os.pullEvent("mouse_click")
- if button == 1 and y==3 then
- return colors.black
- elseif button == 1 and y==4 then
- return colors.gray
- elseif button == 1 and y==5 then
- return colors.lightGray
- elseif button == 1 and y==6 then
- return colors.red
- elseif button == 1 and y==7 then
- return colors.blue
- elseif button == 1 and y==8 then
- return colors.pink
- elseif button == 1 and y==9 then
- return colors.purple
- end
- end
- end
- -- mainFunc
- function mainFunc()
- click()
- if xB == 1 and xX>=1 and xX<=3 and xY == 1 then
- local opSel = dropMenu(1,2,mainOpts)
- if opSel == 3 then
- settings()
- end
- elseif xB == 1 and xX>=4 and xX<=50 and xY == 1 then
- local url = urlBar()
- drawWebsite(url)
- elseif xB == 1 and xX==51 and xY==1 then
- run = false
- end
- end
- -- dropMenu
- function dropMenu(x,y,opts)
- for yD=y,(y+#opts)-1 do
- paintutils.drawLine(x,yD,x+10,yD,userSet.bgColor)
- end
- for k,v in pairs(opts) do
- term.setCursorPos(x,y+k-1)
- write(v)
- end
- local event, button, xPos, yPos = os.pullEvent("mouse_click")
- if xPos>=x and xPos<=x+10 and yPos>=y and yPos<=y+#opts then
- return (yPos-y)+1
- end
- end
- -- >> Startup << --
- -- Loads inzernet API for program
- os.loadAPI("/loc/browser/includes/inzernet")
- -- Startup InZernet API
- inzernet.startup()
- -- Creates webDis
- webDis = window.create(term.native(),1,2,51,18)
- -- >> Main Loop << --
- repeat
- drawMain()
- term.setBackgroundColor(colors.black)
- mainFunc()
- until run ~= true
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement