w filename - запись в filename
parent
cffa12f07e
commit
06f2e59dd3
|
@ -145,6 +145,9 @@ class VimModel:
|
|||
filename = cmd[2:]
|
||||
self.LoadFile(filename)
|
||||
return ReturnCode.SET_BASIC_MODE
|
||||
elif len(cmd) > 2 and cmd[:2] == 'w ':
|
||||
filename = cmd[2:]
|
||||
self.WriteFile(filename)
|
||||
|
||||
|
||||
return ReturnCode.GOOD
|
||||
|
@ -220,14 +223,18 @@ class VimModel:
|
|||
self.displayBuffer = []
|
||||
|
||||
def SaveFile(self) -> None:
|
||||
"""Сохранение файла"""
|
||||
"""Сохранение текущего файла"""
|
||||
self.WriteFile(self.file_path)
|
||||
|
||||
def WriteFile(self, file_path) -> None:
|
||||
"""Запись в файл по указанному пути"""
|
||||
try:
|
||||
with open(self.file_path, "w") as file:
|
||||
with open(file_path, "w") as file:
|
||||
for line in self.displayBuffer:
|
||||
file.write(''.join(line) + '\n')
|
||||
print(f"File {self.file_path} saved successfully.")
|
||||
print(f"In file {file_path} written successfully.")
|
||||
except Exception as e:
|
||||
print(f"Error saving file: {str(e)}")
|
||||
print(f"Error writing file: {str(e)}")
|
||||
|
||||
def Reset(self) -> None:
|
||||
self.displayBuffer = []
|
||||
|
|
Loading…
Reference in New Issue