From 1943b194e4bac1416630292d7c216daddedc0698 Mon Sep 17 00:00:00 2001 From: serr Date: Wed, 5 Feb 2025 01:47:34 +0300 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20us?= =?UTF-8?q?age.txt,=20=D0=B2=D0=BE=D0=B7=D0=BC=D0=BE=D0=B6=D0=BD=D0=BE?= =?UTF-8?q?=D1=81=D1=82=D1=8C=20=D0=B7=D0=B0=D0=BF=D1=83=D1=81=D0=BA=D0=B0?= =?UTF-8?q?=20=D0=BF=D1=80=D0=BE=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D1=8B=20?= =?UTF-8?q?=D1=81=20argv[1]=20=D0=B8=D0=BC=D0=B5=D0=BD=D0=B5=D0=BC=20?= =?UTF-8?q?=D1=84=D0=B0=D0=B9=D0=BB=D0=B0=20=D0=B8=D0=BB=D0=B8=20=D0=B1?= =?UTF-8?q?=D0=B5=D0=B7=20=D0=BD=D0=B5=D0=B3=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- config/usage.txt | 39 +++++++++++++++++++++++++++++++++++++++ main.py | 7 ++++--- mvc/models.py | 11 +++++++---- 3 files changed, 50 insertions(+), 7 deletions(-) create mode 100644 config/usage.txt diff --git a/config/usage.txt b/config/usage.txt new file mode 100644 index 0000000..c0bff20 --- /dev/null +++ b/config/usage.txt @@ -0,0 +1,39 @@ +.:: USAGE ::. + +RIGHT: Move the cursor right by 1 position. +LEFT: Move the cursor left by 1 position. +UP: Move the cursor up by 1 line (the cursor's horizontal position should be preserved, or move to the end of the line if the line is shorter). +DOWN: Move the cursor down by 1 line (the cursor's horizontal position should be preserved, or move to the end of the line if the line is shorter). +^ (or 0): Move the cursor to the beginning of the line. +$: Move the cursor to the end of the line. +w: Move the cursor to the end of the word to the right of the cursor (if the cursor is at the end of a word, move to the end of the next word). +b: Move the cursor to the beginning of the word to the left of the cursor (if the cursor is at the beginning of a word, move to the beginning of the previous word). +gg: Go to the beginning of the file. +G: Go to the end of the file. +NG: Go to line number N. For example, 10G moves to the 10th line. +PG_UP: Move up one screen. +PG_DOWN: Move down one screen. +x: Delete the character after the cursor. +diw: Delete the word under the cursor, including the space to the right. +dd: Cut the current line. +yy: Copy the current line. +yw: Copy the word under the cursor. +p: Paste after the cursor. +/text: Search for the string text from the cursor to the end of the file. If the string is found, move the cursor to the beginning of the string. +?text: Search for the string text from the cursor to the beginning of the file. If the string is found, move the cursor to the beginning of the string. +n: Repeat the search. +N: Repeat the search in the reverse direction. +i: Insert text before the cursor. +I: Move to the beginning of the line and start inserting text. +A: Move to the end of the line and start inserting text. +S: Delete the contents of the line and start inserting text. +r: Replace one character under the cursor. +o filename: Open the file filename. +x: Save the current file and exit. +w: Save the current file. +w filename: Save to filename. +q: Quit. If the file has been modified, quitting is only possible with q!. +q!: Quit without saving. +wq!: Save the current file and quit. +number: Go to line number. +h: Display help for commands. \ No newline at end of file diff --git a/main.py b/main.py index 8640411..06bd56d 100644 --- a/main.py +++ b/main.py @@ -1,3 +1,4 @@ +import sys, time from mvc.models import VimModel from mvc.views import VimView, CursesAdapter from mvc.controllers import Controller, ReturnCode @@ -12,9 +13,9 @@ def main(): strategy = NormalStrategy(model, view.curses_adapter) controller = Controller(strategy) - # Загрузка файла для редактирования - file_path = "example.txt" # Укажите путь к файлу - model.LoadFile(file_path) + # Первинчая загрузка файла для редактирования + if len(sys.argv) > 1: model.LoadFile(sys.argv[1]) + else: model.LoadFile("File not found but i create it"+str(int(time.time()))+".txt") while True: view.Render(model.displayBuffer, diff --git a/mvc/models.py b/mvc/models.py index e033b6f..f1b5dbd 100644 --- a/mvc/models.py +++ b/mvc/models.py @@ -144,6 +144,9 @@ class VimModel: self.currentLine += self.displayLinesCount else: self.currentLine = len(self.displayBuffer) - 1 + case "h": + self.LoadFile("config/usage.txt") + return ReturnCode.SET_BASIC_MODE case _: # Открывает файл if len(cmd) > 2 and cmd[:2] == 'o ': @@ -221,11 +224,11 @@ class VimModel: self.mode = "NORMAL" try: with open(file_path, "r") as file: - self.displayBuffer = [list(line.rstrip('\n')) for line in file.readlines()] - + self.displayBuffer = [list(line.rstrip('\n')) for line in file.readlines()] except FileNotFoundError: - print(f"File {file_path} not found. Starting with empty buffer.") + print(f"File '{file_path}' not found. Starting with empty buffer.") self.displayBuffer = [] + self.displayBuffer.append([]) def SaveFile(self) -> None: """Сохранение текущего файла""" @@ -237,7 +240,7 @@ class VimModel: with open(file_path, "w") as file: for line in self.displayBuffer: file.write(''.join(line) + '\n') - print(f"In file {file_path} written successfully.") + print(f"In file '{file_path}' written successfully.") except Exception as e: print(f"Error writing file: {str(e)}")