diff --git a/halyde/apps/argentum.lua b/halyde/apps/argentum.lua index 8276f19..d2698d6 100644 --- a/halyde/apps/argentum.lua +++ b/halyde/apps/argentum.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a={...}local b=a[1]table.remove(a,1)local c=import("filesystem")local d=import("component")local e=import("/argentum/registry.cfg")if not b then shell.run("help argentum")return end;if not d.list("internet")()then print("\27[91mThis program requires an internet card to run.")return end;local f=d.internet;local g;if table.find(a,"-s")then g=table.remove(a,table.find(a,"-s")+1)table.remove(a,table.find(a,"-s"))print("Using "..g.." as package source")elseif table.find(a,"--source")then g=table.remove(a,table.find(a,"--source")+1)table.remove(a,table.find(a,"--source"))print("Using "..g.." as package source")else print("Using main registry as package source")end;if g and g:sub(1,1)=="/"and g:sub(-1,-1)~="/"then g=g.."/"end;local h=table.copy(a)local function i(a)if a:sub(1,1)=="/"then if not c.exists(a)then return false,"file does not exist"end;local a,b,c=c.open(a,"r"),"",nil;repeat c=a:read(math.huge)b=b..(c or"")until not c;a:close()return b else local b,c,d=nil,"",nil;local a,e=pcall(function()b=f.request(a)b:finishConnect()end)if not a then return false,e end;local a=b:response()if a and a~=200 then return false,a end;repeat d=b.read(math.huge)c=c..(d or"")until not d;return c end end;local f=1;local function j(a,b)b=b or e[a]local b,c=i(b.."argentum.cfg")if not b or b==""then print("\27[91mCould not fetch Ag config: "..(c or"returned nil data"))return false end;local b,c=load(b,"=argentum.cfg","bt",{})if not b then print("\27[91mCould not fetch Ag config: "..c.."\nPlease contact the package owner.")return false end;local c;local b,d=pcall(function()c=b()end)if not b then print("\27[91mCould not fetch Ag config: "..d.."\nPlease contact the package owner.")return false end;if not c[a]or not c[a].maindir or not c[a].directories or not c[a].files or not c[a].version then local a=("\27[91mAg config of "..a.." is improperly configured.\nPlease contact the package owner.")end;return c end;local function k(b)if not e[b]and not g then print("\27[91mPackage "..b.." does not exist.")return false end;if c.exists("/argentum/store/"..b)then print("\27[91mPackage "..b.." is already installed.")return false end;agcfg=j(b,g)if not agcfg then return false end;if agcfg[b].dependencies then for a,a in ipairs(agcfg[b].dependencies)do if not e[a]and not agcfg[a]then local a=read(nil,"\27[91mPackage "..b.." requires dependency "..a.." that does not exist.\n[A - Abort/s - Skip]")if a:lower()~="s"then c.remove("/argentum/store/"..b)return false end end end;for c,c in pairs(agcfg[b].dependencies)do print(b.." depends on "..c)if not table.find(a,c)and k(c)then table.insert(a,table.find(a,b),c)table.insert(h,c)f=f+1 end end end;return true end;local function l(a,b,c)a=tostring(a)if c==nil then c=' 'end;return string.rep(c,b-#a)..a end;local d=d.gpu;local m,n=d.getResolution()local function o(a,b)local a=string.format("%s %s%%",a,l(math.floor(b*100),2))a=a..string.rep(" ",m-#a)local b=math.floor(b*m)d.setBackground(65280)d.setForeground(0)d.set(1,n,a:sub(1,b))d.setBackground(0)d.setForeground(16777215)d.set(b+1,n,a:sub(b+1))end;local function l()d.setBackground(0)d.fill(1,n,m,1," ")end;local function d(a,b)if not b then b=false end;if not b then print("Installing "..a.."...")end;local d=j(a,g)if not d then return false end;local f=g or e[a]local g="V"..d[a].version;if d[a].dependencies then for b,b in ipairs(d[a].dependencies)do if not e[b]and not d[b]then local b=read(nil,"\27[91mPackage "..a.." requires dependency "..b.." that does not exist.\n[A - Abort/s - Skip]")if b:lower()~="s"then c.remove("/argentum/store/"..a)return false end end end;for a,a in pairs(d[a].dependencies)do if e[a]or d[a]then g=g.."\nD"..a end end end;if d[a].directories then for a,a in pairs(d[a].directories)do if a:sub(-1,-1)~="/"then a=a.."/"end;g="A"..a.."\n"..g;if not c.exists(a)then c.makeDirectory(a)end end end;for e,h in ipairs(d[a].files)do l()::retry::print(" Downloading "..h.."...")o(a,e/#d[a].files)local d,e=i(f..d[a].maindir..h)if not d then l()local b=read(nil,"\27[91mCould not fetch "..h..": "..e.."\n\27[0m[a - Abort/R - Retry/s - Skip]")if b:lower()=="a"then c.remove("/argentum/store/"..a)return false elseif b:lower()=="s"then goto skip else goto retry end end;if c.exists(h)and not b then if not c.exists("/argentum/store/"..a.."/files/"..h:match("(.*/)"))then c.makeDirectory("/argentum/store/"..a.."/files/"..h:match("(.*/)"))end;c.copy(h,"/argentum/store/"..a.."/files/"..h)g=g.."\nM"..h else g=g.."\nA"..h end;local a=c.open(h,"w")a:write(d)a:close()::skip::end;l()c.makeDirectory("/argentum/store/"..a)local a=c.open("/argentum/store/"..a.."/package.cfg","w")a:write(g)a:close()return true end;local function m(a)print("Removing "..a.."...")if not c.exists("/argentum/store/"..a.."/package.cfg")then print("\27[91mLocal Ag config of "..a.." does not exist.")return false end;local b,d,e=c.open("/argentum/store/"..a.."/package.cfg","r"),"",nil;repeat e=b:read(math.huge)d=d..(e or"")until not e;b:close()d=d.."\n"local b=0;for e in d:gmatch("(.-)\n")do b=b+1;if e:sub(1,1)=="A"then l()::retry::print(" Removing "..e:sub(2).."...")if e:sub(-1,-1)=="/"and c.list(e:sub(2))[1]then print(" There are still files in "..e:sub(2)..". Skipping.")else o(a,b/select(2,d:gsub("\n","\n")))local a,b=c.remove(e:sub(2))if not a then l()local a=read(nil,"\27[91mFailed to remove "..e:sub(2)..": "..b.."\n\27[0m[a - Abort/r - Retry/S - Skip]")if a:lower()=="a"then return false elseif a:lower()=="r"then goto retry end end end elseif e:sub(1,1)=="M"then l()::retry::print(" Reverting "..e:sub(2).."...")o(a,b/select(2,d:gsub("\n","\n")))local a,b,d=c.open("/argentum/store/"..a.."/files/"..e:sub(2),"r"),"",nil;if not a then l()local a=read(nil,"\27[91mFailed to revert "..e:sub(2)..": "..b.."\n\27[0m[a - Abort/R - Retry/s - Skip]")if a:lower()=="a"then return false elseif a:lower()=="s"then goto skip else goto retry end end;repeat d=a:read(math.huge)b=b..(d or"")until not d;a:close()local a=c.open(e:sub(2),"w")a:write(b)a:close()::skip::end end;l()c.remove("/argentum/store/"..a.."/")return true end;local function l(a)print("Updating "..a.."...")local b=j(a,g)if not b then return false end;local c,e,f=c.open("/argentum/store/"..a.."/package.cfg","r"),"",nil;repeat f=c:read(math.huge)e=e..(f or"")until not f;c:close()local c={}for d in(e.."\n"):gmatch("(.-)\n")do if d:sub(1,1)=="A"or d:sub(1,1)=="M"then if b[a].directories then if not table.find(b[a].files,d:sub(2))and not table.find(b[a].directories,d:sub(2,-2))then table.insert(c,d:sub(2))end else if not table.find(b[a].files,d:sub(2))then table.insert(c,d:sub(2))end end end end;for a,a in pairs(c)do print(" Removing "..a.."...")end;return d(a,true)end;local n={}if b=="install"then if not a or not a[1]then print("Please specify packages to install.")return end;print("Fetching Ag registry...")local b,g=i("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/argentum/registry.cfg")if b then local a=c.open("/argentum/registry.cfg","w")a:write(b)a:close()else print("\27[91mFailed to fetch Ag registry: "..(g or"returned nil"))end;e=import("/argentum/registry.cfg")while true do if not k(a[f])then table.insert(n,a[f])table.remove(h,table.find(h,a[f]))end;f=f+1;if f>#a then break end end;local b;if#n==0 then print("Packages that will be installed: "..table.concat(h,", "))if read(nil,"Would you like to proceed? [Y/n] "):lower()=="n"then return end elseif#h==0 then print("None of the packages can be installed.")return else print("Some packages cannot be installed.")print("Packages that will be installed: "..table.concat(h,", "))print("Packages that cannot be installed: "..table.concat(n,", "))if read(nil,"Would you like to proceed? [y/N] "):lower()~="y"then return end end;for b,b in pairs(n)do table.remove(a,table.find(a,b))end;n={}for a,a in ipairs(a)do if not d(a)then table.insert(n,a)table.remove(h,table.find(h,a))end end;if#n==0 then print("Installation completed successfully.")print("Packages installed: "..table.concat(h,", "))elseif#h==0 then print("All packages failed to install.")print("Packages that could not be installed: "..table.concat(n,", "))else print("Some packages failed to install.")print("Packages installed: "..table.concat(h,", "))print("Packages that could not be installed: "..table.concat(n,", "))end elseif b=="remove"then if not a or not a[1]then print("Please specify packages to remove.")return end;while true do if not c.exists("/argentum/store/"..a[f])then print("\27[91mPackage "..a[f].." is not installed.")table.insert(n,a[f])table.remove(h,table.find(h,a[f]))table.remove(a,table.find(a,a[f]))f=f-1 elseif a[f]=="halyde"then print("\27[91mFor obvious reasons, you can't uninstall Halyde.")table.insert(n,a[f])table.remove(h,table.find(h,a[f]))table.remove(a,table.find(a,a[f]))f=f-1 elseif a[f]=="argentum"then print("\27[91mFor obvious reasons, you can't uninstall Argentum.")table.insert(n,a[f])table.remove(h,table.find(h,a[f]))table.remove(a,table.find(a,a[f]))f=f-1 end;f=f+1;if f>#a then break end end;local b=c.list("/argentum/store")for b,b in pairs(b)do if b:sub(-1,-1)=="/"and c.exists("/argentum/store/"..b.."package.cfg")then local c,d,e=c.open("/argentum/store/"..b.."package.cfg","r"),"",nil;repeat e=c:read(math.huge)d=d..(e or"")until not e;c:close()for c in(d.."\n"):gmatch("(.-)\n")do for d=1,#a do if c=="D"..a[d]then print(a[d].." depends on "..b:sub(1,-2))if not table.find(a,b:sub(1,-2))then table.insert(a,table.find(a,a[d]),b:sub(1,-2))table.insert(h,b:sub(1,-2))d=d+1 end end end end end end;local b;if#n==0 then print("Packages that will be removed: "..table.concat(h,", "))if read(nil,"Would you like to proceed? [Y/n] "):lower()=="n"then return end elseif#h==0 then print("None of the packages can be removed.")return else print("Some packages cannot be removed.")print("Packages that will be removed: "..table.concat(h,", "))print("Packages that cannot be removed: "..table.concat(n,", "))if read(nil,"Would you like to proceed? [y/N] "):lower()~="y"then return end end;for b,b in pairs(n)do table.remove(a,table.find(a,b))end;n={}for a,a in ipairs(a)do if not m(a)then table.insert(n,a)table.remove(h,table.find(h,a))end end;if#n==0 then print("Removal completed successfully.")print("Packages removed: "..table.concat(h,", "))elseif#h==0 then print("All packages failed to be removed.")print("Packages that could not be removed: "..table.concat(n,", "))else print("Some packages failed to be removed.")print("Packages removed: "..table.concat(h,", "))print("Packages that could not be removed: "..table.concat(n,", "))end elseif b=="update"then print("Fetching Ag registry...")local b,d=i("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/argentum/registry.cfg")if b then local a=c.open("/argentum/registry.cfg","w")a:write(b)a:close()else print("\27[91mFailed to fetch Ag registry: "..(d or"returned nil"))end;e=import("/argentum/registry.cfg")if not a[1]then local b=c.list("/argentum/store/")for b,b in pairs(b)do if b:sub(-1,-1)=="/"and c.exists("/argentum/store/"..b.."package.cfg")then table.insert(a,b:sub(1,-2))table.insert(h,b:sub(1,-2))end end end;while true do local b=false;if not c.exists("/argentum/store/"..a[f])then print("\27[91mPackage "..a[f].." is not installed.")table.insert(n,a[f])table.remove(h,table.find(h,a[f]))table.remove(a,table.find(a,a[f]))f=f-1;b=true end;if not b then local b=j(a[f],g)if not b then return false end;local c,d,e=c.open("/argentum/store/"..a[f].."/package.cfg","r"),"",nil;repeat e=c:read(math.huge)d=d..(e or"")until not e;c:close()local c="0.0.0"for a in(d.."\n"):gmatch("(.-)\n")do if a:sub(1,1)=="V"then c=a:sub(2)break end end;if b[a[f]].version==c then table.remove(h,table.find(h,a[f]))table.remove(a,table.find(a,a[f]))f=f-1 else print(a[f].." is out of date [\x1b[93m"..c.."\x1b[39m < \x1b[92m"..b[a[f]].version.."\x1b[39m]")end end;f=f+1;if f>#a then break end end;local b;if#h==0 then if#n==0 then print("All packages are up to date.")return else print("None of the packages can be updated.")return end elseif#n==0 then print("Packages that will be updated: "..table.concat(h,", "))if read(nil,"Would you like to proceed? [Y/n] "):lower()=="n"then return end else print("Some packages cannot be updated.")print("Packages that will be updated: "..table.concat(h,", "))print("Packages that cannot be updated: "..table.concat(n,", "))if read(nil,"Would you like to proceed? [y/N] "):lower()~="y"then return end end;for b,b in pairs(n)do table.remove(a,table.find(a,b))end;n={}for b,b in pairs(a)do if not l(b)then table.insert(n,a[f])table.remove(h,table.find(h,a[f]))table.remove(a,table.find(a,a[f]))goto skip end::skip::end;if#n==0 then print("Update completed successfully.")print("Packages updated: "..table.concat(h,", "))elseif#h==0 then print("All packages failed to update.")print("Packages that could not update: "..table.concat(n,", "))else print("Some packages failed to update.")print("Packages updated: "..table.concat(h,", "))print("Packages that could not update: "..table.concat(n,", "))end elseif b=="info"then if not a[1]then print("Please specify a package to show information about.")return end;print("Fetching Ag registry...")local b,d=i("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/argentum/registry.cfg")if b then local a=c.open("/argentum/registry.cfg","w")a:write(b)a:close()else print("\27[91mFailed to fetch Ag registry: "..(d or"returned nil"))end;e=import("/argentum/registry.cfg")if not e[a[1]]and not g then print("\27[91mPackage "..a[1].." does not exist.")return end;local b=j(a[1],g)if not b then return false end;print("\27[93m"..a[1].."\27[0m v"..b[a[1]].version.."\n "..(b[a[1]].description or"No description."):gsub("\n"," \n"))elseif b=="search"then if not a[1]then print("Please specify a search term.")return end;print("Fetching Ag registry...")local b,d=i("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/argentum/registry.cfg")if b then local a=c.open("/argentum/registry.cfg","w")a:write(b)a:close()else print("\27[91mFailed to fetch Ag registry: "..(d or"returned nil"))end;e=import("/argentum/registry.cfg")local b={}for c,d in pairs(e)do if c:find(a[1],1,true)then table.insert(b,c)end end;if not b[1]then print("No search results found for "..a[1]..".")return end;table.sort(b)print("Search results: \n "..table.concat(b,"\n "))elseif b=="list"then print("Fetching Ag registry...")local a,b=i("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/argentum/registry.cfg")if a then local b=c.open("/argentum/registry.cfg","w")b:write(a)b:close()else print("\27[91mFailed to fetch Ag registry: "..(b or"returned nil"))end;e=import("/argentum/registry.cfg")local a={}for b,c in pairs(e)do table.insert(a,b)end;table.sort(a)print("List of available Ag packages: \n "..table.concat(a,"\n "))else shell.run("help ag")end \ No newline at end of file diff --git a/halyde/apps/boot.lua b/halyde/apps/boot.lua index 8276f19..67d3cef 100644 --- a/halyde/apps/boot.lua +++ b/halyde/apps/boot.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("component")local b=import("computer")local c={...}local d=false;local e=table.find(c,"-f")or table.find(c,"--force")if e then table.remove(c,e)d=true end;local function e(b)local function c(b)for c,d in a.list()do if a.slot(c)==b then return c end end end;if b=="hdd1"or b=="#1"then return c(5)end;if b=="hdd2"or b=="#2"then return c(6)end;if b=="floppy"or b=="#3"then return c(7)end;if#b<3 then return nil,"Abbreviated ID must atleast have 3 characters"end;return a.get(b)end;local function f(b,c)return a.invoke(b,"exists",c)and not a.invoke(b,"isDirectory",c)end;if type(c[1])=="string"then local e,g=e(c[1])if not e then print("\x1b[91mCould not get component ID from '"..c[1].."'.")if type(g)=="string"then print("\x1b[91m"..g)end;return end;if not d then if componentlib.additions[e]then return print("\x1b[91mThis component is virtual and cannot be booted from directly.\nID: "..e)end;local a=a.type(e)if a~="filesystem"and a~="drive"then return print("\x1b[91mThis component is not a storage medium.\nID: "..e)end;if a=="filesystem"and not f(e,"/init.lua")then return print("\x1b[91mThis storage medium doesn't have an \"init.lua\" file.\nID: "..e)end end;b.setBootAddress(e)if b.getBootAddress()~=e then return print("\x1b[91mFailed to set the boot address.")end;b.shutdown(true)else shell.run("help boot")end \ No newline at end of file diff --git a/halyde/apps/cat.lua b/halyde/apps/cat.lua index 8276f19..e2d23dc 100644 --- a/halyde/apps/cat.lua +++ b/halyde/apps/cat.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a={...}local b=import("filesystem")if not a or not a[1]then shell.run("help cat")return end;for a,a in ipairs(a)do if a:sub(1,1)~="/"then a=b.concat(shell.workingDirectory,a)end;if not b.exists(a)then print("\27[91mFile does not exist.")end;local a=b.open(a,"r")local b;repeat b=a:read(math.huge or math.maxinteger)termlib.write(b)until not b end \ No newline at end of file diff --git a/halyde/apps/cd.lua b/halyde/apps/cd.lua index 8276f19..48e169e 100644 --- a/halyde/apps/cd.lua +++ b/halyde/apps/cd.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=...local b=import("filesystem")if not a then return end;if a:sub(1,1)~="/"then a=b.concat(shell.workingDirectory,a)end;if b.exists(a)and b.isDirectory(a)then shell.workingDirectory=b.canonical(a)else print("\27[91mNo such directory.")end \ No newline at end of file diff --git a/halyde/apps/clear.lua b/halyde/apps/clear.lua index 8276f19..5b90cd8 100644 --- a/halyde/apps/clear.lua +++ b/halyde/apps/clear.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +clear() \ No newline at end of file diff --git a/halyde/apps/cp.lua b/halyde/apps/cp.lua index 8276f19..39f034e 100644 --- a/halyde/apps/cp.lua +++ b/halyde/apps/cp.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a,b=...local c=import("filesystem")if not a or not b then shell.run("help cp")return end;if a:sub(1,1)~="/"then a=c.concat(shell.workingDirectory,a)end;if b:sub(1,1)~="/"then b=c.concat(shell.workingDirectory,b)end;if a==b then print("\27[91mSource and destination are the same.")return end;if not c.exists(a)then print("\27[91mSource file does not exist.")return end;if c.exists(b)and not(table.find({...},"-o")or table.find({...},"--overwrite"))then print("\27[91mDestination file already exists. Run this command again with -o to overwrite it.")return end;c.copy(a,b) \ No newline at end of file diff --git a/halyde/apps/download.lua b/halyde/apps/download.lua index 8276f19..1068f20 100644 --- a/halyde/apps/download.lua +++ b/halyde/apps/download.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=...local b=import("component")local c=import("filesystem")if not b.list("internet")()then print("\27[91mThis program requires an internet card to run.")return end;if not a then print("Please enter a URL to download from.")shell.run("help download")return end;if a:sub(-1,-1)=="/"then a=a:sub(1,-2)end;local b=b.internet;local d,e,f=nil,"",nil;local b,g=pcall(function()d=b.request(a)d:finishConnect()end)if not b then print("\27[91mDownload failed: "..g)end;local b=d:response()if b and b~=200 then print("\27[91mDownload failed: "..tostring(b))end;repeat f=d.read(math.huge)e=e..(f or"")until not f;local b;local d=false;repeat b=read(nil,"File save location: ",c.concat(shell.workingDirectory,a:match("/([^/]+)$")))if c.isDirectory(b)then print("\27[91mThe specified location is a directory.")elseif c.exists(b)then local a=read(nil,"\27[91mThere is already a file at the specified directory. Overwrite it? [Y/n]")if a:lower()~="n"then d=true end else d=true end until d;local a=c.open(b,"w")a:write(e)a:close()print("File downloaded successfully.") \ No newline at end of file diff --git a/halyde/apps/echo.lua b/halyde/apps/echo.lua index 8276f19..10efc8c 100644 --- a/halyde/apps/echo.lua +++ b/halyde/apps/echo.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a={...}local b=a[1]table.remove(a,1)for a,a in pairs(a)do b=b.." "..a end;print(b) \ No newline at end of file diff --git a/halyde/apps/edit.lua b/halyde/apps/edit.lua index 8276f19..ad1236e 100644 --- a/halyde/apps/edit.lua +++ b/halyde/apps/edit.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=...local b=import("filesystem")local c=import("event")local d=import("component")local e=import("unicode")local d=d.gpu;local f,g=d.getResolution()local h,i=1,1;local j,k=1,1;local l=true;local m=false;local n=d.allocateBuffer()local o=5;local p=" "local function q(a,b,c)termlib.cursorPosX=a;termlib.cursorPosY=b;termlib.write(c,false)end;local r,s,t,u,v;if a then if a:sub(1,1)=="/"then s=a else s=shell.workingDirectory..a end;t,u,v=b.open(s,"r"),"",nil;if b.exists(s)then r=s;repeat v=t:read(math.huge)u=u..(v or"")until not v;v={}if u:gmatch("(.-)\n")()then for a in u:gmatch("(.-)\n")do local a=a:gsub("\r","")table.insert(v,a)end else v={u}end else s=shell.workingDirectory..a;r="[NEW FILE]"v={""}end else s=""r="[NEW FILE]"v={""}end;local function a()d.setActiveBuffer(n)clear()local a=math.min(j,e.wlen(v[k+i-1])-h+2)if a<1 then h=h+a-1;j=1;a=math.min(j,e.wlen(v[k+i-1])-h+2)end;for a=i,g+i-3 do d.set(1,a-i+1,(v[a]or""):sub(h))end;q(1,g-1,"\27[107m\27[30m"..r..string.rep(" ",f))q(1,g,"\27[107m\27[30m^X\27[0m Exit \27[107m\27[30m^S\27[0m Save"..string.rep(" ",f))local b=d.get(a,k)if l then d.setForeground(0)d.setBackground(16777215)end;d.set(a,k,b)d.bitblt()d.setActiveBuffer(0)end;local n,q=false,false;local function t()k=k-1;q=true;l=true;if k<1 then n=true;i=i-1;k=1 end;if i<1 then n=false;i=1 end;if math.min(j,e.wlen(v[k+i-1])-h+2)<1 then n=true end end;local function u()k=k+1;q=true;l=true;if k+i-1>#v then n=false;k=#v-i+1 end;if k>g-2 then n=true;i=i+1;k=g-2 end;if math.min(j,e.wlen(v[k+i-1])-h+2)<1 then n=true end end;local function w()q=true;l=true;if j>1 then if j<=e.wlen(v[k+i-1])-h+2 then j=j-1 elseif e.wlen(v[k+i-1])-h+1>1 then j=e.wlen(v[k+i-1])-h+1 end elseif h>1 then h=h-1;n=true end;if math.min(j,e.wlen(v[k+i-1])-h+2)<1 then n=true end end;local function x()q=true;l=true;if j<=e.wlen(v[k+i-1])-h+1 then j=j+1 end;if j>f then j=f;h=h+1;n=true end end;local function y(a)n,q=false,false;if a[1]=="key_down"then local b=a[4]local b=keyboard.keys[b]if keyboard.ctrlDown then return false,false,b end;if b=="down"and k<#v then u()end;if b=="up"then t()end;if b=="left"then w()end;if b=="right"then x()end;if b=="enter"then m=true;n=true;l=true;table.insert(v,k+1,v[k+i-1]:sub(j))v[k+i-1]=v[k+i-1]:sub(1,j-1)j=1;k=k+1;h=1;if k>g-2 then i=i+1;k=g-2 end end;if b=="back"then m=true;q=true;l=true;if j==1 and k+i-1>1 then k=k-1;if k<1 then i=i-1;k=1 end;if i<1 then i=1 end;j=e.wlen(v[k+i-1])-h+2;if j>f then h=j-f+1;j=f end;v[k+i-1]=v[k+i-1]..v[k+1]table.remove(v,k+1)n=true else v[k+i-1]=v[k+i-1]:sub(1,j+h-3)..v[k+i-1]:sub(j+h-1)j=math.min(j-1,e.wlen(v[k+i-1])+1)if j<1 then j=1;h=h-1;n=true else d.set(1,k,v[k+i-1]:sub(h).." ")end end end;if b=="tab"then m=true;q=true;l=true;v[k+i-1]=v[k+i-1]:sub(1,j+h-2)..p..v[k+i-1]:sub(j+h-1)j=j+e.wlen(p)if j>f then h=h+j-f;j=f;n=true else d.set(1,k,v[k+i-1]:sub(h))end end;if a[3]>=32 and a[3]<=126 then m=true;q=true;l=true;v[k+i-1]=v[k+i-1]:sub(1,j+h-2)..e.char(a[3])..v[k+i-1]:sub(j+h-1)j=math.min(j,e.wlen(v[k+i-1]))+1;if j>f then j=f;h=h+1;n=true else d.set(1,k,v[k+i-1]:sub(h))end end elseif a[1]=="scroll"then if a[5]==1 then for a=1,o do t()end elseif a[5]==-1 and k<#v then for a=1,o do u()end end end;return n,q end;local function n()d.setBackground(16777215)d.setForeground(0)d.set(1,g-1,string.rep(" ",f))termlib.cursorPosX=1;termlib.cursorPosY=g-1;local a=read(nil,"\27[107m\27[30mSave location: ",s)d.setBackground(16777215)d.setForeground(0)if b.exists(a)then d.set(1,g-1,string.rep(" ",f))local a=read(nil,"\27[107m\27[30mFile already exists. Overwrite it? [Y/n] ")if a:lower()=="n"then d.setBackground(16777215)d.setForeground(0)d.set(1,g-1,r..string.rep(" ",f))return end end;local a,b=b.open(a,"w")if a then if table.concat(v,"\n"):sub(-1,-1)=="\n"then a:write(table.concat(v,"\n"))else a:write(table.concat(v,"\n").."\n")end;a:close()d.set(1,g-1,r..string.rep(" ",f))else d.set(1,g-1,"ERROR: "..b:gsub("\n","")..string.rep(" ",f))end;m=false end;a()while true do local b={c.pull(0.5)}local f,o,p=false,false,nil;local q,r=math.min(j,e.wlen(v[k+i-1])-h+2),k;if b and b[1]then l=true;f,o,p=y(b)if p=="x"then if m then termlib.cursorPosX=1;termlib.cursorPosY=g-1;local a=read(nil,"\27[107m\27[30mWould you like to save changes? [Y/n] ")if a:lower()~="n"then n()end end;d.freeAllBuffers()clear()return end;if p=="s"then n()end;repeat b={c.pull("key_down",0)}if b and b[1]then y(b)end until not b or not b[1]else l=not l;o=true end;if o then local a=d.get(q,r)d.set(q,r,a)local a=math.min(j,e.wlen(v[k+i-1])-h+2)if a<1 then h=h+a-1;j=1;a=math.min(j,e.wlen(v[k+i-1])-h+2)end;local b=d.get(a,k)if l then d.setBackground(16777215)d.setForeground(0)end;d.set(a,k,b)if l then d.setForeground(16777215)d.setBackground(0)end end;if f then a()end end \ No newline at end of file diff --git a/halyde/apps/fetch.lua b/halyde/apps/fetch.lua index 8276f19..198003a 100644 --- a/halyde/apps/fetch.lua +++ b/halyde/apps/fetch.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("component")local b=import("computer")local function c(a)termlib.cursorPosX=35;termlib.write(a.."\n",false)end;termlib.write(_OSLOGO,false)termlib.cursorPosY=termlib.cursorPosY-17;c("\27[92mOS\27[0m: ".._OSVERSION)c("\27[92mArchitecture\27[0m: ".._VERSION)local d=0;for a,a in a.list()do d=d+1 end;c("\27[92mComponents\27[0m: "..tostring(d))c("\27[92mCoroutines\27[0m: "..tostring(#cormgr.corList))c("\27[92mBattery\27[0m: "..tostring(math.floor(b.energy()/b.maxEnergy()*1000+0.5)/10).."%")local d=b.totalMemory()local e=b.totalMemory()-b.freeMemory()local f;if convert(d,"B","GiB")>=1 then f=tostring(math.floor(convert(d,"B","GiB")*100+0.5)/100).." GiB"elseif convert(d,"B","MiB")>=1 then f=tostring(math.floor(convert(d,"B","MiB")*100+0.5)/100).." MiB"elseif convert(d,"B","KiB")>=1 then f=tostring(math.floor(convert(d,"B","KiB")*100+0.5)/100).." KiB"else f=tostring(d).." B"end;local d;if convert(e,"B","GiB")>=1 then d=tostring(math.floor(convert(e,"B","GiB")*100+0.5)/100).." GiB"elseif convert(e,"B","MiB")>=1 then d=tostring(math.floor(convert(e,"B","MiB")*100+0.5)/100).." MiB"elseif convert(e,"B","KiB")>=1 then d=tostring(math.floor(convert(e,"B","KiB")*100+0.5)/100).." KiB"else d=tostring(e).." B"end;c("\27[92mMemory\27[0m: "..d.." / "..f)local d=a.invoke(b.getBootAddress(),"spaceTotal")local b=a.invoke(b.getBootAddress(),"spaceUsed")local e;if convert(d,"B","GiB")>=1 then e=tostring(math.floor(convert(d,"B","GiB")*100+0.5)/100).." GiB"elseif convert(d,"B","MiB")>=1 then e=tostring(math.floor(convert(d,"B","MiB")*100+0.5)/100).." MiB"elseif convert(d,"B","KiB")>=1 then e=tostring(math.floor(convert(d,"B","KiB")*100+0.5)/100).." KiB"else e=tostring(d).." B"end;local d;if convert(b,"B","GiB")>=1 then d=tostring(math.floor(convert(b,"B","GiB")*100+0.5)/100).." GiB"elseif convert(b,"B","MiB")>=1 then d=tostring(math.floor(convert(b,"B","MiB")*100+0.5)/100).." MiB"elseif convert(b,"B","KiB")>=1 then d=tostring(math.floor(convert(b,"B","KiB")*100+0.5)/100).." KiB"else d=tostring(b).." B"end;c("\27[92mDisk\27[0m: "..d.." / "..e)local a,b=a.invoke(a.list("gpu")(),"getResolution")c("\27[92mResolution\27[0m: "..tostring(a).."x"..tostring(b).."\n")c("\27[40m \27[41m \27[42m \27[43m \27[44m \27[45m \27[46m \27[47m ")c("\27[100m \27[101m \27[102m \27[103m \27[104m \27[105m \27[106m \27[107m ")termlib.cursorPosY=termlib.cursorPosY+5 \ No newline at end of file diff --git a/halyde/apps/help.lua b/halyde/apps/help.lua index 8276f19..1531ea0 100644 --- a/halyde/apps/help.lua +++ b/halyde/apps/help.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("filesystem")local b={...}local c=b[1]b=nil;if not c then local a,b,c=a.open("/halyde/apps/helpdb/default.txt","r"),"",nil;repeat c=a:read(math.huge or math.maxinteger)b=b..(c or"")until not c;print(b)return end;if shell.aliases[c]then c=shell.aliases[c]end;if a.exists("/halyde/apps/helpdb/"..c..".txt")then local a,b,d=a.open("/halyde/apps/helpdb/"..c..".txt","r"),"",nil;repeat d=a:read(math.huge or math.maxinteger)b=b..(d or"")until not d;print(b)local a=table.copy(shell.aliases)if table.find(a,c)then local b=table.find(a,c)local d="Aliases:\n "..b;a[b]=nil;while table.find(a,c)do b=table.find(a,c)d=d..", "..b;a[b]=nil end;print(d)end else print("Could not find help file for: "..c..".")end \ No newline at end of file diff --git a/halyde/apps/label.lua b/halyde/apps/label.lua index 8276f19..d59f254 100644 --- a/halyde/apps/label.lua +++ b/halyde/apps/label.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("component")local b=import("computer")local c={...}if not c then return print("\x1b[91mCannot get arguments.")end;if not c[1]then return shell.run("help label")end;local d=c[1]local e;local function f(b)if b>=5 and b<=8 then b=b-1 end;for c,d in a.list()do if a.slot(c)==b then e=a.proxy(c)end end end;if d=="eeprom"then e=a.eeprom elseif d=="halyde"then e=a.proxy(b.getBootAddress())elseif d:sub(1,4)=="slot"and tonumber(d:sub(5))then local a=tonumber(d:sub(5))-1;f(a)elseif d:sub(1,1)=="#"and tonumber(d:sub(2))then local a=tonumber(d:sub(2))+5;f(a)elseif#d>=3 then local b=a.get(d)if not b then return print("\x1b[91mCould not find entire component ID from \""..d.."\".")end;e=a.proxy(b)else print("\x1b[91mAddress must have atleast 3 characters")return shell.run("help label")end;if not e then return print("\x1b[91mCould not find component from \""..d.."\".")end;local a=e.address;local function b(a)return a:sub(1,8).."\x1b[37m"..a:sub(9).."\x1b[39m"end;local function d(c)print("This \x1b[92m"..(e.type or"unknown").."\x1b[39m component doesn't support "..c.." labels.\nID: "..b(a))end;local function f(b,c)print("\x1b[91mAn error occured while "..b.." the label of this component.\nComponent: "..(a or"unknown id").." ("..((e or{}).type or"unknown type")..")\n\n"..c)end;local function g(a)local b="No label defined"if a then b="\""..a.."\""end;return b end;if type(c[2])~="string"then if not e.getLabel then return d("getting")end;local c;local d,h=pcall(function()c=e.getLabel()end)if d then print("Label of "..b(a)..((e.type and e.type~="filesystem")and" ("..e.type..")"or"")..":\n \x1b[92m"..g(c).."\x1b[39m")else f("getting",h)end else if not e.setLabel then return d("setting")end;local d=""for a=2,#c do d=d..tostring(c[a])if a<#c then d=d.." "end end;local c;local d,h=pcall(function()c=e.setLabel(d)end)if d then print("Successfully set label of "..b(a)..(e.type and" ("..e.type..")"or"").." to:\n \x1b[92m"..g(c).."\x1b[39m")else f("setting",h)end end \ No newline at end of file diff --git a/halyde/apps/ls.lua b/halyde/apps/ls.lua index 8276f19..f39c9c0 100644 --- a/halyde/apps/ls.lua +++ b/halyde/apps/ls.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a={...}local b=a[1]a=nil;local a=import("filesystem")local c=import("unicode")local d=0;local e=2;local f={}local g={}if b then if b:sub(1,1)~="/"then b=a.concat(shell.workingDirectory,b)end else b=shell.workingDirectory end;local h=a.list(b)if h then for a,a in pairs(h)do if a:sub(-1,-1)=="/"then table.insert(f,a)a=a:sub(1,-2)else table.insert(g,a)end;if c.wlen(a)>d then d=c.wlen(a)end end;table.sort(f)table.sort(g)h={}for a,a in ipairs(f)do table.insert(h,a)end;for a,a in ipairs(g)do table.insert(h,a)end;f,g=nil,nil;for f,f in ipairs(h)do local g=false;local h;if f:sub(-1,-1)=="/"then g=true;h="\27[93m"..f:sub(1,-2)elseif f:find(".")and f:match("[^.]+$")=="lua"then h="\27[92m"..f end;h=(h or f)..string.rep(" ",d-c.wlen(f)+e)if g then print(h.." \27[0m[DIR]")else local a=a.size(a.concat(b,f))local b;if convert(a,"B","GiB")>=1 then b=tostring(math.floor(convert(a,"B","GiB")*100+0.5)/100).." GiB"elseif convert(a,"B","MiB")>=1 then b=tostring(math.floor(convert(a,"B","MiB")*100+0.5)/100).." MiB"elseif convert(a,"B","KiB")>=1 then b=tostring(math.floor(convert(a,"B","KiB")*100+0.5)/100).." KiB"else b=tostring(a).." B"end;print(h.."\27[0m"..b)end end end \ No newline at end of file diff --git a/halyde/apps/lscor.lua b/halyde/apps/lscor.lua index 8276f19..0c02ddc 100644 --- a/halyde/apps/lscor.lua +++ b/halyde/apps/lscor.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +print("\27[93m"..tostring(#cormgr.corList).."\27[0m coroutines active")for a=1,#cormgr.corList do if a==#cormgr.corList then print("\27[93m└ "..a.."\27[0m - "..cormgr.labelList[a].." \27[0m")else print("\27[93m├ "..a.."\27[0m - "..cormgr.labelList[a].." \27[0m")end end \ No newline at end of file diff --git a/halyde/apps/lsdrv.lua b/halyde/apps/lsdrv.lua index 8276f19..8dfdf3c 100644 --- a/halyde/apps/lsdrv.lua +++ b/halyde/apps/lsdrv.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("serialize")local b=import("component")local c=import("computer")local d=import("unicode")local e,f=b.gpu.getResolution()local f={...}local g=not not(table.find(f,"-a")or table.find(f,"--all"))local h={}local i={}local j={["slot"]="SLOT",["capacity"]="CAPACITY",["managed"]="MANAGED",["readOnly"]="READ-ONLY",["id"]="FULL COMPONENT ID",["mount"]="MOUNT",["bootable"]="BOOTABLE",["label"]="LABEL"}local k={["slot"]=false,["capacity"]=true,["managed"]=false,["readOnly"]=false,["id"]=false,["mount"]=false,["bootable"]=false,["label"]=false}local function l(a)table.insert(i,{k[a],j[a]})h[a]=#i end;for a,b in pairs(h)do print(a,b)end;local function k()l("slot")l("capacity")l("managed")l("readOnly")l("id")l("mount")l("bootable")l("label")end;local function m()if e>100 then l("slot")end;l("capacity")if e>80 then l("id")end;l("mount")l("label")end;local function e(a)print(a)return shell.run("help lsdrv")end;local n=table.find(f,"-o")or table.find(f,"--output")if g then k()elseif n then table.remove(f,n)local a=table.remove(f,n)if not a then return e("Argument -o must have a value")end;if a=="all"then k()else if a:sub(1,1)=="+"then m()end;for a in string.gmatch(a:sub(2),"([^,]+)")do if j[a]then l(a)else print("\x1b[93mCategory \""..a.."\" doesn't exist\x1b[39m")end end end else m()end;local function j(a)return not not h[a]end;local k=not(table.find(f,"-H")or table.find(f,"--si"))local function l(a)local b=k and{"B","KiB","MiB","GiB"}or{"B","KB","MB","GB"}local c=1;local e=k and 1024 or 1000;while a>e and b[c]do c=c+1;a=a/e end;local a=tostring(a):sub(1,5)if d.sub(a,-2)==".0"then a=d.sub(a,1,-3)end;return a.." "..b[c]end;local function k(a,b)return a.exists(b)and not a.isDirectory(b)end;local function m(a)local a=a.readSector(1)for b=1,#a do if a:sub(b,b)=="\0"then a=a:sub(1,b-1)break end end;return a end;local function n(a,b)if b=="drive"then return not not load(m(a))elseif b=="filesystem"then return not not(k(a,"/init.lua")or k(a,"/OS.lua"))end end;local function k(a)return({[true]="Yes",[false]="No"})[a]end;local function m(d,e)if not d then return end;local f=b.proxy(d)if not f then return end;local g,m,o,p,q,r,s;local b=b.slot(d)if b==-1 then g="Virtual"elseif b==9 then g="EEPROM"else g="#"..(b+2)end;o="Yes"p="No"if e=="drive"then o="No"m=l(f.getCapacity())q="/special/drive/"..d:sub(1,3)elseif e=="filesystem"then m=l(f.spaceTotal())if f.isReadOnly()then p="Yes"end;q="/mnt/"..d:sub(1,3)if c.getBootAddress()==d then q="/"end;if c.tmpAddress()==d then q="/tmp"g="Temporary"end elseif e=="eeprom"then m=l(f.getSize()+f.getDataSize())q="/special/eeprom/"end;if j("bootable")then r=k(n(f,e))end;if f.getLabel then local b=f.getLabel()s=b and a.string(b)or"None"else s="Unsupported"end;local function a(a,b)if not h[a]then return end;table.insert(i[h[a]],b or"unknown")end;a("slot",g)a("capacity",m)a("managed",o)a("readOnly",p)a("id",d)a("mount",q)a("bootable",r)a("label",s)end;local function a(a,b)local c=1;while c<=#a do if not b(a[c])then table.remove(a,c)c=c-1 end;c=c+1 end end;local function h(a)local a,d=load("local component,computer,type,id,readonly,capacity=... local managed,eeprom,halyde,tmp,proxy,slot,all=type==\"drive\",type==\"eeprom\",id==\""..c.getBootAddress().."\",id==\""..c.tmpAddress().."\",component.proxy(id),component.slot(id)+2,true return "..a)if a then return function(d)local e,f=false,nil;if d[2]=="filesystem"then e=b.invoke(d[1],"isReadOnly")f=b.invoke(d[1],"spaceTotal")elseif d[2]=="drive"then f=b.invoke(d[1],"getCapacity")elseif d[2]=="eeprom"then f=b.invoke(d[1],"getSize")+b.invoke(d[1],"getDataSize")end;return a(b,c,d[2],d[1],e,f)end else return nil,d end end;local function j(a)if type(a)=="boolean"then if a then return 1 else return 0 end end;return a end;local k={}for a,b in b.list("filesystem")do table.insert(k,{a,b})end;for a,b in b.list("drive")do table.insert(k,{a,b})end;for a,b in b.list("eeprom")do table.insert(k,{a,b})end;if not g then local b=table.find(f,"-s")or table.find(f,"--show")if b then table.remove(f,b)local b=table.remove(f,b)if not b then return e("Argument -s must have a value")end;local b,c=h(b)if b then a(k,b)else return print("\x1b[91mInvalid component filter:\n\n"..tostring(c).."\x1b[39m")end else a(k,function(a)return a[2]~="eeprom"and a[1]~=c.tmpAddress()end)end end;local a=table.find(f,"-S")or table.find(f,"--sort")if a then table.remove(f,a)local a=table.remove(f,a)if not a then return e("Argument -S must have a value")end;local a,b=h(a)if a then table.sort(k,function(b,c)return(j(a(b))or 0)<(j(a(c))or 0)end)else return print("\x1b[91mInvalid sort expression:\n\n"..tostring(b).."\x1b[39m")end else table.sort(k,function(a,b)return a[1]0 then for a,a in ipairs(k)do m(a[1],a[2])end else return print("Could not find storage components for this filter.")end;local function a()local a={}for b=1,#i[1]-1 do table.insert(a,"")end;for b=1,#i do local c=1;for a=1,#a do i[b][a+1]=i[b][a+1]or"[nil]"c=math.max(c,d.wlen(i[b][a+1]))end;for e=1,#a do if i[b][1]then a[e]=a[e]..string.rep(" ",c-d.wlen(i[b][e+1]))..i[b][e+1]elseif b<#i then a[e]=a[e]..i[b][e+1]..string.rep(" ",c-d.wlen(i[b][e+1]))else a[e]=a[e]..i[b][e+1]end;if b<#i then a[e]=a[e].." "end end end;print(a[1].."\n")for b=2,#a do print(a[b])end end;a() \ No newline at end of file diff --git a/halyde/apps/lua.lua b/halyde/apps/lua.lua index 8276f19..618ae73 100644 --- a/halyde/apps/lua.lua +++ b/halyde/apps/lua.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +print("\27[44m".._VERSION.."\27[0m shell")print('Type "exit" to exit.')termlib.readHistory["lua"]={""}local a=import("filesystem")local b=""local a=a.list("halyde/lib")for a,a in pairs(a)do if a:match("(.+)%.lua")then b=b.."local "..a:match("(.+)%.lua")..' = import("'..a:match("(.+)%.lua")..'")\n'end end;while true do local a=read("lua","\27[44mlua>\27[0m ")if a=="exit"then return else local function c()local a=load(b.."return "..a,"=stdin")or load(b..a,"=stdin")local a={assert(a)()}if a and(type(a[1])~="nil"or type(a[2])~="nil")then print(table.unpack(a))end end;local a,b=xpcall(c,function(a)return a.."\n\n"..debug.traceback()end)if not a then print("\27[91m"..b)end end end \ No newline at end of file diff --git a/halyde/apps/maindrv.lua b/halyde/apps/maindrv.lua index 8276f19..e148ff3 100644 --- a/halyde/apps/maindrv.lua +++ b/halyde/apps/maindrv.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("computer")if type(a)~="table"then return print("\x1b[91mComputer library returned '"..type(a).."' type\x1b[39m")end;local a=a.getBootAddress()print(a) \ No newline at end of file diff --git a/halyde/apps/mkdir.lua b/halyde/apps/mkdir.lua index 8276f19..5300e04 100644 --- a/halyde/apps/mkdir.lua +++ b/halyde/apps/mkdir.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=...local b=import("filesystem")if not a then shell.run("help mkdir")return end;if a:sub(1,1)~="/"then a=b.concat(shell.workingDirectory,a)end;if b.exists(a)then print("\27[91mAn object already exists at the specified path.")end;b.makeDirectory(a) \ No newline at end of file diff --git a/halyde/apps/mv.lua b/halyde/apps/mv.lua index 8276f19..1cd8870 100644 --- a/halyde/apps/mv.lua +++ b/halyde/apps/mv.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a,b=...local c=import("filesystem")if not a or not b then shell.run("help mv")return end;if a:sub(1,1)~="/"then a=c.concat(shell.workingDirectory,a)end;if b:sub(1,1)~="/"then b=c.concat(shell.workingDirectory,b)end;if a==b then print("\27[91mSource and destination are the same.")end;if not c.exists(a)then print("\27[91mSource file does not exist.")end;if c.exists(b)and not(table.find({...},"-o")or table.find({...},"--overwrite"))then print("\27[91mDestination file already exists. Run this command again with -o to overwrite it.")return end;c.rename(a,b) \ No newline at end of file diff --git a/halyde/apps/reboot.lua b/halyde/apps/reboot.lua index 8276f19..4a78fff 100644 --- a/halyde/apps/reboot.lua +++ b/halyde/apps/reboot.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +import("computer").shutdown(true) \ No newline at end of file diff --git a/halyde/apps/rm.lua b/halyde/apps/rm.lua index 8276f19..69df32b 100644 --- a/halyde/apps/rm.lua +++ b/halyde/apps/rm.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=...local b=import("filesystem")if not a then shell.run("help rm")return end;if a:sub(1,1)~="/"then a=b.concat(shell.workingDirectory,a)end;if not b.exists(a)then print("\27[91mFile does not exist.")return end;b.remove(a) \ No newline at end of file diff --git a/halyde/apps/rtest.lua b/halyde/apps/rtest.lua index 8276f19..28fc804 100644 --- a/halyde/apps/rtest.lua +++ b/halyde/apps/rtest.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("raster")a.init()local b=import("event")local c=0;local d=0;local e=1;local f=1;local g=8421504;local h=0;while b.pull("key_down",0)==nil do h=h+1;a.set(c,d,g)c=c+e;d=d+f;if c>a.displayWidth then c=a.displayWidth;e=-math.abs(e)g=math.random(0,16777215)end;if c<1 then c=1;e=math.abs(e)g=math.random(0,16777215)end;if d>a.displayHeight-6 then d=a.displayHeight-6;f=-math.abs(f)g=math.random(0,16777215)end;if d<1 then d=1;f=math.abs(f)g=math.random(0,16777215)end;if h>10 and h%15>0 then while true do local b=0;local c,d=math.random(1,a.displayWidth),math.random(1,a.displayHeight-6)if a.get(c,d)~=0 then a.set(c,d,0)break end;b=b+1;if b>20 then break end end end;if h%10==0 then a.update()coroutine.yield()end end;a.free()termlib.cursorPosY=1 \ No newline at end of file diff --git a/halyde/apps/rtest3d.lua b/halyde/apps/rtest3d.lua index 8276f19..1d16aac 100644 --- a/halyde/apps/rtest3d.lua +++ b/halyde/apps/rtest3d.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("component")local b=import("computer")local c=import("raster")local d=import("event")local a,e=a.invoke(a.list("gpu")(),"getResolution")a,e=a*2,e*4;local a=a/2;local e=e/2;local f=10;local g=0;local h=16777215;local i=0.1;local j={{-f,-f,-f},{f,-f,-f},{f,f,-f},{-f,f,-f},{-f,-f,f},{f,-f,f},{f,f,f},{-f,f,f}}local k={{0,1},{1,2},{2,3},{3,0},{4,5},{5,6},{6,7},{7,4},{0,4},{1,5},{2,6},{3,7}}local l=256;local m=300;local n,o,p=0,0,0;local function q(a,b,c)local d,e=math.cos(n),math.sin(n)local f=b*d-c*e;local b=b*e+c*d;local c,d=math.cos(o),math.sin(o)local e=a*c+b*d;local a=-a*d+b*c;local b,c=math.cos(p),math.sin(p)local d=e*b-f*c;local b=e*c+f*b;return d,b,a end;local function r(b,c,d)local d=l/(d+m)local a=b*d+a;local b=c*d+e;return a,b end;local function a()local a=b.uptime()*20;g=a*0.05;f=(math.sin(g)+1)*25;j={{-f,-f,-f},{f,-f,-f},{f,f,-f},{-f,f,-f},{-f,-f,f},{f,-f,f},{f,f,f},{-f,f,f}}c.clear()n=a*i;o=a*i*0.7;p=a*i*0.5;local a={}for b,c in ipairs(j)do local c,d,e=q(c[1],c[2],c[3])local c,d=r(c,d,e)a[b]={c,d}end;for b,b in ipairs(k)do local d=a[b[1]+1]local a=a[b[2]+1]c.drawLine(d[1],d[2],a[1],a[2],h)end;c.update()end;function main()c.init()while true do a()coroutine.yield()if d.pull("key_down",0)then c.free()break end end;return a end;return main() \ No newline at end of file diff --git a/halyde/apps/shutdown.lua b/halyde/apps/shutdown.lua index 8276f19..ca50d7f 100644 --- a/halyde/apps/shutdown.lua +++ b/halyde/apps/shutdown.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +import("computer").shutdown() \ No newline at end of file diff --git a/halyde/core/boot.lua b/halyde/core/boot.lua index 8276f19..9577f8f 100644 --- a/halyde/core/boot.lua +++ b/halyde/core/boot.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=...local b=a("/halyde/lib/filesystem.lua")(a)_G._OSVERSION="Halyde 2.8.1"_G._OSLOGO=""local c,d=b.open("/halyde/config/oslogo.ans","r"),nil;repeat d=c:read(math.huge)_OSLOGO=_OSLOGO..(d or"")until not d;_G.package={["preloaded"]={}}a("/halyde/core/datatools.lua")()function _G.import(a,...)local c=table.pack(...)if package.preloaded[a]then return package.preloaded[a]end;local d;if b.exists(a)then d=a elseif b.exists("/halyde/lib/"..a..".lua")then d="/halyde/lib/"..a..".lua"elseif shell and shell.workingDirectory and b.exists(shell.workingDirectory..a)then d=shell.workingDirectory..a end;assert(d,"module not found\npossible locations:\n/halyde/lib/"..a..".lua")local a,b,e=b.open(d),"",nil;repeat e=a:read(math.huge or math.maxinteger)b=b..(e or"")until not e;a:close()return(assert(load(b,"="..d))(table.unpack(c)))end;local function a(a)local b,c,d=assert(b.open("/halyde/lib/"..a..".lua","r")),"",nil;repeat d=b:read(math.huge or math.maxinteger)c=c..(d or"")until not d;package.preloaded[a]=assert(load(c,"="..a))()_G[a]=nil end;a("component")a("computer")a("filesystem")local a=import("component")local b=a.gpu;local a=a.list("screen")()b.bind(a)b.setResolution(b.maxResolution())local a=import("filesystem")if not a.exists("/halyde/config/shell.json")then a.copy("/halyde/config/generate/shell.json","/halyde/config/shell.json")end;if not a.exists("/halyde/config/startupapps.json")then a.copy("/halyde/config/generate/startupapps.json","/halyde/config/startupapps.json")end;a=nil;import("/halyde/core/cormgr.lua") \ No newline at end of file diff --git a/halyde/core/cormgr.lua b/halyde/core/cormgr.lua index 8276f19..8faf61d 100644 --- a/halyde/core/cormgr.lua +++ b/halyde/core/cormgr.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +_G.cormgr={}_G.cormgr.corList={}_G.cormgr.labelList={}local a=import("component")local b=import("filesystem")local c=import("json")local a=a.gpu;function _G.cormgr.loadCoroutine(b,...)local c={...}local function d()local b,c=xpcall(function(...)import(...)end,function(a)return a.."\n \n"..debug.traceback()end,b,table.unpack(c))if not b then if print then a.freeAllBuffers()print("\n\27[91m"..c)else error(c)end end end;cormgr.addCoroutine(d,string.match(tostring(b),"([^/]+)%.lua$"))end;function _G.cormgr.addCoroutine(a,b)local a=coroutine.create(a)table.insert(cormgr.corList,a)table.insert(cormgr.labelList,b)return a end;function _G.cormgr.removeCoroutine(a)local a=table.find(cormgr.labelList,cor)table.remove(cormgr.corList,a)table.remove(cormgr.labelList,a)end;function handleError(a)if a==nil then error("unknown error")else error(tostring(a).."\n \n"..debug.traceback())end end;local function a()for a=1,#_G.cormgr.corList do if cormgr.corList[a]then local b,c=coroutine.resume(cormgr.corList[a])if cormgr.corList[a]then if not b then handleError(c)end;if coroutine.status(cormgr.corList[a])=="dead"then table.remove(cormgr.corList,a)table.remove(cormgr.labelList,a)a=a-1 end end end end end;local b,d,e=b.open("/halyde/config/startupapps.json","r"),"",nil;repeat e=b:read(math.huge or math.maxinteger)d=d..(e or"")until not e;b:close()for b,b in ipairs(c.decode(d))do if b~=""then _G.cormgr.loadCoroutine(b)a()end end;while true do a()if#_G.cormgr.corList==0 then computer.shutdown()end end \ No newline at end of file diff --git a/halyde/core/datatools.lua b/halyde/core/datatools.lua index 8276f19..a4e2c98 100644 --- a/halyde/core/datatools.lua +++ b/halyde/core/datatools.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a={["bytes"]={["B"]=1,["KB"]=1000,["MB"]=1000000,["GB"]=1000000000},["bibytes"]={["B"]=1,["KiB"]=1024,["MiB"]=1048576,["GiB"]=1073741824}}function table.find(a,b)for a,c in pairs(a)do if c==b then return a end end end;function table.copy(a)local b=type(a)local c;if b=='table'then c={}for a,b in next,a,nil do c[table.copy(a)]=table.copy(b)end;setmetatable(c,table.copy(getmetatable(a)))else c=a end;return c end;function convert(b,c,d)for a,a in pairs(a)do if a[d]then return b/a[d]*a[c]end end;return false,"unit does not exist"end \ No newline at end of file diff --git a/halyde/core/drvload.lua b/halyde/core/drvload.lua index 8276f19..755505c 100644 --- a/halyde/core/drvload.lua +++ b/halyde/core/drvload.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("filesystem")local b="/halyde/drivers"local c=a.list(b)local d={}local function e(f)local a=import(a.concat(b,f))table.remove(c,table.find(c,f))if a.dependencies then for a,a in pairs(a.dependencies)do if table.find(c,a)then e(a)elseif table.find(c,a..".lua")then e(a..".lua")else for b,c in pairs(d)do if c==a then e(b)end end end end end;if a.onStartup then a.onStartup()end end;for c,c in pairs(c)do local a=import(a.concat(b,c))if a.type then d[c]=a.type end end;for a,a in pairs(c)do if a:sub(-1,-1)~="/"then e(a)end end \ No newline at end of file diff --git a/halyde/core/evmgr.lua b/halyde/core/evmgr.lua index 8276f19..6d4082d 100644 --- a/halyde/core/evmgr.lua +++ b/halyde/core/evmgr.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +_G.evmgr={}_G.evmgr.eventQueue={}local a=10;local b=import("computer")keyboard.ctrlDown=false;keyboard.altDown=false;keyboard.shiftDown=false;while true do local c;repeat c={b.uptime(),b.pullSignal(0)}if c and c[2]then table.insert(evmgr.eventQueue,c)if keyboard then if c[2]=="key_down"then local a=c[5]local a=keyboard.keys[a]if a=="lcontrol"then keyboard.ctrlDown=true elseif a=="lmenu"then keyboard.altDown=true elseif a=="lshift"then keyboard.shiftDown=true elseif a=="c"and keyboard.ctrlDown and keyboard.altDown then if print then print("\n\27[91mCoroutine "..tostring(#cormgr.corList).." killed.")end;cormgr.corList[#cormgr.corList]=nil end elseif c[2]=="key_up"then local a=c[5]local a=keyboard.keys[a]if a=="lcontrol"then keyboard.ctrlDown=false elseif a=="lmenu"then keyboard.altDown=false elseif a=="lshift"then keyboard.shiftDown=true end end end;while#evmgr.eventQueue>a do table.remove(evmgr.eventQueue,1)end end until not c or not c[1]coroutine.yield()end \ No newline at end of file diff --git a/halyde/core/fullkb.lua b/halyde/core/fullkb.lua index 8276f19..6496fb5 100644 --- a/halyde/core/fullkb.lua +++ b/halyde/core/fullkb.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +_G.keyboard={["keys"]={}}keyboard.keys["1"]=2;keyboard.keys["2"]=3;keyboard.keys["3"]=4;keyboard.keys["4"]=5;keyboard.keys["5"]=6;keyboard.keys["6"]=7;keyboard.keys["7"]=8;keyboard.keys["8"]=9;keyboard.keys["9"]=10;keyboard.keys["0"]=11;keyboard.keys.a=30;keyboard.keys.b=48;keyboard.keys.c=46;keyboard.keys.d=32;keyboard.keys.e=18;keyboard.keys.f=33;keyboard.keys.g=34;keyboard.keys.h=35;keyboard.keys.i=23;keyboard.keys.j=36;keyboard.keys.k=37;keyboard.keys.l=38;keyboard.keys.m=50;keyboard.keys.n=49;keyboard.keys.o=24;keyboard.keys.p=25;keyboard.keys.q=16;keyboard.keys.r=19;keyboard.keys.s=31;keyboard.keys.t=20;keyboard.keys.u=22;keyboard.keys.v=47;keyboard.keys.w=17;keyboard.keys.x=45;keyboard.keys.y=21;keyboard.keys.z=44;keyboard.keys.apostrophe=40;keyboard.keys.at=145;keyboard.keys.back=14;keyboard.keys.backslash=43;keyboard.keys.capital=58;keyboard.keys.colon=146;keyboard.keys.comma=51;keyboard.keys.enter=28;keyboard.keys.equals=13;keyboard.keys.grave=41;keyboard.keys.lbracket=26;keyboard.keys.lcontrol=29;keyboard.keys.lmenu=56;keyboard.keys.lshift=42;keyboard.keys.minus=12;keyboard.keys.numlock=69;keyboard.keys.pause=197;keyboard.keys.period=52;keyboard.keys.rbracket=27;keyboard.keys.rcontrol=157;keyboard.keys.rmenu=184;keyboard.keys.rshift=54;keyboard.keys.scroll=70;keyboard.keys.semicolon=39;keyboard.keys.slash=53;keyboard.keys.space=57;keyboard.keys.stop=149;keyboard.keys.tab=15;keyboard.keys.underline=147;keyboard.keys.up=200;keyboard.keys.down=208;keyboard.keys.left=203;keyboard.keys.right=205;keyboard.keys.home=199;keyboard.keys["end"]=207;keyboard.keys.pageUp=201;keyboard.keys.pageDown=209;keyboard.keys.insert=210;keyboard.keys.delete=211;keyboard.keys.f1=59;keyboard.keys.f2=60;keyboard.keys.f3=61;keyboard.keys.f4=62;keyboard.keys.f5=63;keyboard.keys.f6=64;keyboard.keys.f7=65;keyboard.keys.f8=66;keyboard.keys.f9=67;keyboard.keys.f10=68;keyboard.keys.f11=87;keyboard.keys.f12=88;keyboard.keys.f13=100;keyboard.keys.f14=101;keyboard.keys.f15=102;keyboard.keys.f16=103;keyboard.keys.f17=104;keyboard.keys.f18=105;keyboard.keys.f19=113;keyboard.keys.kana=112;keyboard.keys.kanji=148;keyboard.keys.convert=121;keyboard.keys.noconvert=123;keyboard.keys.yen=125;keyboard.keys.circumflex=144;keyboard.keys.ax=150;keyboard.keys.numpad0=82;keyboard.keys.numpad1=79;keyboard.keys.numpad2=80;keyboard.keys.numpad3=81;keyboard.keys.numpad4=75;keyboard.keys.numpad5=76;keyboard.keys.numpad6=77;keyboard.keys.numpad7=71;keyboard.keys.numpad8=72;keyboard.keys.numpad9=73;keyboard.keys.numpadmul=55;keyboard.keys.numpaddiv=181;keyboard.keys.numpadsub=74;keyboard.keys.numpadadd=78;keyboard.keys.numpaddecimal=83;keyboard.keys.numpadcomma=179;keyboard.keys.numpadenter=156;keyboard.keys.numpadequals=141;setmetatable(keyboard.keys,{__index=function(a,b)if type(b)~="number"then return end;for a,c in pairs(a)do if c==b then return a end end end}) \ No newline at end of file diff --git a/halyde/core/shell.lua b/halyde/core/shell.lua index 8276f19..e243159 100644 --- a/halyde/core/shell.lua +++ b/halyde/core/shell.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("filesystem")local b=import("json")local c,d,e=a.open("/halyde/config/shell.json","r"),"",nil;repeat e=c:read(math.huge)d=d..(e or"")until not e;c:close()local b=b.decode(d)import("/halyde/core/termlib.lua")local c=import("event")local c=import("component")local c=c.gpu;_G.shell={}_G.shell.workingDirectory=b["defaultWorkingDirectory"]_G.shell.aliases=b["aliases"]local function d(a,...)cormgr.loadCoroutine(a,...)local a=#cormgr.corList;local b=cormgr.corList[#cormgr.corList]repeat coroutine.yield()until cormgr.corList[a]~=b end;function _G.shell.run(c)checkArg(1,c,"string")if shell.aliases[c:match("[^ ]+")]then local a,a=c:find("[^ ]+")c=shell.aliases[c:match("[^ ]+")]..c:sub(a+1)end;local c,e,f,g=c:gmatch("[^ ]+"),nil,{},c;while true do e=c()if not e then break end;if e:find('"')then local a=g:find('"')local b=e:sub(1,e:find('"')-1)if b and b~=""then table.insert(f,b)end;g=g:sub(a+1)if g:find('"')then table.insert(f,g:sub(1,g:find('"')-1))g=g:sub(g:find('"')+1)c=g:gmatch('[^ ]+')else print("\27[91mmalformed shell command")return end else table.insert(f,e)end end;local b=table.copy(b.path)table.insert(b,shell.workingDirectory)if not f[1]then return end;if a.exists(f[1])and not a.isDirectory(f[1])then local a=f[1]table.remove(f,1)d(a,table.unpack(f))return end;for b,b in pairs(b)do if a.exists(b..f[1])and not a.isDirectory(b..f[1])then local a=a.concat(b,f[1])table.remove(f,1)d(a,table.unpack(f))return else local c=a.list(b)or{}for c,c in pairs(c)do if f[1]==c:match("(.+)%.[^%.]+$")and not a.isDirectory(b..c)then table.remove(f,1)d(b..c,table.unpack(f))return end end end end;print("No such file or command: "..f[1])end;print(b["startupMessage"]:format(_OSVERSION,b.splashMessages[math.random(1,#b.splashMessages)]))while true do coroutine.yield()if shell.workingDirectory:sub(-1,-1)~="/"then shell.workingDirectory=shell.workingDirectory.."/"end;local a=read("shell",b.prompt:format(shell.workingDirectory))shell.run(a)c.freeAllBuffers()end \ No newline at end of file diff --git a/halyde/core/termlib.lua b/halyde/core/termlib.lua index 8276f19..2c2eea2 100644 --- a/halyde/core/termlib.lua +++ b/halyde/core/termlib.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("serialize")local b=import("unicode")local c=import("event")local d=import("component")local e=import("computer")local d=d.gpu;_G.termlib={}termlib.cursorPosX=1;termlib.cursorPosY=1;termlib.readHistory={}local f,g=d.getResolution()local h={["dark"]={[0]=0,[1]=8388608,[2]=32768,[3]=8421376,[4]=128,[5]=8388736,[6]=32896,[7]=12632256},["bright"]={[0]=8421504,[1]=16711680,[2]=65280,[3]=16776960,[4]=255,[5]=16711935,[6]=65535,[7]=16777215}}defaultForegroundColor=h["bright"][7]defaultBackgroundColor=h["dark"][0]d.setForeground(defaultForegroundColor)d.setBackground(defaultBackgroundColor)local function i()local a,b=d.getResolution()if d.copy(1,1,a,b,0,-1)then local c=d.getForeground()local e=d.getBackground()d.setForeground(defaultForegroundColor)d.setBackground(defaultBackgroundColor)d.fill(1,b,a,1," ")d.setForeground(c)d.setBackground(e)termlib.cursorPosY=b end end;local function j()termlib.cursorPosX=1;termlib.cursorPosY=termlib.cursorPosY+1;if termlib.cursorPosY>g then i()end end;local function k(a)local b={}for a in a:sub(3,-2):gmatch("[^;]+")do table.insert(b,tonumber(a))end;return b end;local function l(a)a=math.floor(a)&255;if a<16 then return 4473924*((a>>3)&1)+(12255232*((a>>2)&1)|47872*((a>>1)&1)|187*(a&1))end;if a>=232 then return 65793*(8+(a-232)*10)end;a=a-16;local b={0,95,135,175,215,255}return(b[(a//36)%6+1]<<16)|(b[(a//6)%6+1]<<8)|b[a%6+1]end;local function m(a,b,c)a,b,c=math.floor(a)&255,math.floor(b)&255,math.floor(c)&255;return(a<<16)|(b<<8)|c end;local function n(a,b)local function c(a,b,c)return a>=b and a<=c end;b=b+2;while b<=#a and not c(a:byte(b),64,127)do b=b+1 end;return b end;function termlib.write(a,c)local f,g=d.getResolution()if c==nil then c=true end;if not a or not tostring(a)then return end;if a:find("\a")then e.beep()end;a=tostring(a)a="\27[0m"..a:gsub("\t"," ")local e=0;local g=""local function i()if#g==0 then return end;while true do d.set(termlib.cursorPosX,termlib.cursorPosY,g)if b.wlen(g)>f-termlib.cursorPosX+1 and c then g=g:sub(f-termlib.cursorPosX+2)j()else termlib.cursorPosX=termlib.cursorPosX+b.wlen(g)break end end;g=""end;for b=1,#a do if e>0 then e=e-1;goto continue end;if string.byte(a,b)==10 then i()j()elseif string.byte(a,b)==13 then i()termlib.cursorPosX=1 elseif string.byte(a,b)==27 and b<=#a-2 then i()local c=string.sub(a,b+1,b+1)if c=="["then local c=n(a,b)local a=string.sub(a,b,c)e=e+#a-1;local b=k(a)local a=a:sub(-1)if a=="m"then if b[1]>=30 and b[1]<=37 then d.setForeground(h["dark"][b[1]%10])end;if b[1]==38 and b[2]==5 then d.setForeground(l(b[3]))end;if b[1]==38 and b[2]==2 then d.setForeground(m(b[3],b[4],b[5]))end;if b[1]==39 or b[1]==0 then d.setForeground(defaultForegroundColor)end;if b[1]>=40 and b[1]<=47 then d.setBackground(h["dark"][b[1]%10])end;if b[1]==48 and b[2]==5 then d.setBackground(l(b[3]))end;if b[1]==48 and b[2]==2 then d.setBackground(m(b[3],b[4],b[5]))end;if b[1]==49 or b[1]==0 then d.setBackground(defaultBackgroundColor)end;if b[1]>=90 and b[1]<=97 then d.setForeground(h["bright"][b[1]%10])end;if b[1]>=100 and b[1]<=107 then d.setBackground(h["bright"][b[1]%10])end end end else g=g..string.sub(a,b,b)end::continue::end;i()end;function _G.print(...)local b={...}local c={}for b,b in pairs(b)do if type(b)=="table"then table.insert(c,a.table(b,true))elseif tostring(b)then table.insert(c,tostring(b))end end;termlib.write(table.concat(c," ").."\n")end;function _G.clear()f,g=d.getResolution()d.setForeground(defaultForegroundColor)d.setBackground(defaultBackgroundColor)d.fill(1,1,f,g," ")termlib.cursorPosX,termlib.cursorPosY=1,1 end;function _G.read(a,e,h,j)checkArg(1,a,"string","nil")checkArg(2,e,"string","nil")checkArg(3,h,"string","nil")checkArg(4,j,"number","nil")j=j or math.huge;local h=h or""local k;if a then if not termlib.readHistory[a]then termlib.readHistory[a]={h}elseif termlib.readHistory[a][#termlib.readHistory[a]]~=""then table.insert(termlib.readHistory[a],h)end;k=#termlib.readHistory[a]end;local function l()if not a then return end;termlib.readHistory[a][k]=h end;local m=b.len(h)+1;if e then termlib.write(e)end;local e,n=termlib.cursorPosX,termlib.cursorPosY;local o,p=d.getForeground(),d.getBackground()local q=true;local function r(a)a=e+a-1;return d.get(a%f,n+(a//f))end;local function r(a)for a=1,a-g do i()n=n-1 end;return math.min(a,g)end;local function s(a,c,g)if c==nil or c==""then return end;if g then d.setForeground(p)d.setBackground(o)else d.setForeground(o)d.setBackground(p)end;a=e+a-1;local a,e=(a-1)%f+1,n+((a-1)//f+1)-1;e=r(e)d.set(a,e,b.sub(c,1,f-a+1))for g=1,math.ceil((#c+a-1)/f)+1 do d.set(1,e+g,b.sub(c,2-a+g*f,f+g*f-a))e=r(e)end end;local function d(a,b)if#a==0 then return b end;return a end;local function n(a)return b.wlen(b.sub(h,1,a-1))+1 end;local function o(a)if type(a)~="string"or#a==0 then return end;if b.len(h)>=j then return end;if j1 then h=b.sub(h,1,m-2)..b.sub(h,m)m=m-1;s(n(m),d(b.sub(h,m,m)," "),true)q=true;s(n(m)+1,b.sub(h,m+1).." ",false)l()elseif e=="delete"then h=b.sub(h,1,m-1)..b.sub(h,m+1)s(n(m),d(b.sub(h,m,m)," "),true)q=true;if m<=b.len(h)then s(n(m+1),b.sub(h,m+1).." ",false)end;l()elseif e=="enter"then s(n(m),d(b.sub(h,m,m)," "),false)break elseif not(c[3]<32 or(c[3]>127 and c[3]<=159))then o(b.char(c[3])or" ")l()end elseif c and c[1]=="clipboard"then local a=c[3]if not c[3]then goto continue end;while t(b.sub(a,1,1))do a=b.sub(a,2)end;while t(b.sub(a,-1))do a=b.sub(a,1,-2)end;o(a)l()else q=not q;s(n(m),d(b.sub(h,m,m)," "),q)end::continue::end;if a then if termlib.readHistory[a][#termlib.readHistory[a]]==""then table.remove(termlib.readHistory[a],#termlib.readHistory[a])end;if k<#termlib.readHistory[a]then table.remove(termlib.readHistory[a],k)table.insert(termlib.readHistory[a],h)end;while#termlib.readHistory[a]>50 do table.remove(termlib.readHistory[a],1)end end;termlib.cursorPosX=1;termlib.cursorPosY=termlib.cursorPosY+math.ceil((b.wlen(h)+e-1)/f)if termlib.cursorPosY>g then i()end;return h end \ No newline at end of file diff --git a/halyde/lib/component.lua b/halyde/lib/component.lua index 8276f19..8185349 100644 --- a/halyde/lib/component.lua +++ b/halyde/lib/component.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a;local b;if table.copy then a=table.copy(component)b=table.copy(component)else a={}b=component end;_G.componentlib={["additions"]={},["removals"]={}}a.virtual={}function a.virtual.add(a,b,c)checkArg(1,a,"string")checkArg(2,b,"string")checkArg(3,c,"table")c["address"]=a;componentlib.additions[a]={["componentType"]=b,["proxy"]=c}if componentlib.removals[a]then componentlib.removals[a]=nil end end;function a.virtual.remove(a)checkArg(1,a,"string")if componentlib.additions[a]then componentlib.additions[a]=nil else table.insert(componentlib.removals,a)end end;function a.list(a)checkArg(1,a,"string","nil")local b=table.copy(b.list(a))for c,d in pairs(componentlib.additions)do if d.componentType==a or not a then b[c]=d.componentType end end;for a,a in pairs(componentlib.removals)do b[a]=nil end;local a,c;setmetatable(b,{__call=function(b)a,c=next(b,a)return a,c end})return b end;function a.proxy(a)if componentlib.additions[a]then return componentlib.additions[a].proxy else return b.proxy(a)end end;function a.invoke(a,c,...)if componentlib.additions[a]then return componentlib.additions[a].proxy[c](...)else return b.invoke(a,c,...)end end;function a.get(b)checkArg(1,b,"string")if#b<3 then return nil,"abbreviated address must be at least 3 characters long"end;for a,c in a.list()do if a:find("^"..b)then return(a)end end;return nil,"full address not found"end;setmetatable(a,{["__index"]=function(b,b)if a.list(b)()then return a.proxy(a.list(b)())else return a[b]end end})return a \ No newline at end of file diff --git a/halyde/lib/computer.lua b/halyde/lib/computer.lua index 8276f19..3c85eb5 100644 --- a/halyde/lib/computer.lua +++ b/halyde/lib/computer.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=table.copy(computer)local b=table.copy(computer)function a.pullSignal(a)local c=b.uptime()local d;repeat d={b.pullSignal(0)}coroutine.yield()until d or a and b.uptime()>=c+a;return table.unpack(d)end;return a \ No newline at end of file diff --git a/halyde/lib/event.lua b/halyde/lib/event.lua index 8276f19..eada992 100644 --- a/halyde/lib/event.lua +++ b/halyde/lib/event.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=import("computer")local b={}local c=0.1;function b.pull(...)local b={...}local d,e={},nil;for a,a in pairs(b)do if type(a)=="number"and not e then e=a else table.insert(d,tostring(a))end end;local b=a.uptime()while true do for a=1,#evmgr.eventQueue do local e=false;if d[1]then for d,d in pairs(d)do if evmgr.eventQueue[a][2]==d and evmgr.eventQueue[a][1]>=b-c then e=true end end else if evmgr.eventQueue[a][1]>=b-c then e=true end end;if e then local b=table.copy(evmgr.eventQueue[a])table.remove(evmgr.eventQueue,a)table.remove(b,1)return table.unpack(b)end end;if e and a.uptime()>=b+e then return nil end;coroutine.yield()end end;return b \ No newline at end of file diff --git a/halyde/lib/filesystem.lua b/halyde/lib/filesystem.lua index 8276f19..11a721e 100644 --- a/halyde/lib/filesystem.lua +++ b/halyde/lib/filesystem.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a=...local b,c;if a then unicode=a("/halyde/lib/unicode.lua")(a)b=a("/halyde/lib/component.lua")(a)c=_G.computer elseif import then unicode=import("unicode")b=import("component")c=import("computer")end;local a={}function a.canonical(a)checkArg(1,a,"string")local b={}if a:sub(1,1)~="/"then a="/"..a end;a=a:gsub("/+","/")for a in a:gmatch("[^/]+")do if a==".."and b[1]then table.remove(b,#b)elseif a~="."then table.insert(b,a)end end;return"/"..table.concat(b,"/")end;function a.concat(...)local a={...}for a,b in ipairs(a)do checkArg(a,b,"string")end;local b=a[1]:match("(.+)/?$")for c=2,#a do b=b.."/"..a[c]:match("^/?(.+)/?$")end;return b end;function a.absolutePath(d)checkArg(1,d,"string")d=a.canonical(d)local a=nil;if d:find("^/tmp")then a=c.tmpAddress()d=d:sub(5)elseif d:find("^/mnt/...")then a=b.get(d:sub(6,8))if not a then a=c.getBootAddress()else d=d:sub(9)end else a=c.getBootAddress()end;if not a then return nil,"no such component"end;return a,d end;function a.exists(d)checkArg(1,d,"string")local a,d=a.absolutePath(d)if not a then return false end;if d:find("^/special/drive/...")then return not not(c.getBootAddress()and b.get(d:sub(16,18)))end;if d:find("^/special/eeprom/")then return table.find({"init.lua","data.bin","label.txt"},d:sub(17))end;return b.invoke(a,"exists",d)end;local function d(a,b)b=b or 1;if b==1 then local a=a:read(1)if a==nil then return nil end;return string.byte(a)end;local b,c={string.byte(a:read(b),1,b)},0;if a.littleEndian then for a=#b,1,-1 do c=(c<<8)&4294967295|b[a]end else for a=1,#b do c=(c<<8)&4294967295|b[a]end end;return c end;local function e(a)return unicode.readChar(function()return a:readBytes(1)end)end;local function f(a)return function()local b=d(a,1)if b==nil then a:close()end;return b end end;local function g(a)return unicode.iterate(f(a))end;function a.makeReadStream(a)local b={}local c=1;function b.read(b,b)checkArg(2,b,"number")local d=string.len(a)+1;local e=nil;if co then return nil end;local a=m.readSector(a)local a=a:sub(((s-1)%n)+1,((s+math.min(c,n)-2)%n)+1)s=s+#a;if a==""then return nil end;return a else if j then local a=string.len(r)+1;local b=nil;if so then return nil,"not enough space"end;local b=((s-1)%n)+1;local d=m.readSector(a)m.writeSector(a,d:sub(1,b-1)..c:sub(1,n-b+1))for d=2,(#c+b)//n do if a+d-1>o then return nil,"not enough space"end;m.writeSector(a+d-1,c:sub(b+n*(d-1),b+n*d-1))end;s=s+#c;return true else return b.invoke(a.address,"write",a.handle,c)end end;function q.close(a)if j then r=nil else return b.invoke(a.address,"close",a.handle)end end;if h==c.getBootAddress()then local c;pcall(function()c=b.eeprom end)if c then local b,d;if k=="/special/eeprom/init.lua"then b,d="get","set"elseif k=="/special/eeprom/data.bin"then b,d="getData","setData"elseif k=="/special/eeprom/label.txt"then b,d="getLabel","setLabel"end;if i:sub(1,1)=="r"and b then local a=a.makeReadStream(c[b]()or"")q.read=a.read;q.close=a.close elseif i:sub(1,1)=="w"and d then local a=""function q.write(b,b)checkArg(2,b,"string")a=a..b end;function q.close(b)return c[d](a)end end end end;return q end;function a.list(d)checkArg(1,d,"string")d=a.canonical(d)if d=="/mnt"then local a={}local c=c.tmpAddress()for b,d in b.list("filesystem")do if b~=c then table.insert(a,b:sub(1,3).."/")end end;return a elseif d=="/special/drive"then local a={}local c=c.tmpAddress()for b,d in b.list("drive")do if b~=c and d=="drive"then table.insert(a,b:sub(1,3))end end;return a elseif d=="/special/eeprom"then return{"init.lua","data.bin","label.txt"}else local a,c=a.absolutePath(d)if not a then return false end;return b.invoke(a,"list",c)end end;function a.size(d)checkArg(1,d,"string")local a,d=a.absolutePath(d)if not a then return false end;if a==c.getBootAddress()then if d:find("^/special/drive")then local a=b.get(d:sub(16,18))if not a then return false end;return b.invoke(a,"getCapacity")elseif d:find("^/special/eeprom")then local a;pcall(function()a=b.eeprom end)if a then local b;if d=="/special/eeprom/init.lua"then b="get"elseif d=="/special/eeprom/data.bin"then b="getData"elseif d=="/special/eeprom/label.txt"then b="getLabel"end;return#(a[b]())end end end;return b.invoke(a,"size",d)end;local function d(a,c)local d=b.invoke(a,"list",c)local e={}local f=true;while f do f=false;for g=1,#d do if b.invoke(a,"isDirectory",c.."/"..d[g])then f=true;local f=d[g]if f:sub(-1)=="/"then f=f:sub(1,-2)end;table.insert(e,f)table.remove(d,g)local a=b.invoke(a,"list",c.."/"..f)for b=1,#a do table.insert(d,f.."/"..a[b])end end end end;return d,e end;local function e(a,b)if not(a and b)then return end;local c=math.floor(c.freeMemory()*0.8)local d;while true do d=a:read(c)if not d then break end;local a,b=b:write(d)if a~=true then break end end;a:close()b:close()end;local function c(a,c,f,g)if c:sub(-1)=="/"then c=c:sub(1,-2)end;if g:sub(-1)=="/"then g=g:sub(1,-2)end;b.invoke(f,"makeDirectory",g)local d,h=d(a,c)for a=1,#h do b.invoke(f,"makeDirectory",g.."/"..h[a])end;for h=1,#d do local c,d=c.."/"..d[h],g.."/"..d[h]local c=b.invoke(a,"open",c,"r")local c=b.invoke(f,"open",d,"w")e({["read"]=function(...)return b.invoke(a,"read",handle,...)end,["close"]=function(...)return b.invoke(a,"close",handle,...)end},{["write"]=function(...)return b.invoke(a,"write",handle,...)end,["close"]=function(...)return b.invoke(a,"close",handle,...)end})end end;function a.isDirectory(c)checkArg(1,c,"string")local a,c=a.absolutePath(c)if not a then return false end;return b.invoke(a,"isDirectory",c)end;function a.rename(d,e)checkArg(1,d,"string")checkArg(2,e,"string")local f,g=a.absolutePath(d)local h,i=a.absolutePath(e)if not f or not h then return false end;if f==h then return b.invoke(f,"rename",g,i)elseif a.isDirectory(d)then c(f,g,h,i)a.remove(d)else local b,c,f=a.open(d),"",nil;repeat f=b:read(math.huge or math.maxinteger)c=c..(f or"")until not f;f=b:close()local b=a.open(e)b:write(c)b:close()a.remove(d)end end;function a.copy(b,d)checkArg(1,b,"string")checkArg(2,d,"string")local f,g=a.absolutePath(b)local h,i=a.absolutePath(d)if not f or not h then return false end;if a.isDirectory(b)then c(f,g,h,i)else e(a.open(b,"r"),a.open(d,"w"))end end;function a.remove(c)checkArg(1,c,"string")local a,c=a.absolutePath(c)if not a then return false end;if c:find("^/special")then return false end;if c:find("^/tmp")then return false end;if c:find("^/mnt")then return false end;return b.invoke(a,"remove",c)end;function a.makeDirectory(c)checkArg(1,c,"string")local a,c=a.absolutePath(c)if not a then return false end;return b.invoke(a,"makeDirectory",c)end;return(a) \ No newline at end of file diff --git a/halyde/lib/json.lua b/halyde/lib/json.lua index 8276f19..f52f16c 100644 --- a/halyde/lib/json.lua +++ b/halyde/lib/json.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a={_version="0.1.2"}local b;local c={["\\"]="\\",["\""]="\"",["\b"]="b",["\f"]="f",["\n"]="n",["\r"]="r",["\t"]="t"}local d={["/"]="/"}for a,b in pairs(c)do d[b]=a end;local function e(a)return"\\"..(c[a]or string.format("u%04x",a:byte()))end;local function c(a)return"null"end;local function f(a,c)local d={}c=c or{}if c[a]then error("circular reference")end;c[a]=true;if rawget(a,1)~=nil or next(a)==nil then local e=0;for a in pairs(a)do if type(a)~="number"then error("invalid table: mixed or invalid key types")end;e=e+1 end;if e~=#a then error("invalid table: sparse array")end;for a,a in ipairs(a)do table.insert(d,b(a,c))end;c[a]=nil;return"["..table.concat(d,",").."]"else for a,e in pairs(a)do if type(a)~="string"then error("invalid table: mixed or invalid key types")end;table.insert(d,b(a,c)..":"..b(e,c))end;c[a]=nil;return"{"..table.concat(d,",").."}"end end;local function g(a)return'"'..a:gsub('[%z\1-\31\\"]',e)..'"'end;local function e(a)if a~=a or a<=-math.huge or a>=math.huge then error("unexpected number value '"..tostring(a).."'")end;return string.format("%.14g",a)end;local c={["nil"]=c,["table"]=f,["string"]=g,["number"]=e,["boolean"]=tostring}b=function(a,b)local d=type(a)local c=c[d]if c then return c(a,b)end;error("unexpected type '"..d.."'")end;function a.encode(a)return b(a)end;local b;local function c(...)local a={}for b=1,select("#",...)do a[select(b,...)]=true end;return a end;local e=c(" ","\t","\r","\n")local f=c(" ","\t","\r","\n","]","}",",")local g=c("\\","/",'"',"b","f","n","r","t","u")local c=c("true","false","null")local h={["true"]=true,["false"]=false,["null"]=nil}local function i(a,b,c,d)for b=b,#a do if c[a:sub(b,b)]~=d then return b end end;return#a+1 end;local function j(a,b,c)local d=1;local e=1;for b=1,b-1 do e=e+1;if a:sub(b,b)=="\n"then d=d+1;e=1 end end;error(string.format("%s at line %d col %d",c,d,e))end;local function k(a)local b=math.floor;if a<=127 then return string.char(a)elseif a<=2047 then return string.char(b(a/64)+192,a%64+128)elseif a<=65535 then return string.char(b(a/4096)+224,b(a%4096/64)+128,a%64+128)elseif a<=1114111 then return string.char(b(a/262144)+240,b(a%262144/4096)+128,b(a%4096/64)+128,a%64+128)end;error(string.format("invalid unicode codepoint '%x'",a))end;local function l(a)local b=tonumber(a:sub(1,4),16)local a=tonumber(a:sub(7,10),16)if a then return k((b-55296)*1024+a-56320+65536)else return k(b)end end;local function k(a,b)local c=""local e=b+1;local f=e;while e<=#a do local b=a:byte(e)if b<32 then j(a,e,"control character in string")elseif b==92 then c=c..a:sub(f,e-1)e=e+1;local b=a:sub(e,e)if b=="u"then local a=a:match("^[dD][89aAbB]%x%x\\u%x%x%x%x",e+1)or a:match("^%x%x%x%x",e+1)or j(a,e-1,"invalid unicode escape in string")c=c..l(a)e=e+#a else if not g[b]then j(a,e-1,"invalid escape char '"..b.."' in string")end;c=c..d[b]end;f=e+1 elseif b==34 then c=c..a:sub(f,e-1)return c,e+1 end;e=e+1 end;j(a,b,"expected closing quote for string")end;local function d(a,b)local c=i(a,b,f)local d=a:sub(b,c-1)local e=tonumber(d)if not e then j(a,b,"invalid number '"..d.."'")end;return e,c end;local function g(a,b)local d=i(a,b,f)local e=a:sub(b,d-1)if not c[e]then j(a,b,"invalid literal '"..e.."'")end;return h[e],d end;local function c(a,c)local d={}local f=1;c=c+1;while 1 do local g;c=i(a,c,e,true)if a:sub(c,c)=="]"then c=c+1;break end;g,c=b(a,c)d[f]=g;f=f+1;c=i(a,c,e,true)local b=a:sub(c,c)c=c+1;if b=="]"then break end;if b~=","then j(a,c,"expected ']' or ','")end end;return d,c end;local function f(a,c)local d={}c=c+1;while 1 do local f,g;c=i(a,c,e,true)if a:sub(c,c)=="}"then c=c+1;break end;if a:sub(c,c)~='"'then j(a,c,"expected string for key")end;f,c=b(a,c)c=i(a,c,e,true)if a:sub(c,c)~=":"then j(a,c,"expected ':' after key")end;c=i(a,c+1,e,true)g,c=b(a,c)d[f]=g;c=i(a,c,e,true)local b=a:sub(c,c)c=c+1;if b=="}"then break end;if b~=","then j(a,c,"expected '}' or ','")end end;return d,c end;local c={['"']=k,["0"]=d,["1"]=d,["2"]=d,["3"]=d,["4"]=d,["5"]=d,["6"]=d,["7"]=d,["8"]=d,["9"]=d,["-"]=d,["t"]=g,["f"]=g,["n"]=g,["["]=c,["{"]=f}b=function(a,b)local d=a:sub(b,b)local c=c[d]if c then return c(a,b)end;j(a,b,"unexpected character '"..d.."'")end;function a.decode(a)if type(a)~="string"then error("expected argument of type string, got "..type(a))end;local b,c=b(a,i(a,1,e,true))c=i(a,c,e,true)if c<=#a then j(a,c,"trailing garbage")end;return b end;return a \ No newline at end of file diff --git a/halyde/lib/md5.lua b/halyde/lib/md5.lua index 8276f19..d7199bb 100644 --- a/halyde/lib/md5.lua +++ b/halyde/lib/md5.lua @@ -1 +1,24 @@ -utf-8 \ No newline at end of file +local a={_VERSION="md5.lua 1.1.0",_DESCRIPTION="MD5 computation in Lua (5.1-3, LuaJIT)",_URL="https://github.com/kikito/md5.lua",_LICENSE=[[ + MIT LICENSE + + Copyright (c) 2013 Enrique García Cota + Adam Baldwin + hanzao + Equi 4 Software + + Permission is hereby granted, free of charge, to any person obtaining a + copy of this software and associated documentation files (the + "Software"), to deal in the Software without restriction, including + without limitation the rights to use, copy, modify, merge, publish, + distribute, sublicense, and/or sell copies of the Software, and to + permit persons to whom the Software is furnished to do so, subject to + the following conditions: + + The above copyright notice and this permission notice shall be included + in all copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. + IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY + CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. +]]}local b,c,d,e,f=string.char,string.byte,string.format,string.rep,string.sub;local g,h,i,j,k,l;local m,n=pcall(require,'bit')local o,p=pcall(require,'ffi')if m then g,h,i,j,k,l=n.bor,n.band,n.bnot,n.bxor,n.rshift,n.lshift else m,n=pcall(require,'bit32')if m then i=n.bnot;local a=function(a)return a<=2147483647 and a or-(i(a)+1)end;local a=function(b)return function(c,d)return a(b(a(c),a(d)))end end;g,h,j=a(n.bor),a(n.band),a(n.bxor)k,l=a(n.rshift),a(n.lshift)else local function a(a)local b=0;local c=1;for d=1,#a do b=b+a[d]*c;c=c*2 end;return b end;local function b(a,b)local a,b=a,b;if#a<#b then a,b=b,a end;for a=#b+1,#a do b[a]=0 end end;local c;i=function(b)local b=c(b)local c=math.max(#b,32)for a=1,c do if b[a]==1 then b[a]=0 else b[a]=1 end end;return a(b)end;c=function(a)if a<0 then return c(i(math.abs(a))+1)end;local b={}local c=1;local d;while a>0 do d=a%2;b[c]=d;a=(a-d)/2;c=c+1 end;return b end;g=function(d,e)local d=c(d)local c=c(e)b(d,c)local b={}for a=1,#d do if d[a]==0 and c[a]==0 then b[a]=0 else b[a]=1 end end;return a(b)end;h=function(d,e)local d=c(d)local c=c(e)b(d,c)local b={}for a=1,#d do if d[a]==0 or c[a]==0 then b[a]=0 else b[a]=1 end end;return a(b)end;j=function(d,e)local d=c(d)local c=c(e)b(d,c)local b={}for a=1,#d do if d[a]~=c[a]then b[a]=1 else b[a]=0 end end;return a(b)end;k=function(a,b)local c=0;if a<0 then a=i(math.abs(a))+1;c=2147483648 end;local d=math.floor;for b=1,b do a=a/2;a=g(d(a),c)end;return d(a)end;l=function(a,b)if a<0 then a=i(math.abs(a))+1 end;for b=1,b do a=a*2 end;return h(a,4294967295)end end end;local i;if o then local a=p.typeof("int[1]")i=function(b)return p.string(a(b),4)end else i=function(a)local a=function(c)return b(h(k(a,c),255))end;return a(0)..a(8)..a(16)..a(24)end end;local function m(a)local b=0;for d=1,#a do b=b*256+c(a,d)end;return b end;local n;if o then local a=p.typeof("const char*")local b=p.typeof("const int*")n=function(c)local a=a(c)return p.cast(b,a)[0]end else n=function(a)local b=0;for d=#a,1,-1 do b=b*256+c(a,d)end;return b end end;local function c(a)return{n(f(a,1,4)),n(f(a,5,8)),n(f(a,9,12)),n(f(a,13,16)),n(f(a,17,20)),n(f(a,21,24)),n(f(a,25,28)),n(f(a,29,32)),n(f(a,33,36)),n(f(a,37,40)),n(f(a,41,44)),n(f(a,45,48)),n(f(a,49,52)),n(f(a,53,56)),n(f(a,57,60)),n(f(a,61,64))}end;local n={3614090360,3905402710,606105819,3250441966,4118548399,1200080426,2821735955,4249261313,1770035416,2336552879,4294925233,2304563134,1804603682,4254626195,2792965006,1236535329,4129170786,3225465664,643717713,3921069994,3593408605,38016083,3634488961,3889429448,568446438,3275163606,4107603335,1163531501,2850285829,4243563512,1735328473,2368359562,4294588738,2272392833,1839030562,4259657740,2763975236,1272893353,4139469664,3200236656,681279174,3936430074,3572445317,76029189,3654602809,3873151461,530742520,3299628645,4096336452,1126891415,2878612391,4237533241,1700485571,2399980690,4293915773,2240044497,1873313359,4264355552,2734768916,1309151649,4149444226,3174756917,718787259,3951481745,1732584193,4023233417,2562383102,271733878}local o=function(a,b,c)return g(h(a,b),h(-a-1,c))end;local p=function(a,b,c)return g(h(a,c),h(b,-c-1))end;local q=function(a,b,c)return j(a,j(b,c))end;local j=function(a,b,c)return j(b,g(a,-c-1))end;local g=function(a,b,c,d,e,f,i,j)b=h(b+a(c,d,e)+f+j,4294967295)return g(l(h(b,k(4294967295,i)),i),k(b,32-i))+c end;local function k(a,b,c,d,e)local f,i,k,l=a,b,c,d;local m=n;f=g(o,f,i,k,l,e[0],7,m[1])l=g(o,l,f,i,k,e[1],12,m[2])k=g(o,k,l,f,i,e[2],17,m[3])i=g(o,i,k,l,f,e[3],22,m[4])f=g(o,f,i,k,l,e[4],7,m[5])l=g(o,l,f,i,k,e[5],12,m[6])k=g(o,k,l,f,i,e[6],17,m[7])i=g(o,i,k,l,f,e[7],22,m[8])f=g(o,f,i,k,l,e[8],7,m[9])l=g(o,l,f,i,k,e[9],12,m[10])k=g(o,k,l,f,i,e[10],17,m[11])i=g(o,i,k,l,f,e[11],22,m[12])f=g(o,f,i,k,l,e[12],7,m[13])l=g(o,l,f,i,k,e[13],12,m[14])k=g(o,k,l,f,i,e[14],17,m[15])i=g(o,i,k,l,f,e[15],22,m[16])f=g(p,f,i,k,l,e[1],5,m[17])l=g(p,l,f,i,k,e[6],9,m[18])k=g(p,k,l,f,i,e[11],14,m[19])i=g(p,i,k,l,f,e[0],20,m[20])f=g(p,f,i,k,l,e[5],5,m[21])l=g(p,l,f,i,k,e[10],9,m[22])k=g(p,k,l,f,i,e[15],14,m[23])i=g(p,i,k,l,f,e[4],20,m[24])f=g(p,f,i,k,l,e[9],5,m[25])l=g(p,l,f,i,k,e[14],9,m[26])k=g(p,k,l,f,i,e[3],14,m[27])i=g(p,i,k,l,f,e[8],20,m[28])f=g(p,f,i,k,l,e[13],5,m[29])l=g(p,l,f,i,k,e[2],9,m[30])k=g(p,k,l,f,i,e[7],14,m[31])i=g(p,i,k,l,f,e[12],20,m[32])f=g(q,f,i,k,l,e[5],4,m[33])l=g(q,l,f,i,k,e[8],11,m[34])k=g(q,k,l,f,i,e[11],16,m[35])i=g(q,i,k,l,f,e[14],23,m[36])f=g(q,f,i,k,l,e[1],4,m[37])l=g(q,l,f,i,k,e[4],11,m[38])k=g(q,k,l,f,i,e[7],16,m[39])i=g(q,i,k,l,f,e[10],23,m[40])f=g(q,f,i,k,l,e[13],4,m[41])l=g(q,l,f,i,k,e[0],11,m[42])k=g(q,k,l,f,i,e[3],16,m[43])i=g(q,i,k,l,f,e[6],23,m[44])f=g(q,f,i,k,l,e[9],4,m[45])l=g(q,l,f,i,k,e[12],11,m[46])k=g(q,k,l,f,i,e[15],16,m[47])i=g(q,i,k,l,f,e[2],23,m[48])f=g(j,f,i,k,l,e[0],6,m[49])l=g(j,l,f,i,k,e[7],10,m[50])k=g(j,k,l,f,i,e[14],15,m[51])i=g(j,i,k,l,f,e[5],21,m[52])f=g(j,f,i,k,l,e[12],6,m[53])l=g(j,l,f,i,k,e[3],10,m[54])k=g(j,k,l,f,i,e[10],15,m[55])i=g(j,i,k,l,f,e[1],21,m[56])f=g(j,f,i,k,l,e[8],6,m[57])l=g(j,l,f,i,k,e[15],10,m[58])k=g(j,k,l,f,i,e[6],15,m[59])i=g(j,i,k,l,f,e[13],21,m[60])f=g(j,f,i,k,l,e[4],6,m[61])l=g(j,l,f,i,k,e[11],10,m[62])k=g(j,k,l,f,i,e[2],15,m[63])i=g(j,i,k,l,f,e[9],21,m[64])return h(a+f,4294967295),h(b+i,4294967295),h(c+k,4294967295),h(d+l,4294967295)end;local function g(a,b)a.pos=a.pos+#b;b=a.buf..b;for d=1,#b-63,64 do local b=c(f(b,d,d+63))assert(#b==16)b[0]=table.remove(b,1)a.a,a.b,a.c,a.d=k(a.a,a.b,a.c,a.d,b)end;a.buf=f(b,math.floor(#b/64)*64+1,#b)return a end;local function c(a)local c=a.pos;local d=56-c%64;if c%64>56 then d=d+64 end;if d==0 then d=64 end;local b=b(128)..e(b(0),d-1)..i(h(8*c,4294967295))..i(math.floor(c/536870912))g(a,b)assert(a.pos%64==0)return i(a.a)..i(a.b)..i(a.c)..i(a.d)end;function a.new()return{a=n[65],b=n[66],c=n[67],d=n[68],pos=0,buf='',update=g,finish=c}end;function a.tohex(a)return d("%08x%08x%08x%08x",m(f(a,1,4)),m(f(a,5,8)),m(f(a,9,12)),m(f(a,13,16)))end;function a.sum(b)return a.new():update(b):finish()end;function a.sumhexa(b)return a.tohex(a.sum(b))end;return a \ No newline at end of file diff --git a/halyde/lib/raster.lua b/halyde/lib/raster.lua index 8276f19..3978530 100644 --- a/halyde/lib/raster.lua +++ b/halyde/lib/raster.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a={["units"]={},["defaultBackgroundColor"]=0,["defaultForegroundColor"]=16777215,["displayWidth"]=0,["displayHeight"]=0,["charWidth"]=0,["charHeight"]=0,["backgroundColor"]=16777215}local b=import("component")local b=b.gpu;local c={}local d={}local e=nil;function a.units.charToBraille(a,b)return a*2,b*4 end;function a.units.brailleToChar(a,b)return math.ceil(a/2),math.ceil(b/4)end;function a.init(d,f,g)if d==nil and f==nil then d,f=b.getResolution()end;a.charWidth=d;a.charHeight=f;d,f=a.units.charToBraille(d,f)g=g or a.defaultBackgroundColor;if g~=0 then for a=1,d*f do c[a]=g end end;a.displayWidth=d;a.displayHeight=f;a.backgroundColor=g;pcall(function()e=b.allocateBuffer()end)a.clear()end;function a.set(b,e,f)if b<1 or b>a.displayWidth or e<1 or e>a.displayHeight then return false end;f=f or a.defaultForegroundColor;local g=b+e*a.displayWidth;c[g]=f;local a=math.floor((b-1)/2)+math.floor((e-1)/4)*a.charWidth+1;d[a]=true;return true end;function a.get(b,d)local b=b+d*a.displayWidth;return c[b]or a.backgroundColor end;local function f(a)local b={}for c=1,#a do local a=a[c]if b[a]==nil then b[a]=1 else b[a]=b[a]+1 end end;return b end;local function g(a)local b={}for a,c in pairs(a)do table.insert(b,{a,c})end;table.sort(b,function(a,b)return a[2]>b[2]end)for a=1,#b do b[a]=b[a][1]end;return b end;local function h(a,b)return((a>>16)&255)-((b>>16)&255)+((a>>8)&255)-((b>>8)&255)+(a&255)-(b&255)end;local function i(a)local b=g(f(a))for c=1,#a do local d=a[c]if d==b[1]then a[c]=0;goto continue elseif d==b[2]then a[c]=1;goto continue else if h(d,b[1])-h then k=k-h;b=b+i end;if ad then b,d=d,b end;if c>e then c,e=e,c end;for b=b,d do a.set(b,c,f)a.set(b,e,f)end;for c=c+1,e-1 do a.set(b,c,f)a.set(d,c,f)end end;function a.fillRect(b,c,d,e,f)b,c,d,e=math.floor(b),math.floor(c),math.floor(d),math.floor(e)if b>d then b,d=d,b end;if c>e then c,e=e,c end;for b=b,d do for c=c,e do a.set(b,c,f)end end end;function a.drawCircle(b,c,d,e)b=math.floor(b)c=math.floor(c)d=math.floor(d)local f=0;local g=d;local d=3-2*d;while g>=f do a.set(b+f,c+g,e)a.set(b-f,c+g,e)a.set(b+f,c-g,e)a.set(b-f,c-g,e)a.set(b+g,c+f,e)a.set(b-g,c+f,e)a.set(b+g,c-f,e)a.set(b-g,c-f,e)if d<0 then d=d+4*f+6 else d=d+4*(f-g)+10;g=g-1 end;f=f+1 end end;function a.drawEllipse(b,c,d,e,f)if b>d then b,d=d,b end;if c>e then c,e=e,c end;local g=math.floor((b+d)/2)local h=math.floor((c+e)/2)local b=math.floor((d-b)/2)local c=math.floor((e-c)/2)if b<=0 or c<=0 then return end;if b==c then a.drawCircle(g,h,b,f)return end;if b<=1 and c<=1 then a.set(g,h,f)return elseif b<=1 then for b=h-c,h+c do a.set(g,b,f)end;return elseif c<=1 then for b=g-b,g+b do a.set(b,h,f)end;return end;local d=0;local e=c;local b=b*b;local i=c*c;local c=i-(b*c)+(0.25*b)local j=2*i*d;local k=2*b*e;while j=0 do a.set(g+d,h+e,f)a.set(g-d,h+e,f)a.set(g+d,h-e,f)a.set(g-d,h-e,f)if c>0 then e=e-1;k=k-(2*b)c=c-k+b else e=e-1;d=d+1;j=j+(2*i)k=k-(2*b)c=c+j-k+b end end end;function a.fillCircle(b,c,d,e)b,c=math.floor(b+0.5),math.floor(c+0.5)d=math.floor(d+0.5)if d<=0 then return end;local f,g=b-d,b+d;local h,i=c-d,c+d;for h=h,i do for f=f,g do local b,c=f-b,h-c;local b=b*b+c*c;if b<=d*d then a.set(f,h,e)end end end end;function a.fillEllipse(b,c,d,e,f)local g=(b+d)/2;local h=(c+e)/2;local b=math.abs(d-b)/2;local c=math.abs(e-c)/2;g=math.floor(g+0.5)h=math.floor(h+0.5)b=math.floor(b+0.5)c=math.floor(c+0.5)if b<=0 or c<=0 then return end;if b==c then a.fillCircle(g,h,b,f)return end;local d=g-b;local e=g+b;local i=h-c;local j=h+c;for i=i,j do for d=d,e do local e=d-g;local g=i-h;local b=(e*e)/(b*b)+(g*g)/(c*c)if b<=1 then a.set(d,i,f)end end end end;return a \ No newline at end of file diff --git a/halyde/lib/serialize.lua b/halyde/lib/serialize.lua index 8276f19..517bc99 100644 --- a/halyde/lib/serialize.lua +++ b/halyde/lib/serialize.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a={}function a.string(a)return'"'..a:gsub("[%z\1-\31\34\92\127-\159]",function(a)local a=a:byte()if a==7 then return"\\a"end;if a==8 then return"\\b"end;if a==9 then return"\\t"end;if a==10 then return"\\n"end;if a==11 then return"\\v"end;if a==12 then return"\\f"end;if a==13 then return"\\r"end;if a==34 then return"\\\""end;if a==92 then return"\\\\"end;return string.format("\\x%02x",a)end)..'"'end;function a.table(b,c,d)d=table.copy(d or{})table.insert(d,b)local e=0;local f=true;local g=""local h=true;for b,i in pairs(b)do if not h then g=g..",\n"end;h=false;g=g.." "if type(b)=="string"then if b:match("^[%a_][%w_]*$")then g=g..b.."="else g=g..'['..a.string(b)..']='end else g=g.."["..tostring(b).."]="end;if type(b)~="number"then f=false end;local a,b=pcall(function()local b=""if type(i)=="table"then if#d>4 or table.find(d,i)then b="..."else b=a.table(i,c,d)end elseif type(i)=="string"then local c={}for a in(i.."\n"):gmatch("([^\n]*)\n")do table.insert(c,a)end;if#c[#c]==0 then c[#c]=nil;c[#c]=c[#c].."\n"end;for b=1,#c do if b<#c then c[b]=a.string(c[b].."\n")else c[b]=a.string(c[b])end end;b=table.concat(c," ..\n ")else b=tostring(i)end;local a={}for b in(b.."\n"):gmatch("([^\n]*)\n")do table.insert(a,b)end;g=g..table.concat(a,"\n ")a=nil;e=e+1 end)if not a then if c then g=g.."\x1b[91m"end;g=g.."["..tostring(b).."]"if c then g=g.."\x1b[39m"end end;coroutine.yield()end;local h=getmetatable(b)local i={}if type(h)=="table"then for a,b in pairs(h)do f=false;table.insert(i,a)end end;if#i>0 then g=g.."\n "if c then g=g.."\x1b[92m"end;if table.find(i,"__tostring")then g=g.."tostring: "..a.string(tostring(b)).."\n "table.remove(i,table.find(i,"__tostring"))end;g=g..table.concat(i,", ")if c then g=g.."\x1b[39m"end end;if e==0 then return"{}"end;if f then local e={}for b,b in pairs(b)do if#e>=5 and#d>1 then table.insert(e,"...")break end;if type(b)=="table"then table.insert(e,a.table(b,c,d))elseif type(b)=="string"then table.insert(e,a.string(b))else table.insert(e,tostring(b))end end;return"{"..table.concat(e,", ").."}"end;return"{\n"..g.."\n}"end;return a \ No newline at end of file diff --git a/halyde/lib/unicode.lua b/halyde/lib/unicode.lua index 8276f19..c536104 100644 --- a/halyde/lib/unicode.lua +++ b/halyde/lib/unicode.lua @@ -1 +1 @@ -utf-8 \ No newline at end of file +local a;local b;if table.copy then a=table.copy(unicode)b=table.copy(unicode)else a={}b=unicode end;function a.readCodePoint(a)checkArg(1,a,"function")local function b(a,b,...)for c,c in ipairs({...})do if not(c and c>=a and c1 then if not o()then n()return end end;if not j then n()a.stderr.write("All drives are read-only.\nHalyde cannot be installed.")return end;if f<80 then e.set(1,1,"Are you sure you would like to install Halyde?")else e.set(1,1,"Are you sure you would like to install Halyde to "..j.."?")end;e.set(1,2,"This will erase all data on this disk.")e.set(1,g-1,"Press Y to accept, or N to cancel.")e.set(3,4,"Capacity: ")e.set(3,5,"Used: ")e.set(3,6,"ID: ")e.set(3,7,"Label: ")e.setForeground(65280)if f>=80 then e.set(50,1,j)end;e.set(13,4,math.floor(b.invoke(k,"spaceTotal")/1024).." KiB")e.set(9,5,math.floor(b.invoke(k,"spaceUsed")/1024).." KiB")e.set(7,6,k)e.set(10,7,b.invoke(k,"getLabel")or"No label")if i.keys[({h.pull("key_down")})[4]]=="n"then return n()end;local a=require("computer")local function h(a)local b,d,e=nil,"",nil;local a,c=pcall(function()b=c.request(a)b:finishConnect()end)if not a then return false,c end;local a=b:response()if a and a~=200 then return false,a end;repeat e=b.read(math.huge)d=d..(e or"")until not e;return d end;local c;local i={"halyde","edit","argentum","webinstall-extras"}e.setBackground(0)e.setForeground(16777215)e.fill(1,1,f,g," ")local function k(a,b,c)a=tostring(a)if c==nil then c=' 'end;return string.rep(c,b-#a)..a end;local function l(a,b)local d=0;if c and type(c)=="table"then for a,a in ipairs(i)do local a=c[a]d=d+#(a.directories or{})+#(a.files or{})end else d=1 end;local h=""local j=1;if type(a)=="string"then j=b;h=string.format("%s %s%%",a,k(math.floor(b*100),2))else j=0;for d=1,a do local c=c[i[d]]if d==a then j=j+b else local a=#(c.directories or{})+#c.files;j=j+a end end;j=j/d;local c=c[i[a]]b=b/(#(c.directories or{})+#c.files)local a=i[a].." "..k(math.floor(b*100),2).."%"h=string.format("%s%% [%s]",k(math.floor(j*100),2),a)end;h=h..string.rep(" ",f-#h)local a=math.floor(j*f)e.setBackground(65280)e.setForeground(0)e.set(1,g,h:sub(1,a))e.setBackground(0)e.setForeground(16777215)e.set(a+1,g,h:sub(a+1))end;local k=1;local function m(a)if k>=g then e.copy(1,2,f,g-2,0,-1)e.fill(1,g-1,f,1," ")k=k-1 end;e.set(1,k,a)k=k+1 end;m("Fetching Argentum configuration for Halyde")l("Preparing",0)c=h("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/argentum.cfg")m("Loading Argentum configuration")l("Preparing",0.5)c=load(c)c=c()m("Looking for outdated files in the drive")l("Preparing",1)local k={}for a in d.list(j)do local b=false;for d=1,3 do for c,c in pairs(c[i[d]].files)do if a==c then b=true end end;if c[i[d]].directories then for c,c in pairs(c[i[d]].directories)do if a==c.."/"then b=true end end end end;if a=="halyde/"then b=true end;if not b then table.insert(k,a)end end;m("Found "..#k)l(1,0)for a=1,4 do local b=c[i[a]]local c=0;if b.directories then c=#b.directories;for b,c in ipairs(b.directories)do m("Creating "..c.."...")l(a,b-1)d.makeDirectory(j..c)end end;for b,e in ipairs(b.files)do m("Downloading "..e.."...")l(a,b-1+c)local a=d.open(j..e,"w")a:write(h("https://raw.githubusercontent.com/Team-Cerulean-Blue/Halyde/refs/heads/main/"..e))a:close()end end;for a,b in ipairs(k)do m("Removing "..b)l("Finishing up",(a-1)/#k*1)d.remove(j..b)end;m("Setting boot address")l("Finishing up",1)a.setBootAddress(b.get(j:sub(6,-2)))m("Setting label to Halyde")b.invoke(b.get(j:sub(6,-2)),"setLabel","Halyde")e.fill(1,1,f,g," ")a.shutdown(true) \ No newline at end of file