Advertisement
minif

look

Jan 23rd, 2020
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.55 KB | None | 0 0
  1. --Minif OS Look Tool
  2.  
  3. --Functions and Variables
  4. local start = 0
  5. local function drawWindow()
  6. paintutils.drawFilledBox(3,3,osScreenSizeX-2,osScreenSizeY-2,colors.white)
  7. paintutils.drawBox(3,3,osScreenSizeX-2,5,colors.lightGray)
  8. term.setBackgroundColor(colors.white)
  9. term.setTextColor(colors.black)
  10. term.setCursorPos(4,4)
  11. term.write("Open File")
  12. end
  13.  
  14. local function drawFile()
  15. paintutils.drawFilledBox(3,6,osScreenSizeX-2,osScreenSizeY-2,colors.white)
  16. term.setCursorPos(osScreenSizeX-6,osScreenSizeY-3)
  17. term.setTextColor(colors.black)
  18. term.setBackgroundColor(colors.green)
  19. term.write("New")
  20. term.setBackgroundColor(colors.white)
  21. end
  22.  
  23.  
  24. local function runThing(file)
  25. if fs.isDir(file) then
  26. drawWindow()
  27. osListFiles(file.."/")
  28. else
  29. paintutils.drawFilledBox(3,6,osScreenSizeX-2,osScreenSizeY-2,colors.white)
  30. term.setBackgroundColor(colors.white)
  31. term.setTextColor(colors.black)
  32. term.setCursorPos(4,7)
  33. term.write(file)
  34. term.setCursorPos(4,8)
  35. term.write("Open this file using...")
  36. term.setCursorPos(4,10)
  37. term.setBackgroundColor(colors.lightBlue)
  38. term.write("Text")
  39. term.setCursorPos(9,10)
  40. term.write("Draw")
  41. term.setCursorPos(4,12)
  42. term.write("Copy")
  43. term.setCursorPos(9,12)
  44. term.write("Rename")
  45. term.setCursorPos(16,12)
  46. term.write("Delete")
  47. while true do
  48. osPEvent, osPB, osPX, osPY = os.pullEvent()
  49. if osPEvent == "mouse_click" then
  50. if osPY == 10 and osPX >= 4 and osPX <= 7 then
  51. shell.run('edit "'..file..'"')
  52. return
  53. else if osPY == 10 and osPX >= 9 and osPY <= 12 then
  54. shell.run('paint "'..file..'"')
  55. return
  56. else if osPY == 12 and osPX >= 4 and osPX <= 7 then
  57. term.setCursorPos(4,osScreenSizeY-4)
  58. term.setBackgroundColor(colors.white)
  59. term.setTextColor(colors.black)
  60. local fname = read()
  61. if fs.exists("/user/".. osEnteredUser.."/"..fname) then
  62. term.setCursorPos(4,osScreenSizeY-3)
  63. term.setTextColor(colors.red)
  64. term.write("File Exists")
  65. sleep(2)
  66. else
  67. fs.copy(file,"/user/".. osEnteredUser.."/"..fname)
  68. end
  69. return
  70. else if osPY == 12 and osPX >= 9 and osPX <= 14 then
  71. term.setCursorPos(4,osScreenSizeY-4)
  72. term.setBackgroundColor(colors.white)
  73. term.setTextColor(colors.black)
  74. local fname = read()
  75. if fs.exists("/user/".. osEnteredUser.."/"..fname) then
  76. term.setCursorPos(4,osScreenSizeY-3)
  77. term.setTextColor(colors.red)
  78. term.write("File Exists")
  79. sleep(2)
  80. else
  81. fs.move(file,"/user/".. osEnteredUser.."/"..fname)
  82. end
  83. return
  84. else if osPY == 12 and osPX >= 16 and osPX <= 21 then
  85. fs.delete(file)
  86. return
  87. else
  88. return
  89. end
  90. end
  91. end
  92. end
  93. end
  94. else
  95. if osPEvent == "key" then
  96. if osPB == keys.t then
  97. shell.run('edit "'..file..'"')
  98. end
  99. if osPB == keys.d then
  100. shell.run('paint "'..file..'"')
  101. end
  102. return
  103. end
  104. end
  105. end
  106. return
  107. end
  108. end
  109.  
  110. local function newFile(loc)
  111. term.setCursorPos(4,osScreenSizeY-3)
  112. term.setBackgroundColor(colors.white)
  113. term.setTextColor(colors.green)
  114. term.write("New: ")
  115. local newFile = read()
  116. if fs.exists(loc..newFile) then
  117. term.setCursorPos(4,osScreenSizeY-2)
  118. term.setTextColor(colors.red)
  119. print("File Exists!")
  120. sleep(2)
  121. else
  122. run = false
  123. runThing(loc..newFile)
  124. end
  125. term.setTextColor(colors.black)
  126. end
  127.  
  128. function osListFiles(location)
  129. if osDisableSearch == true then
  130. return
  131. end
  132. local run = true
  133. local start = 0
  134. local list = fs.list(location)
  135. drawFile()
  136. while run do
  137. for i, file in ipairs(list) do
  138. if i>osScreenSizeY-4-7+start then
  139. term.setCursorPos(4,osScreenSizeY-3)
  140. term.write("Next>")
  141. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  142. if osPX>=3 and osPX<=(osScreenSizeX-2) and osPY>=7 and osPY<=(osScreenSizeY-5) then
  143. for e, file in ipairs(list) do
  144. if e == osPY + start-6 then
  145. if run then
  146. runThing(location..file)
  147. run = false
  148. end
  149. end
  150. end
  151. return
  152. else
  153. if osPY == osScreenSizeY-3 and osPX >= osScreenSizeX-6 and osPX <= osScreenSizeX-3 then
  154. newFile(location)
  155. return
  156. else
  157. drawFile()
  158. start = i-1
  159. end
  160. end
  161. end
  162. term.setCursorPos(4,i+6-start)
  163. if fs.isDir(location..file) then
  164. term.setTextColor(colors.green)
  165. else
  166. term.setTextColor(colors.black)
  167. end
  168. print(i.." "..file)
  169. end
  170. if run then
  171. osPEvent, osPB, osPX, osPY = os.pullEvent("mouse_click")
  172. if osPX>=3 and osPX<=(osScreenSizeX-2) and osPY>=7 and osPY<=(osScreenSizeY-4) then
  173. for e, file in ipairs(list) do
  174. if e == osPY + start-6 then
  175. if run then
  176. runThing(location..file)
  177. run = false
  178. end
  179. end
  180. end
  181. return
  182. else
  183. if osPY == osScreenSizeY-3 and osPX >= osScreenSizeX-6 and osPX <= osScreenSizeX-3 then
  184. newFile(location)
  185. return
  186. else
  187. return
  188. end
  189. end
  190. end
  191. end
  192. end
  193.  
  194. --Execution
  195.  
  196. drawWindow()
  197. osListFiles("/user/".. osEnteredUser.."/")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement