drProfessorGTA

Notizbuch

May 31st, 2019
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.23 KB | None | 0 0
  1. id = os.getComputerID()
  2.  
  3. if id == 1 then
  4. mon = peripheral.wrap("monitor_0")
  5. elseif id == 2 then
  6. mon = peripheral.wrap("monitor_1")
  7. end
  8.  
  9. mon.setTextScale(0.5)
  10.  
  11. shell.run("clear")
  12. print("IndustrieOS | Notizbuch")
  13. print("")
  14. print("Was möchten Sie tun?")
  15. print("schreiben|lesen|löschen")
  16. print("")
  17. print("")
  18. los = io.read()
  19.  
  20. if los == "schreiben" then
  21. shell.run("clear")
  22. print("IndustrieOS | Notizbuch | Schreiben")
  23. elseif los == "lesen" then
  24. shell.run("clear")
  25. print("IndustrieOS | Notizbuch | Lesen")
  26. elseif los == "löschen" then
  27. shell.run("clear")
  28. print("IndustrieOS | Notizbuch | Löschen")
  29. elseif los == "Desktop" then
  30. shell.run("Desktop")
  31. else
  32. print("Eingabe ungültig!")
  33. sleep(2.0)
  34. shell.run("Notizbuch")
  35. return
  36. end
  37.  
  38.  
  39.  
  40. print("Geben Sie einen Dateinamen an!")
  41. print("")
  42. if los == "lesen" then
  43. local list = fs.list("Notizen/")
  44.     for i = 1,1000,1 do
  45.         if list[i] == nil then
  46.         break
  47.         end
  48.     print(list[i])
  49.     end
  50. elseif los == "löschen" then
  51. local list = fs.list("Notizen/")
  52.     for i = 1,1000,1 do
  53.         if list[i] == nil then
  54.         break
  55.         end
  56.     print(list[i])
  57.     end
  58. end
  59. print("")
  60. local dn = read()
  61.  
  62.  
  63. if los == "schreiben" then
  64.  
  65. fs.makeDir("Notizen")
  66. local ex = fs.exists("Notizen/"..dn)
  67. if ex == true then
  68. print("Die Datei existiert bereits!")
  69. sleep(3.0)
  70. shell.run("Notizbuch")
  71. return
  72. end
  73. local file = fs.open("Notizen/"..dn,"a")
  74.  
  75. elseif los == "lesen" then
  76.  
  77. file = fs.open("Notizen/"..dn,"r")
  78. local ex = fs.exists("Notizen/"..dn)
  79. if ex == false then
  80. print("Die Datei existiert nicht!")
  81. sleep(3.0)
  82. shell.run("Notizbuch")
  83. return
  84. end
  85.  
  86. elseif los == "löschen" then
  87.  
  88. local ex = fs.exists("Notizen/"..dn)
  89. if ex == false then
  90. print("Die Datei existiert nicht!")
  91. sleep(3.0)
  92. shell.run("Notizbuch")
  93. return
  94. end
  95.  
  96. end
  97.  
  98. cursor = 2
  99.  
  100. function schreib()
  101. zeile = io.read()
  102. if zeile == "ENDE" then
  103. local file = fs.open("Notizen/"..dn,"a")
  104. file.close()
  105. print("Notiz erfolgreich gespeichert")
  106. sleep(3.0)
  107. shell.run("Desktop")
  108. stop = 3
  109. else
  110. local file = fs.open("Notizen/"..dn,"a")
  111. file.writeLine(zeile)
  112. mon.setCursorPos(1,cursor)
  113. mon.write(zeile)
  114. cursor = cursor+1
  115. end
  116. end
  117.  
  118.  
  119. function les()
  120. file = fs.open("Notizen/"..dn,"r")
  121.  
  122. local fileData = {}
  123. local line = file.readLine()
  124. repeat
  125. table.insert(fileData,line)
  126. line = file.readLine()
  127. until line == nil
  128. file.close()
  129. for i = 1,1000,1 do
  130.     if fileData[i] == nil then
  131.     break
  132.     end
  133. local wert = fileData[i]
  134. print(wert)
  135. mon.setCursorPos(1,cursor)
  136. mon.write(wert)
  137. cursor = cursor+1
  138. end
  139.  
  140. end
  141.  
  142. if los == "schreiben" then
  143. shell.run("clear")
  144. print("IndustrieOS | Notizbuch | Schreiben")
  145. print("Schreiben Sie und bestätigen Sie die Zeile mit ENTER")
  146. print("Geben Sie 'ENDE' ein um zu Speichern und zu Beenden")
  147. sleep(6.0)
  148. shell.run("clear")
  149. mon.clear()
  150. mon.setCursorPos(1,1)
  151. mon.write("IndustrieOS | Notizbuch | Schreiben")
  152. print("IndustrieOS | Notizbuch | Schreiben")
  153. stop = 1
  154. while stop<2 do
  155. schreib()
  156. end
  157. elseif los == "lesen" then
  158. shell.run("clear")
  159. mon.clear()
  160. mon.setCursorPos(1,1)
  161. mon.write("IndustrieOS | Notizbuch | Lesen")
  162. print("IndustrieOS | Notizbuch | Lesen")
  163. print("")
  164. les()
  165. end
  166.  
  167. if los == "löschen" then
  168. fs.delete("Notizen/"..dn)
  169. print("Datei erfolgreich gelöscht!")
  170. sleep(3.0)
  171. shell.run("Desktop")
  172. end
Advertisement
Add Comment
Please, Sign In to add comment