refactor(shell): 将控制台清理逻辑移至命令执行前

清理控制台的逻辑从循环开始处移动到命令执行前,避免每次循环都进行不必要的清理操作
This commit is contained in:
2025-09-01 11:11:23 +08:00
parent 976769de2d
commit d911c3af34

View File

@@ -81,7 +81,15 @@ end
local history = {} local history = {}
while true do while true do
-- 先清除控制台内容,但保留顶部应用栏 term.setTextColor(colors.yellow)
rc.write("$ "..shell.dir().." >>> ")
term.setTextColor(colors.white)
local text = term.read(nil, history, shell.complete)
if #text > 0 then
history[#history+1] = text
-- 运行命令前先清除控制台内容,但保留顶部应用栏
local w, h = term.getSize() local w, h = term.getSize()
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
@@ -90,13 +98,6 @@ while true do
end end
term.at(1, 2) term.at(1, 2)
term.setTextColor(colors.yellow)
rc.write("$ "..shell.dir().." >>> ")
term.setTextColor(colors.white)
local text = term.read(nil, history, shell.complete)
if #text > 0 then
history[#history+1] = text
local ok, err = shell.run(text) local ok, err = shell.run(text)
if not ok and err then if not ok and err then
io.stderr:write("Application has a error when running and system has stop it. Error:\n", err, "\n") io.stderr:write("Application has a error when running and system has stop it. Error:\n", err, "\n")