Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local osCode = [[
- local windows = {}
- local screenData = {}
- local screenLine = {}
- local clipboard = ""
- local oldSize = term.getSize
- local oldClear = term.clear
- local currentColor = colors.white
- local currentBGColor = colors.black
- term.forceCursorPos = term.setCursorPos
- oldClearLine = term.clearLine
- oldWrite = term.write
- oldSetColour = term.setTextColour
- oldSetBGColour = term.setBackgroundColour
- oldScroll = term.scroll
- fixScreenData = function()
- local sD = screenData
- screenLine = {}
- screenData = {}
- for i,v in pairs(sD) do
- screenData[ #screenData+1 ] = v
- local currentLine = screenLine[ y ]
- if type(screenLine[ y ]) ~= "table" then
- screenLine[ y ] = {}
- end
- screenLine[ y ][#currentLine+1] = SCD
- end
- end
- writeScreenData = function()
- local x,y = term.getCursorPos()
- oldClear()
- oldColor = currentColor
- oldBG = currentBGColor
- for i=1,#screenData do
- local info = screenData[i]
- term.setCursorPos( info["X"], info["Y"] )
- term.setBackgroundColour( info["BG_Color"] )
- term.setTextColour( info["TXT_Color"] )
- write( info["Text"] )
- end
- term.setTextColour( oldColor )
- term.setBackgroundColour( oldBG )
- term.setCursorPos( x, y )
- end
- term.setTextColour = function( color )
- currentColor = color
- return oldSetColour( color )
- end
- term.setBackgroundColor = function( color )
- currentBGColor = color
- return oldSetBGColour( color )
- end
- term.paste = function()
- return os.queueEvent( "char", clipboard )
- end
- term.clear = function()
- screenData = {}
- screenLine = {}
- return oldClear()
- end
- term.clearLine = function()
- local x,y = term.getCursorPos
- local lineExists = screenLine[y]
- if lineExists then
- for i=1,#lineExists do
- textData = lineExists[i]
- if textData then
- screenData[ textData ] = nil
- end
- end
- fixScreenData()
- end
- return oldClearLine()
- end
- term.write = function( text )
- local x,y = term.getCursorPos()
- SCD = #screenData+1
- screenData[ SCD ] = {
- ["Text"] = text,
- ["TXT_Color"] = currentColor,
- ["BG_Color"] = currentBGColor,
- ["X"] = x,
- ["Y"] = y,
- }
- local currentLine = screenLine[ y ]
- if type(screenLine[ y ]) ~= "table" then
- screenLine[ y ] = {}
- currentLine = screenLine[ y ]
- end
- screenLine[ y ][#currentLine+1] = SCD
- return oldWrite( text )
- end
- term.copy = function( text )
- clipboard = text
- end
- term.getClipboard = function()
- return clipboard
- end
- term.getWindows = function()
- return windows
- end
- read = function( _sReplaceChar, _tHistory )
- term.setCursorBlink( true )
- local oldMenu = false
- local hasMenu = false
- local cStart = 0
- local cEnd = 0
- 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 dropdown( x, y )
- prevtc = currentColor
- prevbc = currentBGColor
- for i=1,3 do
- term.setCursorPos(x,y+i-1)
- term.setBackgroundColour( colors.lightGray )
- oldWrite(" ")
- end
- term.setCursorPos( x, y )
- if cStart ~= 0 and cEnd ~= 0 then
- term.setTextColour( colors.gray )
- else
- term.setTextColour( colors.white )
- end
- oldWrite(" Copy ")
- term.setCursorPos( x, y+1 )
- if clipboard ~= "" then
- term.setTextColour( colors.gray )
- else
- term.setTextColour( colors.white )
- end
- oldWrite(" Paste ")
- term.setCursorPos( x, y+2 )
- term.setTextColour( colors.gray )
- oldWrite(" Explorer")
- term.setTextColour( prevtc )
- term.setBackgroundColour( prevbc )
- end
- local function redraw( _sCustomReplaceChar )
- local nScroll = 0
- if sx + nPos >= w then
- nScroll = (sx + nPos) - w
- end
- term.setCursorPos( sx, sy )
- local sReplace = _sCustomReplaceChar or _sReplaceChar
- if sReplace then
- sText = string.rep(sReplace, string.len(sLine) - nScroll)
- else
- sText = string.sub( sLine, nScroll + 1 )
- end
- if cStart ~= 0 and cEnd ~= 0 then
- local sText1 = string.sub( sText, 1, cStart-1 )
- local sHigh = string.sub( sText, cStart, cEnd )
- local sText2 = string.sub( sText, cEnd+1, #sText )
- if sText1 then
- write( sText1 )
- end
- term.setBackgroundColour( colors.blue )
- if sHigh then
- write( sHigh )
- end
- term.setBackgroundColour( currentBGColor )
- if sText2 then
- write( sText2 )
- end
- else
- write( sText )
- end
- if oldMenu ~= hasMenu and oldMenu == true then
- writeScreenData()
- end
- term.setCursorPos( sx + nPos - nScroll, sy )
- oldMenu = hasMenu
- end
- local dragTimer = false
- while true do
- local sEvent, param, key, p2 = os.pullEvent()
- if sEvent == "char" then
- sLine = string.sub( sLine, 1, nPos ) .. param .. string.sub( sLine, nPos + 1 )
- nPos = nPos + 1
- redraw()
- elseif sEvent == "mouse_click" and p2 == sy then
- if param == 1 then
- cStart = 0
- cEnd = 0
- hasMenu = false
- redraw()
- elseif param == 2 then
- dropdown( key, p2 )
- end
- elseif sEvent == "mouse_drag" and param == 1 then
- local p1 = key
- local cPos = p1-sx+1
- if cPos > 0 then
- if dragTimer == false then
- if p2 == sy then
- cStart = cPos
- cEnd = cPos --I repeated code D: *Shoots myself*
- dragTimer = os.startTimer(0.3)--<+---^
- end-- |
- else-- |
- cEnd = cPos-- |
- dragTimer = os.startTimer(0.3)-- <-+
- end
- end
- redraw()
- elseif sEvent == "timer" then
- if param == dragTimer then
- dragTimer = false
- end
- 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
- redraw(" ");
- 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
- redraw(" ");
- sLine = string.sub( sLine, 1, nPos - 1 ) .. string.sub( sLine, nPos + 1 )
- nPos = nPos - 1
- redraw()
- end
- elseif param == keys.home then
- -- Home
- nPos = 0
- redraw()
- elseif param == keys.delete then
- if nPos < string.len(sLine) then
- redraw(" ");
- sLine = string.sub( sLine, 1, nPos ) .. string.sub( sLine, nPos + 2 )
- redraw()
- end
- elseif param == keys["end"] then
- -- End
- nPos = string.len(sLine)
- redraw()
- end
- end
- end
- cStart = 0
- cEnd = 0
- redraw()
- term.setCursorBlink( false )
- term.setCursorPos( w + 1, sy )
- print()
- return sLine
- end
- local x,y = term.getSize()
- local function cPrint( txt, color, isMenu ) --Version 2.1 of cPrint
- local function printC( text )
- x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- oldColz = currentColor
- if isMenu then
- term.setTextColour( colors.orange )
- write("[ ")
- end
- if color then
- term.setTextColour( color )
- end
- write(text.. "\n")
- if isMenu then
- term.setTextColour( colors.orange )
- write(" ]")
- end
- term.setTextColour( oldColz )
- end
- if type(txt) == "string" then
- printC( txt )
- elseif type(txt) == "table" then
- for i=1,#txt do
- printC( txt[i] )
- end
- end
- end
- local drawingBoard = {
- ["A"] = colors.white,
- ["B"] = colors.orange,
- ["C"] = colors.magenta,
- ["D"] = colors.lightBlue,
- ["E"] = colors.yellow,
- ["F"] = colors.lime,
- ["G"] = colors.pink,
- ["H"] = colors.gray,
- ["I"] = colors.lightGray,
- ["J"] = colors.cyan,
- ["K"] = colors.purple,
- ["L"] = colors.blue,
- ["M"] = colors.brown,
- ["N"] = colors.green,
- ["O"] = colors.red,
- ["P"] = colors.black,
- }
- local function advWrite( pos1, pos2, str )
- for i=1,#str do
- local symb = drawingBoard[ string.sub( str, i, i) ]
- term.setCursorPos( pos1 + (i-1) , pos2 )
- if symb then
- term.setBackgroundColour( symb )
- write(" ")
- end
- end
- end
- local function setBG( col, colz )
- term.setBackgroundColour( col )
- term.clear()
- term.setCursorPos(1,1)
- term.setTextColour( colz )
- end
- local function getLines( path )
- local tLines = {}
- local file = fs.open( path, "r" )
- if file then
- line = file.readLine()
- while line do
- tLines[ #tLines+1 ] = line
- line = file.readLine()
- end
- file.close()
- end
- return tLines
- end
- local function drawGUI()
- setBG( colors.black, colors.white )
- cPrint( "NeXoS 3.0" )
- write( string.rep( "-", x ) )
- term.setCursorPos(1,y)
- write("Login (Logged in as guest)")
- term.setCursorPos(1,y-1)
- write( string.rep( "-", x ) )
- term.setCursorPos(1,4)
- end
- local selection = 1
- local menu = {
- [1] = {
- ["Text"] = "Exit",
- ["Color"] = colors.red,
- ["Function"] = error()
- }, --Keep at bottom
- }
- drawGUI()
- local clock_ = os.startTimer( 0.5 )
- while true do
- for i=1,#menu do
- local sText = menu[i]["Text"]
- if menu[i]["Color"] ~= nil then
- sColor = menu[i]["Color"]
- else
- sColor = colors.white
- end
- local isMenu = false
- if selection == i then
- isMenu = true
- end
- term.clearLine()
- cPrint( sText, sColor, isMenu )
- print()
- end
- local event, key = os.pullEvent()
- if event == "timer" then
- if key == clock_ then
- local time_ = textutils.formatTime( os.time() )
- term.setCursorPos( x-#(time_)+1, y )
- write( time_ )
- clock_ = os.startTimer( 0.5 )
- end
- elseif event == "key" then
- if key == keys.up then
- if selection ~= 1 then
- selection = selection -1
- end
- elseif key == keys.down then
- if selection ~= #menu then
- selection = selection +1
- end
- end
- end
- end
- while true do
- end
- --]]
- local x,y = term.getSize()
- local function cPrint( txt ) --Version 2.0 of cPrint
- local function printC( text )
- x2,y2 = term.getCursorPos()
- term.setCursorPos(math.ceil((x / 2) - (text:len() / 2)), y2)
- write(text.. "\n")
- end
- if type(txt) == "string" then
- printC( txt )
- elseif type(txt) == "table" then
- for i=1,#txt do
- printC( txt[i] )
- end
- end
- end
- if fs.exists(".osCache") and fs.isDir(".osCache") then
- fs.delete(".osCache/main")
- file = fs.open(".osCache/main","w")
- file.write( osCode )
- file.close()
- local function BSoD( _error )
- term.setBackgroundColour( colors.blue )
- term.clear()
- term.setCursorPos(1,4)
- term.setBackgroundColour( colors.white )
- term.setTextColour( colors.blue )
- cPrint(" ERROR ")
- term.setTextColour( colors.white )
- term.setBackgroundColour( colors.blue )
- print()
- cPrint( "Failed to run OS: " .._error )
- print()
- cPrint( "Press any key to continue" )
- repeat
- local _, key = os.pullEvent( "key" )
- until key ~= 1
- term.setBackgroundColour( colors.black )
- end
- local result = shell.run( ".osCache/main" )
- if type(result) ~= "boolean" then
- BSoD( result )
- end
- else
- term.clear()
- term.setCursorPos(1,3)
- cPrint("Installing OS")
- write("+" ..string.rep( "-", x-2 ).. "+")
- term.setCursorPos(1,5)
- write("|")
- term.setCursorPos(x,5)
- write("|")
- term.setCursorPos(1,6)
- write("+" ..string.rep( "-", x-2 ).. "+")
- print("\n")
- cPrint("Status")
- local _,statusPos = term.getCursorPos()
- local progress = 0
- function addLoading( status )
- progress = progress +1
- term.setCursorPos(1+progress,5)
- term.setBackgroundColour( colors.blue )
- write(" ")
- term.setBackgroundColour( colors.black )
- if status then
- term.setCursorPos(1,statusPos)
- term.clearLine()
- cPrint( status )
- end
- sleep(0)
- end
- addLoading( "Generating API" )
- addLoading( "Removing Directories" )
- fs.delete( ".osCache" )
- addLoading( "Creating Directories" )
- fs.makeDir( ".osCache" )
- addLoading( "Creating User Folder" )
- fs.makeDir( ".osCache/users" )
- addLoading( "Creating OS Main Class" )
- --Moved up :P
- --Extras
- addLoading( "De-noobing ROM" )
- addLoading( "Emptying Trashcan" )
- addLoading( "Booting GLaDOS" )
- addLoading( "Attending Minecon" )
- addLoading( "Voting against SOPA" )
- --Complete :D
- for i=progress,x-4 do
- addLoading( "Completing" )
- if math.random(1,4) == 4 then
- sleep(0.5)
- end
- end
- addLoading( "Rebooting..." )
- sleep(1)
- os.reboot()
- end
Advertisement
Add Comment
Please, Sign In to add comment