From 8ab1080cc9a333249356db140ebb97bb0226f064 Mon Sep 17 00:00:00 2001 From: MrZ_26 <1046101471@qq.com> Date: Sun, 24 Nov 2024 05:14:55 +0800 Subject: [PATCH] =?UTF-8?q?=E3=80=90WIP=E3=80=91=E5=B8=A6=E7=89=B9?= =?UTF-8?q?=E5=AE=9A=E5=8F=82=E6=95=B0=E6=97=B6=E5=8F=AF=E5=91=88=E7=8E=B0?= =?UTF-8?q?=E4=B8=BA=E6=8E=A7=E5=88=B6=E5=8F=B0=E5=BA=94=E7=94=A8=20?= =?UTF-8?q?=E6=A1=86=E6=9E=B6=E8=B7=9F=E8=BF=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zenitha | 2 +- conf.lua | 13 +++++++ main.lua | 14 +++++++ shell.lua | 113 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 141 insertions(+), 1 deletion(-) create mode 100644 shell.lua diff --git a/Zenitha b/Zenitha index 123e60be..ce22dfac 160000 --- a/Zenitha +++ b/Zenitha @@ -1 +1 @@ -Subproject commit 123e60be43c06f11b51c3073527061cf4be0eaf6 +Subproject commit ce22dfaccd26762673319f75d17a2cc52a1bf1b9 diff --git a/conf.lua b/conf.lua index e7d97a6c..5836c387 100644 --- a/conf.lua +++ b/conf.lua @@ -1,3 +1,16 @@ +ShellOption=require'shell' + +if ShellOption.bootDisabled then + function love.conf(t) + for k in next,t.modules do t.modules[k]=false end + t.window.vsync=0 + t.window.msaa=0 + t.window.depth=0 + t.window.stencil=0 + end + return +end + if love._os=='Web' then local oldRead=love.filesystem.read love.filesystem[('read')]=function(name,size) diff --git a/main.lua b/main.lua index 7c0806fc..ed7e4e0f 100644 --- a/main.lua +++ b/main.lua @@ -22,6 +22,11 @@ -- 5. Readability and Maintainability are not always put to the first place. Codes around hot spot could be optimized for better performance. sorry if it confused you; -- 6. 26 +if not love.window then + love[('run')]=function() return function() return true end end + return +end + ------------------------------------------------------------- -- Load Zenitha @@ -491,12 +496,21 @@ for _,v in next,love.filesystem.getDirectoryItems('assets/scene') do SCN.add(sceneName,FILE.load('assets/scene/'..v,'-lua')) end end +local appletSceneSet={} ---@type Set for _,v in next,love.filesystem.getDirectoryItems('assets/scene_app') do if FILE.isSafe('assets/scene_app/'..v) then local sceneName=v:sub(1,-5) + appletSceneSet[sceneName]=true SCN.add(sceneName,FILE.load('assets/scene_app/'..v,'-lua')) end end +if PROGRESS.get('main')>=3 and ShellOption.launchApplet then + if appletSceneSet[ShellOption.launchApplet] then + ZENITHA.setFirstScene(ShellOption.launchApplet) + else + MSG('error',"Applet scene '"..ShellOption.launchApplet.."' doesn't exist") + end +end for _,v in next,{ 'brik_template', -- Shouldn't be used diff --git a/shell.lua b/shell.lua new file mode 100644 index 00000000..b56e458c --- /dev/null +++ b/shell.lua @@ -0,0 +1,113 @@ +-- [WARNING] Run before main.lua + +function simpRequire(path) + return function(module) return require(path..module) end +end +local _require=require +local require=simpRequire('Zenitha.') +STRING=require'stringExtend' +TABLE=require'tableExtend' +AE=require'escape' + +local stdout=io.stdout +function write(text) + stdout:write(text) + stdout:flush() +end +local function sleep(time) + if love._os=='Linux' then + os.execute('sleep '..time) + else + local fin=os.clock()+time + repeat until os.clock()>fin + end +end +local function feed(...) + local d={...} + for i=1,#d do + if type(d[i])=='number' then + sleep(d[i]) + else + write(d[i]) + end + end +end + +local rArg=TABLE.sub(arg,(arg[-2]=='love' or arg[-1]=='love') and 2 or 1) + +for k,v in next,rArg do print(k,v)end + +local option={} + +local commands={} +function commands.help() + option.bootDisabled=true + feed( + "\n", + AE[533].."TechOS"..AE.." help page\n", + .260, + "[no args] "..AE._d"Start default booting process\n", + "-h, --help "..AE._d"Show this help message then exit\n", + "-v, --version "..AE._d"Show version information then exit\n", + "-s, --shell "..AE._d"Start the interactive shell\n", + .120 + ) +end +function commands.version() + option.bootDisabled=true + sleep(.1) + print(("TechOS %s (%s)"):format(_require'version'.appVer,_require'version'.verCode)) +end +function commands.shell() + feed( + .000,AE[425].. " _____ _ _ "..AE._d" _ "..AE[005].." _____ _", + .260,AE[425].."\n|_ _|___ ___| |_ _____|_|___ ___ "..AE._d" |_| "..AE[005].." | __|___| |___ _ _ _ _", + .120,AE[425].."\n | | | -_| _| | | | | . | "..AE._d" _ "..AE[005].." | | | .'| | .'|_'_| | |", + .120,AE[425].."\n |_| |___|___|_|_|_|_|_|_|_|_|___| "..AE._d" |_| "..AE[005].." |_____|__,|_|__,|_,_|_ |", + .120,AE[533].."\n The ultra-improved version of Techmino, for YOU."..AE[005].. " |___|", + .620,AE.."\n\nWelcome to the TechOS shell!\n",.260 + ) + while true do + write("\n> ") + local input=io.read() + if input~='' then + local args=STRING.split(input,' ') + if args[1]=='help' then + feed( + "Available Commands:\n", + "help Show this help message\n", + "start Continue normal booting process\n", + "exit Interrupt booting process and exit shell\n" + ) + elseif args[1]=='start' then + if args[2]=='app' then + option.launchApplet=args[3] + end + feed(.1,"Starting application...\n",.1) + break + elseif args[1]=='exit' then + print("Exiting shell...") + option.bootDisabled=true + break + else + print("Unknown command. Try 'help'") + end + end + end +end +function commands.unknown() + print("Unknown switch. Run with '--help' for help.") + option.bootDisabled=true +end + +if rArg[1]=="-h" or rArg[1]=="--help" then + commands.help() +elseif rArg[1]=='-s' or rArg[1]=='--shell' then + commands.shell() +elseif rArg[1]=='-v' or rArg[1]=='--version' then + commands.version() +else + commands.unknown() +end + +return option