Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[ iWolf
- Lua Browser ]]
- browserID = "wolf"
- if not term.isColor() then
- error("iWolf needs a Advanced Computer/PDA",0)
- end
- local modemSide
- for _,v in pairs(peripheral.getNames()) do
- if peripheral.getType(v) == "modem" and peripheral.call(v,"isWireless") == true then
- modemSide = v
- break
- end
- end
- if modemSide then
- rednet.open(modemSide)
- else
- error("iWolf needs a Wireless Modem!",0 )
- end
- local logo = {
- {{1,2,1,512,32768,1,1,1,1,512,32768,1,1,1,1,1,512,32768,1,1,512,512,32768,},},
- {{1,1,1,512,32768,1,1,1,1,512,32768,1,1,1,1,1,512,32768,1,512,32768,1,1},},
- {{1,2,1,512,32768,1,1,1,1,512,32768,1,512,512,32768,1,512,32768,512,512,512,512,32768,},},
- {{1,2,1,512,32768,1,512,32768,1,512,32768,512,32768,1,512,32768,512,32768,1,512,32768,},},
- {{1,2,1,512,32768,512,32768,512,32768,512,32768,512,32768,1,512,32768,512,32768,1,512,32768,},},
- {{1,2,1,512,512,32768,1,1,512,512,32768,1,512,512,32768,1,1,512,32768,512,32768,},},
- }
- local termX,termY = term.getSize()
- local centerX,centerY = termX/2+1,termY/2+1
- function cWrite(text,y)
- local _,cy = term.getCursorPos()
- term.setCursorPos(centerX-#text/2,y or cy)
- write(text.."\n")
- end
- function rWrite(text,y)
- local _,cy = term.getCursorPos()
- term.setCursorPos(termX-#text,y or cy)
- write(text)
- end
- local function wait(t)
- parallel.waitForAny(
- function() sleep(t or 3) end,
- function() os.pullEvent("key") end,
- function() os.pullEvent("mouse_click") end)
- end
- local function fadeIn()
- term.setBackgroundColor(colors.black)
- term.clear() sleep(.1)
- term.setBackgroundColor(colors.gray)
- term.clear() sleep(.1)
- term.setBackgroundColor(colors.lightGray)
- term.clear() sleep(.1)
- term.setBackgroundColor(colors.white)
- term.clear() sleep(.1)
- end
- local function fadeOut()
- term.setBackgroundColor(colors.white)
- term.clear() sleep(.1)
- term.setBackgroundColor(colors.lightGray)
- term.clear() sleep(.1)
- term.setBackgroundColor(colors.gray)
- term.clear() sleep(.1)
- term.setBackgroundColor(colors.black)
- term.clear() sleep(.1)
- end
- local settings
- local function getSettings()
- if fs.exists(".wolfSettings") then
- local settingsF = fs.open(".wolfSettings","r")
- settings = textutils.unserialize(settingsF.readAll())
- else
- settings = {home="wolf/home"}
- local settingsF = fs.open(".wolfSettings","w")
- settingsF.write(textutils.serialize(settings))
- end
- settingsF.close()
- end
- local function welcomeScreen()
- fadeIn()
- local startX = centerY-5
- for i = 1,#logo do
- sleep(.1)
- paintutils.drawImage(logo[i],centerX-12,startX-1+i)
- end
- term.setBackgroundColor(colors.white)
- term.setTextColor(colors.black)
- for i = termX,centerX-5,-3 do
- term.setCursorPos(i,centerY+2)
- term.write("Web Browser ")
- sleep(.01)
- end
- term.setCursorPos(centerX-5,centerY+2)
- term.write("Web Browser ")
- wait(3)
- fadeOut()
- end
- --# Local Sites #--
- local wolfPages = {
- home = [[
- termX,termY = term.getSize()
- cx,cy = termX/2+1,termY/2+1
- term.setBackgroundColor(colors.gray) term.clear()
- term.setTextColor(colors.white)
- cWrite("iWolf Homepage",1)
- paintutils.drawFilledBox(1,3,cx+5,9,colors.blue)
- term.setTextColor(colors.white)
- term.setCursorPos(1,4)
- write(" With iWolf, you can access\n Lua based websites, in your")
- write("\n Rednet network OR in REAL\n WebServers!")
- ]],
- notFound = [[
- termX,termY = term.getSize()
- cx,cy = termX/2+1,termY/2+1
- term.setBackgroundColor(colors.white) term.clear()
- paintutils.drawFilledBox(10,2,termX-9,4,colors.red)
- term.setTextColor(colors.white)
- cWrite("This website isn't available",3)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- cWrite("Sorry, but I couldn't connect")
- cWrite("to the requested page.")
- cWrite("Are you sure the server is online,")
- cWrite("or it's in range?")
- ]],
- settings = [[
- term.setBackgroundColor(colors.white) term.clear()
- term.setCursorPos
- ]],
- }
- --# Browser Core #--
- -- Windows
- local wSite
- local wUrl
- local cTerm = term.current()
- function goto(url)
- local loadedPage = loadstring(wolfPages["notFound"])
- domain = url:match("^(.-)/")
- page = url:match("/(.+)$")
- if domain == "wolf" then
- for k,v in pairs(wolfPages) do
- if k == page then
- loadedPage = loadstring(v)
- end
- end
- else
- rednet.broadcast(page,domain)
- end
- setfenv(loadedPage, getfenv())
- term.redirect(wSite)
- loadedPage()
- term.redirect(cTerm)
- end
- local function enterUrl()
- term.redirect(wUrl)
- term.clear()
- term.setCursorPos(1,1)
- local url = read()
- goto(url)
- if term.current() ~= wUrl then term.redirect(wUrl) end
- term.setCursorPos(1,1)
- if #url>38 then
- write(url:sub(1,38))
- write "..."
- else
- write(url)
- end
- term.redirect(cTerm)
- end
- local guiReady
- local function createGui()
- fadeIn()
- paintutils.drawFilledBox(1,1,termX,2,colors.gray)
- term.setTextColor(colors.white)
- term.setCursorPos(1,1)
- write "iWolf"
- term.setCursorPos(termX,1)
- write "X"
- paintutils.drawFilledBox(7,1,termX-2,1,colors.lightGray)
- wUrl = window.create(term.current(),8,1,termX-10,1,true)
- wUrl.setBackgroundColor(colors.lightGray)
- wUrl.clear()
- wSite = window.create(term.current(),1,3,termX,termY-2,true)
- wSite.setBackgroundColor(colors.white)
- wSite.clear()
- guiReady = true
- end
- function events()
- while true do
- local event = {os.pullEventRaw()}
- if event[1] == "mouse_click" and guiReady then
- x, y = event[3], event[4]
- if x>=7 and x<=termX-2 and y==1 then
- enterUrl()
- elseif x==termX and y==1 then
- os.queueEvent("terminate")
- end
- elseif event[1] == "terminate" then
- if term.current() ~= cTerm then term.redirect(cTerm) end
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setTextColor(colors.white)
- cWrite("Thanks for using iWolf!",1)
- error("\n",0)
- end
- end
- end
- local args = {...}
- local function start()
- if args[1] == "q" or args[1] == "quick" then
- createGui()
- else
- welcomeScreen()
- createGui()
- end
- goto("wolf/home")
- end
- parallel.waitForAll(events, start)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement