Skip to content

Commit

Permalink
feat: 自定义Shell前缀(Linux PS1功能)
Browse files Browse the repository at this point in the history
  • Loading branch information
lanbinshijie committed Apr 13, 2023
1 parent 14c812b commit 2aeb924
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
3 changes: 2 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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~")
Expand Down
20 changes: 20 additions & 0 deletions tools/Phraser.py
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 2aeb924

Please sign in to comment.