cmd整理代码,系统log支持颜色,新增rst命令,修改scrinfo说明

This commit is contained in:
MrZ626
2021-03-08 12:21:07 +08:00
parent f9b2929a64
commit f17a776c14

View File

@@ -4,12 +4,14 @@ local ins=table.insert
local inputBox=WIDGET.newInputBox{name="input",x=40,y=650,w=1200,h=50} local inputBox=WIDGET.newInputBox{name="input",x=40,y=650,w=1200,h=50}
local outputBox=WIDGET.newTextBox{name="output",x=40,y=30,w=1200,h=600,font=25,lineH=25,fix=true} local outputBox=WIDGET.newTextBox{name="output",x=40,y=30,w=1200,h=600,font=25,lineH=25,fix=true}
outputBox:push("Techmino Shell") local function log(str)outputBox:push(str)end
outputBox:push("©2020 26F Studio some rights reserved") log{COLOR.lGrape,"Techmino Shell"}
log{COLOR.lY,"©2020 26F Studio some rights reserved"}
local history,hisPtr={"?"} local history,hisPtr={"?"}
local noLog=false local noLog=false
local function log(str) local function log_user(str)
if noLog then return end if noLog then return end
outputBox:push(tostring(str)) outputBox:push(tostring(str))
end end
@@ -21,24 +23,17 @@ local userG={
tonumber=tonumber,tostring=tostring, tonumber=tonumber,tostring=tostring,
select=select,next=next, select=select,next=next,
ipairs=ipairs,pairs=pairs, ipairs=ipairs,pairs=pairs,
print=log,type=type, print=log_user,type=type,
pcall=pcall,xpcall=xpcall, pcall=pcall,xpcall=xpcall,
rawget=rawget,rawset=rawset,rawlen=rawlen,rawequal=rawequal, rawget=rawget,rawset=rawset,rawlen=rawlen,rawequal=rawequal,
setfenv=setfenv,setmetatable=setmetatable, setfenv=setfenv,setmetatable=setmetatable,
-- require=require,
-- load=load,loadfile=loadfile,dofile=dofile, -- load=load,loadfile=loadfile,dofile=dofile,
-- getfenv=getfenv,getmetatable=getmetatable, -- getfenv=getfenv,getmetatable=getmetatable,
-- collectgarbage=collectgarbage, -- collectgarbage=collectgarbage,
math={}, math={},string={},table={},bit={},coroutine={},
table={}, debug={"No way."},package={"No way."},io={"No way."},os={"No way."},
string={},
coroutine={},
bit={},
debug={"No way."},
package={"No way."},
io={"No way."},
os={"No way."},
}userG._G=userG }userG._G=userG
TABLE.complete(math, userG.math) TABLE.complete(math, userG.math)
TABLE.complete(string, userG.string) TABLE.complete(string, userG.string)
@@ -46,6 +41,7 @@ userG.string.dump=nil
TABLE.complete(table, userG.table) TABLE.complete(table, userG.table)
TABLE.complete(bit, userG.bit) TABLE.complete(bit, userG.bit)
TABLE.complete(coroutine, userG.coroutine) TABLE.complete(coroutine, userG.coroutine)
--Puzzle box --Puzzle box
local first_key={} local first_key={}
local fleg={ local fleg={
@@ -100,8 +96,7 @@ do--commands.help(arg)
details={ details={
"Run arbitrary Lua code.", "Run arbitrary Lua code.",
"", "",
"Usage:", "Usage: #[lua_source_code]",
"#[lua_source_code]",
"", "",
"print() can be used to print text into this window.", "print() can be used to print text into this window.",
"There is a strange box.", "There is a strange box.",
@@ -114,19 +109,15 @@ do--commands.help(arg)
"", "",
"Aliases: exit quit bye", "Aliases: exit quit bye",
"", "",
"Usage:", "Usage: exit",
"exit",
}, },
}, },quit="exit",bye="exit",
quit="exit",
bye="exit",
echo={ echo={
description="Print a message to this window.", description="Print a message to this window.",
details={ details={
"Print a message to this window.", "Print a message to this window.",
"", "",
"Usage:", "Usage: echo [message]",
"echo [message]",
}, },
}, },
cls={ cls={
@@ -134,8 +125,15 @@ do--commands.help(arg)
details={ details={
"Clear the log output.", "Clear the log output.",
"", "",
"Usage:", "Usage: cls",
"cls", },
},
rst={
description="Clear the command history.",
details={
"Clear the command history.",
"",
"Usage: rst",
}, },
}, },
shutdown={ shutdown={
@@ -155,17 +153,15 @@ do--commands.help(arg)
"Acts as if you have pressed a function key (i.e. F1-F12) on a keyboard.", "Acts as if you have pressed a function key (i.e. F1-F12) on a keyboard.",
"Useful if you are on a mobile device without access to these keys.", "Useful if you are on a mobile device without access to these keys.",
"", "",
"Usage:", "Usage: fn <1-12>",
"fn <1-12>",
}, },
}, },
scrinfo={ scrinfo={
description="Display information about your screen.", description="Display information about game window'.",
details={ details={
"Display information about your screen.", "Display information about game window'.",
"", "",
"Usage:", "Usage: scrinfo",
"scrinfo",
}, },
}, },
wireframe={ wireframe={
@@ -173,8 +169,7 @@ do--commands.help(arg)
details={ details={
"Enable or disable wireframe.", "Enable or disable wireframe.",
"", "",
"Usage:", "Usage: wireframe <true|false>",
"wireframe <true|false>",
}, },
}, },
gammacorrect={ gammacorrect={
@@ -182,8 +177,7 @@ do--commands.help(arg)
details={ details={
"Enable or disable gamma correction.", "Enable or disable gamma correction.",
"", "",
"Usage:", "Usage: gammacorrect <true|false>",
"gammacorrect <true|false>",
}, },
}, },
rmwtm={ rmwtm={
@@ -192,8 +186,7 @@ do--commands.help(arg)
"Remove the \"no recording\" watermark.", "Remove the \"no recording\" watermark.",
"You will need a password to do that.", "You will need a password to do that.",
"", "",
"Usage:", "Usage: rmwtm [password]",
"rmwtm [password]",
}, },
}, },
unlockall={ unlockall={
@@ -201,8 +194,7 @@ do--commands.help(arg)
details={ details={
"Unlock all modes on the map.", "Unlock all modes on the map.",
"", "",
"Usage:", "Usage: unlockall",
"unlockall",
}, },
}, },
play={ play={
@@ -210,8 +202,7 @@ do--commands.help(arg)
details={ details={
"Load a game mode, including those that are not on the map.", "Load a game mode, including those that are not on the map.",
"", "",
"Usage:", "Usage: play [mode_name]",
"play [mode_name]",
}, },
}, },
festival={ festival={
@@ -219,8 +210,7 @@ do--commands.help(arg)
details={ details={
"Load a festival theme.", "Load a festival theme.",
"", "",
"Usage:", "Usage: festival [festival_name]",
"festival [festival_name]",
"", "",
"Available festivals:", "Available festivals:",
"classic|xmas|sprfes|zday", "classic|xmas|sprfes|zday",
@@ -228,15 +218,13 @@ do--commands.help(arg)
}, },
}TABLE.reIndex(command_help_messages) }TABLE.reIndex(command_help_messages)
-- while I could have used a for loop to get this... the order at which the
-- table elements turn up in the loop is not quite ideal. Doing this manually
-- so that at least the most basic commands are on page 1.
local command_help_list={ local command_help_list={
"help", "help",
"#", "#",
"exit", "exit",
"echo", "echo",
"cls", "cls",
"rst",
"shutdown", "shutdown",
"fn", "fn",
"scrinfo", "scrinfo",
@@ -247,37 +235,35 @@ do--commands.help(arg)
"play", "play",
"festival" "festival"
} }
local total_pages=math.ceil(#command_help_list/10)
local command_help_page_size=10
function commands.help(arg) function commands.help(arg)
if command_help_messages[arg]then -- help [command] -- help [command]
if command_help_messages[arg]then
for _,v in ipairs(command_help_messages[arg].details)do for _,v in ipairs(command_help_messages[arg].details)do
log(v) log(v)
end end
return return
end end
if tonumber(arg)then
arg=int(tonumber(arg)) -- help or help [page]
arg=tonumber(arg)and int(tonumber(arg))or 1
if arg>0 and arg<=total_pages then
log"Use help [page] to view more commands,"
log"or help [command_name] for more info on a command."
log""
log("Page "..arg.." of "..total_pages)
for i=(arg-1)*10+1,math.min(arg*10,#command_help_list)do
local _c=command_help_list[i]
log("".._c.." - "..command_help_messages[_c].description)
end
else else
arg=1
end -- help or help [page]
local total_pages=math.ceil(#command_help_list/command_help_page_size)
if arg<=0 or arg>total_pages then
log("Invalid page number. Must be between 1 and "..total_pages.." (inclusive).") log("Invalid page number. Must be between 1 and "..total_pages.." (inclusive).")
return
end
log"Use help [page] to view more commands,"
log"or help [command_name] for more info on a command."
log""
log("Page "..arg.." of "..total_pages)
for i=(arg-1)*10+1,math.min(arg*10,#command_help_list)do
local _c=command_help_list[i]
log("".._c.." - "..command_help_messages[_c].description)
end end
end end
end end
function commands.shutdown(arg)os.execute("shutdown "..arg)end function commands.shutdown(arg)os.execute("shutdown "..arg)end
function commands.cls()outputBox:clear()end function commands.cls()outputBox:clear()end
function commands.rst()history,hisPtr={}end
commands.echo=log commands.echo=log
commands.exit=backScene commands.exit=backScene
commands.quit=backScene commands.quit=backScene
@@ -292,15 +278,19 @@ function commands.fn(n)
return return
end end
end end
log"Usage: fn [1~12]" log{COLOR.water,"Usage: fn [1~12]"}
end
function commands.scrinfo()
for _,v in next,SCR.info()do
log(v)
end
end end
function commands.scrinfo()for _,v in next,SCR.info()do log(v)end end
function commands.wireframe(bool) function commands.wireframe(bool)
if bool=="true"or bool=="false"then if bool=="true"or bool=="false"then
gc.setWireframe(bool=="true") gc.setWireframe(bool=="true")
log("Wireframe: "..(gc.isWireframe()and"on"or"off")) log("Wireframe: "..(gc.isWireframe()and"on"or"off"))
else else
log"Usage: wireframe [true|false]" log{COLOR.water,"Usage: wireframe [true|false]"}
end end
end end
function commands.gammacorrect(bool) function commands.gammacorrect(bool)
@@ -308,7 +298,7 @@ function commands.gammacorrect(bool)
love._setGammaCorrect(bool=="true") love._setGammaCorrect(bool=="true")
log("GammaCorrect: "..(gc.isGammaCorrect()and"on"or"off")) log("GammaCorrect: "..(gc.isGammaCorrect()and"on"or"off"))
else else
log"Usage: gammacorrect [true|false]" log{COLOR.water,"Usage: gammacorrect [true|false]"}
end end
end end
function commands.rmwtm(pw) function commands.rmwtm(pw)
@@ -317,7 +307,7 @@ function commands.rmwtm(pw)
log("\68\69\86\58\87\97\116\101\114\109\97\114\107\32\82\101\109\111\118\101\100") log("\68\69\86\58\87\97\116\101\114\109\97\114\107\32\82\101\109\111\118\101\100")
SFX.play("clear") SFX.play("clear")
else else
log"Usage: None." log{COLOR.water,"Usage: rmwtm [password]"}
end end
end end
function commands.unlockall(bool) function commands.unlockall(bool)
@@ -341,7 +331,7 @@ function commands.play(m)--marathon_bfmax can only entered through here
elseif m then elseif m then
log("No mode called "..m) log("No mode called "..m)
else else
log"Usage: play [modeName]" log{COLOR.water,"Usage: play [modeName]"}
end end
end end
function commands.festival(name) function commands.festival(name)
@@ -369,7 +359,7 @@ function commands.festival(name)
if name~=""then if name~=""then
log("No festival called "..name) log("No festival called "..name)
end end
log"Usage: festival [fesitivalName]" log{COLOR.water,"Usage: festival [fesitivalName]"}
end end
end end
@@ -385,24 +375,31 @@ end
function scene.keyDown(k) function scene.keyDown(k)
if k=="return"then if k=="return"then
local input=inputBox.value local input=inputBox.value
--Write History
ins(history,input)
hisPtr=nil
--Insert empty line
log"" log""
log("> "..input)
--Execute
if input:byte()==35 then if input:byte()==35 then
--Execute code log{COLOR.grass,"> "..input}
--Execute lua code
local code,err=loadstring(input:sub(2)) local code,err=loadstring(input:sub(2))
if code then if code then
setfenv(code,userG) setfenv(code,userG)
code,err=pcall(code) code,err=pcall(code)
if not code then if not code then
log("[ERR] "..err) log{COLOR.R,"[ERR] ",COLOR.W,err}
end end
else else
log("[SYNTAX ERR] "..err) log{COLOR.R,"[SYNTAX ERR] ",COLOR.W,err}
end end
ins(history,input)
hisPtr=nil
elseif input~=""then elseif input~=""then
--Load command log{COLOR.sky,"> "..input}
--Execute builtin command
local p=input:find(" ") local p=input:find(" ")
local cmd,arg local cmd,arg
if p then if p then
@@ -415,10 +412,8 @@ function scene.keyDown(k)
if commands[cmd]then if commands[cmd]then
commands[cmd](arg) commands[cmd](arg)
else else
log("No command called "..cmd) log{COLOR.R,"No command called "..cmd}
end end
ins(history,input)
hisPtr=nil
end end
inputBox:clear() inputBox:clear()
elseif k=="up"then elseif k=="up"then