-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheditorcore.py
More file actions
57 lines (48 loc) · 1.68 KB
/
editorcore.py
File metadata and controls
57 lines (48 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#Harmony NEW code editor core version 1.1
#Copyright Eyescary development 2026
#Modified? []
#imports
import extensions
import os
#put your imports here
class editor:
def openfile(self): #copies the file contents to self.lines
try:
with open(self.filename, "r") as file:
return file.readlines()
except:
return []
def write(self): #writes self.lines to the file
with open(self.filename, "w") as file:
file.write(''.join(self.lines))
def printfilecore(self): #basic print file function
os.system("cls" if os.name == "nt" else "clear")
linenum = 1
for item in self.lines:
print(str(linenum)+"|"+item, end="")
linenum+=1
def main(self): #main editor function
editor.printfilecore(self)
userInput=input("|")
if userInput.startswith(":"):
self.lines = extensions.commands(userInput.strip(), self.lines, self.filename, self.extension)
else:
self.lines.append(userInput+'\n')
editor.write(self)
def __init__(self): #init menu
name=input("what is the name of the file you wish to edit?: ")
if "." in name:
self.extension = "." + name.split(".")[1]
self.filename = name
else:
self.extension = input("what is the extension of the file?: ")
if not self.extension.startswith("."):
self.extension = "." + self.extension
self.filename = name + self.extension
self.lines = editor.openfile(self)
def main():
instance = editor()
while True:
instance.main()
if __name__ == "__main__":
main()