Advertisement
Leprofourbus

notepad

Aug 3rd, 2024
18
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | Gaming | 0 0
  1. -- notepad.lua
  2.  
  3. local function drawMenu()
  4. term.clear()
  5. term.setCursorPos(1, 1)
  6. print("Notepad")
  7. print("1. Nouveau Fichier")
  8. print("2. Ouvrir Fichier")
  9. write("Selection: ")
  10. end
  11.  
  12. local function createNewFile()
  13. term.clear()
  14. term.setCursorPos(1, 1)
  15. print("Nouveau Fichier")
  16. write("Nom du fichier: ")
  17.  
  18. local fileName = read()
  19.  
  20. print("Contenu: ")
  21. local content = read()
  22.  
  23. local file = fs.open(fileName, "w")
  24. file.write(content)
  25. file.close()
  26.  
  27. print("Fichier sauvegardé!")
  28. sleep(2)
  29. drawMenu()
  30. end
  31.  
  32. local function openFile()
  33. term.clear()
  34. term.setCursorPos(1, 1)
  35. print("Ouvrir Fichier")
  36. write("Nom du fichier: ")
  37.  
  38. local fileName = read()
  39.  
  40. if not fs.exists(fileName) then
  41. print("Fichier non trouvé!")
  42. sleep(2)
  43. drawMenu()
  44. return
  45. end
  46.  
  47. local file = fs.open(fileName, "r")
  48. local content = file.readAll()
  49. file.close()
  50.  
  51. term.clear()
  52. term.setCursorPos(1, 1)
  53. print("Contenu du fichier: ")
  54. print(content)
  55. sleep(5)
  56. drawMenu()
  57. end
  58.  
  59. local function main()
  60. drawMenu()
  61. while true do
  62. local choice = read()
  63.  
  64. if choice == "1" then
  65. createNewFile()
  66. elseif choice == "2" then
  67. openFile()
  68. else
  69. print("Option invalide")
  70. sleep(2)
  71. drawMenu()
  72. end
  73. end
  74. end
  75.  
  76. main()
  77.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement