Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- CC forwards compatibility mode "fcomp"
- -- working title
- -- goal: to get as many new programs to work with older versions of CC by recreating functions
- -- pastebin get ZXCbDnTY fcomp
- local fileToRun = nil --string, run this if no argument is given. if nil, then, like, do fuck all after.
- -- 'skipCheck' skips checking whether or not you have certain functions, solely for testing.
- local skipCheck = true
- -- 'lddterm' stores metadata used by new term functions.
- local lddterm = {
- cursor = {
- x = 1,
- y = 1,
- blink = true,
- },
- textcol = colors.white,
- bgcol = colors.black,
- turtleslot = 1,
- native = term.native,
- }
- -- DEFINE TERM FUNCTIONS --
- if type(term.native) ~= "function" then
- term.native = function()
- return lddterm.native
- end
- end
- if skipCheck or not term.current then
- local native = (term.native and term.native()) or term
- local redirectTarget = native
- local function wrap( _sFunction )
- return function( ... )
- return redirectTarget[ _sFunction ]( ... )
- end
- end
- local term = {}
- term.redirect = function( target )
- if target == nil or type( target ) ~= "table" then
- error( "Invalid redirect target", 2 )
- end
- if target == term then
- error( "term is not a recommended redirect target, try term.current() instead", 2 )
- end
- for k,v in pairs( native ) do
- if type( k ) == "string" and type( v ) == "function" then
- if type( target[k] ) ~= "function" then
- target[k] = function()
- error( "Redirect object is missing method "..k..".", 2 )
- end
- end
- end
- end
- local oldRedirectTarget = redirectTarget
- redirectTarget = target
- return oldRedirectTarget
- end
- term.current = function()
- return redirectTarget
- end
- term.native = function()
- -- NOTE: please don't use this function unless you have to.
- -- If you're running in a redirected or multitasked enviorment, term.native() will NOT be
- -- the current terminal when your program starts up. It is far better to use term.current()
- return native
- end
- for k,v in pairs( native ) do
- if type( k ) == "string" and type( v ) == "function" then
- if term[k] == nil then
- term[k] = wrap( k )
- end
- end
- end
- end
- -- 'origterm' used for accessing original term functions in new functions
- local origterm = {}
- for k,v in pairs(term) do
- origterm[k] = v
- end
- -- 'explode' function for separating strings
- local explode = function(div,str)
- if (div=='') then return false end
- local pos,arr = 0,{}
- for st,sp in function() return string.find(str,div,pos,false) end do
- table.insert(arr,string.sub(str,pos,st-1))
- pos = sp + 1
- end
- table.insert(arr,string.sub(str,pos))
- return arr
- end
- local getFileTreeSize = function(path)
- return #explode("/",fs.combine("",path))
- end
- if skipCheck or not term.getCursorPos then
- term.getCursorPos = function()
- return lddterm.cursor.x, lddterm.cursor.y
- end
- term.setCursorPos = function(x,y)
- origterm.setCursorPos(x,y)
- lddterm.cursor.x = x
- lddterm.cursor.y = y
- end
- term.write = function(text)
- origterm.write(text)
- lddterm.cursor.x = lddterm.cursor.x + #tostring(text)
- end
- term.blit = function(tx,bg,text)
- origterm.blit(tx,bg,text)
- lddterm.cursor.x = lddterm.cursor.x + #tostring(text)
- end
- end
- if skipCheck or not term.getTextColor then
- term.getTextColor = function()
- return lddterm.textcol
- end
- term.getTextColour = term.getTextColor
- term.getBackgroundColor = function()
- return lddterm.bgcol
- end
- term.getBackgroundColour = term.getBackgroundColor
- term.setTextColor = function(col)
- origterm.setTextColor(col)
- lddterm.textcol = col
- end
- term.setTextColour = term.setTextColor
- term.setBackgroundColor = function(col)
- origterm.setBackgroundColor(col)
- lddterm.bgcol = col
- end
- term.setBackgroundColour = term.setBackgroundColor
- end
- if skipCheck or not fs.getDir then
- fs.getDir = function(dir)
- local tree = explode("/", dir or "")
- for a = 1, #tree do
- tree[a] = fs.combine("",tree[a])
- end
- if #tree == 0 then
- return ".."
- elseif #tree == 1 then
- return ""
- else
- return tree[#tree-1]
- end
- end
- end
- write = function( sText ) --can't go wrong with this
- local w,h = term.getSize()
- local x,y = term.getCursorPos()
- local nLinesPrinted = 0
- local function newLine()
- if y + 1 <= h then
- term.setCursorPos(1, y + 1)
- else
- term.setCursorPos(1, h)
- term.scroll(1)
- end
- x, y = term.getCursorPos()
- nLinesPrinted = nLinesPrinted + 1
- end
- while string.len(sText) > 0 do
- local whitespace = string.match( sText, "^[ \t]+" )
- if whitespace then
- -- Print whitespace
- term.write( whitespace )
- x,y = term.getCursorPos()
- sText = string.sub( sText, string.len(whitespace) + 1 )
- end
- local newline = string.match( sText, "^\n" )
- if newline then
- newLine()
- sText = string.sub( sText, 2 )
- end
- local text = string.match( sText, "^[^ \t\n]+" )
- if text then
- sText = string.sub( sText, string.len(text) + 1 )
- if string.len(text) > w then
- -- Print a multiline word
- while string.len( text ) > 0 do
- if x > w then
- newLine()
- end
- term.write( text )
- text = string.sub( text, (w-x) + 2 )
- x,y = term.getCursorPos()
- end
- else
- -- Print a word normally
- if x + string.len(text) - 1 > w then
- newLine()
- end
- term.write( text )
- x,y = term.getCursorPos()
- end
- end
- end
- return nLinesPrinted
- end
- local env = _ENV
- for k,v in pairs( term ) do
- env[k] = v
- end
- if skipCheck or not fs.find then --thank you bomb bloke
- fs.find = function(path)
- if type(path) ~= "string" then error("bad argument #1 (expected string, got " .. type(path) .. ")", 2 ) end
- local pathParts, results, curfolder = {}, {}, "/"
- for part in path:gmatch("[^/]+") do pathParts[#pathParts + 1] = part:gsub("*", "[^/]*") end
- if #pathParts == 0 then return {} end
- local prospects = fs.list(curfolder)
- for i = 1, #prospects do prospects[i] = {["parent"] = curfolder, ["depth"] = 1, ["name"] = prospects[i]} end
- while #prospects > 0 do
- local thisProspect = table.remove(prospects, 1)
- local fullPath = fs.combine(thisProspect.parent, thisProspect.name)
- if thisProspect.name == thisProspect.name:match(pathParts[thisProspect.depth]) then
- if thisProspect.depth == #pathParts then
- results[#results + 1] = fullPath
- elseif fs.isDir(fullPath) and thisProspect.depth < #pathParts then
- local newList = fs.list(fullPath)
- for i = 1, #newList do prospects[#prospects + 1] = {["parent"] = fullPath, ["depth"] = thisProspect.depth + 1, ["name"] = newList[i]} end
- end
- end
- end
- return results
- end
- end
- if skipCheck or not fs.complete then
- fscomplete = function(pstr,path,_inclfile,_inclslash)
- if type(_inclfile) == "boolean" then
- inclfile = _inclfile
- else
- inclfile = true
- end
- if type(_inclslash) == "boolean" then
- inclslash = _inclslash
- else
- inclslash = true
- end
- output,f1,f2,file = {}
- list = fs.list(path)
- for a = 1, #list do
- file = fs.combine(path,list[a])
- if fs.isDir(file) or inclfile then
- f1,f2 = list[a]:find("^"..pstr)
- if f2 then
- if (inclslash == true) and fs.isDir(file) then
- output[#output+1] = list[a]:sub(f2+1).."/"
- end
- output[#output+1] = list[a]:sub(f2+1)
- end
- end
- end
- return output
- end
- end
- if skipCheck or not rednet.host then --all ripped straight from /rom/apis/rednet
- rednet.lookup = function( sProtocol, sHostname )
- if type( sProtocol ) ~= "string" then
- error( "expected string", 2 )
- end
- -- Build list of host IDs
- local tResults = nil
- if sHostname == nil then
- tResults = {}
- end
- -- Check localhost first
- if tHostnames[ sProtocol ] then
- if sHostname == nil then
- table.insert( tResults, os.getComputerID() )
- elseif sHostname == "localhost" or sHostname == tHostnames[ sProtocol ] then
- return os.getComputerID()
- end
- end
- if not isOpen() then
- if tResults then
- return table.unpack( tResults )
- end
- return nil
- end
- -- Broadcast a lookup packet
- rednet.broadcast( {
- sType = "lookup",
- sProtocol = sProtocol,
- sHostname = sHostname,
- }, "dns" )
- -- Start a timer
- local timer = os.startTimer( 2 )
- -- Wait for events
- while true do
- local event, p1, p2, p3 = os.pullEvent()
- if event == "rednet_message" then
- -- Got a rednet message, check if it's the response to our request
- local nSenderID, tMessage, sMessageProtocol = p1, p2, p3
- if sMessageProtocol == "dns" and type(tMessage) == "table" and tMessage.sType == "lookup response" then
- if tMessage.sProtocol == sProtocol then
- if sHostname == nil then
- table.insert( tResults, nSenderID )
- elseif tMessage.sHostname == sHostname then
- return nSenderID
- end
- end
- end
- else
- -- Got a timer event, check it's the end of our timeout
- if p1 == timer then
- break
- end
- end
- end
- if tResults then
- return table.unpack( tResults )
- end
- return nil
- end
- rednet.host = function( sProtocol, sHostname )
- if type( sProtocol ) ~= "string" or type( sHostname ) ~= "string" then
- error( "expected string, string", 2 )
- end
- if sHostname == "localhost" then
- error( "Reserved hostname", 2 )
- end
- if tHostnames[ sProtocol ] ~= sHostname then
- if rednet.lookup( sProtocol, sHostname ) ~= nil then
- error( "Hostname in use", 2 )
- end
- tHostnames[ sProtocol ] = sHostname
- end
- end
- rednet.unhost = function( sProtocol )
- if type( sProtocol ) ~= "string" then
- error( "expected string", 2 )
- end
- tHostnames[ sProtocol ] = nil
- end
- end
- if skipCheck or not settings then
- local tSettings = {}
- settings.set = function( sName, value )
- if type(sName) ~= "string" or
- (type(value) ~= "string" and type(value) ~= "number" and type(value) ~= "boolean" and type(value) ~= "table") then
- error( "Expected string, value", 2 )
- end
- if type(value) == "table" then
- -- Ensure value is serializeable
- value = textutils.unserialize( textutils.serialize(value) )
- end
- tSettings[ sName ] = value
- end
- local copy
- copy = function( value )
- if type(value) == "table" then
- local result = {}
- for k,v in pairs(value) do
- result[k] = copy(v)
- end
- return result
- else
- return value
- end
- end
- settings.get = function( sName, default )
- if type(sName) ~= "string" then
- error( "Expected string", 2 )
- end
- local result = tSettings[ sName ]
- if result ~= nil then
- return copy(result)
- else
- return default
- end
- end
- settings.unset = function( sName )
- if type(sName) ~= "string" then
- error( "Expected string", 2 )
- end
- tSettings[ sName ] = nil
- end
- settings.clear = function()
- tSettings = {}
- end
- settings.getNames = function()
- local result = {}
- for k,v in pairs( tSettings ) do
- result[ #result + 1 ] = k
- end
- return result
- end
- settings.load = function( sPath )
- if type(sPath) ~= "string" then
- error( "Expected string", 2 )
- end
- local file = fs.open( sPath, "r" )
- if not file then
- return false
- end
- local sText = file.readAll()
- file.close()
- local tFile = textutils.unserialize( sText )
- if type(tFile) ~= "table" then
- return false
- end
- for k,v in pairs(tFile) do
- if type(k) == "string" and
- (type(v) == "string" or type(v) == "number" or type(v) == "boolean" or type(v) == "table") then
- settings.set( k, v )
- end
- end
- return true
- end
- settings.save = function( sPath )
- if type(sPath) ~= "string" then
- error( "Expected string", 2 )
- end
- local file = fs.open( sPath, "w" )
- if not file then
- return false
- end
- file.write( textutils.serialize( tSettings ) )
- file.close()
- return true
- end
- end
- if skipCheck or not textutils.serializeJSON then
- local empty_json_array = {}
- local serializeJSONImpl
- function serializeJSONImpl( t, tTracking, bNBTStyle )
- local sType = type(t)
- if t == empty_json_array then
- return "[]"
- elseif sType == "table" then
- if tTracking[t] ~= nil then
- error( "Cannot serialize table with recursive entries", 0 )
- end
- tTracking[t] = true
- if next(t) == nil then
- -- Empty tables are simple
- return "{}"
- else
- -- Other tables take more work
- local sObjectResult = "{"
- local sArrayResult = "["
- local nObjectSize = 0
- local nArraySize = 0
- for k,v in pairs(t) do
- if type(k) == "string" then
- local sEntry
- if bNBTStyle then
- sEntry = tostring(k) .. ":" .. serializeJSONImpl( v, tTracking, bNBTStyle )
- else
- sEntry = string.format( "%q", k ) .. ":" .. serializeJSONImpl( v, tTracking, bNBTStyle )
- end
- if nObjectSize == 0 then
- sObjectResult = sObjectResult .. sEntry
- else
- sObjectResult = sObjectResult .. "," .. sEntry
- end
- nObjectSize = nObjectSize + 1
- end
- end
- for n,v in ipairs(t) do
- local sEntry = serializeJSONImpl( v, tTracking, bNBTStyle )
- if nArraySize == 0 then
- sArrayResult = sArrayResult .. sEntry
- else
- sArrayResult = sArrayResult .. "," .. sEntry
- end
- nArraySize = nArraySize + 1
- end
- sObjectResult = sObjectResult .. "}"
- sArrayResult = sArrayResult .. "]"
- if nObjectSize > 0 or nArraySize == 0 then
- return sObjectResult
- else
- return sArrayResult
- end
- end
- elseif sType == "string" then
- return string.format( "%q", t )
- elseif sType == "number" or sType == "boolean" then
- return tostring(t)
- else
- error( "Cannot serialize type "..sType, 0 )
- end
- end
- function urlEncode( str )
- if str then
- str = string.gsub(str, "\n", "\r\n")
- str = string.gsub(str, "([^A-Za-z0-9 %-%_%.])", function(c)
- local n = string.byte(c)
- if n < 128 then
- -- ASCII
- return string.format("%%%02X", n)
- else
- -- Non-ASCII (encode as UTF-8)
- return
- string.format("%%%02X", 192 + bit32.band( bit32.arshift(n,6), 31 ) ) ..
- string.format("%%%02X", 128 + bit32.band( n, 63 ) )
- end
- end )
- str = string.gsub(str, " ", "+")
- end
- return str
- end
- local tEmpty = {}
- function complete( sSearchText, tSearchTable )
- local nStart = 1
- local nDot = string.find( sSearchText, ".", nStart, true )
- local tTable = tSearchTable or _ENV
- while nDot do
- local sPart = string.sub( sSearchText, nStart, nDot - 1 )
- local value = tTable[ sPart ]
- if type( value ) == "table" then
- tTable = value
- nStart = nDot + 1
- nDot = string.find( sSearchText, ".", nStart, true )
- else
- return tEmpty
- end
- end
- local sPart = string.sub( sSearchText, nStart, nDot )
- local nPartLength = string.len( sPart )
- local tResults = {}
- local tSeen = {}
- while tTable do
- for k,v in pairs( tTable ) do
- if not tSeen[k] and type(k) == "string" then
- if string.find( k, sPart, 1, true ) == 1 then
- if not g_tLuaKeywords[k] and string.match( k, "^[%a_][%a%d_]*$" ) then
- local sResult = string.sub( k, nPartLength + 1 )
- if type(v) == "function" then
- sResult = sResult .. "("
- elseif type(v) == "table" and next(v) ~= nil then
- sResult = sResult .. "."
- end
- table.insert( tResults, sResult )
- end
- end
- end
- tSeen[k] = true
- end
- local tMetatable = getmetatable( tTable )
- if tMetatable and type( tMetatable.__index ) == "table" then
- tTable = tMetatable.__index
- else
- tTable = nil
- end
- end
- table.sort( tResults )
- return tResults
- end
- end
- -- GB versions of serialise
- serialise = serialize
- unserialise = unserialize
- serialiseJSON = serializeJSON
- if turtle then
- if skipCheck or not turtle.getSelectedSlot then
- local tselect = turtle.select
- turtle.select = function(slot)
- local success = tselect(slot)
- if success then
- lddterm.turtleslot = slot
- end
- return success
- end
- turtle.getSelectedSlot = function()
- return lddterm.turtleslot
- end
- end
- end
- local tablCopy = function(tabl)
- local output = {}
- for k,v in pairs(tabl) do
- output[k] = v
- end
- return output
- end
- if skipCheck or not window then
- local tHex = {
- [ colors.white ] = "0",
- [ colors.orange ] = "1",
- [ colors.magenta ] = "2",
- [ colors.lightBlue ] = "3",
- [ colors.yellow ] = "4",
- [ colors.lime ] = "5",
- [ colors.pink ] = "6",
- [ colors.gray ] = "7",
- [ colors.lightGray ] = "8",
- [ colors.cyan ] = "9",
- [ colors.purple ] = "a",
- [ colors.blue ] = "b",
- [ colors.brown ] = "c",
- [ colors.green ] = "d",
- [ colors.red ] = "e",
- [ colors.black ] = "f",
- }
- local string_rep = string.rep
- local string_sub = string.sub
- function window.create( parent, nX, nY, nWidth, nHeight, bStartVisible )
- if type( parent ) ~= "table" or
- type( nX ) ~= "number" or
- type( nY ) ~= "number" or
- type( nWidth ) ~= "number" or
- type( nHeight ) ~= "number" or
- (bStartVisible ~= nil and type( bStartVisible ) ~= "boolean") then
- error( "Expected object, number, number, number, number, [boolean]", 2 )
- end
- --[[
- if parent == term then
- error( "term is not a recommended window parent, try term.current() instead", 2 )
- end
- --]]
- local sEmptySpaceLine
- local tEmptyColorLines = {}
- local function createEmptyLines( nWidth )
- sEmptySpaceLine = string_rep( " ", nWidth )
- for n=0,15 do
- local nColor = 2^n
- local sHex = tHex[nColor]
- tEmptyColorLines[nColor] = string_rep( sHex, nWidth )
- end
- end
- createEmptyLines( nWidth )
- -- Setup
- local bVisible = (bStartVisible ~= false)
- local nCursorX = 1
- local nCursorY = 1
- local bCursorBlink = false
- local nTextColor = colors.white
- local nBackgroundColor = colors.black
- local tLines = {}
- do
- local sEmptyText = sEmptySpaceLine
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]
- for y=1,nHeight do
- tLines[y] = {
- text = sEmptyText,
- textColor = sEmptyTextColor,
- backgroundColor = sEmptyBackgroundColor,
- }
- end
- end
- -- Helper functions
- local function updateCursorPos()
- if nCursorX >= 1 and nCursorY >= 1 and
- nCursorX <= nWidth and nCursorY <= nHeight then
- parent.setCursorPos( nX + nCursorX - 1, nY + nCursorY - 1 )
- else
- parent.setCursorPos( 0, 0 )
- end
- end
- local function updateCursorBlink()
- parent.setCursorBlink( bCursorBlink )
- end
- local function updateCursorColor()
- parent.setTextColor( nTextColor )
- end
- local function redrawLine( n )
- local tLine = tLines[ n ]
- parent.setCursorPos( nX, nY + n - 1 )
- parent.blit( tLine.text, tLine.textColor, tLine.backgroundColor )
- end
- local function redraw()
- for n=1,nHeight do
- redrawLine( n )
- end
- end
- local function internalBlit( sText, sTextColor, sBackgroundColor )
- local nStart = nCursorX
- local nEnd = nStart + #sText - 1
- if nCursorY >= 1 and nCursorY <= nHeight then
- if nStart <= nWidth and nEnd >= 1 then
- -- Modify line
- local tLine = tLines[ nCursorY ]
- if nStart == 1 and nEnd == nWidth then
- tLine.text = sText
- tLine.textColor = sTextColor
- tLine.backgroundColor = sBackgroundColor
- else
- local sClippedText, sClippedTextColor, sClippedBackgroundColor
- if nStart < 1 then
- local nClipStart = 1 - nStart + 1
- local nClipEnd = nWidth - nStart + 1
- sClippedText = string_sub( sText, nClipStart, nClipEnd )
- sClippedTextColor = string_sub( sTextColor, nClipStart, nClipEnd )
- sClippedBackgroundColor = string_sub( sBackgroundColor, nClipStart, nClipEnd )
- elseif nEnd > nWidth then
- local nClipEnd = nWidth - nStart + 1
- sClippedText = string_sub( sText, 1, nClipEnd )
- sClippedTextColor = string_sub( sTextColor, 1, nClipEnd )
- sClippedBackgroundColor = string_sub( sBackgroundColor, 1, nClipEnd )
- else
- sClippedText = sText
- sClippedTextColor = sTextColor
- sClippedBackgroundColor = sBackgroundColor
- end
- local sOldText = tLine.text
- local sOldTextColor = tLine.textColor
- local sOldBackgroundColor = tLine.backgroundColor
- local sNewText, sNewTextColor, sNewBackgroundColor
- if nStart > 1 then
- local nOldEnd = nStart - 1
- sNewText = string_sub( sOldText, 1, nOldEnd ) .. sClippedText
- sNewTextColor = string_sub( sOldTextColor, 1, nOldEnd ) .. sClippedTextColor
- sNewBackgroundColor = string_sub( sOldBackgroundColor, 1, nOldEnd ) .. sClippedBackgroundColor
- else
- sNewText = sClippedText
- sNewTextColor = sClippedTextColor
- sNewBackgroundColor = sClippedBackgroundColor
- end
- if nEnd < nWidth then
- local nOldStart = nEnd + 1
- sNewText = sNewText .. string_sub( sOldText, nOldStart, nWidth )
- sNewTextColor = sNewTextColor .. string_sub( sOldTextColor, nOldStart, nWidth )
- sNewBackgroundColor = sNewBackgroundColor .. string_sub( sOldBackgroundColor, nOldStart, nWidth )
- end
- tLine.text = sNewText
- tLine.textColor = sNewTextColor
- tLine.backgroundColor = sNewBackgroundColor
- end
- -- Redraw line
- if bVisible then
- redrawLine( nCursorY )
- end
- end
- end
- -- Move and redraw cursor
- nCursorX = nEnd + 1
- if bVisible then
- updateCursorColor()
- updateCursorPos()
- end
- end
- -- Terminal implementation
- local window = {}
- function window.write( sText )
- sText = tostring( sText )
- internalBlit( sText, string_rep( tHex[ nTextColor ], #sText ), string_rep( tHex[ nBackgroundColor ], #sText ) )
- end
- function window.blit( sText, sTextColor, sBackgroundColor )
- if type(sText) ~= "string" or type(sTextColor) ~= "string" or type(sBackgroundColor) ~= "string" then
- error( "Expected string, string, string", 2 )
- end
- if #sTextColor ~= #sText or #sBackgroundColor ~= #sText then
- error( "Arguments must be the same length", 2 )
- end
- internalBlit( sText, sTextColor, sBackgroundColor )
- end
- function window.clear()
- local sEmptyText = sEmptySpaceLine
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]
- for y=1,nHeight do
- tLines[y] = {
- text = sEmptyText,
- textColor = sEmptyTextColor,
- backgroundColor = sEmptyBackgroundColor,
- }
- end
- if bVisible then
- redraw()
- updateCursorColor()
- updateCursorPos()
- end
- end
- function window.clearLine()
- if nCursorY >= 1 and nCursorY <= nHeight then
- local sEmptyText = sEmptySpaceLine
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]
- tLines[ nCursorY ] = {
- text = sEmptyText,
- textColor = sEmptyTextColor,
- backgroundColor = sEmptyBackgroundColor,
- }
- if bVisible then
- redrawLine( nCursorY )
- updateCursorColor()
- updateCursorPos()
- end
- end
- end
- function window.getCursorPos()
- return nCursorX, nCursorY
- end
- function window.setCursorPos( x, y )
- nCursorX = math.floor( x )
- nCursorY = math.floor( y )
- if bVisible then
- updateCursorPos()
- end
- end
- function window.setCursorBlink( blink )
- bCursorBlink = blink
- if bVisible then
- updateCursorBlink()
- end
- end
- local function isColor()
- return parent.isColor()
- end
- function window.isColor()
- return isColor()
- end
- function window.isColour()
- return isColor()
- end
- local function setTextColor( color )
- if not parent.isColor() then
- if color ~= colors.white and color ~= colors.black and color ~= colors.gray and color ~= colors.lightGray then
- error( "Color not supported", 3 )
- end
- end
- nTextColor = color
- if bVisible then
- updateCursorColor()
- end
- end
- function window.setTextColor( color )
- setTextColor( color )
- end
- function window.setTextColour( color )
- setTextColor( color )
- end
- local function setBackgroundColor( color )
- if not parent.isColor() then
- if color ~= colors.white and color ~= colors.black and color ~= colors.gray and color ~= colors.lightGray then
- error( "Color not supported", 3 )
- end
- end
- nBackgroundColor = color
- end
- function window.setBackgroundColor( color )
- setBackgroundColor( color )
- end
- function window.setBackgroundColour( color )
- setBackgroundColor( color )
- end
- function window.getSize()
- return nWidth, nHeight
- end
- function window.scroll( n )
- if n ~= 0 then
- local tNewLines = {}
- local sEmptyText = sEmptySpaceLine
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]
- for newY=1,nHeight do
- local y = newY + n
- if y >= 1 and y <= nHeight then
- tNewLines[newY] = tLines[y]
- else
- tNewLines[newY] = {
- text = sEmptyText,
- textColor = sEmptyTextColor,
- backgroundColor = sEmptyBackgroundColor,
- }
- end
- end
- tLines = tNewLines
- if bVisible then
- redraw()
- updateCursorColor()
- updateCursorPos()
- end
- end
- end
- function window.getTextColor()
- return nTextColor
- end
- function window.getTextColour()
- return nTextColor
- end
- function window.getBackgroundColor()
- return nBackgroundColor
- end
- function window.getBackgroundColour()
- return nBackgroundColor
- end
- -- Other functions
- function window.setVisible( bVis )
- if bVisible ~= bVis then
- bVisible = bVis
- if bVisible then
- window.redraw()
- end
- end
- end
- function window.redraw()
- if bVisible then
- redraw()
- updateCursorBlink()
- updateCursorColor()
- updateCursorPos()
- end
- end
- function window.restoreCursor()
- if bVisible then
- updateCursorBlink()
- updateCursorColor()
- updateCursorPos()
- end
- end
- function window.getPosition()
- return nX, nY
- end
- function window.reposition( nNewX, nNewY, nNewWidth, nNewHeight )
- nX = nNewX
- nY = nNewY
- if nNewWidth and nNewHeight then
- local tNewLines = {}
- createEmptyLines( nNewWidth )
- local sEmptyText = sEmptySpaceLine
- local sEmptyTextColor = tEmptyColorLines[ nTextColor ]
- local sEmptyBackgroundColor = tEmptyColorLines[ nBackgroundColor ]
- for y=1,nNewHeight do
- if y > nHeight then
- tNewLines[y] = {
- text = sEmptyText,
- textColor = sEmptyTextColor,
- backgroundColor = sEmptyBackgroundColor
- }
- else
- local tOldLine = tLines[y]
- if nNewWidth == nWidth then
- tNewLines[y] = tOldLine
- elseif nNewWidth < nWidth then
- tNewLines[y] = {
- text = string_sub( tOldLine.text, 1, nNewWidth ),
- textColor = string_sub( tOldLine.textColor, 1, nNewWidth ),
- backgroundColor = string_sub( tOldLine.backgroundColor, 1, nNewWidth ),
- }
- else
- tNewLines[y] = {
- text = tOldLine.text .. string_sub( sEmptyText, nWidth + 1, nNewWidth ),
- textColor = tOldLine.textColor .. string_sub( sEmptyTextColor, nWidth + 1, nNewWidth ),
- backgroundColor = tOldLine.backgroundColor .. string_sub( sEmptyBackgroundColor, nWidth + 1, nNewWidth ),
- }
- end
- end
- end
- nWidth = nNewWidth
- nHeight = nNewHeight
- tLines = tNewLines
- end
- if bVisible then
- window.redraw()
- end
- end
- if bVisible then
- window.redraw()
- end
- return window
- end
- end
- if skipCheck or not redstone.setAnalogOutput then
- redstone.setAnalogOutput = function(side,amnt)
- if amnt > 0 then
- redstone.setOutput(side,true)
- else
- redstone.setOutput(side,false)
- end
- end
- redstone.getAnalogInput = function(side)
- return redstone.getInput(side) and 16 or 0
- end
- redstone.getAnalogOutput = function(side)
- return redstone.getOutput(side) and 16 or 0
- end
- end
- local tArg = {...}
- fileToRun = fileToRun or tArg
- if (fileToRun) and (fileToRun ~= {}) then
- if shell then
- shell.run(fileToRun)
- else
- dofile(fileToRun)
- end
- else
- term.setCursorPos(1,1)
- term.clear()
- print("FCOMP ACTIVE!")
- end
- --[[
- TODO:
- + test test test!
- --]]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement