mldierks

luaEDIT - Install

Dec 6th, 2013
562
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.78 KB | None | 0 0
  1. -- VARIABLES --
  2. links = {
  3. ["luaedit"] = {"https://raw.github.com/wieselkatze/luaedit/master/dev/luaedit", true};
  4. [".ldt/schemes/default.scm"] = {"https://raw.github.com/wieselkatze/luaedit/master/schemes/default.scm", false};
  5. [".ldt/schemes/fire.scm"] = {"https://raw.github.com/wieselkatze/luaedit/master/schemes/fire.scm", false};
  6. [".ldt/schemes/np.scm"] = {"https://raw.github.com/wieselkatze/luaedit/master/schemes/np.scm", false};
  7. }
  8.  
  9. tlog = {}
  10. -- VARIABLES END --
  11.  
  12.  
  13. -- FUNCTIONS --
  14. function fwrite(file, path)
  15. local newpath = string.match(path, ".+/") or string.match(path, ".+\\")
  16.   if newpath and not fs.exists(newpath) then
  17.   fs.makeDir(newpath)
  18.   end
  19.   if not fs.isReadOnly(path) then
  20.   local f = io.open(path, "w")
  21.     if f then
  22.       if type(file) == "table" then
  23.         for _, v in pairs(file) do
  24.         f:write(tostring(v).."\n")
  25.         end
  26.       end
  27.     end
  28.   f:close()
  29.   end
  30. end
  31.  
  32. function makeField(x1, y1, x2, y2, color)
  33. term.setBackgroundColor(color)
  34.   for y = y1, y2 do
  35.   term.setCursorPos(x1, y)
  36.   write(string.rep(" ", x2-x1+1))
  37.   end
  38. end
  39.  
  40. function makeButton(x1, y1, x2, y2, name, text, color, pos)
  41. makeField(x1, y1, x2, y2, color)
  42.   if type(text) == "string" then
  43.     if not pos or pos == "c" then
  44.     local x = math.floor(((x2-x1+1)-#text)/2)+x1
  45.     local y = math.ceil((y2-y1+1)/2)+y1-1
  46.     term.setCursorPos(x, y)
  47.     write(text)
  48.     elseif pos == "l" then
  49.     local y = math.ceil((y2-y1+1)/2)+y1-1
  50.     term.setCursorPos(x1+1, y)
  51.     write(text)
  52.     elseif pos == "r" then
  53.     local y = math.ceil((y2-y1+1)/2)+y1-1
  54.     term.setCursorPos(x2-text:len(), y)
  55.     write(text)
  56.     end
  57.   end
  58.   if not prg.buttons then
  59.   buttons = {}
  60.   end
  61. buttons[name] = {x1, y1, x2, y2, text, pos}
  62. end
  63.  
  64. function checkButton(x1, y1)
  65.   for i, v in pairs(buttons) do
  66.     if x1 >= v[1] and x1 <= v[3] and y1 >= v[2] and y1 <= v[4] then
  67.     return i
  68.     end
  69.   end
  70. end
  71.  
  72. function writeLog()
  73. local scroll = 1
  74.   if #tlog > Y-8 then
  75.   scroll = #tlog-Y+9
  76.   end
  77.   if #tlog > Y-8 then
  78.     for i = 1, Y-8 do
  79.     term.setCursorPos(2, 6+i)
  80.     write(string.rep(" ", X-2))
  81.     term.setCursorPos(2, 6+i)
  82.     write(tlog[i+scroll-1])
  83.     end
  84.   else
  85.     for i = 1, #tlog do
  86.     term.setCursorPos(2, 6+i)
  87.     write(string.rep(" ", X-2))
  88.     term.setCursorPos(2, 6+i)
  89.     write(tlog[i])
  90.     end
  91.   end
  92. end
  93.  
  94. function startUI()
  95.   local function clear()
  96.   term.setBackgroundColor(128)
  97.   term.clear()
  98.   makeField(1, 2, X, 4, 256)
  99.   term.setCursorPos(2, 3)
  100.   write("Welcome to the installer of luaedit!")
  101.   makeField(1, 6, X, Y-1, 256)
  102.   end
  103. clear()
  104.   for i, v in pairs(links) do
  105.     if not http then
  106.     table.insert(tlog, "HTTP-API not enabled, aborting")
  107.     writeLog()
  108.     break
  109.     else
  110.     table.insert(tlog, "Getting "..i)
  111.     writeLog()
  112.     local resp = http.get(v[1])
  113.       if resp then
  114.       local file = {}
  115.       local ln = resp.readLine()
  116.         while ln ~= nil do
  117.         table.insert(file, ln)
  118.         ln = resp.readLine()
  119.         end
  120.       fwrite(file, i)
  121.       table.insert(tlog, "Got file "..i)
  122.       writeLog()
  123.       else
  124.         if v[2] then
  125.         table.insert(tlog, "Failed to get main file, aborting")
  126.         writeLog()
  127.         break
  128.         else
  129.         table.insert(tlog, "Failed to get "..i)
  130.         writeLog()
  131.         end
  132.       end
  133.     end
  134.   end
  135. table.insert(tlog, "Finished, click anywhere to exit")
  136. writeLog()
  137. os.pullEvent("mouse_click")
  138. end
  139. -- FUNCTIONS END --
  140.  
  141.  
  142. -- INITIALIZE --
  143. X, Y = term.getSize()
  144.   if term.isColor() then
  145.   running = true
  146.   else
  147.   print("Sorry, this program is only for advanced computers")
  148.   running = false
  149.   end
  150. -- INITIALIZE END --
  151.  
  152.  
  153. -- MAIN LOOP --
  154.   if running then
  155.   startUI()
  156.   term.setBackgroundColor(32768)
  157.   term.clear()
  158.   term.setCursorPos(1, 1)
  159.   end
  160. -- MAIN LOOP END --
Advertisement
Add Comment
Please, Sign In to add comment