Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- notepad.lua
- local function drawMenu()
- term.clear()
- term.setCursorPos(1, 1)
- print("Notepad")
- print("1. Nouveau Fichier")
- print("2. Ouvrir Fichier")
- write("Selection: ")
- end
- local function createNewFile()
- term.clear()
- term.setCursorPos(1, 1)
- print("Nouveau Fichier")
- write("Nom du fichier: ")
- local fileName = read()
- print("Contenu: ")
- local content = read()
- local file = fs.open(fileName, "w")
- file.write(content)
- file.close()
- print("Fichier sauvegardé!")
- sleep(2)
- drawMenu()
- end
- local function openFile()
- term.clear()
- term.setCursorPos(1, 1)
- print("Ouvrir Fichier")
- write("Nom du fichier: ")
- local fileName = read()
- if not fs.exists(fileName) then
- print("Fichier non trouvé!")
- sleep(2)
- drawMenu()
- return
- end
- local file = fs.open(fileName, "r")
- local content = file.readAll()
- file.close()
- term.clear()
- term.setCursorPos(1, 1)
- print("Contenu du fichier: ")
- print(content)
- sleep(5)
- drawMenu()
- end
- local function main()
- drawMenu()
- while true do
- local choice = read()
- if choice == "1" then
- createNewFile()
- elseif choice == "2" then
- openFile()
- else
- print("Option invalide")
- sleep(2)
- drawMenu()
- end
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement