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