Skip to content

Commit

Permalink
【WIP】添加控制台启动
Browse files Browse the repository at this point in the history
框架跟进
  • Loading branch information
MrZ626 committed Nov 23, 2024
1 parent b9a496c commit e7cecd2
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Zenitha
Submodule Zenitha updated 2 files
+31 −12 escape.lua
+2 −2 stringExtend.lua
13 changes: 13 additions & 0 deletions conf.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
TerminalResult=require'terminal'

if TerminalResult.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)
Expand Down
14 changes: 14 additions & 0 deletions main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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<string>
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 TerminalResult.launchApplet then
if appletSceneSet[TerminalResult.launchApplet] then
ZENITHA.setFirstScene(TerminalResult.launchApplet)
else
MSG('error',"Applet scene '"..TerminalResult.launchApplet.."' doesn't exist")
end
end

for _,v in next,{
'brik_template', -- Shouldn't be used
Expand Down
113 changes: 113 additions & 0 deletions terminal.lua
Original file line number Diff line number Diff line change
@@ -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 result={}

local commands={}
function commands.help()
result.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()
result.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
result.launchApplet=args[3]
end
feed(.1,"Starting application...\n",.1)
break
elseif args[1]=='exit' then
print("Exiting shell...")
result.bootDisabled=true
break
else
print("Unknown command. Try 'help'")
end
end
end
end
function commands.unknown()
print("Unknown switch. Run with '--help' for help.")
result.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 result

0 comments on commit e7cecd2

Please sign in to comment.