Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require('config')
- local version = 1.2
- local DISK_SIDE = 'bottom'
- local W, H = term.getSize()
- local totalSpace = 2097152
- local totalSpaceFloppy = 524288
- local freeSpace = fs.getFreeSpace('/')
- local debug = false
- local selected = 1
- choice = {}
- function addChoice(name, path, spacer)
- choice[#choice+1] = {}
- choice[#choice].name = name
- choice[#choice].path = path
- end
- setup_menu()
- local timeout = os.startTimer(1)
- while true do
- local dt = 0
- term.clear()
- term.setCursorPos(1, 1)
- term.write('bubOS 2019 v'..version)
- term.setCursorPos(W-4, 1)
- term.write(textutils.formatTime(os.time(), true))
- term.setCursorPos(W-tostring(freeSpace..'B / '..totalSpace..'B free'):len(), H-1)
- term.write(freeSpace..'B / '..totalSpace..'B free')
- term.setCursorPos(1, H-1)
- term.write('[')
- for n = 1, W/2-2 do
- if n < (W/2-2)*(totalSpace-freeSpace)/totalSpace then
- term.write('|')
- end
- end
- term.setCursorPos(W/2, H-1)
- term.write(']')
- if disk.isPresent(DISK_SIDE) and disk.hasData(DISK_SIDE) then
- term.setCursorPos(W-tostring(fs.getFreeSpace('disk')..'B / '..totalSpaceFloppy..'B free'):len(), H)
- term.write(fs.getFreeSpace('disk')..'B / '..totalSpaceFloppy..'B free')
- term.setCursorPos(W/4, H)
- term.write('disk')
- term.setCursorPos(1, H)
- term.write('[')
- for n = 1, W/2-2 do
- if n < (W/2-2)*(totalSpaceFloppy-fs.getFreeSpace('disk'))/totalSpaceFloppy then
- term.write('|')
- end
- end
- term.setCursorPos(W/2, H)
- term.write(']')
- end
- for n = 1, #choice do
- term.setCursorPos(W/2+3-choice[n].name:len(), (H-#choice)/2+n-1)
- term.write(choice[n].name)
- if n == selected then
- term.write(' <-')
- end
- end
- term.setCursorPos(1, H)
- if debug then
- term.write('['..selected..'] '..choice[selected].path)
- end
- local event = {os.pullEvent()}
- if event[1] == 'key' then
- if event[2] == keys.up then
- selected = selected - 1
- elseif event[2] == keys.down then
- selected = selected + 1
- end
- if selected > #choice then
- selected = 1
- end
- if selected < 1 then
- selected = #choice
- end
- if event[2] == 28 then
- shell.run(choice[selected].path)
- return
- end
- if event[2] == 50 then
- term.clear()
- term.setCursorPos(1, 1)
- peripheral.wrap('top').setTextScale(0.5)
- shell.run('monitor top', choice[selected].path)
- return
- end
- if event[2] == 59 then
- debug = not debug
- end
- elseif event[1] == 'monitor_touch' or event[1] == 'mouse_click' then
- --shell.run(choice[selected].path)
- --return
- elseif event[1] == 'timer' and event[2] == timeout then
- timeout = os.startTimer(1)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement