Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local programOptions = {
- {"Button1", button1},
- }
- local varY = 3
- local s = 1
- local w,h = term.getSize()
- local function center(text, line, col)
- term.setCursorPos(math.floor(w/2)-string.len(text)/2, line)
- term.setBackgroundColour(col)
- term.clearLine()
- print(text)
- end
- local function space()
- print("")
- end
- local function cPrint(str)
- x, _ = term.getSize()
- _, y = term.getCursorPos()
- term.setCursorPos((x-#str)/2, y)
- print(str)
- end
- local function drawTitle()
- term.setTextColor(32)
- term.clear()
- term.setCursorPos(1,1)
- cPrint("[ SelectOS BETA ]")
- space()
- space()
- end
- local function drawMain(_table)
- for i = 1, #_table do
- if s == i then
- center(_table[i][1], varY + i, colours.cyan)
- else
- center(_table[i][1], varY + i, colours.blue)
- end
- end
- end
- local function gui(_table)
- while true do
- term.clear()
- term.setCursorPos(1,1)
- term.setBackgroundColor(colors.blue)
- drawTitle()
- term.setTextColor(colors.white)
- drawMain(_table)
- local event, p1, p2, p3 = os.pullEvent()
- if event == "key" then
- if p1 == keys.down or p1 == 31 then
- s = s + 1
- if s >= #_table + 1 then s = 1 end
- elseif p1 == keys.up or p1 == 17 then
- s = s - 1
- if s <= 0 then s = #_table end
- elseif p1 == keys.enter then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- print(type(_table[s][2])) sleep(1)
- _table[s][2]()
- end
- elseif event == "mouse_click" then
- if _table[p3 - 3] ~= nil then
- start=math.floor(math.floor(51/2)-(string.len(_table[p3-3][1])+4)/2)-1
- if start <p2 and start+(string.len(_table[p3-3][1])+5)>p2 then
- term.setBackgroundColor(colors.black)
- term.setTextColor(colors.white)
- _table[p3-3][2]()
- end
- end
- elseif event == "mouse_scroll" then
- s = s + p1
- if s >= #_table + 1 then s = 1 end
- if s <= 0 then s = #_table end
- end
- end
- end
- local function drawPrograms()
- gui(programOptions)
- end
- local mainOptions = {
- {"Programs", drawPrograms},
- {"Control Panal", drawCP},
- {"File Browser", bFile},
- {"Command Prompt", drawCMD},
- {"Exit to CraftOS", function() term.clear() term.setCursorPos(1,1) error();end},
- {"Restart Computer", os.reboot},
- {"Shutdown Computer", os.shutdown},
- }
- gui(mainOptions)
Advertisement
Add Comment
Please, Sign In to add comment