View difference between Paste ID: VPqVrDq0 and ptiTwFSP
SHOW: | | - or go back to the newest paste.
1
local w,h = term.getSize()
2
3
--Center Text
4
5
function printCentered (y,s)
6
    local x = math.floor((w - string.len(s)) /2)
7
    term.setCursorPos(x,y)
8
    term.clearLine()
9
    term.write(s)
10
end
11
12
--Drawmenu
13
14
local nOption = 1
15
16
local function drawMenu()
17
    term.setBackgroundColor(colors.cyan)
18
    term.clear()
19
    term.setCursorPos(1,1)
20
    logo = paintutils.loadImage("os/.logo")
21
    paintutils.drawImage(logo, 1, 1)
22
    term.setBackgroundColor(colors.cyan)
23
    
24
    term.setCursorPos(w-11,1)
25
    if nOption == 1 then
26
        term.write("Shutdown")
27
    elseif nOption == 2 then
28
        term.write("Reboot")
29
    elseif nOption == 3 then
30
        term.write("Log off")
31
    elseif nOption == 4 then
32
        term.write("Exit")
33
    else
34
        end
35
end    
36
37
--GUI
38
39
term.clear()
40
local function drawFrontend()
41
    printCentered(math.floor(h/2) -3, "")
42
    printCentered(math.floor(h/2) -2, "SHUTDOWN")
43
    printCentered(math.floor(h/2) -1, "")
44
    printCentered(math.floor(h/2) + 0, (nOption == 1 and "[ Shutdown ]") or "Shutdown")
45
    printCentered(math.floor(h/2) + 1, (nOption == 2 and "[ Reboot ]") or "Reboot")
46
    printCentered(math.floor(h/2) + 2, (nOption == 3 and "[ Log off ]") or "Log off")
47
    printCentered(math.floor(h/2) + 3, (nOption == 4 and "[ Exit ]") or "Exit")
48
end
49
50
--Display
51
52
drawMenu()
53
drawFrontend()
54
55
while true do
56
    local e,p = os.pullEvent()
57
        if e == "key" then
58
            local key = p
59-
            if key == 17 or key == 200 then
59+
            if key == keys.up or key == 200 then
60
            
61
                if nOption > 1 then
62
                    nOption = nOption -1
63
                    drawMenu()
64
                    drawFrontend()
65
                end
66-
            elseif key == 31 or key == 208 then
66+
            elseif key == keys.down or key == 208 then
67
                if nOption < 4 then
68
                    nOption = nOption +1
69
                    drawMenu()
70
                    drawFrontend()
71
                end
72-
        elseif key == 28 then
72+
        elseif key == keys.enter then
73
            break
74
end
75
end
76
end
77
78
term.clear()
79
80
--Conditions
81
if nOption == 1 then
82-
    term.setBackgroundColor(colors.black)
82+
83
elseif nOption == 2 then
84
    term.setCursorPos(1,1)
85
    shell.run("reboot")
86
elseif nOption == 3 then
87
    term.setCursorPos(1,1)
88
    shell.run("os/Starter")
89
else
90
    shell.run("os/.functions")
91
end