Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if not term.isColor() then
- error("Invalid display")
- end
- local w,h = term.getSize()
- defaultConfig = {
- desktop = {
- background = 2,
- },
- user = {
- name = nil,
- password = nil,
- }
- }
- params = {}
- --display functions
- function nicePrint(text, x, y, bcolor, fcolor)
- if bcolor ~= nil then
- term.setBackgroundColor(bcolor)
- end
- term.setTextColor(fcolor)
- term.setCursorPos(x, y)
- term.write(text)
- end
- function centerPrint(text, y, bcolor, fcolor)
- nicePrint(text, w / 2 - #text / 2, y, bcolor, fcolor)
- end
- function rectangle(x, y, w, h, color)
- paintutils.drawFilledBox(x + 1, y + 1, x + 1 + w, y + 1 + h, color)
- end
- --main functions
- function setup()
- local step = 0
- local username = "Username: "
- local password = "Password: "
- local confirmPassword = "Confirm password: "
- local bgColor = "Desktop color: "
- while true do
- rectangle(0, 0, w, h, 1)
- rectangle(0, 0, w, 2, 128)
- nicePrint("Welcome to BeraudOS !", 2, 2, nil, 1)
- nicePrint("Let's configure your desktop !", 2, 5, 1, 32768)
- nicePrint("> Fill in the informations bellow", 2, 6, 1, 2048)
- nicePrint(username, 4, 8, 1, 256)
- nicePrint(password, 4, 9, 1, 256)
- if step > 3 then
- nicePrint(confirmPassword, 4, 10, 1, 8192)
- else
- nicePrint(confirmPassword, 4, 10, 1, 256)
- end
- nicePrint(bgColor, 4, 11, 1, 256)
- if step < 4 then
- nicePrint(">", 2, 8 + step, 1, 2048)
- if step == 0 then
- term.setCursorPos(14, 8)
- defaultConfig.user.name = io.read()
- username = username .. defaultConfig.user.name
- elseif step == 1 then
- term.setCursorPos(14, 9)
- defaultConfig.user.password = read("*")
- password = password .. "Hidden"
- elseif step == 2 then
- local p = nil
- while p ~= defaultConfig.user.password do
- rectangle(22, 10, 30, 1, 1)
- term.setCursorPos(22, 10)
- p = read("*")
- end
- confirmPassword = confirmPassword .. "Hidden"
- elseif step == 3 then
- local c = 2
- local r = true
- while r do
- nicePrint("<Next>", 20, 11, 2^c, 1)
- nicePrint(" OK ", 26, 11, 2048, 1)
- e = {os.pullEvent()}
- if e[1] == "mouse_click" then
- if e[4] == 11 then
- if e[3] >= 20 and e[3] <= 25 then
- if c + 1 < 14 then
- c = c + 1
- else
- c = 2
- end
- elseif e[3] >= 26 and e[3] <= 30 then
- defaultConfig.desktop.background = c
- bgColor = bgColor .. "Chosen"
- r = false
- end
- end
- end
- end
- end
- step = step + 1
- elseif step == 4 then
- nicePrint(" Done ", w - 9, h - 2, 2048, 1)
- e = {os.pullEvent()}
- if e[1] == "mouse_click" and e[3] >= w - 9 and e[3] <= w - 1 and e[4] == h - 2 then
- local f = fs.open("/os/config.cfg", "w")
- f.write("return " .. textutils.serialize(defaultConfig))
- step = 5
- end
- elseif step == 5 then
- nicePrint(" Rebooting ", w - 11, h - 2, 512, 1)
- sleep(2)
- os.reboot()
- end
- end
- end
- function desktop()
- local i = 0
- while true do
- rectangle(0, 0, w, h, 1)
- centerPrint("BeraudOS is loading (" .. i .. " %) ...", h / 2, 1, 32768)
- sleep(2)
- if i + 1 == 100 then
- i = 0
- else
- i = i + 1
- end
- end
- end
- function init()
- rectangle(0, 0, w, h, 128)
- sleep(0.1)
- rectangle(0, 0, w, h, 256)
- sleep(0.1)
- rectangle(0, 0, w, h, 1)
- local boot = true
- local timer = os.startTimer(2)
- while boot do
- e = {os.pullEvent()}
- if e[1] == "timer" then
- boot = false
- desktop()
- elseif e[1] == "key" and e[2] == keys.c then
- boot = false
- os.cancelTimer(timer)
- term.setBackgroundColor(32768)
- term.clear()
- term.setTextColor(1)
- term.setCursorPos(1, 1)
- shell.run("shell")
- end
- end
- end
- if fs.exists("/os/config.cfg") then
- params = dofile("/os/config.cfg")
- init()
- else
- setup()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement