Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- rColor = function(col)
- colors = {
- [1] = {decimal=1, name="white", hexadecimal="0x1", paint="0", hex="#F0F0F0", hex2="#f0f0f0"},
- [2] = {decimal=2, name="orange", hexadecimal="0x2", paint="1", hex="#F2B233", hex2="#f2b233"},
- [4] = {decimal=4, name="magenta", hexadecimal="0x4", paint="2", hex="#E57FD8", hex2="#e57fd8"},
- [8] = {decimal=8, name="lightBlue", hexadecimal="0x8", paint="3", hex="#99B2F2", hex2="#99b2f2"},
- [16] = {decimal=16, name="yellow", hexadecimal="0x10", paint="4", hex="#DEDE6C", hex2="#dede6c"},
- [32] = {decimal=32, name="lime", hexadecimal="0x20", paint="5", hex="#7FCC19", hex2="#7fcc19"},
- [64] = {decimal=64, name="pink", hexadecimal="0x40", paint="6", hex="#F2B2CC", hex2="#f2b2cc"},
- [128] = {decimal=128, name="gray", hexadecimal="0x80", paint="7", hex="#4C4C4C", hex2="#4c4c4c"},
- [256] = {decimal=256, name="lightGray", hexadecimal="0x100", paint="8", hex="#999999", hex2="#999999"},
- [512] = {decimal=512, name="cyan", hexadecimal="0x200", paint="9", hex="#4C99B2", hex2="#4c99b2"},
- [1024] = {decimal=1024, name="purple", hexadecimal="0x400", paint="a", hex="#B266E5", hex2="#b266e5"},
- [2048] = {decimal=2048, name="blue", hexadecimal="0x800", paint="b", hex="#3366CC", hex2="#3366cc"},
- [4096] = {decimal=4096, name="brown", hexadecimal="0x1000", paint="c", hex="#7F664C", hex2="#7f664c"},
- [8192] = {decimal=8192, name="green", hexadecimal="0x2000", paint="d", hex="#57A64E", hex2="#57a64e"},
- [16384] = {decimal=16384, name="red", hexadecimal="0x4000", paint="e", hex="#CC4C4C", hex2="#cc4c4c"},
- [32768] = {decimal=32768, name="black", hexadecimal="0x8000", paint="f", hex="#191919", hex2="#191919"},
- }
- match = false
- for k,x in pairs(colors) do
- for i,v in pairs(x) do
- if v == col then
- return k
- end
- end
- end
- end
- rClear = function(...)
- clearArgs = {...}
- -- Args [1] = Line (-ln) or screen (-scr)
- -- Args [2][1] = Colour
- -- Args [2][2] = Y Pos (Applies to Line clear)
- term.setBackgroundColor(rColor(clearArgs[2][1]))
- if clearArgs[1] == "-ln" or clearArgs[1] == "-line" or clearArgs[1] == "-l" or clearArgs[1] == "-L" then
- term.setCursorPos(1,clearArgs[2][2])
- term.clearLine()
- elseif clearArgs[1] == "-scr" or clearArgs[1] == "-a" or clearArgs[1] == "-A" or clearArgs[1] == "-all" or clearArgs[1] == "-screen" then
- term.clear()
- end
- end
- rPrint = function(...)
- local w,h = term.getSize()
- printArgs = {...}
- -- Args[1] = Alignment
- -- Args[2][1] = X Pos (Needed but only applies to left align)
- -- Args[2][2] = Y pos
- -- Args[3][...] = Text to print
- -- Args[4][1] = Text Colour
- -- Args[4][2] = Background Colour
- -- Args[5] = Right align offset
- --(alignment, {x, y}, {Text}, {textColor}, {Alight offset})
- local tmpStr = ""
- for i,v in pairs(printArgs[3]) do
- tmpStr = tmpStr..v.." "
- end
- local yOffset = 0
- if printArgs[5] then
- yOffset = printArgs[5]
- end
- if printArgs[4][1] then
- term.setTextColor(rColor(printArgs[4][1]))
- end
- if printArgs[4][2] then
- term.setBackgroundColor(rColor(printArgs[4][2]))
- end
- if printArgs[1] == "-l" or printArgs[1] == "-L" or printArgs[1] == "-left" then
- term.setCursorPos(printArgs[2][1], printArgs[2][2])
- print(tmpStr)
- elseif printArgs[1] == "-r" or printArgs[1] == "-R" or printArgs[1] == "-right" then
- term.setCursorPos(math.floor(w)-tonumber(#tmpStr+yOffset), printArgs[2][2])
- print(tmpStr)
- elseif printArgs[1] == "-c" or printArgs[1] == "-C" or printArgs[1] == "-center" then
- term.setCursorPos(math.floor(w/2)-tonumber(#tmpStr/2), printArgs[2][2])
- print(tmpStr)
- end
- end
- function exists(path)
- if fs.exists(path) then
- return true
- end
- return false
- end
- function getTable(path)
- if exists(path) then
- local file = io.open(path, "r")
- local lines = {}
- local i = 1
- local line = file:read("*l")
- while line ~= nil do
- lines[i] = line
- line = file:read("*l")
- i = i + 1
- end
- file:close()
- return lines
- end
- return {}
- end
- function getLine(path, n)
- if exists(path) then
- local lines = getTable(path)
- return lines[n]
- end
- return ""
- end
- function getText(path)
- if exists(path) then
- local file = assert(io.open(path, "r"))
- return file:read("*a")
- end
- return ""
- end
- function fappend(path, text)
- local file = assert(io.open(path, "a"))
- file:write(text.."\n")
- file:close()
- end
- function fwrite(path, text)
- local file = assert(io.open(path, "w"))
- file:write(text)
- file:close()
- end
- function fwriteAtStart(path, text)
- local _text = getText(path)
- fwrite(path, text.."\n".._text)
- end
- function fwriteFromTable(path, t)
- local text = ""
- for _, line in pairs(t) do
- text = text..line.."\n"
- end
- fwrite(path, text)
- end
- function fappendFromTable(path, t)
- local text = ""
- for _, line in pairs(t) do
- text = text..line.."\n"
- end
- fappend(path, text)
- end
- function fwriteAtStartFromTable(path, t)
- local text = ""
- for _, line in pairs(t) do
- text = text..line.."\n"
- end
- fwriteAtStart(path, text)
- end
- function replaceLine(path, n, text)
- local lines = getTable(path)
- lines[n] = text
- fwriteFromTable(path, lines)
- end
- function getName(path)
- if exists(path) then
- local lastSlashPos = 1
- for i = 1, path:len() do
- if path:sub(i, i) == "/" then
- lastSlashPos = i
- end
- end
- return path:sub(lastSlashPos + 1)
- end
- return ""
- end
- function getPath(path)
- if exists(path) then
- local lastSlashPos = 1
- for i = 1, path:len() do
- if path:sub(i, i) == "/" then
- lastSlashPos = i
- end
- end
- return path:sub(1, lastSlashPos)
- end
- return ""
- end
- function fremove(path)
- os.remove(path)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement