From 8e2a273236a4638c805f83f81ef8e3cbc9019c58 Mon Sep 17 00:00:00 2001 From: OusmBlueNinja Date: Sun, 27 Aug 2023 00:20:47 -0500 Subject: [PATCH] added recovery code if files deleated --- main.py | 3 +++ packages/tedit.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 packages/tedit.py diff --git a/main.py b/main.py index aeee772..2163db2 100644 --- a/main.py +++ b/main.py @@ -266,6 +266,9 @@ def main(): def start(): + if not os.path.exists(f"./packages"): + with open(f"/packages", "w") as f: + f.close() try: print("") main() diff --git a/packages/tedit.py b/packages/tedit.py new file mode 100644 index 0000000..f6a21ec --- /dev/null +++ b/packages/tedit.py @@ -0,0 +1,42 @@ +import curses + +def main(stdscr): + curses.curs_set(1) # Show cursor + stdscr.addstr(0, 0, "Simple Text Editor - Press Ctrl-G to exit") + stdscr.refresh() + + text = [] + row, col = 1, 0 + + while True: + stdscr.move(row, col) + key = stdscr.getch() + + if key == 7: # Ctrl-G to exit + break + elif key == 10: # Enter key + text.append("") + row += 1 + col = 0 + elif key == curses.KEY_BACKSPACE or key == 127: # Backspace key + if col > 0: + col -= 1 + stdscr.delch(row, col) + text[row - 1] = text[row - 1][:col] + text[row - 1][col + 1:] + elif key == curses.KEY_LEFT: + col = max(col - 1, 0) + elif key == curses.KEY_RIGHT: + col = min(col + 1, len(text[row - 1])) + else: + char = chr(key) + stdscr.addch(row, col, char) + if col == len(text[row - 1]): + text[row - 1] += char + else: + text[row - 1] = text[row - 1][:col] + char + text[row - 1][col:] + col += 1 + + stdscr.refresh() + +def tedit(args): + curses.wrapper(main)