Advertisement
Guest User

color.lua

a guest
Jun 17th, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.43 KB | None | 0 0
  1. local c=require("filesystem")local d=require("unicode")local e=require("bit32")function _G.getCurrentScript()local f;for g=0,math.huge do f=debug.getinfo(g)if f then if f.what=="main"then return f.source:sub(2,-1)end else error("Failed to get debug info for runlevel "..g)end end end;function e.merge(h,i)local j=math.ceil(math.log(i+1,256))*8;while h>0 do i,h,j=e.bor(e.lshift(e.band(h,0xFF),j),i),e.rshift(h,8),j+8 end;return i end;function e.numberToByteArray(k)local l={}repeat table.insert(l,1,e.band(k,0xFF))k=e.rshift(k,8)until k<=0;return l end;function e.numberToFixedSizeByteArray(k,m)local l,n={},0;repeat table.insert(l,1,e.band(k,0xFF))k=e.rshift(k,8)n=n+1 until k<=0;for o=1,m-n do table.insert(l,1,0x0)end;return l end;function e.byteArrayToNumber(l)local p=l[1]for o=2,#l do p=e.bor(e.lshift(p,8),l[o])end;return p end;function e.bitArrayToByte(q)local p=0;for o=1,#q do p=e.bor(q[o],e.lshift(p,1))end;return p end;function math.round(r)if r>=0 then return math.floor(r+0.5)else return math.ceil(r-0.5)end end;function math.roundToDecimalPlaces(r,s)local t=10^(s or 0)return math.round(r*t)/t end;function math.getDigitCount(r)return r==0 and 1 or math.ceil(math.log(r+1,10))end;function math.shorten(k,u)local v={"K","M","B","T"}local w=math.floor(math.log(k,1000))if k<1000 then return k elseif w>#v then w=#v end;return math.roundToDecimalPlaces(k/1000^w,u)..v[w]end;function c.extension(x,y)local z=x:match("[^%/]+(%.[^%/]+)%/?$")return y and z and d.lower(z)or z end;function c.hideExtension(x)return x:match("(.+)%..+")or x end;function c.isFileHidden(x)if x:match("^%..+$")then return true end;return false end;function c.sortedList(x,A,B,C,D)if not c.exists(x)then error("Failed to get file list: directory \""..tostring(x).."\" doesn't exists")end;if not c.isDirectory(x)then error("Failed to get file list: path \""..tostring(x).."\" is not a directory")end;local E,F={},{}for G in c.list(x)do if not C or string.unicodeFind(D and G or d.lower(G),D and C or d.lower(C))then table.insert(E,G)end end;if#E>0 then if A=="type"then local z;for o=1,#E do z=c.extension(E[o])or"Script"if c.isDirectory(x..E[o])and z~=".app"then z=".01_Folder"end;E[o]={E[o],z}end;table.sort(E,function(a,b)return d.lower(a[2])<d.lower(b[2])end)local H,I={},E[1][2]for o=1,#E do if I==E[o][2]then table.insert(H,E[o][1])else table.sort(H,function(a,b)return d.lower(a)<d.lower(b)end)for J=1,#H do table.insert(F,H[J])end;H,I={E[o][1]},E[o][2]end end;table.sort(H,function(a,b)return d.lower(a)<d.lower(b)end)for J=1,#H do table.insert(F,H[J])end elseif A=="name"then F=E;table.sort(F,function(a,b)return d.lower(a)<d.lower(b)end)elseif A=="date"then for o=1,#E do E[o]={E[o],c.lastModified(x..E[o])}end;table.sort(E,function(a,b)return d.lower(a[2])>d.lower(b[2])end)for o=1,#E do table.insert(F,E[o][1])end else error("Unknown sorting method: "..tostring(A))end;local o=1;while o<=#F do if not B and c.isFileHidden(F[o])then table.remove(F,o)else o=o+1 end end end;return F end;function c.directorySize(x)local m=0;for G in c.list(x)do if c.isDirectory(x..G)then m=m+c.directorySize(x..G)else m=m+c.size(x..G)end end;return m end;function c.readUnicodeChar(G)local l={string.byte(G:read(1))}local K=0;for o=1,7 do if e.band(e.rshift(l[1],8-o),0x1)==0x0 then K=o;break end end;for o=1,K-2 do table.insert(l,string.byte(G:read(1)))end;return string.char(table.unpack(l))end;function table.serialize(L,M,N,O,P)checkArg(1,L,"table")P=P or math.huge;local Q=string.rep(O and"   "or" ",N or 2)local R=M and" = "or"="local function S(L,T,U)local p,V,W,X,Y={"{"},T..Q;if M then table.insert(p,"\n")end;for Z,_ in pairs(L)do W,X,Y=type(Z),type(_),tostring(_)if M then table.insert(p,V)end;if W=="number"then table.insert(p,"[")table.insert(p,Z)table.insert(p,"]")table.insert(p,R)elseif W=="string"then if M and Z:match("^%a")and Z:match("^[%w%_]+$")then table.insert(p,Z)else table.insert(p,"[\"")table.insert(p,Z)table.insert(p,"\"]")end;table.insert(p,R)end;if X=="number"or X=="boolean"or X=="nil"then table.insert(p,Y)elseif X=="string"or X=="function"then table.insert(p,"\"")table.insert(p,Y)table.insert(p,"\"")elseif X=="table"then if U<P then table.insert(p,table.concat(S(_,V,U+1)))else table.insert(p,"\"\"")end end;table.insert(p,",")if M then table.insert(p,"\n")end end;if M then if#p>2 then table.remove(p,#p-1)end;table.insert(p,T)else if#p>1 then table.remove(p,#p)end end;table.insert(p,"}")return p end;return table.concat(S(L,"",1))end;function table.unserialize(a0)checkArg(1,a0,"string")local p,a1=load("return "..a0)if p then p,a1=pcall(p)if p then return a1 else return nil,a1 end else return nil,a1 end end;table.toString=table.serialize;table.fromString=table.unserialize;function table.toFile(x,L,M,N,O,P,a2)checkArg(1,x,"string")checkArg(2,L,"table")c.makeDirectory(c.path(x)or"")local G,a1=io.open(x,a2 and"a"or"w")if G then G:write(table.serialize(L,M,N,O,P))G:close()else error("Failed to open file for writing: "..tostring(a1))end end;function table.fromFile(x)checkArg(1,x,"string")local G,a1=io.open(x,"r")if G then local a3,a1=table.unserialize(G:read("*a"))G:close()if a3 then return a3 else error("Failed to unserialize file \""..x.."\": "..tostring(a1))end else error("Failed to open file \""..x.."\" for reading: "..tostring(a1))end end;function table.copy(a4)local function a5(a6,a7)for Z,_ in pairs(a6)do if type(_)=="table"then a7[Z]={}doTableCopy(a6[Z],a7[Z])else a7[Z]=_ end end end;local p={}a5(a4,p)return p end;function table.size(a8)local m=0;for Z in pairs(a8)do m=m+1 end;return m end;function table.contains(a8,a9)for aa,_ in pairs(a8)do if _==a9 then return true end end;return false end;function table.indexOf(a8,a9)for o=1,#a8 do if a8[o]==a9 then return o end end end;function table.sortAlphabetically(a8)table.sort(a8,function(a,b)return a<b end)end;function string.brailleChar(a,b,ab,ac,ad,ae,af,ag)return d.char(10240+128*ag+64*af+32*ae+16*ac+8*b+4*ad+2*ab+a)end;function string.canonicalPath(ah)return string.gsub("/"..ah,"%/+","/")end;function string.optimize(ah,N)ah=string.gsub(ah,"\r\n","\n")ah=string.gsub(ah,"    ",string.rep(" ",N or 2))return ah end;function string.optimizeForURLRequests(ai)if ai then ai=string.gsub(ai,"([^%w ])",function(ab)return string.format("%%%02X",string.byte(ab))end)ai=string.gsub(ai," ","+")end;return ai end;function string.unicodeFind(ah,aj,ak,al)if ak then if ak<0 then ak=-#d.sub(ah,ak)elseif ak>0 then ak=#d.sub(ah,1,ak-1)+1 end end;a,b=string.find(ah,aj,ak,al)if a then local am,an=ah:sub(1,a-1),ah:sub(a,b)a=d.len(am)+1;b=a+d.len(an)-1;return a,b else return a end end;function string.limit(ao,ap,aq,ar)local as=d.len(ao)if as<=ap then return ao end;if aq=="left"then if ar then return d.sub(ao,as-ap+1,-1)else return"…"..d.sub(ao,as-ap+2,-1)end elseif aq=="center"then local at,au=math.modf(ap/2)if au==0 then return d.sub(ao,1,at).."…"..d.sub(ao,-at+1,-1)else return d.sub(ao,1,at).."…"..d.sub(ao,-at,-1)end else if ar then return d.sub(ao,1,ap)else return d.sub(ao,1,ap-1).."…"end end end;function string.wrap(a3,ap)if type(a3)=="string"then a3={a3}end;local av,p,aw,ax={}for o=1,#a3 do av[o]=a3[o]end;local o=1;while o<=#av do local ax=string.unicodeFind(av[o],"\n")if ax then table.insert(av,o+1,d.sub(av[o],ax+1,-1))av[o]=d.sub(av[o],1,ax-1)end;o=o+1 end;local o=1;while o<=#av do p=""for ay in av[o]:gmatch("[^%s]+")do aw=p..ay;if d.len(aw)>ap then if d.len(ay)>ap then table.insert(av,o+1,d.sub(av[o],ap+1,-1))p=d.sub(av[o],1,ap)else table.insert(av,o+1,d.sub(av[o],d.len(p)+1,-1))end;break else p=aw.." "end end;av[o]=p:gsub("%s+$",""):gsub("^%s+","")o=o+1 end;return av end;return{loaded=true}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement