Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- if #args ~= 1 and #args ~= 2 then
- print('Usage: bbar <bar> [t/top/b/bottom]')
- return
- end
- local barCallback = dofile(args[1])
- if type(barCallback) ~= 'function' then
- print('Invalid bar file (not a function)')
- return
- end
- if #args == 2 then
- local arg2 = args[2]
- if arg2 ~= 't' and arg2 ~= 'top' and arg2 ~= 'b' and arg2 ~= 'bottom' then
- print('Invalid argument #2 (expected t/top/b/bottom): ' .. arg2)
- end
- end
- local barHeight = 1
- local topBar = #args == 2 and args[2]:sub(1, 1) == 't'
- local w, h = term.getSize()
- local container = window.create(term.current(), 1, (topBar and barHeight or 0) + 1, w, h - barHeight)
- local orig_term = term.redirect(container)
- local bar = window.create(orig_term, 1, (topBar and 1 or h + 1 - barHeight), w, barHeight)
- local program = coroutine.create(function()
- if fs.exists('/rom/programs/shell.lua') then
- os.run({}, '/rom/programs/shell.lua')
- else
- os.run({}, '/rom/programs/shell')
- end
- end)
- local _, eventfilter = coroutine.resume(program)
- local timer = os.startTimer(0)
- while true do
- if coroutine.status(program) == 'dead' then
- break
- end
- local event = {os.pullEventRaw()}
- if event[1] == 'timer' and event[2] == timer then
- barCallback(bar)
- container.restoreCursor()
- timer = os.startTimer(0.05)
- elseif event[1] == 'terminate' then
- local _, _eventfilter = coroutine.resume(program, 'terminate')
- eventfilter = _eventfilter
- elseif eventfilter == nil or event[1] == eventfilter then
- local pass = true
- if event[1] == 'mouse_click' or event[1] == 'mouse_up' or event[1] == 'mouse_scroll' or event[1] == 'mouse_drag' or event[1] == 'monitor_touch' then
- if topBar and event[4] <= barHeight or event[4] > h - barHeight then
- pass = false
- elseif topBar then
- event[4] = event[4] - barHeight
- end
- end
- if pass == true then
- local _, _eventfilter = coroutine.resume(program, table.unpack(event))
- eventfilter = _eventfilter
- end
- end
- end
- term.redirect(orig_term)
- local cx, cy = term.getCursorPos()
- bar.clear()
- term.setCursorPos(cx, cy)
- print('Ended')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement