Advertisement
zahar0401

A glorified cat

Jul 30th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.28 KB | None | 0 0
  1. bArgs = {...}
  2. local ignoreScripts, isScript = false
  3. local handle, details, contents = nil
  4.  
  5. local function loadPage(url)
  6.  if not fs.exists(url) then
  7.   if fs.isDir(url) then
  8.    if fs.exists(url.."/index") then
  9.     return fs.open(url.."/index", "r"), nil
  10.    elseif fs.exists(url.."/index.php") then
  11.     return fs.open(url.."/index.php", "r"), nil
  12.    end
  13.   else
  14.    return nil, "404: File not found!"
  15.   end
  16.  elseif fs.exists(url..".php") then
  17.   return fs.open(url..".php", "r"), nil
  18.  elseif fs.exists(url..".script") then
  19.   if ignoreScripts then
  20.    return nil, "Scripts are unavailable; Try not using the -ns parameter"
  21.   end
  22.   isScript = true
  23.   print("Running "..url..".script")
  24.   shell.run(url..".script")
  25.  else
  26.   return fs.open(url, "r"), nil
  27.  end
  28. end
  29.  
  30. if #bArgs < 1 then
  31.  print("browser < url > [ -ns/--no-scripts ]")
  32. else
  33.  if bArgs[2] == "--no-scripts" or bArgs[2] == "-ns" then
  34.   ignoreScripts = true
  35.  end
  36.  handle, details = loadPage(bArgs[1])
  37.  if handle and details == nil then
  38.   contents = handle.readAll()
  39.   shell.run("clear")
  40.   term.setCursorPos(1,1)
  41.   print(contents)
  42.   os.pullEventRaw("key")
  43.   handle.close()
  44.  elseif isScript then
  45.   return
  46.  elseif details ~= nil then
  47.   printError([[
  48.   Atom Browser has crashed!
  49.  
  50.   Details:
  51.   ]]..details)
  52.  end
  53. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement