|
| 1 | +# 欢迎使用 PythonIDE!如果觉得好用,请给个好评哦~ |
| 2 | +# cmd简练版 |
| 3 | +R = "" # 红 |
| 4 | +G = "" # 绿 |
| 5 | +Y = "" # 黄 |
| 6 | +B = "" # 蓝 |
| 7 | +C = "" # 青 |
| 8 | +M = "" # 紫 |
| 9 | +X = "" |
| 10 | +new_l = "\n" |
| 11 | +import json |
| 12 | +cmd = "" |
| 13 | +show = ">" |
| 14 | +file={"command.com":"bin,can't see", |
| 15 | + "io.sys":"bin,can't see", |
| 16 | + "msdos.sys":"bin,can't see", |
| 17 | + "ms.txt":"hello user!", |
| 18 | + "sys.txt":"看到这个的人我祝福他幸福快乐每一天", |
| 19 | + "thank.xz":"敢看嘛,其实是感谢使用" |
| 20 | +} |
| 21 | +print("DOS改版") |
| 22 | +print("输入help以了解命令") |
| 23 | +while True: |
| 24 | + |
| 25 | + cmd = input(show).strip() #del " " |
| 26 | + if not cmd == new_l: |
| 27 | + # help |
| 28 | + if cmd.startswith("help"): |
| 29 | + print("echo 打印文字,如echo hello") |
| 30 | + print("echo on 开启提示符,echo off 关闭提示符") |
| 31 | + print("dir显示文件") |
| 32 | + print("type显示文件内容") |
| 33 | + print("del可以删除文件,无需路径") |
| 34 | + print("我自定义了文件的写入方式") |
| 35 | + print("add file-text") |
| 36 | + print("new file name") |
| 37 | + print("exit 退出程序") |
| 38 | + print("(del如果显示文件名就是删除成功)") |
| 39 | + #echo |
| 40 | + elif cmd.startswith("echo"): |
| 41 | + input_str = cmd[4:].lstrip() |
| 42 | + if input_str.startswith("on"): |
| 43 | + show = ">" |
| 44 | + elif input_str.startswith("off"): |
| 45 | + show = "" |
| 46 | + else: |
| 47 | + print(input_str) |
| 48 | + # exit |
| 49 | + elif cmd == "exit": |
| 50 | + |
| 51 | + exit() |
| 52 | + elif cmd=="dir": |
| 53 | + print("file:") |
| 54 | + |
| 55 | + for i in list(file): |
| 56 | + B=float('%.2f'%(len(str(file[i]))/1024)) |
| 57 | + leng=32-len(str(i)) |
| 58 | + print(f"- {i}"+f'%{leng}s'%(f'{B}KB')) |
| 59 | + print("file number:"+str(len(file))) |
| 60 | + elif cmd == "oaoa": |
| 61 | + print("91*10086=917826") |
| 62 | + # 在命令判断里加一段 |
| 63 | + elif cmd.startswith("cls"): |
| 64 | + for I in range(1): |
| 65 | + print("\a") |
| 66 | + elif cmd.startswith("type"): |
| 67 | + print(file.get(cmd[5:],"无法找到此文件")) |
| 68 | + elif cmd.startswith("del"): |
| 69 | + if not cmd.endswith(".sys"): |
| 70 | + if file.pop(cmd[4:],False): |
| 71 | + |
| 72 | + |
| 73 | + |
| 74 | + bool=True |
| 75 | + else: |
| 76 | + bool=False |
| 77 | + print("try del file:"+cmd[4:] if bool else "cannot find or del this file") |
| 78 | + elif cmd.startswith("add"): |
| 79 | + try: |
| 80 | + file[cmd[4:]]+=input(">>text") |
| 81 | + except: |
| 82 | + file[cmd[4:]]=input(">>text") |
| 83 | + elif cmd.startswith("new"): |
| 84 | + name=cmd[4:] |
| 85 | + text=input(">>text") |
| 86 | + file[name]=text |
| 87 | + elif cmd.startswith("format"): |
| 88 | + file={} |
| 89 | + exit() |
| 90 | + # read 命令 |
| 91 | + elif cmd.startswith('load'): |
| 92 | + with open("dosfile.txt", "r", encoding="utf-8") as f: |
| 93 | + file = json.load(f) |
| 94 | + elif cmd.startswith("save"): |
| 95 | + with open("dosfile.txt", "w", encoding="utf-8") as f: |
| 96 | + json.dump(file, f, ensure_ascii=False, indent=2) |
| 97 | + else: |
| 98 | + print(f"'{cmd}' 不是内部或外部命令,也不是可运行的程序") |
0 commit comments