Advertisement
MAG_Gen

C SuS SuS Framework installer for CraftOS.

Jan 5th, 2025 (edited)
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 25.01 KB | Software | 0 0
  1. --#region Locals
  2. local PrimeUI,PrimeUI_borderBox
  3. local license
  4. local cssf_repo = "https://raw.githubusercontent.com/MAGGen-hub/C-SuS-SuS-Framework/ac04b23efb60cfd159c0eddff47d8e07d92f896a/"
  5. local path,install_prog,st_path,is_minified
  6. local tArgs={...}
  7. is_minified=true
  8. --#endregion Locals
  9.  
  10. --#region GitLoader
  11. local err_codes={[-2]="Broken URL",[-3]="No responce",[-4]="No result"}
  12. local try_get_git_file= function(url)
  13.     local res,rez = http.checkURL(url)
  14.     if not res then return -2 end
  15.     res = http.get(url)
  16.     if not res then return -3 end
  17.     rez=res.readAll()
  18.     res.close()
  19.     return rez or -4
  20. end
  21. --#endregion GitLoader
  22.  
  23. --#region Install
  24. local install = function()
  25.     local files = {
  26.     --#region C SuS SuS Files
  27.         "features/code/cssc/op_stack.lua",
  28.         "features/code/cssc/runtime.lua",
  29.         "features/code/cssc/typeof.lua",
  30.         --
  31.         "features/code/lua/base.lua",
  32.         "features/code/lua/meta_opt.lua",
  33.         "features/code/lua/struct.lua",
  34.         --
  35.         "features/code/cdata.lua",
  36.         "features/code/syntax_loader.lua",
  37.  
  38.         "features/common/level.lua",
  39.         "features/common/event.lua",
  40.  
  41.         "features/text/dual_queue/base.lua",
  42.         "features/text/dual_queue/iterator.lua",
  43.         "features/text/dual_queue/make_react.lua",
  44.         "features/text/dual_queue/parser.lua",
  45.         "features/text/dual_queue/space_handler.lua",
  46.  
  47.  
  48.         "modules/cssc/BO.lua",
  49.         "modules/cssc/CA.lua",
  50.         "modules/cssc/DA.lua",
  51.         "modules/cssc/IS.lua",
  52.         "modules/cssc/KS.lua",
  53.         "modules/cssc/LF.lua",
  54.         "modules/cssc/NC.lua",
  55.         "modules/cssc/ncbf.lua",
  56.         "modules/cssc/NF.lua",
  57.         "modules/cssc.lua",
  58.  
  59.         "modules/minify.lua",
  60.  
  61.         "modules/sys/dbg_hl.lua",
  62.         "modules/sys/err.lua",
  63.         "modules/sys.lua",
  64.  
  65.  
  66.         "cssf__craft_os.lua"
  67.     --#endregion C SuS SuS Files
  68.     }
  69.     local code = {}
  70.     local base_path = "out/release/"
  71.     local ver = is_minified and "minify/" or "original/"
  72.     local api_url = cssf_repo..base_path..ver
  73.     --download & install api
  74.     --install prog & startup
  75.     --local craftos_url = cssf_repo..base_path.."craftos_url"..ver
  76.     print("Path:",path)
  77.     print("Startup: "..st_path)
  78.     print()
  79.     local x,y = term.getCursorPos()
  80.     y=y-3
  81.     term.setCursorPos(x,y)
  82.     sleep(1.5)
  83.     term.setCursorPos(x,y+1) term.clearLine()
  84.     term.setCursorPos(x,y) term.clearLine()
  85.     for i=1, #files do
  86.         term.setCursorPos(x,y)
  87.         term.write("Downloading API...")
  88.         term.setCursorPos(x,y+1)
  89.         term.write(("Progress:[%d/%d]"):format(i-1,#files))
  90.         term.setCursorPos(x,y+2)
  91.         term.clearLine()
  92.         term.write("File:"..files[i])
  93.         code[fs.combine(path,files[i]=="cssf__craft_os.lua"and "cssf.lua"or files[i])]=try_get_git_file(api_url..files[i])
  94.     end
  95.     term.setCursorPos(x,y)
  96.     term.write("Downloading API - success!")
  97.     term.setCursorPos(x,y+1)
  98.     term.write(("Progress:[%d/%d]"):format(#files,#files))
  99.     term.setCursorPos(x,y+2)
  100.     term.clearLine()
  101.     term.write("Saving files...")
  102.     sleep(0.5)
  103.     term.setCursorPos(x,y)
  104.  
  105.     local api_path =  fs.combine(path,"cssf.lua")
  106.     print()
  107.     --configure api path
  108.     code[api_path]=code[api_path]:gsub("(local base_path=%[%[)(.-)(%]%])",function(a,b,c) return a..path:gsub("([^/])$","%1/")..c end)
  109.    
  110.     if install_prog then
  111.         code[fs.combine(path,"cssc_prog.lua")] =
  112.         [==[local tArgs,cssf,prog={...},cssf or error"C SuS SuS Framework not found!"
  113. if not cssf.default then cssf.default=cssf"config=cssc_user" end
  114. if #tArgs<1 then print"Usage: cssf <prog>"return end
  115. prog=shell.resolveProgram(...) or error("Program `"..tArgs[1].."` not found!")
  116. local file,err = fs.open(prog,"r")
  117. local code=file and file.readAll():gsub("^#!cssc\n","",1) or error(err)
  118. file.close()
  119. local func,err = cssf.default.load(code,"@"..prog,nil,_ENV)
  120. arg[0]=err and error(err) or table.remove(arg,1)
  121. table.remove(tArgs,1)
  122. return func(unpack(tArgs))]==]
  123.     end
  124.  
  125.     if st_path then
  126.         --settings.define("cssf.enable",{default=true,type="boolean"})
  127.         --settings.get("cssf.enable")
  128.         code[st_path] =
  129.         [==[local C,p,d = require"cc.shell.completion","cssc_prog.lua",__PATH__
  130. _G.cssf=loadfile(d.."cssf.lua",nil,_ENV)()
  131. cssf.default=cssf"config=cssc_user"
  132. _G.typeof=cssf.default.typeof
  133. __PROG__]==]
  134.         code[st_path]=code[st_path]:gsub("__PATH__","[=["..path:gsub("([^/])$","%1/").."]=]")
  135.         if install_prog then
  136.             code[st_path]=code[st_path]:gsub("__PROG__",[[shell.setAlias("cssc",d..p)
  137. shell.setCompletionFunction(fs.combine(d..p),C.build{C.programWithArgs,2,many=true})]])
  138.         else
  139.             code[st_path]=code[st_path]:gsub("__PROG__","")
  140.         end
  141.     end
  142.  
  143.     for k,v in pairs(code) do
  144.         local file,err = fs.open(k,"w")
  145.         if err then
  146.             local clr= term.getTextColor()
  147.             term.setTextColor(color.red)
  148.             print("Instalation error!")
  149.             print(err)
  150.             print("Press any key to exit...")
  151.             os.pullEvent("key")
  152.             term.setTextColor(clr)
  153.         end
  154.         file.write(v)
  155.         file.close()
  156.     end
  157.     print()
  158.     print("Instalation complete.")
  159.     sleep(0.5)
  160. end
  161. --#endregion Install
  162.  
  163. --#region CLI mode (if any args was detected)
  164. if #tArgs>0 then
  165.     for k,v in pairs(tArgs)do
  166.         if v=="--help" or v=="-H" then
  167.             print("Usage:\n"..
  168.                 "  -H  --help --Show this message and exit\n"..
  169.                 "  -D=*path* --dir=*path*\n"..
  170.                 "        --Set path to installation folder\n"..
  171.                 "  -S=*path* --startup=*path*\n"..
  172.                 "        --Enable startup and set it's name\n"..
  173.                 "  -P  --prog\n"..
  174.                 "        --Enable launching CSSC from shell\n"..
  175.                 "  -M  --minified (default)\n"..
  176.                 "        --Set API version to minified\n"..
  177.                 "  -O  --original\n"..
  178.                 "        --Set API version to original\n")
  179.             return
  180.         end
  181.         install_prog=install_prog or v=="-P" or v=="--prog"
  182.         st_path=st_path or v:match("^%-S=(.+)") or v:match("^-%-startup=(.+)")
  183.         path=path or v:match("^%-D=(.+)") or v:match("^-%-dir=(.+)")
  184.         if v=="-O" or v=="--original" then is_minified= false end
  185.         if v=="-M" or v=="--minified"then is_minified= true end
  186.     end
  187.     path=path or error("Instalation directory not set!")
  188.     print("CSSF>startup: "..(st_path or"disabled"))
  189.     print("CSSF>path: "..(path))
  190.     print("CSSF>prog: "..(install_prog and "enabled" or "disabled"))
  191.     print()
  192.     install()
  193.     return
  194. end
  195. --#endregion CLI mode
  196.  
  197. --#region Animation API
  198. local blit_pic=function(pic,x,y,font,back)
  199.     font,back=font or function()end,back or function()end
  200.     for i=1,#pic,3 do
  201.         term.setCursorPos(x,y+i/3)
  202.         term.blit(pic[i],font(pic[i+1]),back(pic[i+2]))
  203.     end
  204. end
  205.  
  206. local pal_ctrl=function(pal)
  207.     if pal then for i=0,15 do term.setPaletteColor(2^i,unpack(pal[2^i]))end
  208.     else pal={} for i=0,15 do pal[2^i]={term.getPaletteColor(2^i)}end return pal end
  209. end
  210.  
  211. local color_animate=function(clr,time,steps,r,g,b)
  212.     local R,G,B=term.getPaletteColor(clr)
  213.     local s={r=(r-R)/steps,g=(g-G)/steps,b=(b-B)/steps}
  214.     time=time/steps
  215.     for i=1,steps do
  216.         R,G,B=R+s.r,G+s.g,B+s.b sleep(time)
  217.         term.setPaletteColor(clr,R,G,B)
  218.     end
  219. end
  220.  
  221. -- Keep pal ctrl
  222.  
  223. function rainbowPrintEffect(text,delay)
  224.     local next,fg,bg,X,Y,prev=0,term.getTextColor(),term.getBackgroundColor()
  225.     for char in (text.." "):gmatch"."do
  226.         if prev then term.setCursorPos(X-1,Y) term.write(prev) prev=nil end
  227.         if char:find"%s" then  term.write(char)
  228.         else
  229.             repeat next=(next+1)%16 until 2^next ~= fg and 2^next ~= bg
  230.             term.blit(char,colors.toBlit(2^next),colors.toBlit(bg))
  231.             prev=char
  232.             sleep(delay or 0.4)
  233.         end
  234.         X,Y=term.getCursorPos()
  235.     end
  236. end
  237.  
  238. local pal=pal_ctrl() --variable to keep default pallete unchanged
  239. local max_x,max_y=term.getSize()
  240.  
  241. --#endregion Animation API
  242.  
  243. --#region Splash Screen
  244. local Splash_Screen = function()
  245.     -- Animate background
  246.     term.setPaletteColor(colors.lightBlue,0,0,0) -- lBlue - Set black color for animation
  247.     term.setBackgroundColor(colors.lightBlue)
  248.     term.clear()
  249.     color_animate(colors.lightBlue,0.5,50,unpack(pal[colors.lightBlue]))
  250.  
  251.     -- Animate "W E L C O M E" message
  252.     term.setCursorPos((max_x-13)/2,max_y/2-4)
  253.     term.setTextColor(colors.red)
  254.     rainbowPrintEffect("W E L C O M E",0.3)
  255.  
  256.     sleep(0.3) --small delay
  257.  
  258.     --Animate "t o" message
  259.     term.setCursorPos((max_x-3)/2,max_y/2-2)
  260.     term.setTextColor(colors.blue)
  261.     textutils.slowWrite("t o",5)
  262.  
  263.     -- Animate C_SuS_SuS splash
  264.     local C_SuS_SuS_print={
  265.         "\x98\x8C\x9B  \x98\x8C\x9B \x20\x20\x20 \x98\x8C\x9B  \x98\x8C\x9B \x20\x20\x20 \x98\x8C\x9B","bb*  ee*     ee*  ee*     ee*","  b    e       e    e       e",
  266.         "\x95\x20\x20  \x89\x8C\x9B \x95\x20\x95 \x89\x8C\x9B  \x89\x8C\x9B \x95\x20\x95 \x89\x8C\x9B","bbb  ee* ee* ee*  ee* ee* ee*","       e   e   e    e   e   e",
  267.         "\x89\x8C\x86  \x89\x8C\x86 \x89\x8C\x86 \x89\x8C\x86  \x89\x8C\x86 \x89\x8C\x86 \x89\x8C\x86","bbb  eee eee eee  eee eee eee","                             "}
  268.     term.setPaletteColor(colors.green,unpack(pal[colors.lightBlue])) -- Green - used as process color
  269.     term.setPaletteColor(colors.lime ,unpack(pal[colors.lightBlue])) -- Lime  - used as process color
  270.     blit_pic(C_SuS_SuS_print,(max_x-28.5)/2,max_y/2,function(a)return a:gsub("*","3"):gsub("b","5"):gsub("e","d") end,function(a)return a:gsub(" ","3"):gsub("b","5"):gsub("e","d") end)
  271.     color_animate(colors.lime ,0.4,30,unpack(pal[colors.blue]))
  272.     color_animate(colors.green,0.4,30,unpack(pal[colors.red]))
  273.     blit_pic(C_SuS_SuS_print,(max_x-28.5)/2,max_y/2,function(a)return a:gsub("*","3") end,function(a)return a:gsub(" ","3") end)
  274.  
  275.     sleep(0.3) --small delay
  276.  
  277.     -- Hide colors
  278.     parallel.waitForAll(
  279.         function()color_animate(colors.blue,0.4,30,unpack(pal[colors.lightBlue]))end,
  280.         function()color_animate(colors.red ,0.4,30,unpack(pal[colors.lightBlue]))end)
  281.     term.clear()
  282. end
  283. --#endregion Splash Screen
  284.  
  285. --#region End Screen
  286. local exit_animation = function()
  287.     parallel.waitForAny(
  288.         function()
  289.             repeat  local ev,key=os.pullEvent"key"
  290.             if key==keys.space or key==keys.enter then break end
  291.             until false
  292.         end,
  293.         function()
  294.             parallel.waitForAny(
  295.                 function()color_animate(colors.blue  ,0.2,30,unpack(pal[colors.lightBlue]))end,
  296.                 function()color_animate(colors.cyan  ,0.2,30,unpack(pal[colors.lightBlue]))end,
  297.                 function()color_animate(colors.orange,0.2,30,unpack(pal[colors.lightBlue]))end,
  298.                 function()color_animate(colors.red   ,0.2,30,unpack(pal[colors.lightBlue]))end)
  299.             term.setBackgroundColor(colors.lightBlue)
  300.             term.clear()
  301.             color_animate(colors.lightBlue,0.4,30,unpack(pal[colors.black]))
  302.         end)
  303.     pal_ctrl(pal)
  304.     term.setBackgroundColor(colors.black)
  305.     term.setTextColor(colors.white)
  306.     term.clear()
  307.     term.setCursorPos(1,1)
  308. end
  309. --#endregion End Screen
  310.  
  311. --#region Download_PrimeUI
  312. -- Load files right from git
  313. local make_git_require = function(repo_url,display_name,log)
  314.     display_name=display_name or"X"
  315.     local s,Print,Write,f,w=""
  316.     Print=log and function()end or print
  317.     Write=log or write
  318.     f = function(obj)
  319.         local res,out = pcall(require,obj)
  320.         if res then return out end
  321.         if w then Print"Loading..."end Write(s.."GitR["..display_name.."]:"..obj..".lua - ")
  322.         w=true
  323.         s=s.."    "
  324.         local git_file = try_get_git_file(repo_url..obj..".lua")
  325.         if err_codes[git_file] then Print"Failure" error("Cant reach["..git_file.."]: "..repo_url..obj..".lua")end
  326.         func,err = load(git_file,"@git:"..obj..".lua",nil,setmetatable({require=f},{__index=_G}))
  327.         if err then  Print"Failure" error("Git err:"..err)end
  328.         res,out=pcall(func)
  329.         if not res then  Print"Failure" error("Git err"..out) end
  330.         package.loaded[obj]=out Print("Success"..(w and""or(": "..obj..".lua")))
  331.         s=s:sub(1,-5)
  332.         w=false
  333.         return out
  334.     end
  335.     return f
  336. end
  337. local Download_PrimeUI = function()
  338.     license = try_get_git_file(cssf_repo.."LICENSE")
  339.     local expect = require"cc.expect".expect
  340.     PrimeUI_borderBox = function(win, x, y, width, height, fgColor, bgColor)
  341.         expect(1, win, "table")
  342.         expect(2, x, "number")
  343.         expect(3, y, "number")
  344.         expect(4, width, "number")
  345.         expect(5, height, "number")
  346.         fgColor = expect(6, fgColor, "number", "nil") or colors.white
  347.         bgColor = expect(7, bgColor, "number", "nil") or colors.black
  348.         -- Draw the top-left corner & top border.
  349.         win.setBackgroundColor(bgColor)
  350.         win.setTextColor(fgColor)
  351.         win.setCursorPos(x - 1, y - 1)
  352.         win.write("\x9F" .. ("\x8F"):rep(width))
  353.         -- Draw the top-right corner.
  354.         win.setBackgroundColor(fgColor)
  355.         win.setTextColor(bgColor)
  356.         win.write("\x90")
  357.         -- Draw the right border.
  358.         for i = 1, height do
  359.             win.setCursorPos(win.getCursorPos() - 1, y + i - 1)
  360.             win.write("\x95")
  361.         end
  362.         -- Draw the left border.
  363.         win.setBackgroundColor(bgColor)
  364.         win.setTextColor(fgColor)
  365.         for i = 1, height do
  366.             win.setCursorPos(x - 1, y + i - 1)
  367.             win.write("\x95")
  368.         end
  369.         -- Draw the bottom border and corners.
  370.  
  371.         win.setBackgroundColor(fgColor)
  372.         win.setTextColor(bgColor )
  373.         win.setCursorPos(x - 1, y + height)
  374.         win.write("\x82" .. ("\x83"):rep(width) .. "\x81")
  375.  
  376.         win.setBackgroundColor(bgColor)
  377.         win.setTextColor(fgColor)
  378.     end
  379.     if not _G.PrimeUI then
  380.         --Get PrimeUI-218b28d version (21 Oct 2024 - commit by MCJack123) [stable] - for this project
  381.         local PrimeUI_repo,i = "https://raw.githubusercontent.com/MCJack123/PrimeUI/218b28d4185ddc3ad15594910877eb5f0e858cfd/",1
  382.         local PrimeUI_require = make_git_require(PrimeUI_repo,"PrimeUI",function()end)
  383.         PrimeUI = PrimeUI_require("init")
  384.         _G.PrimeUI=PrimeUI
  385.     else PrimeUI=_G.PrimeUI end
  386. end
  387. --#endregion Download_PrimeUI
  388.  
  389. --#region Download_PrimeUI & ShowSplash
  390. term.setPaletteColor(colors.orange,unpack(pal[colors.red]))
  391. parallel.waitForAny(
  392.     function()parallel.waitForAll(Splash_Screen,Download_PrimeUI) end,
  393.     function() repeat
  394.         local ev,key=os.pullEvent"key"
  395.         if key==keys.space or key==keys.enter then
  396.             if PrimeUI and license then break
  397.             else
  398.                 local X,Y,c,x,y=term.getSize()
  399.                 c,x,y=term.getTextColor(),term.getCursorPos()
  400.                 term.setTextColor(colors.orange)
  401.                 term.setCursorPos(1,Y-1)
  402.                 print(" PrimeUI downloading... Please wait...")
  403.                 term.setCursorPos(x,y)
  404.                 term.setTextColor(c)
  405.             end
  406.         end
  407.     until false end)
  408.  
  409. pal_ctrl(pal) --recover palette
  410.  
  411. --#endregion Download_PrimeUI & ShowSplash
  412.  
  413. --PrimeUI GUI
  414. --#region PrimeUI Locals
  415. local comp=require"cc.shell.completion"
  416. local main=term.current()
  417. local x,y=6,8
  418. local act,_,scroll_box="done"
  419. --#endregion PrimeUI Locals
  420.  
  421. --#region GUI_base func
  422. function make_gui(tm)
  423.     term.setBackgroundColor(colors.lightBlue)
  424.     term.clear()
  425.  
  426.     -- Logo
  427.     blit_pic({"\x96\x83 \x8C\x82 \x8C\x82","bb b* b*","   ee ee",
  428.                 "\x82\x83 \x81\x81 \x81\x81","bb ee ee","        "},4,2,function(a)return a:gsub("*","3") end,function(a)return a:gsub(" ","3") end)
  429.     term.setCursorPos(4+8,2)
  430.     term.setTextColor(colors.blue)
  431.     write(" Framework V4.6-beta Installer. ")
  432.  
  433.     -- PrimeUI CC0 "copyright"
  434.     local p_msg ="PrimeUI-218b28d by MCJack123 "
  435.     term.setCursorPos(math.max(14+9,max_x-#p_msg+1),max_y-1)
  436.     write(p_msg)
  437.  
  438.     -- Box
  439.     local clr = (tm=="LICENSE"or tm=="DESCRIPTION")and colors.white or colors.lightBlue
  440.     PrimeUI_borderBox(main,3,5,max_x-x+2,max_y-y,colors.blue,clr)--paintutils.drawBox(2,4,max_x-1,max_y-3,colors.blue)
  441.  
  442.     -- Name
  443.     clr=colors.toBlit(clr)
  444.     term.setCursorPos(4+8,3) term.blit("\x9F"..("\x8F"):rep(2+#tm).."\x90",("3"):rep(3+#tm).."b",("b"):rep(3+#tm).."3")
  445.     term.setCursorPos(3+9,4) term.blit("\x90["..tm.."]\x9F",clr..("1"):rep(#tm+2)..'b','b'..("b"):rep(#tm+2)..clr)
  446.  
  447.     -- Buttons & Keys
  448.     PrimeUI.keyCombo(keys.c,true,false,false,"exit") -- Ctrl+C exit
  449.     if tm=="INSTALL" then
  450.         PrimeUI.label(main,2,max_y-1," Continue ",colors.lightGray,colors.blue)
  451.         PrimeUI.label(main,2+11,max_y-1," Cancel ",colors.lightGray,colors.blue)
  452.     elseif tm== "LICENSE" then
  453.         PrimeUI.button(main,13,max_y-1,"Cancel" ,"exit",colors.orange,colors.blue,colors.cyan)
  454.         PrimeUI.keyAction(keys.enter,"done")
  455.     elseif tm=="PATH" or tm=="STARTUP"then
  456.         --PrimeUI.label(main,2,max_y-1," Continue ",colors.lightGray,colors.blue)
  457.         PrimeUI.button(main,13,max_y-1,"Cancel" ,"exit",colors.orange,colors.blue,colors.cyan)
  458.     else
  459.         PrimeUI.keyAction(keys.enter,"done")
  460.         PrimeUI.button(main,2,max_y-1,"Continue","done",colors.orange,colors.blue,colors.cyan)
  461.         PrimeUI.button(main,13,max_y-1,"Cancel" ,"exit",colors.orange,colors.blue,colors.cyan)
  462.     end
  463.  
  464.     -- Return Normal Color
  465.     term.setBackgroundColor(colors.lightBlue)
  466. end
  467. --#endregion GUI_base func
  468.  
  469. --#region CancelInstalation
  470. local on_cancel = function()
  471.    
  472.     PrimeUI.clear()
  473.     --wnd.clear()
  474.     make_gui("Cancel")
  475.     PrimeUI.label(main ,3,5,"Instalation canceled. Press any key to exit.",colors.red,colors.lightBlue)
  476.     PrimeUI.label(main ,3,6,"Program will exit automaticly in 3 seconds.",colors.blue,colors.lightBlue)
  477.     PrimeUI.addTask(function()while true do
  478.         local ev=os.pullEvent"key"
  479.         ev=ev and PrimeUI.resolve()
  480.         end
  481.     end)
  482.     PrimeUI.timeout(3,"timeout")
  483.     _,act=PrimeUI.run()
  484.     exit_animation()
  485. end
  486. --#endregion CancelInstalation
  487.  
  488. -- GUI START
  489. --#region ShowDescription
  490. PrimeUI.clear()
  491. make_gui("DESCRIPTION")
  492. paintutils.drawFilledBox(3,5,max_x-x+4,max_y-y+4,colors.white)
  493. scroll_box=PrimeUI.scrollBox(main,3,5,max_x-x+2, max_y-y,999,true,true,colors.blue,colors.white)
  494. PrimeUI.drawText(scroll_box,
  495. [[Use `-H` to get info about CLI mode.
  496.  
  497. C SuS SuS Framework (Very Suspisious C++)
  498. Modular data parsing system.
  499. Currently, it's main purpose - extending
  500. base Lua functional by adding new syntax.
  501.  
  502. Project features:
  503. 1. Fully configurable instances!
  504. All syntax additions are independend, and
  505. can be easily enabled/disabled.
  506.  
  507. 2. Full support of bitwize and `//` opts from
  508. Lua5.3, including their metamethods.
  509.  
  510. 3. Default arguments and strict types:
  511. Tired of `require'cc.expect'.expect`?
  512. Use: `function(*arg*: *type*=*default*)`!
  513.  
  514. 4. Custom types for your objects.
  515. `typeof` function and `is` keyword.
  516.  
  517. 5. Octal and binary number formats.
  518. 0o71, 0b101 - both support binary exponenta
  519. and floating point.
  520.  
  521. 6. Lambda function operators: `->` `=>`
  522. For realy short funcs.
  523.  
  524. 7. Additional assignment: `a X= 1`
  525. Including opts like this: `>>=`
  526.  
  527. 8. Weird keyword shortcuts and
  528. number concatenation bug fix.
  529.  
  530. 9. Experimental code minification module.
  531.  
  532. For more information visit:
  533. github.com/MAGGen-hub/C-SuS-SuS-Framework
  534. ]],true,colors.brown,colors.white)
  535.  
  536. term.setBackgroundColor(colors.lightBlue)
  537. _,act = PrimeUI.run()
  538. if act=="exit" then on_cancel() return end
  539.  
  540.  
  541. --@endregion ShowDescription
  542.  
  543.  
  544. --#endregion PrimeUI GUI part
  545.  
  546. --#region LICENSE (with timer)
  547. PrimeUI.clear()
  548. local time=skip_timer and 0 or 3--time to accept
  549. make_gui("LICENSE")
  550. paintutils.drawFilledBox(3,5,max_x-x+4,max_y-y+4,colors.white)
  551. local is_active={active=false}
  552. scroll_box=PrimeUI.scrollBox(main,3,5,max_x-x+2, max_y-y,999,true,true,colors.blue,colors.white)
  553. PrimeUI.drawText(scroll_box,license,true,colors.brown,colors.white)
  554. PrimeUI.button(main,2,max_y-1," Accept ","done",colors.orange,colors.blue,colors.cyan)
  555. PrimeUI.keyAction(keys.enter,function()if time<1 then PrimeUI.resolve(nil,"done")end end)
  556. _,act = PrimeUI.run()
  557. if act=="exit" then on_cancel() return end
  558. --#endregion LICENCE
  559.  
  560. --#region ChooseModules
  561. local wnd=window.create(term.current(),3,7,max_x-x+2,4)--API chooser window
  562. local base_modules={["Original"]=false, ["Minified"]=true, ["Startup"]= true, ["Program"]= true}
  563. --Module Descriptions
  564. local desc={
  565.     ["Original"]="Original C SuS SuS package - 57.68 KBs",
  566.     ["Minified"]="Minified C SuS SuS package - 28.35 KBs",
  567.     ["Startup"] ="Startup module. CSSF API auto-load.",
  568.     ["Program"] ="Program to launch CSSF programs from shell. Recomended to install."}
  569. setmetatable(base_modules,{__pairs=function(a)
  570.     return function(t,i)
  571.         local order={"Original",["Original"]="Minified",["Minified"]="Startup",["Startup"]="Program"}--["Program"]=nil}
  572.         local ind=order[i or 1]
  573.         return ind,base_modules[ind]
  574.     end,desc
  575. end})
  576. local sel_desk=desc["Minified"]--defalut
  577. local redr_func=function()PrimeUI.textBox(main,3,12,max_x-x+2,1,sel_desk or "",colors.blue,colors.lightBlue)end
  578.  
  579. local selc="Original"
  580. repeat
  581.     PrimeUI.clear()
  582.     make_gui("MODULES")
  583.     PrimeUI.label(main,3,5,"Select API and modules to install [space & \x12]",colors.blue,colors.lightBlue)
  584.     redr_func()--PrimeUI.textBox(main,4,15,max_x-x,1,sel_desk,colors.blue,colors.lightBlue)
  585.     PrimeUI.checkSelectionBox(wnd,1, 1,max_x-x+2,8,base_modules,
  586.         function(k)
  587.             local i = 0
  588.             for kk in pairs(base_modules)do
  589.                 i=i+1
  590.                 if not({["Startup"]=1,["Program"]=1})[k] and i<3 then
  591.                     base_modules[kk]=false
  592.                 end
  593.             end
  594.             if i<3 then
  595.                 base_modules[k]=true
  596.             else
  597.                 base_modules[k]=not base_modules[k]
  598.             end
  599.             sel_desk=desc[k]
  600.             selc=k
  601.             PrimeUI.resolve(_,"api")
  602.         end,colors.brown,colors.lightBlue)
  603.     PrimeUI.addTask(--task to put cursor on it's place
  604.             function()
  605.                 for k,v in pairs(base_modules)do
  606.                     if k~=selc then os.queueEvent("key",keys.down,false)
  607.                     else break end
  608.                 end
  609.                 while true do coroutine.yield() end
  610.             end)
  611.     _,act,key,value=PrimeUI.run()
  612. until act~="api"
  613. is_minified = base_modules["Minified"]
  614. if act=="exit" then on_cancel() return end
  615. --#endregion ChooseModules
  616.  
  617. --#region ChoosePath
  618. --Path to cssf directory
  619. local cssf_folder,prev_folder,err
  620. local histor={"/","/progs/cssf","/programs/cssf","/disk/cssf","/lib/cssf","/apis/cssf","/cssf"}-- posible names for directory
  621. repeat
  622.     cssf_folder=nil
  623.     PrimeUI.clear()
  624.     make_gui("PATH")
  625.     PrimeUI.button(main,2,max_y-1,"Continue",function()os.queueEvent("key",keys.enter)end,colors.orange,colors.blue,colors.cyan)
  626.     PrimeUI.label(main,3,5,"Choose instalation folder (use \x12):",colors.blue,colors.lightBlue)
  627.     paintutils.drawLine(3,7,max_x-x+3,10,colors.lightGray)
  628.     PrimeUI.inputBox(main,4,7,max_x-x+1,"done",colors.white,colors.lightGray,nil,histor,
  629.         function(sLine) if #sLine>0 then return comp.dir(shell,sLine)end end,histor[#histor])
  630.    
  631.     PrimeUI.textBox(main,4,8,max_x-x,3,err or"",colors.red,colors.lightBlue)
  632.     term.setTextColor(colors.yellow)
  633.     term.setCursorBlink(true)
  634.     term.setCursorPos(5+5,7)
  635.     _,act,cssf_folder=PrimeUI.run()--attempt to get the way
  636.     _,err=pcall(function()
  637.         if cssf_folder then --create files if posible
  638.             if prev_folder~=cssf_folder and fs.isDir(cssf_folder) and (fs.exists(fs.combine(cssf_folder,"cssf.lua")) or fs.exists(fs.combine(cssf_folder,"cssc_prog.lua")))then
  639.                 prev_folder=cssf_folder
  640.                 error("Warning! Files will be rewriten! Are you sure? [Enter]")
  641.             end
  642.             local tmp1,err1
  643.             if base_modules["Program"] then
  644.                 tmp1=not fs.isReadOnly(fs.combine(cssf_folder,"cssf.lua")) or error("File is read-only!")
  645.             end
  646.             local tmp2=not fs.isReadOnly(fs.combine(cssf_folder,"cssc_prog.lua")) or error("File is read-only!")
  647.            
  648.             install_prog=tmp1 and fs.combine(cssf_folder,"cssc_prog.lua")-- fs.combine(cssf_folder,"cssf.lua")
  649.             path =tmp2 and cssf_folder -- fs.combine(cssf_folder,"cssc_prog.lua")
  650.         end
  651.     end)
  652.     histor[#histor+1]=cssf_folder~=histor[#histor] and cssf_folder or nil
  653. until path or act=="exit"
  654. if act=="exit" then on_cancel() return end
  655. --#endregion ChoosePath
  656.  
  657. --#region ChooseStartup
  658. err=nil
  659. local st_path_tmp,prev_st_path
  660. --Startup path
  661. if base_modules["Startup"] then
  662.     local histor={"/startup.lua","/disk/startup.lua","/disk/startup/00_cssf.lua","/startup/cssf.lua","/startup/02_cssf.lua","/startup/01_cssf.lua"}
  663.     repeat
  664.         PrimeUI.clear()
  665.         make_gui("STARTUP")
  666.         PrimeUI.button(main,2,max_y-1,"Continue",function()os.queueEvent("key",keys.enter)end,colors.orange,colors.blue,colors.cyan)
  667.         PrimeUI.label(main,3,5,"Enter startup (use \x12):",colors.blue,colors.lightBlue)
  668.         paintutils.drawLine(3,7,max_x-x+4,7,colors.lightGray)
  669.         PrimeUI.inputBox(main,3,7,max_x-x+2,"done",colors.white,colors.lightGray,nil,histor,
  670.             function(sLine) if #sLine>0 then return comp.dirOrFile(shell,sLine)end end, histor[#histor])
  671.         PrimeUI.textBox(main,4,8,max_x-x,3,err or"",colors.red,colors.lightBlue)
  672.         _,act,st_path_tmp=PrimeUI.run()
  673.         _,err=pcall(function()
  674.                 if st_path_tmp then
  675.                     if fs.exists(st_path_tmp) and prev_st_path~=st_path_tmp then
  676.                         prev_st_path=st_path_tmp
  677.                         error("Warning! File '"..st_path_tmp.."' will be rewriten! Are you sure? [Enter]")
  678.                     end
  679.                     local tmp =not fs.isReadOnly(st_path_tmp) or error("File is read-only!")
  680.                     st_path=tmp and fs.combine(st_path_tmp)
  681.                 end
  682.             end)
  683.         histor[#histor+1]=st_path_tmp~=histor[#histor] and st_path_tmp or nil
  684.     until st_path or act=="exit"
  685. end
  686. if act=="exit" then on_cancel() return end
  687. --#endregion ChooseStartup
  688.  
  689. --#region ProgressBar & Size calculation & Instalation Completion
  690. PrimeUI.clear()
  691. make_gui("INSTALL")
  692. --term.setBackgroundColor(colors.black)
  693. --term.clear()
  694. --PrimeUI.textBox(main,3,5,max_x-x+4,max_y-y+4,"Ins\nIns\n",colors.blue,colors.lightBlue)
  695. PrimeUI.addTask(function()
  696.     local wnd = window.create(main,3,5,max_x-x+2,max_y-y,true)
  697.     term.redirect(wnd)
  698.     term.setBackgroundColor(colors.lightBlue)
  699.     term.setTextColor(colors.blue)
  700.     term.clear()
  701.     term.setCursorPos(1,1)
  702.     install()
  703.     term.redirect(main)
  704.     PrimeUI.resolve("install","done")
  705. end)
  706. _,act=PrimeUI.run()
  707. if act=="exit" then on_cancel() return end
  708. --#endregion ProgressBar & Size calculation & Instalation Completion
  709.  
  710. --#region Final
  711. PrimeUI.clear()
  712. make_gui("FINAL")
  713. PrimeUI.label(main ,3,5,"Instalation complete. Press any key to exit.",colors.blue,colors.lightBlue)
  714. PrimeUI.label(main ,3,6,"Program will exit automaticly in 3 seconds.",colors.blue,colors.lightBlue)
  715. PrimeUI.addTask(function()while true do
  716.     local ev=os.pullEvent"key"
  717.     ev=ev and PrimeUI.resolve()
  718.     end
  719. end)
  720. PrimeUI.timeout(3,"timeout")
  721. _,act=PrimeUI.run()
  722. exit_animation()
  723. --#endregion Final
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement