From 2aeb9240eeb9925455a0e612074310dadbb53015 Mon Sep 17 00:00:00 2001 From: lanbinshijie Date: Thu, 13 Apr 2023 17:43:47 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=87=AA=E5=AE=9A=E4=B9=89Shell?= =?UTF-8?q?=E5=89=8D=E7=BC=80=EF=BC=88Linux=20PS1=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- main.py | 3 ++- tools/Phraser.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+), 1 deletion(-) create mode 100644 tools/Phraser.py diff --git a/main.py b/main.py index 980480e..5971c68 100644 --- a/main.py +++ b/main.py @@ -10,6 +10,7 @@ from tools.SelfCheck import SelfCheck from misc.Info import ProgramInfo from misc.Error import Error +from tools.Phraser import PS1 def ExecuteModel(args, moduleName): if not SelfCheck.CheckModel(moduleName): return @@ -27,7 +28,7 @@ def ExecuteModel(args, moduleName): def IceShell(): extra = "" - commandN = input(Colors.RED + extra + "IShell> " + Colors.END) + commandN = input(Colors.RED + extra + PS1.paraphraser() + Colors.END) command = commandN.split(" ") if command[0] == "q": print("Bye~") diff --git a/tools/Phraser.py b/tools/Phraser.py new file mode 100644 index 0000000..e9aec22 --- /dev/null +++ b/tools/Phraser.py @@ -0,0 +1,20 @@ + +# 字符替换工具 + +from misc.Info import ProgramInfo + +class PS1: + def paraphraser(prompt="[IShell] %u> "): + # 返回值:替换后的字符串 + # 将prompt中的特殊字符替换成对应的内容 + # 特殊字符: + # %n 程序名:默认为IShell + # %v 版本号:默认为ProgramInfo.version + # %u 用户:默认为Lanbin + + # 替换 + prompt = prompt.replace("%n", "IShell") + prompt = prompt.replace("%v", ProgramInfo.version) + prompt = prompt.replace("%u", "Lanbin") + return prompt +