Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- VARIABLES --
- links = {
- ["luaedit"] = {"https://raw.github.com/wieselkatze/luaedit/master/dev/luaedit", true};
- [".ldt/schemes/default.scm"] = {"https://raw.github.com/wieselkatze/luaedit/master/schemes/default.scm", false};
- [".ldt/schemes/fire.scm"] = {"https://raw.github.com/wieselkatze/luaedit/master/schemes/fire.scm", false};
- [".ldt/schemes/np.scm"] = {"https://raw.github.com/wieselkatze/luaedit/master/schemes/np.scm", false};
- }
- tlog = {}
- -- VARIABLES END --
- -- FUNCTIONS --
- function fwrite(file, path)
- local newpath = string.match(path, ".+/") or string.match(path, ".+\\")
- if newpath and not fs.exists(newpath) then
- fs.makeDir(newpath)
- end
- if not fs.isReadOnly(path) then
- local f = io.open(path, "w")
- if f then
- if type(file) == "table" then
- for _, v in pairs(file) do
- f:write(tostring(v).."\n")
- end
- end
- end
- f:close()
- end
- end
- function makeField(x1, y1, x2, y2, color)
- term.setBackgroundColor(color)
- for y = y1, y2 do
- term.setCursorPos(x1, y)
- write(string.rep(" ", x2-x1+1))
- end
- end
- function makeButton(x1, y1, x2, y2, name, text, color, pos)
- makeField(x1, y1, x2, y2, color)
- if type(text) == "string" then
- if not pos or pos == "c" then
- local x = math.floor(((x2-x1+1)-#text)/2)+x1
- local y = math.ceil((y2-y1+1)/2)+y1-1
- term.setCursorPos(x, y)
- write(text)
- elseif pos == "l" then
- local y = math.ceil((y2-y1+1)/2)+y1-1
- term.setCursorPos(x1+1, y)
- write(text)
- elseif pos == "r" then
- local y = math.ceil((y2-y1+1)/2)+y1-1
- term.setCursorPos(x2-text:len(), y)
- write(text)
- end
- end
- if not prg.buttons then
- buttons = {}
- end
- buttons[name] = {x1, y1, x2, y2, text, pos}
- end
- function checkButton(x1, y1)
- for i, v in pairs(buttons) do
- if x1 >= v[1] and x1 <= v[3] and y1 >= v[2] and y1 <= v[4] then
- return i
- end
- end
- end
- function writeLog()
- local scroll = 1
- if #tlog > Y-8 then
- scroll = #tlog-Y+9
- end
- if #tlog > Y-8 then
- for i = 1, Y-8 do
- term.setCursorPos(2, 6+i)
- write(string.rep(" ", X-2))
- term.setCursorPos(2, 6+i)
- write(tlog[i+scroll-1])
- end
- else
- for i = 1, #tlog do
- term.setCursorPos(2, 6+i)
- write(string.rep(" ", X-2))
- term.setCursorPos(2, 6+i)
- write(tlog[i])
- end
- end
- end
- function startUI()
- local function clear()
- term.setBackgroundColor(128)
- term.clear()
- makeField(1, 2, X, 4, 256)
- term.setCursorPos(2, 3)
- write("Welcome to the installer of luaedit!")
- makeField(1, 6, X, Y-1, 256)
- end
- clear()
- for i, v in pairs(links) do
- if not http then
- table.insert(tlog, "HTTP-API not enabled, aborting")
- writeLog()
- break
- else
- table.insert(tlog, "Getting "..i)
- writeLog()
- local resp = http.get(v[1])
- if resp then
- local file = {}
- local ln = resp.readLine()
- while ln ~= nil do
- table.insert(file, ln)
- ln = resp.readLine()
- end
- fwrite(file, i)
- table.insert(tlog, "Got file "..i)
- writeLog()
- else
- if v[2] then
- table.insert(tlog, "Failed to get main file, aborting")
- writeLog()
- break
- else
- table.insert(tlog, "Failed to get "..i)
- writeLog()
- end
- end
- end
- end
- table.insert(tlog, "Finished, click anywhere to exit")
- writeLog()
- os.pullEvent("mouse_click")
- end
- -- FUNCTIONS END --
- -- INITIALIZE --
- X, Y = term.getSize()
- if term.isColor() then
- running = true
- else
- print("Sorry, this program is only for advanced computers")
- running = false
- end
- -- INITIALIZE END --
- -- MAIN LOOP --
- if running then
- startUI()
- term.setBackgroundColor(32768)
- term.clear()
- term.setCursorPos(1, 1)
- end
- -- MAIN LOOP END --
Advertisement
Add Comment
Please, Sign In to add comment