调整cmd小程序的ui和部分交互逻辑

This commit is contained in:
MrZ626
2021-03-08 15:53:55 +08:00
parent 057b36bf5b
commit 44a859296a

View File

@@ -6,7 +6,7 @@ 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}
local function log(str)outputBox:push(str)end local function log(str)outputBox:push(str)end
log{COLOR.lGrape,"Techmino Shell"} log{COLOR.lGrape,"Techmino Shell"}
log{COLOR.lY,"©2020 26F Studio some rights reserved"} log{COLOR.lBlue,"©2020 26F Studio some rights reserved"}
local history,hisPtr={"?"} local history,hisPtr={"?"}
@@ -242,9 +242,10 @@ do--commands.help(arg)
"rmwtm", "rmwtm",
"unlockall", "unlockall",
"play", "play",
"theme" "theme",
} }
local total_pages=math.ceil(#command_help_list/10) local pageSize=10
local maxPage=math.ceil(#command_help_list/pageSize)
function commands.help(arg) function commands.help(arg)
-- help [command] -- help [command]
if command_help_messages[arg]then if command_help_messages[arg]then
@@ -255,24 +256,29 @@ do--commands.help(arg)
end end
-- help or help [page] -- help or help [page]
arg=tonumber(arg)and int(tonumber(arg))or 1 arg=tonumber(arg)
if arg>0 and arg<=total_pages then if arg and arg>=1 and arg<=maxPage then
log"Use help [page] to view more commands," log"Use help [page] to view more commands,"
log"or help [command_name] for more info on a command." log"or help [command_name] for details of a command."
log"" log""
log("Page "..arg.." of "..total_pages) log{COLOR.lPink,"Page ",COLOR.lG,arg,COLOR.lPink," of ",COLOR.lG,maxPage}
for i=(arg-1)*10+1,math.min(arg*10,#command_help_list)do for i=pageSize*(arg-1)+1,math.min(pageSize*arg,#command_help_list)do
local _c=command_help_list[i] local cmd=command_help_list[i]
log("".._c.." - "..command_help_messages[_c].description) log{COLOR.W,cmd,COLOR.grey," "..command_help_messages[cmd].description}
end end
else else
log("Invalid page number. Must be between 1 and "..total_pages.." (inclusive).") log{COLOR.red,"Invalid page number. Must be between 1 and "..maxPage.." (inclusive)."}
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 function commands.rst()history,hisPtr={}end
function commands.echo(str)
if str~=""then
outputBox:push(str)
end
end
function commands.url(url) function commands.url(url)
if url~=""then if url~=""then
local res,err=pcall(love.system.openURL,url) local res,err=pcall(love.system.openURL,url)
@@ -393,6 +399,7 @@ 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
if input==""then return end
--Write History --Write History
ins(history,input) ins(history,input)
@@ -402,9 +409,10 @@ function scene.keyDown(k)
log"" log""
--Execute --Execute
input=input:sub((input:find("%S")))
if input:byte()==35 then if input:byte()==35 then
log{COLOR.grass,"> "..input}
--Execute lua code --Execute lua code
log{COLOR.lC,"> "..input}
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)
@@ -415,14 +423,14 @@ function scene.keyDown(k)
else else
log{COLOR.R,"[SYNTAX ERR] ",COLOR.W,err} log{COLOR.R,"[SYNTAX ERR] ",COLOR.W,err}
end end
elseif input~=""then else
log{COLOR.sky,"> "..input}
--Execute builtin command --Execute builtin command
log{COLOR.lSea,"> "..input}
local p=input:find(" ") local p=input:find(" ")
local cmd,arg local cmd,arg
if p then if p then
cmd=input:sub(1,p-1):lower() cmd=input:sub(1,p-1):lower()
arg=input:sub(p+1) arg=input:sub(input:find("%S",p+1)or -1)
else else
cmd=input cmd=input
arg="" arg=""