добавил usage.txt, возможность запуска программы с argv[1] именем файла или без него

master
serr 2025-02-05 01:47:34 +03:00
parent 6c80db924e
commit 1943b194e4
3 changed files with 50 additions and 7 deletions

39
config/usage.txt Normal file
View File

@ -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<CR>: 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<CR>: 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.

View File

@ -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,

View File

@ -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)}")