From d911c3af34b3505d12721da7d01b1e6ae9045501 Mon Sep 17 00:00:00 2001 From: Leonmmcoset Date: Mon, 1 Sep 2025 11:11:23 +0800 Subject: [PATCH] =?UTF-8?q?refactor(shell):=20=E5=B0=86=E6=8E=A7=E5=88=B6?= =?UTF-8?q?=E5=8F=B0=E6=B8=85=E7=90=86=E9=80=BB=E8=BE=91=E7=A7=BB=E8=87=B3?= =?UTF-8?q?=E5=91=BD=E4=BB=A4=E6=89=A7=E8=A1=8C=E5=89=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 清理控制台的逻辑从循环开始处移动到命令执行前,避免每次循环都进行不必要的清理操作 --- data/computercraft/lua/rom/programs/shell.lua | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/data/computercraft/lua/rom/programs/shell.lua b/data/computercraft/lua/rom/programs/shell.lua index 6a5048b..c4f2bd8 100644 --- a/data/computercraft/lua/rom/programs/shell.lua +++ b/data/computercraft/lua/rom/programs/shell.lua @@ -81,15 +81,6 @@ end local history = {} while true do - -- 先清除控制台内容,但保留顶部应用栏 - local w, h = term.getSize() - term.setTextColor(colors.white) - term.setBackgroundColor(colors.black) - for y=2, h do - term.at(1, y).clearLine() - end - term.at(1, 2) - term.setTextColor(colors.yellow) rc.write("$ "..shell.dir().." >>> ") term.setTextColor(colors.white) @@ -97,6 +88,16 @@ while true do local text = term.read(nil, history, shell.complete) if #text > 0 then history[#history+1] = text + + -- 运行命令前先清除控制台内容,但保留顶部应用栏 + local w, h = term.getSize() + term.setTextColor(colors.white) + term.setBackgroundColor(colors.black) + for y=2, h do + term.at(1, y).clearLine() + end + term.at(1, 2) + local ok, err = shell.run(text) if not ok and err then io.stderr:write("Application has a error when running and system has stop it. Error:\n", err, "\n")