Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pauseKey = 68 --f10
- local ignoreEvent = {mouse_click=true,term_resize=true}
- local dropEvent = {key=true,char=true,mouse_click=true,mouse_scroll=true,paste=true,terminate=true}
- local password = ""
- if #password > 0 then
- ignoreEvent["char"] = false
- end
- local paused = false
- local qEvents = {}
- local pchars = 0
- local ptyped
- local needRedraw = false
- local dragX,dragY
- local oldPull = os.pullEventRaw
- local tx,ty = term.native().getSize()
- local nTerm = term.native()
- local pTerm = term.current()
- local mx,my = (#password > 5 and #password+5 or 10),(#password>0 and 7 or 5)
- ptyped = #password > 0 and mx-5 or 0
- local pauseImg = window.create(nTerm, math.floor((tx-mx)/2), math.floor((ty-my)/2),mx,my,false)
- if nTerm.isColor() then
- pauseImg.setBackgroundColor(colors.gray)
- pauseImg.clear()
- pauseImg.setBackgroundColor(colors.lightGray)
- for i=2,my-1 do
- pauseImg.setCursorPos(1,i)
- pauseImg.write(" ")
- pauseImg.setCursorPos(mx,i)
- pauseImg.write(" ")
- end
- for i=1,mx do
- pauseImg.setCursorPos(i,1)
- pauseImg.write(" ")
- pauseImg.setCursorPos(i,my)
- pauseImg.write(" ")
- end
- pauseImg.setBackgroundColor(colors.gray)
- pauseImg.setTextColor(colors.green)
- else
- for i=2,my-1 do
- pauseImg.setCursorPos(1,i)
- pauseImg.write("|")
- pauseImg.setCursorPos(mx,i)
- pauseImg.write("|")
- end
- for j=0,1 do
- pauseImg.setCursorPos(1,j*(my-1)+1)
- pauseImg.write("#")
- for i=2,mx-1 do
- pauseImg.write("-")
- end
- pauseImg.write("#")
- end
- end
- pauseImg.setCursorPos(mx/2-2,3)
- pauseImg.write("Paused")
- pauseImg.setCursorPos(3,5)
- pauseImg.setBackgroundColor(colors.black)
- if #password>0 then
- pauseImg.write(">")
- pauseImg.setCursorBlink(true)
- end
- local function osQueue()
- for i,j in pairs(qEvents) do
- os.queueEvent(unpack(j))
- end
- qEvents = {}
- if multishell then
- --term.current().redraw()
- --multishell.setFocus(multishell.getFocus())
- os.queueEvent("term_resize")
- else
- term.clear()
- term.setCursorPos(1,1)
- end
- end
- local function clrPw()
- pchars = 0
- pauseImg.setCursorPos(4,5)
- for i=1,ptyped do
- pauseImg.write(" ")
- end
- pauseImg.setCursorPos(4,5)
- ptyped=0
- end
- if #password>0 then
- clrPw()
- end
- local function onImg(r)
- local px,py = pauseImg.getPosition()
- return (r[1] == "mouse_click" or r[1] == "mouse_drag") and r[3] >= px and r[3] <= px+mx and r[4] >= py and r[4] <= py+my
- end
- os.pullEventRaw = function(filter)
- while true do
- local r = {oldPull()}
- if needRedraw then
- pauseImg.redraw()
- needRedraw = false
- end
- if r[1] == "key" and r[2] and (r[2] == pauseKey or (r[2] == 28 and paused)) and (pchars == #password or not paused) then
- paused = not paused
- pauseImg.setVisible(paused)
- if not paused then
- osQueue()
- clrPw()
- end
- elseif paused and ((not ignoreEvent[r[1]]) or onImg(r)) then
- if r[1] == "terminate" and pchars == #password then
- --print("Pause Programm unloaded")
- os.pullEventRaw = oldPull
- paused=false
- pauseKey = -1 --Because of other instances
- osQueue()
- return oldPull(filter)
- end
- if r[1] == "char" and r[2] and #password > 0 then
- if ptyped < mx - 5 then
- ptyped = ptyped + 1
- pauseImg.write("*")
- end
- pchars = pchars + 1
- if r[2] ~= password:sub(pchars,pchars) then
- pchars = -1 --r[2] == password:sub(1,1) and 1 or 0
- end
- elseif r[1] == "key" and r[2] and (r[2] == 14 or r[2] == pauseKey or r[2] == 28) and #password>0 then
- clrPw()
- elseif r[1] == "mouse_click" and onImg(r) then
- local px,py = pauseImg.getPosition()
- dragX,dragY = r[3]-px,r[4]-py
- elseif r[1] == "mouse_drag" and dragX then
- pauseImg.reposition(r[3]-dragX,r[4]-dragY)
- os.queueEvent("term_resize")
- --pauseImg.redraw()
- elseif not dropEvent[r[1]] then
- table.insert(qEvents,r)
- end
- elseif not filter or r[1]==filter or (r[1]=="terminate" and not paused) then
- if paused then
- needRedraw = true
- end
- return unpack(r)
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment