From bec5fd303292c241e35ec72b4a47c43a55070cf7 Mon Sep 17 00:00:00 2001 From: pythonleo Date: Sun, 2 Aug 2020 21:01:36 +0800 Subject: [PATCH] R M --- files.img | 40 ---------------------------------------- rm.py | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 40 deletions(-) create mode 100644 rm.py diff --git a/files.img b/files.img index 9490743..29e1832 100644 --- a/files.img +++ b/files.img @@ -234,43 +234,3 @@ while True: elif event.type == pygame.MOUSEMOTION: framework.mouseMotion(event.pos) framework.launch() - -!LOC=/sys/ -!FNAME=vis.py -# vis.py -# Basic CLI text editor - -import sys - -# Accepts text input from user -def write(f): - # Keeps asking for input - while True: - line = input() - if line == ".": - f.close() - break - line += "\n" - f.write(line) - -# Checks for valid arguments -try: - filename = sys.argv[1] -except IndexError: - print("Missing argument.") - print("Usage: vis ") - sys.exit(0) - -# Main editor loop -while True: - cmd = input() - if cmd == "i": - f = open(sys.argv[1], "w+") - write(f); - elif cmd == "a": - f = open(sys.argv[1], "a+") - write(f) - elif cmd == "q": - sys.exit(0) - else: - print("?") diff --git a/rm.py b/rm.py new file mode 100644 index 0000000..95deb9b --- /dev/null +++ b/rm.py @@ -0,0 +1,24 @@ +# The `rm` command +# Removes a file in pwd (hopefully) + +def rm(working_dir, *args): + files = open("files.img", 'r+') + to_be_written = [] + target = args[0] + lines = files.read().strip('\0').split('\n') + write_or_not = True + for i, line in enumerate(lines): + if write_or_not: + if line == '!FNAME=%s' % target\ + and lines[i-1] == '!LOC=%s' % working_dir: + write_or_not = False + del to_be_written[-1] + else: + if line and line[0] == '!': + write_or_not = True + if write_or_not: + to_be_written.append(line) + files.close() + fw = open("files.img", 'w+') + fw.write('\n'.join(to_be_written)) + fw.close()