Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local oldevent = os.pullEventRaw
- local x,y = term.getSize()
- tabbing = false;
- isMultitasking = false
- screenMemory = {}
- multiMemory = {
- "CraftOS vM.1",
- }
- local cPrint = function(text)
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- print(text)
- end
- function mRead( _sReplaceChar, _tHistory )
- term.setCursorBlink( true )
- local sLine = ""
- local nHistoryPos = nil
- local nPos = 0
- if _sReplaceChar then
- _sReplaceChar = string.sub( _sReplaceChar, 1, 1 )
- end
- local w, h = term.getSize()
- local sx, sy = term.getCursorPos()
- local function redraw()
- local nScroll = 0
- if sx + nPos >= w then
- nScroll = (sx + nPos) - w
- end
- term.setCursorPos( sx, sy )
- mWrite( "> " ..string.rep(" ", 14) )
- term.setCursorPos( sx, sy )
- if _sReplaceChar then
- mWrite( "> " ..string.rep(_sReplaceChar, string.len(sLine) - nScroll) )
- else
- mWrite( "> " ..string.sub( sLine, nScroll + 1 ) )
- end
- term.setCursorPos( sx + nPos - nScroll, sy )
- end
- while true do
- local sEvent, param = os.pullEvent()
- if sEvent == "char" then
- if nPos < 14 then
- sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
- nPos = nPos + 1
- end
- redraw()
- elseif sEvent == "key" then
- if param == keys.enter then
- -- Enter
- break
- elseif param == keys.left then
- -- Left
- if nPos > 0 then
- nPos = nPos - 1
- redraw()
- end
- elseif param == keys.right then
- -- Right
- if nPos < string.len(sLine) then
- nPos = nPos + 1
- redraw()
- end
- elseif param == keys.up or param == keys.down then
- -- Up or down
- if _tHistory then
- if param == keys.up then
- -- Up
- if nHistoryPos == nil then
- if #_tHistory > 0 then
- nHistoryPos = #_tHistory
- end
- elseif nHistoryPos > 1 then
- nHistoryPos = nHistoryPos - 1
- end
- else
- -- Down
- if nHistoryPos == #_tHistory then
- nHistoryPos = nil
- elseif nHistoryPos ~= nil then
- nHistoryPos = nHistoryPos + 1
- end
- end
- if nHistoryPos then
- sLine = _tHistory[nHistoryPos]
- nPos = string.len( sLine )
- else
- sLine = ""
- nPos = 0
- end
- redraw()
- end
- elseif param == keys.backspace then
- -- Backspace
- if nPos > 0 then
- sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
- nPos = nPos - 1
- redraw()
- end
- end
- end
- end
- term.setCursorBlink( false )
- term.setCursorPos( w + 1, sy )
- print()
- return sLine
- end
- mWrite = function(text)
- length1 = #("| |")
- length2 = math.ceil((x /2) - (length1 / 2))
- local x2,y2 = term.getCursorPos()
- term.setCursorPos(length2+2, y2)
- write(text)
- end
- local _write = function(text)
- multiMemory[#multiMemory+1] = text
- end
- function newevent( _sFilter )
- local event, p1, p2, p3, p4, p5 = oldevent( _sFilter )
- if event == "key" then
- if p1 == 15 then
- if tabbing == false then
- tabbing = true
- thattimer = os.startTimer(0.7)
- else
- tabbing = false
- isMultitasking = true
- while isMultitasking do
- term.setCursorPos(1,3)
- cPrint("+------Simulated_Shell------+")
- cPrint("| |")
- cPrint("| |")
- cPrint("| |")
- cPrint("| |")
- cPrint("| |")
- cPrint("| |")
- cPrint("+---------------------------+")
- local testPos1 = 1
- if #multiMemory < 5 then
- for i=1,5 do
- if multiMemory[i] then
- term.setCursorPos(1, 3+i)
- mWrite(string.sub(multiMemory[i], 1, 26))
- testPos1 = testPos1+1
- end
- end
- else
- for i=#multiMemory-4,#multiMemory do
- if multiMemory[i] then
- term.setCursorPos(1, 3+testPos1)
- mWrite(string.sub(multiMemory[i], 1, 26))
- testPos1 = testPos1+1
- end
- end
- end
- term.setCursorPos(1, 3+testPos1)
- mWrite("> ")
- local request = mRead()
- _write("> " ..request)
- if request ~= "" then
- _write("Not yet implemented")
- end
- end
- end
- else
- tabbing = false
- end
- elseif event == "timer" and p1 == thattimer then
- tabbing = false
- end
- return event, p1, p2, p3, p4, p5
- end
- print("Loading multitasker... ")
- textutils.slowPrint("Creating new events...")
- sleep(0)
- textutils.slowPrint("Generating event function...")
- sleep(0)
- textutils.slowPrint("Overwriting old events...")
- sleep(0)
- textutils.slowPrint("Done!")
- print("Multitasker loaded. Version: 1.0 PR1")
- print("Run a program and double press Tab to multitask.")
- os.pullEventRaw = newevent
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement