-
Notifications
You must be signed in to change notification settings - Fork 2
/
settingsmanager.lua
92 lines (86 loc) · 2.06 KB
/
settingsmanager.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
local function addSetting(set,text)
local tmpta = {}
tmpta["name"] = set
tmpta["con"] = settings.get(set)
tmpta["text"] = text
table.insert(setta,tmpta)
end
local function getBoolean(str)
if str == true then
return "Enabled"
else
return "Disabled"
end
end
local function drawText()
term.clear()
term.setCursorPos(1,1)
tablecou = 0
for nu,conta in ipairs(setta) do
local posx,posy = term.getCursorPos()
write(conta["text"])
term.setCursorPos(35,posy)
if cupos == nu then
write("["..getBoolean(conta["con"]).."]")
else
write(getBoolean(conta["con"]))
end
print()
tablecou = tablecou + 1
end
print()
print("Press up/down to select option")
print("Press left/right to enable/disable")
print("Press Enter to save and exit")
print("Press C to cancel")
print("Press D to restore defaults")
end
local function saveSettings()
for _,seta in ipairs(setta) do
settings.set(seta["name"],seta["con"])
end
settings.save(".settings")
end
local function setDefault()
setta[1]["con"] = true
setta[2]["con"] = true
setta[3]["con"] = true
setta[4]["con"] = true
setta[5]["con"] = true
setta[6]["con"] = false
setta[7]["con"] = true
end
os.sleep(0.2)
setta = {}
cupos = 1
addSetting("bios.use_multishell","Use Multishell")
addSetting("shell.autocomplete","Allow autocomplete in the Shell")
addSetting("shell.allow_disk_startup","Allow startup from Disk")
addSetting("shell.allow_startup","Allow atartup from Computer")
addSetting("lua.autocomplete","Allow autocomplete in lua")
addSetting("list.show_hidden","List hidden files")
addSetting("edit.autocomplete","Allow autocomplete in edit")
while true do
drawText()
local ev,key = os.pullEvent("key_up")
if key == keys.down and not (cupos == tablecou) then
cupos = cupos + 1
elseif key == keys.up and cupos > 1 then
cupos = cupos - 1
elseif key == keys.left or key == keys.right then
if setta[cupos]["con"] == true then
setta[cupos]["con"] = false
else
setta[cupos]["con"] = true
end
elseif key == keys.enter then
saveSettings()
break
elseif key == keys.c then
break
elseif key == keys.d then
setDefault()
end
end
term.clear()
term.setCursorPos(1,1)