function yN() --declare a function (note that I am not actually runningit anywhere)
local n=1 --declares the starting selected option (a 'yes')
while true do -- a loop, necessary for going from step4 to step 1
term.clearLine() --clears one line for writing
if n==1 then write("[YES] NO") else write (" YES [NO]") end --writes options with one highlighted
a, b=os.pullEvent("key") --waits for a key press
if b==203 and n==2 then n=1 end --if pressed arrow left and selected option is 'no' then select 'yes'
if b==205 and n==1 then n=2 end --if pressed arrow right and selected option is 'yes' then select 'no'
if b==28 then print("") break end --if pressed enter then break the loop and execute the code outside it
end --close the loop code
if n==1 then return true end --if chosen 'yes' then return true
if n==2 then return false end --if chosen 'no', return false
end --close the function
local line01 = "01: "
local line02 = "02: "
local line03 = "03: "
local line04 = "04: "
local line05 = "05: "
local line06 = "06: "
local line07 = "07: "
local line08 = "08: "
local line09 = "09: "
local line10 = "10: "
function Main()
term.clear()
term.setCursorPos(1,1)
print("--------------------To Do--------------------")
print(line01)
print(line02)
print(line03)
print(line04)
print(line05)
print(line06)
print(line07)
print(line08)
print(line09)
print(line10)
print("Press any #(1-10) to change item.")
while true do
a, b=os.pullEvent("key")
if b == 2 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line01)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line01 = "01: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 3 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line02)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line02 = "02: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 4 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line03)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line03 = "03: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 5 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line04)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line04 = "04: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 6 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line05)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line05 = "05: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 7 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line06)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line06 = "06: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 8 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line07)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line07 = "07: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 9 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line08)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line08 = "08: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 10 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line09)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line09 = "09: " ..new
Main()
else
Main()
end
else
Main()
end
end
if b == 11 then
term.clear()
term.setCursorPos(1,1)
local linenum = b - 1
print("Do you want to edit Item " ..linenum.. "?")
if yN() == true then
print(line10)
print("New Item:")
local new = read()
print("Are you sure you want to change Item " ..linenum.. "?")
if yN() == true then
line10 = "10: " ..new
Main()
else
Main()
end
else
Main()
end
end
end
end
Main()
Also there is an odd bug where if you hit any key in my menu it moves across the screen instead of staying in one place.