nikov2002

dev12 hotfix 1.0

Jun 23rd, 2015
684
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 379.06 KB | None | 0 0
  1. --  Hideously Smashed Together by Compilr, a Hideous Smash-Stuff-Togetherer, (c) 2014 oeed  --
  2.  
  3. --  This file REALLLLLLLY isn't suitable to be used for anything other than being executed --
  4.  
  5. --  To extract all the files, run: "<filename> --extract" in the Shell --
  6. local files = {
  7.   instfiles = {
  8.     [ "rootfs.zip" ] = "{\
  9.  {\
  10.    text = \"os.loadAPI(\\\"system/api/windows\\\")\\\
  11. \\\
  12. --ПАРОЛЬ\\\
  13. local password = \\\"12345\\\"\\\
  14. \\\
  15. --СКОЛЬКО БУДЕТ ОТКРЫТА ДВЕРЬ\\\
  16. local doorOpenTime = 5\\\
  17. \\\
  18. --СКОЛЬКО БУДЕТ НАЖАТА КНОПКА\\\
  19. local buttonPressTime = 0.2\\\
  20. \\\
  21. --ПЕРЕМЕННАЯ ТАЙМЕРА\\\
  22. local changePasswordTimer = nil\\\
  23. \\\
  24. --РЕЖпМ РАБОТЫ ДпСПЛЕЯ\\\
  25. local mode = \\\"default\\\"\\\
  26. \\\
  27. --СКРЫВАТЬ Лп ВВОДпМЫЙ ПАРОЛЬ\\\
  28. local hidePassword = \\\"false\\\"\\\
  29. \\\
  30. --ОТСЮДА пЗЛУЧАТЬ СпГНАЛ РЕДА, ЕСЛп ПАРОЛЬ ВЕРЕН\\\
  31. local redstoneSide = \\\"left\\\"\\\
  32. --А ОТСЮДА, ЕСЛп НЕ ВЕРЕН\\\
  33. local redstoneSideOnWrongPassword = \\\"right\\\"\\\
  34. \\\
  35. --КНОПОЧКп\\\
  36. local buttons = {\\\
  37.     {\\\"1\\\",\\\"2\\\",\\\"3\\\"},\\\
  38.     {\\\"4\\\",\\\"5\\\",\\\"6\\\"},\\\
  39.     {\\\"7\\\",\\\"8\\\",\\\"9\\\"},\\\
  40.     {\\\"C\\\",\\\"0\\\",\\\"#\\\"},\\\
  41. }\\\
  42. \\\
  43. --МАССпВ ОБЪЕКТОВ\\\
  44. local Obj = {}\\\
  45. \\\
  46. --МАССпВ СпМВОЛОВ, ВВЕДЕННЫХ С ПОМОЩЬЮ КНОПОК\\\
  47. local inputCode = {}\\\
  48. \\\
  49. --ПОЛУЧЕНпЕ РАЗМЕРА МОНпТОРА\\\
  50. local xSize, ySize = term.getSize()\\\
  51. \\\
  52. --ПОпСК ПЕРпФЕРпп\\\
  53. local function findPeripheral(whatToFind)\\\
  54.  local PeriList = peripheral.getNames()\\\
  55.  for i=1,#PeriList do\\\
  56.    if peripheral.getType(PeriList[i]) == whatToFind then\\\
  57.      return PeriList[i]\\\
  58.    end\\\
  59.  end\\\
  60. end\\\
  61. \\\
  62. --УНпВЕРСАЛЬНАЯ ФУНКЦпЯ ДЛЯ ОТОБРАЖЕНпЯ ТЕКСТА ПО ЦЕНТРУ ЭКРАНА\\\
  63. local function centerText(how,coord,text,textColor,backColor)\\\
  64.     term.setTextColor(textColor)\\\
  65.     term.setBackgroundColor(backColor)\\\
  66.     if how == \\\"xy\\\" then\\\
  67.         term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2))\\\
  68.     elseif how == \\\"x\\\" then\\\
  69.         term.setCursorPos(math.floor(xSize/2-#text/2),coord)\\\
  70.     elseif how == \\\"y\\\" then\\\
  71.         term.setCursorPos(coord,math.floor(ySize/2))\\\
  72.     end\\\
  73.     term.write(text)\\\
  74. end\\\
  75. \\\
  76. --ЧТЕНпЕ КОНФпГА\\\
  77. function configRead(pathToConfig,whatToRead)\\\
  78.     if not fs.exists(pathToConfig) then error(\\\"No such file\\\") end\\\
  79.     local file = fs.open(pathToConfig,\\\"r\\\")\\\
  80.     while true do\\\
  81.         local line = file.readLine()\\\
  82.         if line ~= nil then \\\
  83.             local key, value = string.match(line,\\\"(.*)=(.*)\\\")\\\
  84.             if value ~= nil and key == whatToRead then\\\
  85.                 file.close()\\\
  86.                 return value\\\
  87.             end\\\
  88.         else\\\
  89.             file.close()\\\
  90.             break\\\
  91.         end\\\
  92.     end\\\
  93. end\\\
  94. \\\
  95. --ЗАПпСЬ В КОНФпГ\\\
  96. local function configWrite(pathToConfig,key,value)\\\
  97.     if not fs.exists(pathToConfig) then\\\
  98.         local file = fs.open(pathToConfig,\\\"w\\\")\\\
  99.         file.close()\\\
  100.     end\\\
  101. \\\
  102.     local file = fs.open(pathToConfig,\\\"r\\\")\\\
  103.     local Massiv = {}\\\
  104.     \\\
  105.     local lineCounter = 1\\\
  106.     while true do\\\
  107.         local line = file.readLine()\\\
  108.         if line ~= nil then \\\
  109.             Massiv[lineCounter] = line\\\
  110.         else\\\
  111.             file.close()\\\
  112.             break\\\
  113.         end\\\
  114.         lineCounter = lineCounter + 1\\\
  115.     end\\\
  116. \\\
  117.     local success = false\\\
  118.     for i=1,#Massiv do\\\
  119.         local key1, value1 = string.match(Massiv[i],\\\"(.*)=(.*)\\\")\\\
  120.         if value1 ~= nil and key1 == key then\\\
  121.             Massiv[i] = key..\\\"=\\\"..value\\\
  122.             success = true\\\
  123.         end\\\
  124.     end\\\
  125. \\\
  126.     if success == false then Massiv[#Massiv+1] = key..\\\"=\\\"..value end\\\
  127. \\\
  128.     local file = fs.open(pathToConfig,\\\"w\\\")\\\
  129.     for i=1,#Massiv do\\\
  130.         file.writeLine(Massiv[i])\\\
  131.     end\\\
  132.     file.close()\\\
  133. end\\\
  134. \\\
  135. --ОБЪЕКТЫ\\\
  136. local function newObj(name,x,y)\\\
  137.     Obj[name]={}\\\
  138.     Obj[name][\\\"x\\\"]=x\\\
  139.     Obj[name][\\\"y\\\"]=y\\\
  140. end\\\
  141. \\\
  142. --ПРОСТАЯ ЗАЛпВКА ЭКРАНА ЦВЕТОМ\\\
  143. local function clearScreen(color)\\\
  144.     term.setBackgroundColor(color)\\\
  145.     term.clear()\\\
  146. end\\\
  147. \\\
  148. --ПРОСТОЙ ТЕКСТ\\\
  149. local function usualText(x,y,text)\\\
  150.     term.setCursorPos(x,y)\\\
  151.     term.write(text)\\\
  152. end\\\
  153. \\\
  154. --ОТРпСОВКА ВЕРХНЕЙ ШТУЧКп\\\
  155. local function drawTab(textColor,backColor)\\\
  156.     term.setBackgroundColor(backColor)\\\
  157.     term.setTextColor(textColor)\\\
  158.     term.setCursorPos(2,1)\\\
  159.     term.clearLine()\\\
  160.     term.write(\\\"-----\\\")\\\
  161. \\\
  162.     for i=1,#inputCode do\\\
  163.         if hidePassword == \\\"true\\\" then\\\
  164.             usualText(i+1,1,\\\"*\\\")\\\
  165.         else\\\
  166.             usualText(i+1,1,inputCode[i])\\\
  167.         end\\\
  168.     end\\\
  169. end\\\
  170. \\\
  171. --ОТРпСОВКА КОНКРЕТНОЙ КНОПКп\\\
  172. local function drawButton(name,textColor,backColor)\\\
  173.     term.setBackgroundColor(backColor)\\\
  174.     term.setTextColor(textColor)\\\
  175.     usualText(Obj[name][\\\"x\\\"],Obj[name][\\\"y\\\"],name)\\\
  176. end\\\
  177. \\\
  178. \\\
  179. --ОТРпСОВКА ВСЕГО пНТЕРФЕЙСА\\\
  180. local function gui()\\\
  181.     --ОЧпСТКА ЭКРАНА\\\
  182.     term.setCursorBlink(false)\\\
  183.     clearScreen(colors.white)\\\
  184.     term.setTextColor(colors.black)\\\
  185. \\\
  186.     --ОТРпСОВКА КНОПОЧЕК\\\
  187.     for j=1,#buttons do\\\
  188.         for i=1,#buttons[j] do\\\
  189.             local xPos = i*2\\\
  190.             local yPos = 1+j\\\
  191.             usualText(xPos,yPos,buttons[j][i])\\\
  192.             newObj(buttons[j][i],xPos,yPos)\\\
  193.         end\\\
  194.     end\\\
  195. \\\
  196.     --ОТРпСОВКА ВЕРХНЕЙ ШНЯГп\\\
  197.     drawTab(colors.white,colors.black)\\\
  198. end\\\
  199. \\\
  200. ------------------------------CТАРТ ПРОГРАММЫ------------------------------------\\\
  201. \\\
  202. if not term.isColor() then\\\
  203.     error(\\\"This program requires an advanced computer.\\\")\\\
  204. end\\\
  205. \\\
  206. --РпСУЕМ В КОМПЕ ХУЙНЮ\\\
  207. clearScreen(colors.white)\\\
  208. centerText(\\\"xy\\\",0,\\\"Program started.\\\",colors.lightGray,colors.white)\\\
  209. \\\
  210. --ПОДКЛЮЧЕНпЕ МОНпТОРА\\\
  211. local m = findPeripheral(\\\"monitor\\\")\\\
  212. if m ~= nil then\\\
  213.     m = peripheral.wrap(m)\\\
  214.     if not m.isColor() then\\\
  215.         windows.error(\\\"This program works only with advanced monitor.\\\")\\\
  216.         do return end\\\
  217.     end\\\
  218.     m.setTextScale(1)\\\
  219.     term.redirect(m)\\\
  220. else\\\
  221.     windows.error(\\\"This program requires advanced external monitor.\\\")\\\
  222.     do return end\\\
  223. end\\\
  224. \\\
  225. --ЧТЕНпЕ КОНФпГА\\\
  226. if fs.exists(\\\"system/config/codedoor.cfg\\\") then\\\
  227.     password = configRead(\\\"system/config/codedoor.cfg\\\",\\\"password\\\")\\\
  228.     redstoneSide = configRead(\\\"system/config/codedoor.cfg\\\",\\\"redstone side\\\")\\\
  229.     redstoneSideOnWrongPassword = configRead(\\\"system/config/codedoor.cfg\\\",\\\"redstone side on wrong password\\\")\\\
  230.     doorOpenTime = configRead(\\\"system/config/codedoor.cfg\\\",\\\"door open time\\\")\\\
  231.     hidePassword = configRead(\\\"system/config/codedoor.cfg\\\",\\\"hide password\\\")\\\
  232. else\\\
  233.     configWrite(\\\"system/config/codedoor.cfg\\\",\\\"password\\\",password)\\\
  234.     configWrite(\\\"system/config/codedoor.cfg\\\",\\\"redstone side\\\",redstoneSide)\\\
  235.     configWrite(\\\"system/config/codedoor.cfg\\\",\\\"redstone side on wrong password\\\",redstoneSideOnWrongPassword)\\\
  236.     configWrite(\\\"system/config/codedoor.cfg\\\",\\\"door open time\\\",doorOpenTime)\\\
  237.     configWrite(\\\"system/config/codedoor.cfg\\\",\\\"hide password\\\",hidePassword)\\\
  238. end\\\
  239. \\\
  240. --РпСУЕМ ВСЕ\\\
  241. gui()\\\
  242. \\\
  243. --АНАЛпЗ КАСАНпЙ ЭКРАНА\\\
  244. while true do\\\
  245.     --ЗАКРЫВАЕМ ДВЕРЬ НА ВСЯКпЙ ПОЖАРНЫЙ\\\
  246.     rs.setOutput(redstoneSide,false)\\\
  247.     rs.setOutput(redstoneSideOnWrongPassword,false)\\\
  248. \\\
  249.     local event,side,x,y = os.pullEvent()\\\
  250.     if event == \\\"monitor_touch\\\" then\\\
  251.         --ПЕРЕБОР ВСЕХ ЭЛЕМЕНТОВ МАССпВА ОБЪЕКТОВ\\\
  252.         for key,val in pairs(Obj) do\\\
  253.             --ПРОВЕРКА СОВПАДЕНпЯ КООРДпНАТ КАСАНпЯ п КООРДпНАТ ОБЪЕКТОВ\\\
  254.             if x==Obj[key][\\\"x\\\"] and y==Obj[key][\\\"y\\\"] then\\\
  255.                 --РпСУЕМ НАЖАТУЮ КНОПОЧКУ\\\
  256.                 drawButton(key,colors.white,colors.green)\\\
  257.                 sleep(buttonPressTime)\\\
  258.                 drawButton(key,colors.black,colors.white)\\\
  259. \\\
  260.                 --ПРОВЕРКА, ЧТО ЗА КЛАВпША НАЖАТА - ЦпФРА пЛп СпСТЕМНАЯ КЛАВпША\\\
  261.                 if key == \\\"C\\\" then\\\
  262.                     inputCode = {}\\\
  263.                     if mode == \\\"edit\\\" then\\\
  264.                         drawTab(colors.white,colors.orange)\\\
  265.                     else\\\
  266.                         drawTab(colors.white,colors.black)\\\
  267.                     end\\\
  268. \\\
  269.                 elseif key == \\\"#\\\" then\\\
  270.                     --СОВМЕЩЕНпЕ ВСЕХ ЭЛЕМЕНТОВ МАССпВА ВВОДА В ОДНУ СТРОКУ\\\
  271.                     local inputPass = \\\"\\\"\\\
  272.                     for i=1,#inputCode do\\\
  273.                         inputPass = inputPass..inputCode[i]\\\
  274.                     end\\\
  275. \\\
  276.                     --ПРОВЕРКА РЕЖпМА\\\
  277.                     if mode == \\\"edit\\\" then\\\
  278.                         --СМЕНА ПАРОЛЯ\\\
  279.                         password = inputPass\\\
  280.                         configWrite(\\\"system/config/codedoor.cfg\\\",\\\"password\\\",password)\\\
  281.                         inputCode = {}\\\
  282.                         term.setCursorPos(3,1)\\\
  283.                         term.setBackgroundColor(colors.orange)\\\
  284.                         term.clearLine()\\\
  285.                         term.setTextColor(colors.white)\\\
  286.                         term.write(\\\"Ok!\\\")\\\
  287. \\\
  288.                         sleep(2)\\\
  289. \\\
  290.                         drawTab(colors.white,colors.black)\\\
  291.                         mode = \\\"default\\\"\\\
  292.                     else\\\
  293.                         --СРАВНЕНпЕ ВВЕДЕННОГО ГОВНА С ПЕРЕМЕННОЙ ПАРОЛЯ\\\
  294.                         if inputPass == password then\\\
  295.                             drawTab(colors.white,colors.green)\\\
  296.                             rs.setOutput(redstoneSide,true)\\\
  297.                             rs.setOutput(redstoneSideOnWrongPassword,false)\\\
  298. \\\
  299.                             --СТАРТУЕМ ТАЙМЕР НА УКАЗАННОЕ ВРЕМЯ\\\
  300.                             changePasswordTimer = os.startTimer(tonumber(doorOpenTime))\\\
  301.                             while true do\\\
  302.                                 local event2,side2,x2,y2 = os.pullEvent()\\\
  303.                                 --ЕСЛп НпЧЕГО НЕ НАЖАТО, ТО ВЫХОД пЗ ЦпКЛА\\\
  304.                                 if event2 == \\\"timer\\\" then\\\
  305.                                     if side2 == changePasswordTimer then\\\
  306.                                         break\\\
  307.                                     end\\\
  308.                                 --ЕСЛп НАЖАТА КЛАВпША \\\"С\\\", ТО ЗАПУСТпТЬ РЕЖпМ СМЕНЫ ПАРОЛЯ\\\
  309.                                 elseif event2 == \\\"monitor_touch\\\" then\\\
  310.                                     if x2==Obj[\\\"C\\\"][\\\"x\\\"] and y2==Obj[\\\"C\\\"][\\\"y\\\"] then\\\
  311.                                         drawButton(\\\"C\\\",colors.white,colors.green)\\\
  312.                                         sleep(buttonPressTime)\\\
  313.                                         drawButton(\\\"C\\\",colors.black,colors.white)\\\
  314.                                         mode = \\\"edit\\\"\\\
  315.                                         os.queueEvent(\\\"timer\\\",changePasswordTimer)\\\
  316.                                     end\\\
  317.                                 end \\\
  318.                             end\\\
  319. \\\
  320.                             --ОЧпЩАЕМ ВВЕДЕННЫЙ ТЕКСТ п ЗАКРЫВАЕМ ДВЕРЬ\\\
  321.                             inputCode = {}\\\
  322.                             rs.setOutput(redstoneSide,false)\\\
  323. \\\
  324.                             --РпСУЕМ ВЕРХНЮЮ ШНЯГУ РАЗНОГО ЦВЕТА В ЗАВпСпМОСТп ОТ РЕЖпМА\\\
  325.                             if mode == \\\"edit\\\" then\\\
  326.                                 drawTab(colors.white,colors.orange)\\\
  327.                             else\\\
  328.                                 drawTab(colors.white,colors.black)\\\
  329.                             end\\\
  330.                         --ЕСЛп ВВЕДЕН НЕВЕРНЫЙ ПАРОЛЬ\\\
  331.                         else\\\
  332.                             drawTab(colors.white,colors.red)\\\
  333.                             rs.setOutput(redstoneSide,false)\\\
  334.                             rs.setOutput(redstoneSideOnWrongPassword,true)\\\
  335.                             sleep(3)\\\
  336.                             rs.setOutput(redstoneSideOnWrongPassword,false)\\\
  337.                             inputCode = {}\\\
  338.                             drawTab(colors.white,colors.black)\\\
  339.                         end\\\
  340.                     end\\\
  341.                 --ЕСЛп НАЖАТА ЛЮБАЯ ЦпФРА\\\
  342.                 else\\\
  343.                     if #inputCode < 5 then\\\
  344.                         inputCode[#inputCode+1] = key\\\
  345.                         if mode == \\\"edit\\\" then\\\
  346.                             drawTab(colors.white,colors.orange)\\\
  347.                         else\\\
  348.                             drawTab(colors.white,colors.black)\\\
  349.                         end\\\
  350.                     end\\\
  351.                 end\\\
  352.                 --ВЫХОД пЗ ЦпКЛА ПЕРЕБОРА ОБЪЕКТОВ\\\
  353.                 break\\\
  354.             end\\\
  355.         end\\\
  356. \\\
  357.     --ЕСЛп НАЖАТА КЛАВпША ENTER\\\
  358.     elseif event == \\\"key\\\" and side == 28 then\\\
  359.         break\\\
  360.     end\\\
  361. end\\\
  362. \\\
  363. clearScreen(colors.black)\\\
  364. term.setTextColor(colors.white)\\\
  365. \\\
  366. term.redirect(term.native())\\\
  367. \\\
  368. clearScreen(colors.black)\\\
  369. term.setTextColor(colors.white)\\\
  370. term.setCursorPos(1,1)\",\
  371.    path = \"/rootfs/apps/CodeDoor.app/main\",\
  372.  },\
  373.  {\
  374.    text = \" ff-0f-0f-0f ff###\\\
  375. f01f02f03f0 f0###\\\
  376. f04f05f06f0 f0###\\\
  377. f07f08f09f0 f0###\",\
  378.    path = \"/rootfs/apps/CodeDoor.app/Resources/icon.png\",\
  379.  },\
  380.  {\
  381.    text = \"os.loadAPI(\\\"system/api/image\\\")\\\
  382. os.loadAPI(\\\"system/api/filemanager\\\")\\\
  383. os.loadAPI(\\\"system/api/windows\\\")\\\
  384. \\\
  385. local filem = filemanager.open(\\\"\\\")\\\
  386. if windows.getFileFormat(filem) == nil then\\\
  387. shell.run(filem) \\\
  388. elseif windows.getFileFormat(filem) == \\\".app\\\" then\\\
  389. path = filem..\\\"/main\\\"\\\
  390. shell.run(path)\\\
  391. elseif windows.getFileFormat(filem) == \\\".png\\\" then\\\
  392. shell.run(\\\"/apps/photoshop.app/main o \\\"..filem)\\\
  393. elseif windows.getFileFormat(filem) == \\\".txt\\\" then\\\
  394. shell.run(\\\"/apps/ink.app/main \\\"..filem)\\\
  395. elseif windows.getFileFormat(filem) == \\\".cfg\\\" then\\\
  396. shell.run(\\\"/apps/ink.app/main \\\"..filem)\\\
  397. elseif windows.getFileFormat(filem) == \\\".lua\\\" then\\\
  398. shell.run(\\\"/apps/luaide.app/main \\\"..filem)\\\
  399. else\\\
  400. windows.attention({\\\"Can't open file\\\"},{\\\"This file format\\\",\\\"is not supported.\\\"})\\\
  401. return 0\\\
  402. end\",\
  403.    path = \"/rootfs/apps/FileManager.app/main\",\
  404.  },\
  405.  {\
  406.    text = \" 84 84############\\\
  407. -84-84-84-84-84-84\\\
  408. -84-84-84-84-84-84\\\
  409. -84-84-84-84-84-84\",\
  410.    path = \"/rootfs/apps/FileManager.app/Resources/icon.png\",\
  411.  },\
  412.  {\
  413.    text = \"tArgs = {...}\\\
  414. term.clear()\\\
  415. \\\
  416. \\\
  417. if OneOS then\\\
  418.     --running under OneOS\\\
  419.     OneOS.ToolBarColour = colours.grey\\\
  420.     OneOS.ToolBarTextColour = colours.white\\\
  421. end\\\
  422. \\\
  423. local _w, _h = term.getSize()\\\
  424. \\\
  425. local round = function(num, idp)\\\
  426.     local mult = 10^(idp or 0)\\\
  427.     return math.floor(num * mult + 0.5) / mult\\\
  428. end\\\
  429. \\\
  430. UIColours = {\\\
  431.     Toolbar = colours.grey,\\\
  432.     ToolbarText = colours.lightGrey,\\\
  433.     ToolbarSelected = colours.lightBlue,\\\
  434.     ControlText = colours.white,\\\
  435.     ToolbarItemTitle = colours.black,\\\
  436.     Background = colours.lightGrey,\\\
  437.     MenuBackground = colours.white,\\\
  438.     MenuText = colours.black,\\\
  439.     MenuSeparatorText = colours.grey,\\\
  440.     MenuDisabledText = colours.lightGrey,\\\
  441.     Shadow = colours.grey,\\\
  442.     TransparentBackgroundOne = colours.white,\\\
  443.     TransparentBackgroundTwo = colours.lightGrey,\\\
  444.     MenuBarActive = colours.white\\\
  445. }\\\
  446. \\\
  447. local getNames = peripheral.getNames or function()\\\
  448.     local tResults = {}\\\
  449.     for n,sSide in ipairs( rs.getSides() ) do\\\
  450.         if peripheral.isPresent( sSide ) then\\\
  451.             table.insert( tResults, sSide )\\\
  452.             local isWireless = false\\\
  453.             if not pcall(function()isWireless = peripheral.call(sSide, 'isWireless') end) then\\\
  454.                 isWireless = true\\\
  455.             end     \\\
  456.             if peripheral.getType( sSide ) == \\\"modem\\\" and not isWireless then\\\
  457.                 local tRemote = peripheral.call( sSide, \\\"getNamesRemote\\\" )\\\
  458.                 for n,sName in ipairs( tRemote ) do\\\
  459.                     table.insert( tResults, sName )\\\
  460.                 end\\\
  461.             end\\\
  462.         end\\\
  463.     end\\\
  464.     return tResults\\\
  465. end\\\
  466. \\\
  467. Peripheral = {\\\
  468.     GetPeripheral = function(_type)\\\
  469.         for i, p in ipairs(Peripheral.GetPeripherals()) do\\\
  470.             if p.Type == _type then\\\
  471.                 return p\\\
  472.             end\\\
  473.         end\\\
  474.     end,\\\
  475. \\\
  476.     Call = function(type, ...)\\\
  477.         local tArgs = {...}\\\
  478.         local p = Peripheral.GetPeripheral(type)\\\
  479.         peripheral.call(p.Side, unpack(tArgs))\\\
  480.     end,\\\
  481. \\\
  482.     GetPeripherals = function(filterType)\\\
  483.         local peripherals = {}\\\
  484.         for i, side in ipairs(getNames()) do\\\
  485.             local name = peripheral.getType(side):gsub(\\\"^%l\\\", string.upper)\\\
  486.             local code = string.upper(side:sub(1,1))\\\
  487.             if side:find('_') then\\\
  488.                 code = side:sub(side:find('_')+1)\\\
  489.             end\\\
  490. \\\
  491.             local dupe = false\\\
  492.             for i, v in ipairs(peripherals) do\\\
  493.                 if v[1] == name .. ' ' .. code then\\\
  494.                     dupe = true\\\
  495.                 end\\\
  496.             end\\\
  497. \\\
  498.             if not dupe then\\\
  499.                 local _type = peripheral.getType(side)\\\
  500.                 local isWireless = false\\\
  501.                 if _type == 'modem' then\\\
  502.                     if not pcall(function()isWireless = peripheral.call(sSide, 'isWireless') end) then\\\
  503.                         isWireless = true\\\
  504.                     end     \\\
  505.                     if isWireless then\\\
  506.                         _type = 'wireless_modem'\\\
  507.                         name = 'W '..name\\\
  508.                     end\\\
  509.                 end\\\
  510.                 if not filterType or _type == filterType then\\\
  511.                     table.insert(peripherals, {Name = name:sub(1,8) .. ' '..code, Fullname = name .. ' ('..side:sub(1, 1):upper() .. side:sub(2, -1)..')', Side = side, Type = _type, Wireless = isWireless})\\\
  512.                 end\\\
  513.             end\\\
  514.         end\\\
  515.         return peripherals\\\
  516.     end,\\\
  517. \\\
  518.     PresentNamed = function(name)\\\
  519.         return peripheral.isPresent(name)\\\
  520.     end,\\\
  521. \\\
  522.     CallType = function(type, ...)\\\
  523.         local tArgs = {...}\\\
  524.         local p = GetPeripheral(type)\\\
  525.         return peripheral.call(p.Side, unpack(tArgs))\\\
  526.     end,\\\
  527. \\\
  528.     CallNamed = function(name, ...)\\\
  529.         local tArgs = {...}\\\
  530.         return peripheral.call(name, unpack(tArgs))\\\
  531.     end\\\
  532. }\\\
  533. \\\
  534. TextLine = {\\\
  535.     Text = \\\"\\\",\\\
  536.     Alignment = AlignmentLeft,\\\
  537. \\\
  538.     Initialise = function(self, text, alignment)\\\
  539.         local new = {}    -- the new instance\\\
  540.         setmetatable( new, {__index = self} )\\\
  541.         new.Text = text\\\
  542.         new.Alignment = alignment or AlignmentLeft\\\
  543.         return new\\\
  544.     end\\\
  545. }\\\
  546. \\\
  547. local StripColours = function(str)\\\
  548.     return str:gsub('['..string.char(14)..'-'..string.char(29)..']','')\\\
  549. end\\\
  550. \\\
  551. Printer = {\\\
  552.     Name = nil,\\\
  553.     PeripheralType = 'printer',\\\
  554. \\\
  555.     paperLevel = function(self)\\\
  556.         return Peripheral.CallNamed(self.Name, 'getPaperLevel')\\\
  557.     end,\\\
  558. \\\
  559.     newPage = function(self)\\\
  560.         return Peripheral.CallNamed(self.Name, 'newPage')\\\
  561.     end,\\\
  562. \\\
  563.     endPage = function(self)\\\
  564.         return Peripheral.CallNamed(self.Name, 'endPage')\\\
  565.     end,\\\
  566. \\\
  567.     pageWrite = function(self, text)\\\
  568.         return Peripheral.CallNamed(self.Name, 'write', text)\\\
  569.     end,\\\
  570. \\\
  571.     setPageTitle = function(self, title)\\\
  572.         return Peripheral.CallNamed(self.Name, 'setPageTitle', title)\\\
  573.     end,\\\
  574. \\\
  575.     inkLevel = function(self)\\\
  576.         return Peripheral.CallNamed(self.Name, 'getInkLevel')\\\
  577.     end,\\\
  578. \\\
  579.     getCursorPos = function(self)\\\
  580.         return Peripheral.CallNamed(self.Name, 'getCursorPos')\\\
  581.     end,\\\
  582. \\\
  583.     setCursorPos = function(self, x, y)\\\
  584.         return Peripheral.CallNamed(self.Name, 'setCursorPos', x, y)\\\
  585.     end,\\\
  586. \\\
  587.     pageSize = function(self)\\\
  588.         return Peripheral.CallNamed(self.Name, 'getPageSize')\\\
  589.     end,\\\
  590. \\\
  591.     Present = function()\\\
  592.         if Peripheral.GetPeripheral(Printer.PeripheralType) == nil then\\\
  593.             return false\\\
  594.         else\\\
  595.             return true\\\
  596.         end\\\
  597.     end,\\\
  598. \\\
  599.     PrintLines = function(self, lines, title, copies)\\\
  600.         local pages = {}\\\
  601.         local pageLines = {}\\\
  602.         for i, line in ipairs(lines) do\\\
  603.             table.insert(pageLines, TextLine:Initialise(StripColours(line)))\\\
  604.             if i % 25 == 0 then\\\
  605.                 table.insert(pages, pageLines)\\\
  606.                 pageLines = {}\\\
  607.             end\\\
  608.         end\\\
  609.         if #pageLines ~= 0 then\\\
  610.                 table.insert(pages, pageLines)\\\
  611.         end\\\
  612.         return self:PrintPages(pages, title, copies)\\\
  613.     end,\\\
  614. \\\
  615.     PrintPages = function(self, pages, title, copies)\\\
  616.         copies = copies or 1\\\
  617.         for c = 1, copies do\\\
  618.             for p, page in ipairs(pages) do\\\
  619.                 if self:paperLevel() < #pages * copies then\\\
  620.                     return 'Add more paper to the printer'\\\
  621.                 end\\\
  622.                 if self:inkLevel() < #pages * copies then\\\
  623.                     return 'Add more ink to the printer'\\\
  624.                 end\\\
  625.                 self:newPage()\\\
  626.                 for i, line in ipairs(page) do\\\
  627.                     self:setCursorPos(1, i)\\\
  628.                     self:pageWrite(StripColours(line.Text))\\\
  629.                 end\\\
  630.                 if title then\\\
  631.                     self:setPageTitle(title)\\\
  632.                 end\\\
  633.                 self:endPage()\\\
  634.             end\\\
  635.         end\\\
  636.     end,\\\
  637. \\\
  638.     Initialise = function(self, name)\\\
  639.         if Printer.Present() then --fix\\\
  640.             local new = {}    -- the new instance\\\
  641.             setmetatable( new, {__index = self} )\\\
  642.             if name and Peripheral.PresentNamed(name) then\\\
  643.                 new.Name = name\\\
  644.             else\\\
  645.                 new.Name = Peripheral.GetPeripheral(Printer.PeripheralType).Side\\\
  646.             end\\\
  647.             return new\\\
  648.         end\\\
  649.     end\\\
  650. }\\\
  651. \\\
  652. Clipboard = {\\\
  653.     Content = nil,\\\
  654.     Type = nil,\\\
  655.     IsCut = false,\\\
  656. \\\
  657.     Empty = function()\\\
  658.         Clipboard.Content = nil\\\
  659.         Clipboard.Type = nil\\\
  660.         Clipboard.IsCut = false\\\
  661.     end,\\\
  662. \\\
  663.     isEmpty = function()\\\
  664.         return Clipboard.Content == nil\\\
  665.     end,\\\
  666. \\\
  667.     Copy = function(content, _type)\\\
  668.         Clipboard.Content = content\\\
  669.         Clipboard.Type = _type or 'generic'\\\
  670.         Clipboard.IsCut = false\\\
  671.     end,\\\
  672. \\\
  673.     Cut = function(content, _type)\\\
  674.         Clipboard.Content = content\\\
  675.         Clipboard.Type = _type or 'generic'\\\
  676.         Clipboard.IsCut = true\\\
  677.     end,\\\
  678. \\\
  679.     Paste = function()\\\
  680.         local c, t = Clipboard.Content, Clipboard.Type\\\
  681.         if Clipboard.IsCut then\\\
  682.             Clipboard.Empty()\\\
  683.         end\\\
  684.         return c, t\\\
  685.     end\\\
  686. }\\\
  687. \\\
  688. if OneOS and OneOS.Clipboard then\\\
  689.     Clipboard = OneOS.Clipboard\\\
  690. end\\\
  691. \\\
  692. Drawing = {\\\
  693.     \\\
  694.     Screen = {\\\
  695.         Width = _w,\\\
  696.         Height = _h\\\
  697.     },\\\
  698. \\\
  699.     DrawCharacters = function (x, y, characters, textColour,bgColour)\\\
  700.         Drawing.WriteStringToBuffer(x, y, characters, textColour, bgColour)\\\
  701.     end,\\\
  702.     \\\
  703.     DrawBlankArea = function (x, y, w, h, colour)\\\
  704.         Drawing.DrawArea (x, y, w, h, \\\" \\\", 1, colour)\\\
  705.     end,\\\
  706. \\\
  707.     DrawArea = function (x, y, w, h, character, textColour, bgColour)\\\
  708.         --width must be greater than 1, other wise we get a stack overflow\\\
  709.         if w < 0 then\\\
  710.             w = w * -1\\\
  711.         elseif w == 0 then\\\
  712.             w = 1\\\
  713.         end\\\
  714. \\\
  715.         for ix = 1, w do\\\
  716.             local currX = x + ix - 1\\\
  717.             for iy = 1, h do\\\
  718.                 local currY = y + iy - 1\\\
  719.                 Drawing.WriteToBuffer(currX, currY, character, textColour, bgColour)\\\
  720.             end\\\
  721.         end\\\
  722.     end,\\\
  723. \\\
  724.     DrawImage = function(_x,_y,tImage, w, h)\\\
  725.         if tImage then\\\
  726.             for y = 1, h do\\\
  727.                 if not tImage[y] then\\\
  728.                     break\\\
  729.                 end\\\
  730.                 for x = 1, w do\\\
  731.                     if not tImage[y][x] then\\\
  732.                         break\\\
  733.                     end\\\
  734.                     local bgColour = tImage[y][x]\\\
  735.                     local textColour = tImage.textcol[y][x] or colours.white\\\
  736.                     local char = tImage.text[y][x]\\\
  737.                     Drawing.WriteToBuffer(x+_x-1, y+_y-1, char, textColour, bgColour)\\\
  738.                 end\\\
  739.             end\\\
  740.         elseif w and h then\\\
  741.             Drawing.DrawBlankArea(x, y, w, h, colours.green)\\\
  742.         end\\\
  743.     end,\\\
  744.     --using .nft\\\
  745.     LoadImage = function(path)\\\
  746.         local image = {\\\
  747.             text = {},\\\
  748.             textcol = {}\\\
  749.         }\\\
  750.         local fs = fs\\\
  751.         if OneOS then\\\
  752.             fs = OneOS.FS\\\
  753.         end\\\
  754.         if fs.exists(path) then\\\
  755.             local _open = io.open\\\
  756.             if OneOS then\\\
  757.                 _open = OneOS.IO.open\\\
  758.             end\\\
  759.             local file = _open(path, \\\"r\\\")\\\
  760.             local sLine = file:read()\\\
  761.             local num = 1\\\
  762.             while sLine do  \\\
  763.                     table.insert(image, num, {})\\\
  764.                     table.insert(image.text, num, {})\\\
  765.                     table.insert(image.textcol, num, {})\\\
  766.                                                 \\\
  767.                     --As we're no longer 1-1, we keep track of what index to write to\\\
  768.                     local writeIndex = 1\\\
  769.                     --Tells us if we've hit a 30 or 31 (BG and FG respectively)- next char specifies the curr colour\\\
  770.                     local bgNext, fgNext = false, false\\\
  771.                     --The current background and foreground colours\\\
  772.                     local currBG, currFG = nil,nil\\\
  773.                     for i=1,#sLine do\\\
  774.                             local nextChar = string.sub(sLine, i, i)\\\
  775.                             if nextChar:byte() == 30 then\\\
  776.                                bgNext = true\\\
  777.                             elseif nextChar:byte() == 31 then\\\
  778.                                fgNext = true\\\
  779.                             elseif bgNext then\\\
  780.                                currBG = Drawing.GetColour(nextChar)\\\
  781.                                bgNext = false\\\
  782.                             elseif fgNext then\\\
  783.                                currFG = Drawing.GetColour(nextChar)\\\
  784.                                fgNext = false\\\
  785.                             else\\\
  786.                                if nextChar ~= \\\" \\\" and currFG == nil then\\\
  787.                                       currFG = colours.white\\\
  788.                                end\\\
  789.                                image[num][writeIndex] = currBG\\\
  790.                                image.textcol[num][writeIndex] = currFG\\\
  791.                                image.text[num][writeIndex] = nextChar\\\
  792.                                writeIndex = writeIndex + 1\\\
  793.                             end\\\
  794.                     end\\\
  795.                     num = num+1\\\
  796.                     sLine = file:read()\\\
  797.             end\\\
  798.             file:close()\\\
  799.         end\\\
  800.         return image\\\
  801.     end,\\\
  802. \\\
  803.     DrawCharactersCenter = function(x, y, w, h, characters, textColour,bgColour)\\\
  804.         w = w or Drawing.Screen.Width\\\
  805.         h = h or Drawing.Screen.Height\\\
  806.         x = x or 0\\\
  807.         y = y or 0\\\
  808.         x = math.ceil((w - #characters) / 2) + x\\\
  809.         y = math.floor(h / 2) + y\\\
  810. \\\
  811.         Drawing.DrawCharacters(x, y, characters, textColour, bgColour)\\\
  812.     end,\\\
  813. \\\
  814.     GetColour = function(hex)\\\
  815.         if hex == ' ' then\\\
  816.             return colours.transparent\\\
  817.         end\\\
  818.         local value = tonumber(hex, 16)\\\
  819.         if not value then return nil end\\\
  820.         value = math.pow(2,value)\\\
  821.         return value\\\
  822.     end,\\\
  823. \\\
  824.     Clear = function (_colour)\\\
  825.         _colour = _colour or colours.black\\\
  826.         Drawing.ClearBuffer()\\\
  827.         Drawing.DrawBlankArea(1, 1, Drawing.Screen.Width, Drawing.Screen.Height, _colour)\\\
  828.     end,\\\
  829. \\\
  830.     Buffer = {},\\\
  831.     BackBuffer = {},\\\
  832. \\\
  833.     DrawBuffer = function()\\\
  834.         for y,row in pairs(Drawing.Buffer) do\\\
  835.             for x,pixel in pairs(row) do\\\
  836.                 local shouldDraw = true\\\
  837.                 local hasBackBuffer = true\\\
  838.                 if Drawing.BackBuffer[y] == nil or Drawing.BackBuffer[y][x] == nil or #Drawing.BackBuffer[y][x] ~= 3 then\\\
  839.                     hasBackBuffer = false\\\
  840.                 end\\\
  841.                 if hasBackBuffer and Drawing.BackBuffer[y][x][1] == Drawing.Buffer[y][x][1] and Drawing.BackBuffer[y][x][2] == Drawing.Buffer[y][x][2] and Drawing.BackBuffer[y][x][3] == Drawing.Buffer[y][x][3] then\\\
  842.                     shouldDraw = false\\\
  843.                 end\\\
  844.                 if shouldDraw then\\\
  845.                     term.setBackgroundColour(pixel[3])\\\
  846.                     term.setTextColour(pixel[2])\\\
  847.                     term.setCursorPos(x, y)\\\
  848.                     term.write(pixel[1])\\\
  849.                 end\\\
  850.             end\\\
  851.         end\\\
  852.         Drawing.BackBuffer = Drawing.Buffer\\\
  853.         Drawing.Buffer = {}\\\
  854.         term.setCursorPos(1,1)\\\
  855.     end,\\\
  856. \\\
  857.     ClearBuffer = function()\\\
  858.         Drawing.Buffer = {}\\\
  859.     end,\\\
  860. \\\
  861.     WriteStringToBuffer = function (x, y, characters, textColour,bgColour)\\\
  862.         for i = 1, #characters do\\\
  863.             local character = characters:sub(i,i)\\\
  864.             Drawing.WriteToBuffer(x + i - 1, y, character, textColour, bgColour)\\\
  865.         end\\\
  866.     end,\\\
  867. \\\
  868.     WriteToBuffer = function(x, y, character, textColour,bgColour)\\\
  869.         x = round(x)\\\
  870.         y = round(y)\\\
  871.         if bgColour == colours.transparent then\\\
  872.             Drawing.Buffer[y] = Drawing.Buffer[y] or {}\\\
  873.             Drawing.Buffer[y][x] = Drawing.Buffer[y][x] or {\\\"\\\", colours.white, colours.black}\\\
  874.             Drawing.Buffer[y][x][1] = character\\\
  875.             Drawing.Buffer[y][x][2] = textColour\\\
  876.         else\\\
  877.             Drawing.Buffer[y] = Drawing.Buffer[y] or {}\\\
  878.             Drawing.Buffer[y][x] = {character, textColour, bgColour}\\\
  879.         end\\\
  880.     end,\\\
  881. }\\\
  882. \\\
  883. Current = {\\\
  884.     Document = nil,\\\
  885.     TextInput = nil,\\\
  886.     CursorPos = {1,1},\\\
  887.     CursorColour = colours.black,\\\
  888.     Selection = {8, 36},\\\
  889.     Window = nil,\\\
  890.     Modified = false,\\\
  891. }\\\
  892. \\\
  893. local isQuitting = false\\\
  894. \\\
  895. function OrderSelection()\\\
  896.     if Current.Selection then\\\
  897.         if Current.Selection[1] <= Current.Selection[2] then\\\
  898.             return Current.Selection\\\
  899.         else\\\
  900.             return {Current.Selection[2], Current.Selection[1]}\\\
  901.         end\\\
  902.     end\\\
  903. end\\\
  904. \\\
  905. function StripColours(str)\\\
  906.     return str:gsub('['..string.char(14)..'-'..string.char(29)..']','')\\\
  907. end\\\
  908. \\\
  909. function FindColours(str)\\\
  910.     local _, count = str:gsub('['..string.char(14)..'-'..string.char(29)..']','')\\\
  911.     return count\\\
  912. end\\\
  913. \\\
  914. ColourFromCharacter = function(character)\\\
  915.     local n = character:byte() - 14\\\
  916.     if n > 16 then\\\
  917.         return nil\\\
  918.     else\\\
  919.         return 2^n\\\
  920.     end\\\
  921. end\\\
  922. \\\
  923. CharacterFromColour = function(colour)\\\
  924.     return string.char(math.floor(math.log(colour)/math.log(2))+14)\\\
  925. end\\\
  926. \\\
  927. Events = {}\\\
  928. \\\
  929. Button = {\\\
  930.     X = 1,\\\
  931.     Y = 1,\\\
  932.     Width = 0,\\\
  933.     Height = 0,\\\
  934.     BackgroundColour = colours.lightGrey,\\\
  935.     TextColour = colours.white,\\\
  936.     ActiveBackgroundColour = colours.lightGrey,\\\
  937.     Text = \\\"\\\",\\\
  938.     Parent = nil,\\\
  939.     _Click = nil,\\\
  940.     Toggle = nil,\\\
  941. \\\
  942.     AbsolutePosition = function(self)\\\
  943.         return self.Parent:AbsolutePosition()\\\
  944.     end,\\\
  945. \\\
  946.     Draw = function(self)\\\
  947.         local bg = self.BackgroundColour\\\
  948.         local tc = self.TextColour\\\
  949.         if type(bg) == 'function' then\\\
  950.             bg = bg()\\\
  951.         end\\\
  952. \\\
  953.         if self.Toggle then\\\
  954.             tc = UIColours.MenuBarActive\\\
  955.             bg = self.ActiveBackgroundColour\\\
  956.         end\\\
  957. \\\
  958.         local pos = GetAbsolutePosition(self)\\\
  959.         Drawing.DrawBlankArea(pos.X, pos.Y, self.Width, self.Height, bg)\\\
  960.         Drawing.DrawCharactersCenter(pos.X, pos.Y, self.Width, self.Height, self.Text, tc, bg)\\\
  961.     end,\\\
  962. \\\
  963.     Initialise = function(self, x, y, width, height, backgroundColour, parent, click, text, textColour, toggle, activeBackgroundColour)\\\
  964.         local new = {}    -- the new instance\\\
  965.         setmetatable( new, {__index = self} )\\\
  966.         height = height or 1\\\
  967.         new.Width = width or #text + 2\\\
  968.         new.Height = height\\\
  969.         new.Y = y\\\
  970.         new.X = x\\\
  971.         new.Text = text or \\\"\\\"\\\
  972.         new.BackgroundColour = backgroundColour or colours.lightGrey\\\
  973.         new.TextColour = textColour or colours.white\\\
  974.         new.ActiveBackgroundColour = activeBackgroundColour or colours.lightGrey\\\
  975.         new.Parent = parent\\\
  976.         new._Click = click\\\
  977.         new.Toggle = toggle\\\
  978.         return new\\\
  979.     end,\\\
  980. \\\
  981.     Click = function(self, side, x, y)\\\
  982.         if self._Click then\\\
  983.             if self:_Click(side, x, y, not self.Toggle) ~= false and self.Toggle ~= nil then\\\
  984.                 self.Toggle = not self.Toggle\\\
  985.                 Draw()\\\
  986.             end\\\
  987.             return true\\\
  988.         else\\\
  989.             return false\\\
  990.         end\\\
  991.     end\\\
  992. }\\\
  993. \\\
  994. TextBox = {\\\
  995.     X = 1,\\\
  996.     Y = 1,\\\
  997.     Width = 0,\\\
  998.     Height = 0,\\\
  999.     BackgroundColour = colours.lightGrey,\\\
  1000.     TextColour = colours.black,\\\
  1001.     Parent = nil,\\\
  1002.     TextInput = nil,\\\
  1003.     Placeholder = '',\\\
  1004. \\\
  1005.     AbsolutePosition = function(self)\\\
  1006.         return self.Parent:AbsolutePosition()\\\
  1007.     end,\\\
  1008. \\\
  1009.     Draw = function(self)       \\\
  1010.         local pos = GetAbsolutePosition(self)\\\
  1011.         Drawing.DrawBlankArea(pos.X, pos.Y, self.Width, self.Height, self.BackgroundColour)\\\
  1012.         local text = self.TextInput.Value\\\
  1013.         if #tostring(text) > (self.Width - 2) then\\\
  1014.             text = text:sub(#text-(self.Width - 3))\\\
  1015.             if Current.TextInput == self.TextInput then\\\
  1016.                 Current.CursorPos = {pos.X + 1 + self.Width-2, pos.Y}\\\
  1017.             end\\\
  1018.         else\\\
  1019.             if Current.TextInput == self.TextInput then\\\
  1020.                 Current.CursorPos = {pos.X + 1 + self.TextInput.CursorPos, pos.Y}\\\
  1021.             end\\\
  1022.         end\\\
  1023.         \\\
  1024.         if #tostring(text) == 0 then\\\
  1025.             Drawing.DrawCharacters(pos.X + 1, pos.Y, self.Placeholder, colours.lightGrey, self.BackgroundColour)\\\
  1026.         else\\\
  1027.             Drawing.DrawCharacters(pos.X + 1, pos.Y, text, self.TextColour, self.BackgroundColour)\\\
  1028.         end\\\
  1029. \\\
  1030.         term.setCursorBlink(true)\\\
  1031.         \\\
  1032.         Current.CursorColour = self.TextColour\\\
  1033.     end,\\\
  1034. \\\
  1035.     Initialise = function(self, x, y, width, height, parent, text, backgroundColour, textColour, done, numerical)\\\
  1036.         local new = {}    -- the new instance\\\
  1037.         setmetatable( new, {__index = self} )\\\
  1038.         height = height or 1\\\
  1039.         new.Width = width or #text + 2\\\
  1040.         new.Height = height\\\
  1041.         new.Y = y\\\
  1042.         new.X = x\\\
  1043.         new.TextInput = TextInput:Initialise(text or '', function(key)\\\
  1044.             if done then\\\
  1045.                 done(key)\\\
  1046.             end\\\
  1047.             Draw()\\\
  1048.         end, numerical)\\\
  1049.         new.BackgroundColour = backgroundColour or colours.lightGrey\\\
  1050.         new.TextColour = textColour or colours.black\\\
  1051.         new.Parent = parent\\\
  1052.         return new\\\
  1053.     end,\\\
  1054. \\\
  1055.     Click = function(self, side, x, y)\\\
  1056.         Current.Input = self.TextInput\\\
  1057.         self:Draw()\\\
  1058.     end\\\
  1059. }\\\
  1060. \\\
  1061. TextInput = {\\\
  1062.     Value = \\\"\\\",\\\
  1063.     Change = nil,\\\
  1064.     CursorPos = nil,\\\
  1065.     Numerical = false,\\\
  1066.     IsDocument = nil,\\\
  1067. \\\
  1068.     Initialise = function(self, value, change, numerical, isDocument)\\\
  1069.         local new = {}    -- the new instance\\\
  1070.         setmetatable( new, {__index = self} )\\\
  1071.         new.Value = tostring(value)\\\
  1072.         new.Change = change\\\
  1073.         new.CursorPos = #tostring(value)\\\
  1074.         new.Numerical = numerical\\\
  1075.         new.IsDocument = isDocument or false\\\
  1076.         return new\\\
  1077.     end,\\\
  1078. \\\
  1079.     Insert = function(self, str)\\\
  1080.         if self.Numerical then\\\
  1081.             str = tostring(tonumber(str))\\\
  1082.         end\\\
  1083. \\\
  1084.         local selection = OrderSelection()\\\
  1085. \\\
  1086.         if self.IsDocument and selection then\\\
  1087.             self.Value = string.sub(self.Value, 1, selection[1]-1) .. str .. string.sub( self.Value, selection[2]+2)\\\
  1088.             self.CursorPos = selection[1]\\\
  1089.             Current.Selection = nil\\\
  1090.         else\\\
  1091.             local _, newLineAdjust = string.gsub(self.Value:sub(1, self.CursorPos), '\\\\n','')\\\
  1092. \\\
  1093.             self.Value = string.sub(self.Value, 1, self.CursorPos + newLineAdjust) .. str .. string.sub( self.Value, self.CursorPos + 1  + newLineAdjust)\\\
  1094.             self.CursorPos = self.CursorPos + 1\\\
  1095.         end\\\
  1096.         \\\
  1097.         self.Change(key)\\\
  1098.     end,\\\
  1099. \\\
  1100.     Extract = function(self, remove)\\\
  1101.         local selection = OrderSelection()\\\
  1102.         if self.IsDocument and selection then\\\
  1103.             local _, newLineAdjust = string.gsub(self.Value:sub(selection[1], selection[2]), '\\\\n','')\\\
  1104.             local str = string.sub(self.Value, selection[1], selection[2]+1+newLineAdjust)\\\
  1105.             if remove then\\\
  1106.                 self.Value = string.sub(self.Value, 1, selection[1]-1) .. string.sub( self.Value, selection[2]+2+newLineAdjust)\\\
  1107.                 self.CursorPos = selection[1] - 1\\\
  1108.                 Current.Selection = nil\\\
  1109.             end\\\
  1110.             return str\\\
  1111.         end\\\
  1112.     end,\\\
  1113. \\\
  1114.     Char = function(self, char)\\\
  1115.         if char == 'nil' then\\\
  1116.             return\\\
  1117.         end\\\
  1118.         self:Insert(char)\\\
  1119.     end,\\\
  1120. \\\
  1121.     Key = function(self, key)\\\
  1122.         if key == keys.enter then\\\
  1123.             if self.IsDocument then\\\
  1124.                 self.Value = string.sub(self.Value, 1, self.CursorPos ) .. '\\\\n' .. string.sub( self.Value, self.CursorPos + 1 )\\\
  1125.                 self.CursorPos = self.CursorPos + 1\\\
  1126.             end\\\
  1127.             self.Change(key)        \\\
  1128.         elseif key == keys.left then\\\
  1129.             -- Left\\\
  1130.             if self.CursorPos > 0 then\\\
  1131.                 local colShift = FindColours(string.sub( self.Value, self.CursorPos, self.CursorPos))\\\
  1132.                 self.CursorPos = self.CursorPos - 1 - colShift\\\
  1133.                 self.Change(key)\\\
  1134.             end\\\
  1135.             \\\
  1136.         elseif key == keys.right then\\\
  1137.             -- Right                \\\
  1138.             if self.CursorPos < string.len(self.Value) then\\\
  1139.                 local colShift = FindColours(string.sub( self.Value, self.CursorPos+1, self.CursorPos+1))\\\
  1140.                 self.CursorPos = self.CursorPos + 1 + colShift\\\
  1141.                 self.Change(key)\\\
  1142.             end\\\
  1143.         \\\
  1144.         elseif key == keys.backspace then\\\
  1145.             -- Backspace\\\
  1146.             if self.IsDocument and Current.Selection then\\\
  1147.                 self:Extract(true)\\\
  1148.                 self.Change(key)\\\
  1149.             elseif self.CursorPos > 0 then\\\
  1150.                 local colShift = FindColours(string.sub( self.Value, self.CursorPos, self.CursorPos))\\\
  1151.                 local _, newLineAdjust = string.gsub(self.Value:sub(1, self.CursorPos), '\\\\n','')\\\
  1152. \\\
  1153.                 self.Value = string.sub( self.Value, 1, self.CursorPos - 1 - colShift + newLineAdjust) .. string.sub( self.Value, self.CursorPos + 1 - colShift + newLineAdjust)\\\
  1154.                 self.CursorPos = self.CursorPos - 1 - colShift\\\
  1155.                 self.Change(key)\\\
  1156.             end\\\
  1157.         elseif key == keys.home then\\\
  1158.             -- Home\\\
  1159.             self.CursorPos = 0\\\
  1160.             self.Change(key)\\\
  1161.         elseif key == keys.delete then\\\
  1162.             if self.IsDocument and Current.Selection then\\\
  1163.                 self:Extract(true)\\\
  1164.                 self.Change(key)\\\
  1165.             elseif self.CursorPos < string.len(self.Value) then\\\
  1166.                 self.Value = string.sub( self.Value, 1, self.CursorPos ) .. string.sub( self.Value, self.CursorPos + 2 )                \\\
  1167.                 self.Change(key)\\\
  1168.             end\\\
  1169.         elseif key == keys[\\\"end\\\"] then\\\
  1170.             -- End\\\
  1171.             self.CursorPos = string.len(self.Value)\\\
  1172.             self.Change(key)\\\
  1173.         elseif key == keys.up and self.IsDocument then\\\
  1174.             -- Up\\\
  1175.             if Current.Document.CursorPos then\\\
  1176.                 local page = Current.Document.Pages[Current.Document.CursorPos.Page]\\\
  1177.                 self.CursorPos = page:GetCursorPosFromPoint(Current.Document.CursorPos.Collum + page.MarginX, Current.Document.CursorPos.Line - page.MarginY - 1 + Current.Document.ScrollBar.Scroll, true)\\\
  1178.                 self.Change(key)\\\
  1179.             end\\\
  1180.         elseif key == keys.down and self.IsDocument then\\\
  1181.             -- Down\\\
  1182.             if Current.Document.CursorPos then\\\
  1183.                 local page = Current.Document.Pages[Current.Document.CursorPos.Page]\\\
  1184.                 self.CursorPos = page:GetCursorPosFromPoint(Current.Document.CursorPos.Collum + page.MarginX, Current.Document.CursorPos.Line - page.MarginY + 1 + Current.Document.ScrollBar.Scroll, true)\\\
  1185.                 self.Change(key)\\\
  1186.             end\\\
  1187.         end\\\
  1188.     end\\\
  1189. }\\\
  1190. \\\
  1191. Menu = {\\\
  1192.     X = 0,\\\
  1193.     Y = 0,\\\
  1194.     Width = 0,\\\
  1195.     Height = 0,\\\
  1196.     Owner = nil,\\\
  1197.     Items = {},\\\
  1198.     RemoveTop = false,\\\
  1199. \\\
  1200.     Draw = function(self)\\\
  1201.         Drawing.DrawBlankArea(self.X + 1, self.Y + 1, self.Width, self.Height, UIColours.Shadow)\\\
  1202.         if not self.RemoveTop then\\\
  1203.             Drawing.DrawBlankArea(self.X, self.Y, self.Width, self.Height, UIColours.MenuBackground)\\\
  1204.             for i, item in ipairs(self.Items) do\\\
  1205.                 if item.Separator then\\\
  1206.                     Drawing.DrawArea(self.X, self.Y + i, self.Width, 1, '-', colours.grey, UIColours.MenuBackground)\\\
  1207.                 else\\\
  1208.                     local textColour = item.Colour or UIColours.MenuText\\\
  1209.                     if (item.Enabled and type(item.Enabled) == 'function' and item.Enabled() == false) or item.Enabled == false then\\\
  1210.                         textColour = UIColours.MenuDisabledText\\\
  1211.                     end\\\
  1212.                     Drawing.DrawCharacters(self.X + 1, self.Y + i, item.Title, textColour, UIColours.MenuBackground)\\\
  1213.                 end\\\
  1214.             end\\\
  1215.         else\\\
  1216.             Drawing.DrawBlankArea(self.X, self.Y, self.Width, self.Height, UIColours.MenuBackground)\\\
  1217.             for i, item in ipairs(self.Items) do\\\
  1218.                 if item.Separator then\\\
  1219.                     Drawing.DrawArea(self.X, self.Y + i - 1, self.Width, 1, '-', colours.grey, UIColours.MenuBackground)\\\
  1220.                 else\\\
  1221.                     local textColour = item.Colour or UIColours.MenuText\\\
  1222.                     if (item.Enabled and type(item.Enabled) == 'function' and item.Enabled() == false) or item.Enabled == false then\\\
  1223.                         textColour = UIColours.MenuDisabledText\\\
  1224.                     end\\\
  1225.                     Drawing.DrawCharacters(self.X + 1, self.Y + i - 1, item.Title, textColour, UIColours.MenuBackground)\\\
  1226. \\\
  1227.                     Drawing.DrawCharacters(self.X - 1 + self.Width-#item.KeyName, self.Y + i - 1, item.KeyName, textColour, UIColours.MenuBackground)\\\
  1228.                 end\\\
  1229.             end\\\
  1230.         end\\\
  1231.     end,\\\
  1232. \\\
  1233.     NameForKey = function(self, key)\\\
  1234.         if key == keys.leftCtrl then\\\
  1235.             return '^'\\\
  1236.         elseif key == keys.tab then\\\
  1237.             return 'Tab'\\\
  1238.         elseif key == keys.delete then\\\
  1239.             return 'Delete'\\\
  1240.         elseif key == keys.n then\\\
  1241.             return 'N'\\\
  1242.         elseif key == keys.a then\\\
  1243.             return 'A'\\\
  1244.         elseif key == keys.s then\\\
  1245.             return 'S'\\\
  1246.         elseif key == keys.o then\\\
  1247.             return 'O'\\\
  1248.         elseif key == keys.z then\\\
  1249.             return 'Z'\\\
  1250.         elseif key == keys.y then\\\
  1251.             return 'Y'\\\
  1252.         elseif key == keys.c then\\\
  1253.             return 'C'\\\
  1254.         elseif key == keys.x then\\\
  1255.             return 'X'\\\
  1256.         elseif key == keys.v then\\\
  1257.             return 'V'\\\
  1258.         elseif key == keys.r then\\\
  1259.             return 'R'\\\
  1260.         elseif key == keys.l then\\\
  1261.             return 'L'\\\
  1262.         elseif key == keys.t then\\\
  1263.             return 'T'\\\
  1264.         elseif key == keys.h then\\\
  1265.             return 'H'\\\
  1266.         elseif key == keys.e then\\\
  1267.             return 'E'\\\
  1268.         elseif key == keys.p then\\\
  1269.             return 'P'\\\
  1270.         elseif key == keys.f then\\\
  1271.             return 'F'\\\
  1272.         elseif key == keys.m then\\\
  1273.             return 'M'\\\
  1274.         elseif key == keys.q then\\\
  1275.             return 'Q'\\\
  1276.         else\\\
  1277.             return '?'      \\\
  1278.         end\\\
  1279.     end,\\\
  1280. \\\
  1281.     Initialise = function(self, x, y, items, owner, removeTop)\\\
  1282.         local new = {}    -- the new instance\\\
  1283.         setmetatable( new, {__index = self} )\\\
  1284.         if not owner then\\\
  1285.             return\\\
  1286.         end\\\
  1287. \\\
  1288.         local keyNames = {}\\\
  1289. \\\
  1290.         for i, v in ipairs(items) do\\\
  1291.             items[i].KeyName = ''\\\
  1292.             if v.Keys then\\\
  1293.                 for _i, key in ipairs(v.Keys) do\\\
  1294.                     items[i].KeyName = items[i].KeyName .. self:NameForKey(key)\\\
  1295.                 end\\\
  1296.             end\\\
  1297.             if items[i].KeyName ~= '' then\\\
  1298.                 table.insert(keyNames, items[i].KeyName)\\\
  1299.             end\\\
  1300.         end\\\
  1301.         local keysLength = LongestString(keyNames)\\\
  1302.         if keysLength > 0 then\\\
  1303.             keysLength = keysLength + 2\\\
  1304.         end\\\
  1305. \\\
  1306.         new.Width = LongestString(items, 'Title') + 2 + keysLength\\\
  1307.         if new.Width < 10 then\\\
  1308.             new.Width = 10\\\
  1309.         end\\\
  1310.         new.Height = #items + 2\\\
  1311.         new.RemoveTop = removeTop or false\\\
  1312.         if removeTop then\\\
  1313.             new.Height = new.Height - 1\\\
  1314.         end\\\
  1315.         \\\
  1316.         if y < 1 then\\\
  1317.             y = 1\\\
  1318.         end\\\
  1319.         if x < 1 then\\\
  1320.             x = 1\\\
  1321.         end\\\
  1322. \\\
  1323.         if y + new.Height > Drawing.Screen.Height + 1 then\\\
  1324.             y = Drawing.Screen.Height - new.Height\\\
  1325.         end\\\
  1326.         if x + new.Width > Drawing.Screen.Width + 1 then\\\
  1327.             x = Drawing.Screen.Width - new.Width\\\
  1328.         end\\\
  1329. \\\
  1330. \\\
  1331.         new.Y = y\\\
  1332.         new.X = x\\\
  1333.         new.Items = items\\\
  1334.         new.Owner = owner\\\
  1335.         return new\\\
  1336.     end,\\\
  1337. \\\
  1338.     New = function(self, x, y, items, owner, removeTop)\\\
  1339.         if Current.Menu and Current.Menu.Owner == owner then\\\
  1340.             Current.Menu = nil\\\
  1341.             return\\\
  1342.         end\\\
  1343. \\\
  1344.         local new = self:Initialise(x, y, items, owner, removeTop)\\\
  1345.         Current.Menu = new\\\
  1346.         return new\\\
  1347.     end,\\\
  1348. \\\
  1349.     Click = function(self, side, x, y)\\\
  1350.         local i = y-1\\\
  1351.         if self.RemoveTop then\\\
  1352.             i = y\\\
  1353.         end\\\
  1354.         if i >= 1 and y < self.Height then\\\
  1355.             if not ((self.Items[i].Enabled and type(self.Items[i].Enabled) == 'function' and self.Items[i].Enabled() == false) or self.Items[i].Enabled == false) and self.Items[i].Click then\\\
  1356.                 self.Items[i]:Click()\\\
  1357.                 if Current.Menu.Owner and Current.Menu.Owner.Toggle then\\\
  1358.                     Current.Menu.Owner.Toggle = false\\\
  1359.                 end\\\
  1360.                 Current.Menu = nil\\\
  1361.                 self = nil\\\
  1362.             end\\\
  1363.             return true\\\
  1364.         end\\\
  1365.     end\\\
  1366. }\\\
  1367. \\\
  1368. MenuBar = {\\\
  1369.     X = 1,\\\
  1370.     Y = 1,\\\
  1371.     Width = Drawing.Screen.Width,\\\
  1372.     Height = 1,\\\
  1373.     MenuBarItems = {},\\\
  1374. \\\
  1375.     AbsolutePosition = function(self)\\\
  1376.         return {X = self.X, Y = self.Y}\\\
  1377.     end,\\\
  1378. \\\
  1379.     Draw = function(self)\\\
  1380.         --Drawing.DrawArea(self.X - 1, self.Y, 1, self.Height, \\\"|\\\", UIColours.ToolbarText, UIColours.Background)\\\
  1381. \\\
  1382.         Drawing.DrawBlankArea(self.X, self.Y, self.Width, self.Height, colours.grey)\\\
  1383.         for i, button in ipairs(self.MenuBarItems) do\\\
  1384.             button:Draw()\\\
  1385.         end\\\
  1386.     end,\\\
  1387. \\\
  1388.     Initialise = function(self, items)\\\
  1389.         local new = {}    -- the new instance\\\
  1390.         setmetatable( new, {__index = self} )\\\
  1391.         new.X = 1\\\
  1392.         new.Y = 1\\\
  1393.         new.MenuBarItems = items\\\
  1394.         return new\\\
  1395.     end,\\\
  1396. \\\
  1397.     AddToolbarItem = function(self, item)\\\
  1398.         table.insert(self.ToolbarItems, item)\\\
  1399.         self:CalculateToolbarItemPositions()\\\
  1400.     end,\\\
  1401. \\\
  1402.     CalculateToolbarItemPositions = function(self)\\\
  1403.         local currY = 1\\\
  1404.         for i, toolbarItem in ipairs(self.ToolbarItems) do\\\
  1405.             toolbarItem.Y = currY\\\
  1406.             currY = currY + toolbarItem.Height\\\
  1407.         end\\\
  1408.     end,\\\
  1409. \\\
  1410.     Click = function(self, side, x, y)\\\
  1411.         for i, item in ipairs(self.MenuBarItems) do\\\
  1412.             if item.X <= x and item.X + item.Width > x then\\\
  1413.                 if item:Click(item, side, x - item.X + 1, 1) then\\\
  1414.                     return true\\\
  1415.                 end\\\
  1416.             end\\\
  1417.         end\\\
  1418.         return false\\\
  1419.     end\\\
  1420. }\\\
  1421. \\\
  1422. TextFormatPlainText = 1\\\
  1423. TextFormatInkText = 2\\\
  1424. \\\
  1425. Document = {\\\
  1426.     X = 1,\\\
  1427.     Y = 1,\\\
  1428.     PageSize = {Width = 25, Height = 21},\\\
  1429.     TextInput = nil,\\\
  1430.     Pages = {},\\\
  1431.     Format = TextFormatPlainText,\\\
  1432.     Title = '',\\\
  1433.     Path = nil,\\\
  1434.     ScrollBar = nil,\\\
  1435.     Lines = {},\\\
  1436.     CursorPos = nil,\\\
  1437. \\\
  1438.     CalculateLineWrapping = function(self)\\\
  1439.         local limit = self.PageSize.Width\\\
  1440.         local text = self.TextInput.Value\\\
  1441.        local lines = {''}\\\
  1442.        local words = {}\\\
  1443. \\\
  1444.        for word, space in text:gmatch('(%S+)(%s*)') do\\\
  1445.             for i = 1, math.ceil(#word/limit) do\\\
  1446.                 local _space = ''\\\
  1447.                 if i == math.ceil(#word/limit) then\\\
  1448.                     _space = space\\\
  1449.                 end\\\
  1450.                 table.insert(words, {word:sub(1+limit*(i-1), limit*i), _space})\\\
  1451.             end\\\
  1452.        end\\\
  1453. \\\
  1454.        for i, ws in ipairs(words) do\\\
  1455.                 local word = ws[1]\\\
  1456.                 local space = ws[2]\\\
  1457.                local temp = lines[#lines] .. word .. space:gsub('\\\\n','')\\\
  1458.                if #temp > limit then\\\
  1459.                    table.insert(lines, '')\\\
  1460.                end\\\
  1461.                if space:find('\\\\n') then\\\
  1462.                    lines[#lines] = lines[#lines] .. word\\\
  1463.                    \\\
  1464.                    space = space:gsub('\\\\n', function()\\\
  1465.                            table.insert(lines, '')\\\
  1466.                            return ''\\\
  1467.                    end)\\\
  1468.                else\\\
  1469.                    lines[#lines] = lines[#lines] .. word .. space\\\
  1470.                end\\\
  1471.        end\\\
  1472.        return lines\\\
  1473.     end,\\\
  1474. \\\
  1475.     CalculateCursorPos = function(self)\\\
  1476.         local passedCharacters = 0\\\
  1477.         Current.CursorPos = nil\\\
  1478.         for p, page in ipairs(self.Pages) do\\\
  1479.             page:Draw()\\\
  1480.             if not Current.CursorPos then\\\
  1481.                 for i, line in ipairs(page.Lines) do\\\
  1482.                     local relCursor = self.TextInput.CursorPos - FindColours(self.TextInput.Value:sub(1,self.TextInput.CursorPos))\\\
  1483.                     if passedCharacters + #StripColours(line.Text:gsub('\\\\n','')) >= relCursor then\\\
  1484.                         Current.CursorPos = {self.X + page.MarginX + (relCursor - passedCharacters), page.Y + 1 + i}\\\
  1485.                         self.CursorPos = {Page = p, Line = i, Collum = relCursor - passedCharacters - FindColours(self.TextInput.Value:sub(1,self.TextInput.CursorPos-1))}\\\
  1486.                         break\\\
  1487.                     end\\\
  1488.                     passedCharacters = passedCharacters + #StripColours(line.Text:gsub('\\\\n',''))\\\
  1489.                 end\\\
  1490.             end\\\
  1491.         end\\\
  1492.     end,\\\
  1493. \\\
  1494.     Draw = function(self)\\\
  1495.         self:CalculatePages()\\\
  1496.         self:CalculateCursorPos()\\\
  1497.         self.ScrollBar:Draw()\\\
  1498.     end,\\\
  1499. \\\
  1500.     CalculatePages = function(self)\\\
  1501.         self.Pages = {}\\\
  1502.         local lines = self:CalculateLineWrapping()\\\
  1503.         self.Lines = lines\\\
  1504.         local pageLines = {}\\\
  1505.         local totalPageHeight = (3 + self.PageSize.Height + 2 * Page.MarginY)\\\
  1506.         for i, line in ipairs(lines) do\\\
  1507.             table.insert(pageLines, TextLine:Initialise(line))\\\
  1508.             if i % self.PageSize.Height == 0 then\\\
  1509.                 table.insert(self.Pages, Page:Initialise(self, pageLines, 3 - self.ScrollBar.Scroll + totalPageHeight*(#self.Pages)))\\\
  1510.                 pageLines = {}\\\
  1511.             end\\\
  1512.         end\\\
  1513.         if #pageLines ~= 0 then\\\
  1514.             table.insert(self.Pages, Page:Initialise(self, pageLines, 3 - self.ScrollBar.Scroll + totalPageHeight*(#self.Pages)))\\\
  1515.         end\\\
  1516. \\\
  1517.         self.ScrollBar.MaxScroll = totalPageHeight*(#self.Pages) - Drawing.Screen.Height + 1\\\
  1518.     end,\\\
  1519. \\\
  1520.     ScrollToCursor = function(self)\\\
  1521.         self:CalculateCursorPos()\\\
  1522.         if Current.CursorPos and \\\
  1523.             (Current.CursorPos[2] > Drawing.Screen.Height \\\
  1524.             or Current.CursorPos[2] < 2) then\\\
  1525.             self.ScrollBar:DoScroll(Current.CursorPos[2] - Drawing.Screen.Height)\\\
  1526.         end\\\
  1527.     end,\\\
  1528. \\\
  1529.     SetSelectionColour = function(self, colour)\\\
  1530.         local selection = OrderSelection()\\\
  1531.         local text = self.TextInput:Extract(true)\\\
  1532.         local colChar = CharacterFromColour(colour)\\\
  1533.         local precedingColour = ''\\\
  1534.         if FindColours(self.TextInput.Value:sub(self.TextInput.CursorPos+1, self.TextInput.CursorPos+1)) == 0 then\\\
  1535.             for i = 1, self.TextInput.CursorPos do\\\
  1536.                 local c = self.TextInput.Value:sub(self.TextInput.CursorPos - i,self.TextInput.CursorPos - i)\\\
  1537.                 if FindColours(c) == 1 then\\\
  1538.                     precedingColour = c\\\
  1539.                     break\\\
  1540.                 end\\\
  1541.             end\\\
  1542.             if precedingColour == '' then\\\
  1543.                 precedingColour = CharacterFromColour(colours.black)\\\
  1544.             end\\\
  1545.         end\\\
  1546. \\\
  1547.         self.TextInput:Insert(colChar..StripColours(text)..precedingColour)\\\
  1548.         --text = text:gsub('['..string.char(14)..'-'..string.char(29)..']','')\\\
  1549.     end,\\\
  1550. \\\
  1551.     Initialise = function(self, text, title, path)\\\
  1552.         local new = {}    -- the new instance\\\
  1553.         setmetatable( new, {__index = self} )\\\
  1554.         new.Title = title or 'New Document'\\\
  1555.         new.Path = path\\\
  1556.         new.X = (Drawing.Screen.Width - (new.PageSize.Width + 2*(Page.MarginX)))/2\\\
  1557.         new.Y = 2\\\
  1558.         new.TextInput = TextInput:Initialise(text, function()\\\
  1559.             new:ScrollToCursor() \\\
  1560.             Current.Modified = true\\\
  1561.             Draw()\\\
  1562.         end, false, true)\\\
  1563.         new.ScrollBar = ScrollBar:Initialise(Drawing.Screen.Width, new.Y, Drawing.Screen.Height-1, 0, nil, nil, nil, function()end)\\\
  1564.         Current.TextInput = new.TextInput\\\
  1565.         Current.ScrollBar = new.ScrollBar\\\
  1566.         return new\\\
  1567.     end\\\
  1568. }\\\
  1569. \\\
  1570. ScrollBar = {\\\
  1571.     X = 1,\\\
  1572.     Y = 1,\\\
  1573.     Width = 1,\\\
  1574.     Height = 1,\\\
  1575.     BackgroundColour = colours.grey,\\\
  1576.     BarColour = colours.lightBlue,\\\
  1577.     Parent = nil,\\\
  1578.     Change = nil,\\\
  1579.     Scroll = 0,\\\
  1580.     MaxScroll = 0,\\\
  1581.     ClickPoint = nil,\\\
  1582. \\\
  1583.     AbsolutePosition = function(self)\\\
  1584.         return self.Parent:AbsolutePosition()\\\
  1585.     end,\\\
  1586. \\\
  1587.     Draw = function(self)\\\
  1588.         local pos = GetAbsolutePosition(self)\\\
  1589.         local barHeight = self.Height - self.MaxScroll\\\
  1590.         if barHeight < 3 then\\\
  1591.           barHeight = 3\\\
  1592.         end\\\
  1593.         local percentage = (self.Scroll/self.MaxScroll)\\\
  1594. \\\
  1595.         Drawing.DrawBlankArea(pos.X, pos.Y, self.Width, self.Height, self.BackgroundColour)\\\
  1596.         Drawing.DrawBlankArea(pos.X, pos.Y + round(self.Height*percentage - barHeight*percentage), self.Width, barHeight, self.BarColour)\\\
  1597.     end,\\\
  1598. \\\
  1599.     Initialise = function(self, x, y, height, maxScroll, backgroundColour, barColour, parent, change)\\\
  1600.         local new = {}    -- the new instance\\\
  1601.         setmetatable( new, {__index = self} )\\\
  1602.         new.Width = 1\\\
  1603.         new.Height = height\\\
  1604.         new.Y = y\\\
  1605.         new.X = x\\\
  1606.         new.BackgroundColour = backgroundColour or colours.grey\\\
  1607.         new.BarColour = barColour or colours.lightBlue\\\
  1608.         new.Parent = parent\\\
  1609.         new.Change = change or function()end\\\
  1610.         new.MaxScroll = maxScroll\\\
  1611.         new.Scroll = 0\\\
  1612.         return new\\\
  1613.     end,\\\
  1614. \\\
  1615.     DoScroll = function(self, amount)\\\
  1616.         amount = round(amount)\\\
  1617.         if self.Scroll < 0 or self.Scroll > self.MaxScroll then\\\
  1618.             return false\\\
  1619.         end\\\
  1620.         self.Scroll = self.Scroll + amount\\\
  1621.         if self.Scroll < 0 then\\\
  1622.             self.Scroll = 0\\\
  1623.         elseif self.Scroll > self.MaxScroll then\\\
  1624.             self.Scroll = self.MaxScroll\\\
  1625.         end\\\
  1626.         self.Change()\\\
  1627.         return true\\\
  1628.     end,\\\
  1629. \\\
  1630.     Click = function(self, side, x, y, drag)\\\
  1631.         local percentage = (self.Scroll/self.MaxScroll)\\\
  1632.         local barHeight = (self.Height - self.MaxScroll)\\\
  1633.         if barHeight < 3 then\\\
  1634.             barHeight = 3\\\
  1635.         end\\\
  1636.         local relScroll = (self.MaxScroll*(y + barHeight*percentage)/self.Height)\\\
  1637.         if not drag then\\\
  1638.             self.ClickPoint = self.Scroll - relScroll + 1\\\
  1639.         end\\\
  1640. \\\
  1641.         if self.Scroll-1 ~= relScroll then\\\
  1642.             self:DoScroll(relScroll-self.Scroll-1 + self.ClickPoint)\\\
  1643.         end\\\
  1644.         return true\\\
  1645.     end\\\
  1646. }\\\
  1647. \\\
  1648. AlignmentLeft = 1\\\
  1649. AlignmentCentre = 2\\\
  1650. AlignmentRight = 3\\\
  1651. \\\
  1652. TextLine = {\\\
  1653.     Text = \\\"\\\",\\\
  1654.     Alignment = AlignmentLeft,\\\
  1655. \\\
  1656.     Initialise = function(self, text, alignment)\\\
  1657.         local new = {}    -- the new instance\\\
  1658.         setmetatable( new, {__index = self} )\\\
  1659.         new.Text = text\\\
  1660.         new.Alignment = alignment or AlignmentLeft\\\
  1661.         return new\\\
  1662.     end\\\
  1663. }\\\
  1664. \\\
  1665. local clickPos = 1\\\
  1666. Page = {\\\
  1667.     X = 1,\\\
  1668.     Y = 1,\\\
  1669.     Width = 1,\\\
  1670.     Height = 1,\\\
  1671.     MarginX = 3,\\\
  1672.     MarginY = 2,\\\
  1673.     BackgroundColour = colours.white,\\\
  1674.     TextColour = colours.white,\\\
  1675.     ActiveBackgroundColour = colours.lightGrey,\\\
  1676.     Lines = {},\\\
  1677.     Parent = nil,\\\
  1678. \\\
  1679.     AbsolutePosition = function(self)\\\
  1680.         return self.Parent:AbsolutePosition()\\\
  1681.     end,\\\
  1682. \\\
  1683.     Draw = function(self)\\\
  1684.         local pos = GetAbsolutePosition(self)\\\
  1685. \\\
  1686.         if pos.Y > Drawing.Screen.Height or pos.Y + self.Height < 1 then\\\
  1687.             return\\\
  1688.         end\\\
  1689. \\\
  1690.         Drawing.DrawBlankArea(pos.X+self.Width,pos.Y -1 + 1, 1, self.Height, UIColours.Shadow)\\\
  1691.         Drawing.DrawBlankArea(pos.X+1, pos.Y -1 + self.Height, self.Width, 1, UIColours.Shadow)\\\
  1692.         Drawing.DrawBlankArea(pos.X, pos.Y -1, self.Width, self.Height, self.BackgroundColour)\\\
  1693. \\\
  1694.         local textColour = self.TextColour\\\
  1695.         if not Current.Selection then\\\
  1696.             for i, line in ipairs(self.Lines) do\\\
  1697.                 local _c = 1\\\
  1698.                 for c = 1, #line.Text do\\\
  1699.                     local col = ColourFromCharacter(line.Text:sub(c,c))\\\
  1700.                     if col then\\\
  1701.                         textColour = col\\\
  1702.                     else\\\
  1703.                         Drawing.WriteToBuffer(pos.X + self.MarginX - 1 + _c, pos.Y -2 + i + self.MarginY, line.Text:sub(c,c), textColour, self.BackgroundColour)\\\
  1704.                         _c = _c + 1\\\
  1705.                     end\\\
  1706.                 end\\\
  1707.             end\\\
  1708.         else\\\
  1709.             local selection = OrderSelection()\\\
  1710.             local char = 1\\\
  1711.             local textColour = self.TextColour\\\
  1712.             for i, line in ipairs(self.Lines) do\\\
  1713.                 local _c = 1\\\
  1714.                 for c = 1, #line.Text do\\\
  1715.                     local col = ColourFromCharacter(line.Text:sub(c,c))\\\
  1716.                     if col then\\\
  1717.                         textColour = col\\\
  1718.                     else\\\
  1719.                         local tc = textColour\\\
  1720.                         local colour = colours.white\\\
  1721.                         if char >= selection[1] and char <= selection[2] then\\\
  1722.                             colour = colours.lightBlue\\\
  1723.                             tc = colours.white\\\
  1724.                         end\\\
  1725. \\\
  1726.                         Drawing.WriteToBuffer(pos.X + self.MarginX - 1 + _c, pos.Y -2 + i + self.MarginY, line.Text:sub(c,c), tc, colour)\\\
  1727.                         _c = _c + 1\\\
  1728.                     end\\\
  1729.                     char = char + 1\\\
  1730.                 end\\\
  1731.             end\\\
  1732.         end\\\
  1733.     end,\\\
  1734. \\\
  1735.     Initialise = function(self, parent, lines, y)\\\
  1736.         local new = {}    -- the new instanc\\\
  1737.         setmetatable( new, {__index = self} )\\\
  1738.         new.Height = parent.PageSize.Height + 2 * self.MarginY\\\
  1739.         new.Width = parent.PageSize.Width + 2 * self.MarginX\\\
  1740.         new.X = 1\\\
  1741.         new.Y = y or 1\\\
  1742.         new.Lines = lines or {}\\\
  1743.         new.BackgroundColour = colours.white\\\
  1744.         new.TextColour = colours.black\\\
  1745.         new.Parent = parent\\\
  1746.         new.ClickPos = 1\\\
  1747.         return new\\\
  1748.     end,\\\
  1749. \\\
  1750.     GetCursorPosFromPoint = function(self, x, y, rel)\\\
  1751.         local pos = GetAbsolutePosition(self)\\\
  1752.         if rel then\\\
  1753.             pos = {Y = 0, X = 0}\\\
  1754.         end\\\
  1755.         local row = y - pos.Y + self.MarginY - self.Parent.ScrollBar.Scroll\\\
  1756.         local col = x - self.MarginX - pos.X + 1\\\
  1757.         local cursorPos = 0\\\
  1758.         if row <= 0 or col <= 0 then\\\
  1759.             return 0\\\
  1760.         end\\\
  1761. \\\
  1762.         if row > #self.Lines then\\\
  1763.             for i, v in ipairs(self.Lines) do\\\
  1764.                 cursorPos = cursorPos + #v.Text-- - FindColours(v.Text)\\\
  1765.             end\\\
  1766.             return cursorPos\\\
  1767.         end\\\
  1768. \\\
  1769.         --term.setCursorPos(1,3)\\\
  1770.         local prevLineCount = 0\\\
  1771.         for i, v in ipairs(self.Lines) do\\\
  1772.             if i == row then\\\
  1773.                 if col > #v.Text then\\\
  1774.                     col = #v.Text-- + FindColours(v.Text)\\\
  1775.                 else\\\
  1776.                     col = col + FindColours(v.Text:sub(1, col))\\\
  1777.                 end\\\
  1778.                 --term.setCursorPos(1,2)\\\
  1779.                 --print(prevLineCount)\\\
  1780.                 cursorPos = cursorPos + col + 2 - i - prevLineCount\\\
  1781.                 break\\\
  1782.             else\\\
  1783.                 prevLineCount = FindColours(v.Text)\\\
  1784.                 if prevLineCount ~= 0 then\\\
  1785.                     prevLineCount = prevLineCount\\\
  1786.                 end\\\
  1787.                 cursorPos = cursorPos + #v.Text + 2 - i + FindColours(v.Text)\\\
  1788.             end\\\
  1789.         end\\\
  1790. \\\
  1791.         return cursorPos - 2\\\
  1792.     end,\\\
  1793. \\\
  1794.     Click = function(self, side, x, y, drag)\\\
  1795.         local cursorPos = self:GetCursorPosFromPoint(x, y)\\\
  1796.         self.Parent.TextInput.CursorPos = cursorPos\\\
  1797.         if drag == nil then\\\
  1798.             Current.Selection = nil\\\
  1799.             clickPos = x\\\
  1800.         else\\\
  1801.             local relCursor = cursorPos-- - FindColours(self.Parent.TextInput.Value:sub(1,cursorPos)) + 1\\\
  1802.             if not Current.Selection then\\\
  1803.                 local adder = 1\\\
  1804.                 if clickPos and clickPos < x then\\\
  1805.                     adder = 0\\\
  1806.                 end\\\
  1807.                 Current.Selection = {relCursor + adder, relCursor + 1 + adder}\\\
  1808.             else\\\
  1809.                 Current.Selection[2] = relCursor + 1\\\
  1810.             end\\\
  1811.         end\\\
  1812.         Draw()\\\
  1813.         return true\\\
  1814.     end\\\
  1815. }\\\
  1816. \\\
  1817. function GetAbsolutePosition(object)\\\
  1818.     local obj = object\\\
  1819.     local i = 0\\\
  1820.     local x = 1\\\
  1821.     local y = 1\\\
  1822.     while true do\\\
  1823.         x = x + obj.X - 1\\\
  1824.         y = y + obj.Y - 1\\\
  1825. \\\
  1826.         if not obj.Parent then\\\
  1827.             return {X = x, Y = y}\\\
  1828.         end\\\
  1829. \\\
  1830.         obj = obj.Parent\\\
  1831. \\\
  1832.         if i > 32 then\\\
  1833.             return {X = 1, Y = 1}\\\
  1834.         end\\\
  1835. \\\
  1836.         i = i + 1\\\
  1837.     end\\\
  1838. \\\
  1839. end\\\
  1840. \\\
  1841. function Draw()\\\
  1842.     if not Current.Window then\\\
  1843.         Drawing.Clear(colours.lightGrey)\\\
  1844.     else\\\
  1845.         Drawing.DrawArea(1, 2, Drawing.Screen.Width, Drawing.Screen.Height, '|', colours.black, colours.lightGrey)\\\
  1846.     end\\\
  1847. \\\
  1848.     if Current.Document then\\\
  1849.         Current.Document:Draw()\\\
  1850.     end\\\
  1851. \\\
  1852.     Current.MenuBar:Draw()\\\
  1853. \\\
  1854.     if Current.Window then\\\
  1855.         Current.Window:Draw()\\\
  1856.     end\\\
  1857. \\\
  1858.     if Current.Menu then\\\
  1859.         Current.Menu:Draw()\\\
  1860.     end\\\
  1861. \\\
  1862.     Drawing.DrawBuffer()\\\
  1863. \\\
  1864.     if Current.TextInput and Current.CursorPos and not Current.Menu and not(Current.Window and Current.Document and Current.TextInput == Current.Document.TextInput) and Current.CursorPos[2] > 1 then\\\
  1865.         term.setCursorPos(Current.CursorPos[1], Current.CursorPos[2])\\\
  1866.         term.setCursorBlink(true)\\\
  1867.         term.setTextColour(Current.CursorColour)\\\
  1868.     else\\\
  1869.         term.setCursorBlink(false)\\\
  1870.     end\\\
  1871. end\\\
  1872. MainDraw = Draw\\\
  1873. \\\
  1874. LongestString = function(input, key)\\\
  1875.     local length = 0\\\
  1876.     for i = 1, #input do\\\
  1877.         local value = input[i]\\\
  1878.         if key then\\\
  1879.             if value[key] then\\\
  1880.                 value = value[key]\\\
  1881.             else\\\
  1882.                 value = ''\\\
  1883.             end\\\
  1884.         end\\\
  1885.         local titleLength = string.len(value)\\\
  1886.         if titleLength > length then\\\
  1887.             length = titleLength\\\
  1888.         end\\\
  1889.     end\\\
  1890.     return length\\\
  1891. end\\\
  1892. \\\
  1893. function LoadMenuBar()\\\
  1894.     Current.MenuBar = MenuBar:Initialise({\\\
  1895.         Button:Initialise(1, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
  1896.             if toggle then\\\
  1897.                 Menu:New(1, 2, {\\\
  1898.                     {\\\
  1899.                         Title = \\\"New...\\\",\\\
  1900.                         Click = function()\\\
  1901.                             Current.Document = Document:Initialise('')                          \\\
  1902.                         end,\\\
  1903.                         Keys = {\\\
  1904.                             keys.leftCtrl,\\\
  1905.                             keys.n\\\
  1906.                         }\\\
  1907.                     },\\\
  1908.                     {\\\
  1909.                         Title = 'Open...',\\\
  1910.                         Click = function()\\\
  1911.                             DisplayOpenDocumentWindow()\\\
  1912.                         end,\\\
  1913.                         Keys = {\\\
  1914.                             keys.leftCtrl,\\\
  1915.                             keys.o\\\
  1916.                         }\\\
  1917.                     },\\\
  1918.                     {\\\
  1919.                         Separator = true\\\
  1920.                     },\\\
  1921.                     {\\\
  1922.                         Title = 'Save...',\\\
  1923.                         Click = function()\\\
  1924.                             SaveDocument()\\\
  1925.                         end,\\\
  1926.                         Keys = {\\\
  1927.                             keys.leftCtrl,\\\
  1928.                             keys.s\\\
  1929.                         },\\\
  1930.                         Enabled = function()\\\
  1931.                             return true\\\
  1932.                         end\\\
  1933.                     },\\\
  1934.                     {\\\
  1935.                         Separator = true\\\
  1936.                     },\\\
  1937.                     {\\\
  1938.                         Title = 'Print...',\\\
  1939.                         Click = function()\\\
  1940.                             PrintDocument()\\\
  1941.                         end,\\\
  1942.                         Keys = {\\\
  1943.                             keys.leftCtrl,\\\
  1944.                             keys.p\\\
  1945.                         },\\\
  1946.                         Enabled = function()\\\
  1947.                             return true\\\
  1948.                         end\\\
  1949.                     },\\\
  1950.                     {\\\
  1951.                         Separator = true\\\
  1952.                     },\\\
  1953.                     {\\\
  1954.                         Title = 'Quit',\\\
  1955.                         Click = function()\\\
  1956.                             Close()\\\
  1957.                         end\\\
  1958.                     },\\\
  1959.             --[[\\\
  1960.                     {\\\
  1961.                         Title = 'Save As...',\\\
  1962.                         Click = function()\\\
  1963. \\\
  1964.                         end\\\
  1965.                     }   \\\
  1966.             ]]--\\\
  1967.                 }, self, true)\\\
  1968.             else\\\
  1969.                 Current.Menu = nil\\\
  1970.             end\\\
  1971.             return true \\\
  1972.         end, 'File', colours.lightGrey, false),\\\
  1973.         Button:Initialise(7, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
  1974.             if not self.Toggle then\\\
  1975.                 Menu:New(7, 2, {\\\
  1976.             --[[\\\
  1977.                     {\\\
  1978.                         Title = \\\"Undo\\\",\\\
  1979.                         Click = function()\\\
  1980.                         end,\\\
  1981.                         Keys = {\\\
  1982.                             keys.leftCtrl,\\\
  1983.                             keys.z\\\
  1984.                         },\\\
  1985.                         Enabled = function()\\\
  1986.                             return false\\\
  1987.                         end\\\
  1988.                     },\\\
  1989.                     {\\\
  1990.                         Title = 'Redo',\\\
  1991.                         Click = function()\\\
  1992.                             \\\
  1993.                         end,\\\
  1994.                         Keys = {\\\
  1995.                             keys.leftCtrl,\\\
  1996.                             keys.y\\\
  1997.                         },\\\
  1998.                         Enabled = function()\\\
  1999.                             return false\\\
  2000.                         end\\\
  2001.                     },\\\
  2002.                     {\\\
  2003.                         Separator = true\\\
  2004.                     },\\\
  2005.             ]]--\\\
  2006.                     {\\\
  2007.                         Title = 'Cut',\\\
  2008.                         Click = function()\\\
  2009.                             Clipboard.Cut(Current.Document.TextInput:Extract(true), 'text')\\\
  2010.                         end,\\\
  2011.                         Keys = {\\\
  2012.                             keys.leftCtrl,\\\
  2013.                             keys.x\\\
  2014.                         },\\\
  2015.                         Enabled = function()\\\
  2016.                             return Current.Document ~= nil and Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil\\\
  2017.                         end\\\
  2018.                     },\\\
  2019.                     {\\\
  2020.                         Title = 'Copy',\\\
  2021.                         Click = function()\\\
  2022.                             Clipboard.Copy(Current.Document.TextInput:Extract(), 'text')\\\
  2023.                         end,\\\
  2024.                         Keys = {\\\
  2025.                             keys.leftCtrl,\\\
  2026.                             keys.c\\\
  2027.                         },\\\
  2028.                         Enabled = function()\\\
  2029.                             return Current.Document ~= nil and Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil\\\
  2030.                         end\\\
  2031.                     },\\\
  2032.                     {\\\
  2033.                         Title = 'Paste',\\\
  2034.                         Click = function()\\\
  2035.                             local paste = Clipboard.Paste()\\\
  2036.                             Current.Document.TextInput:Insert(paste)\\\
  2037.                             Current.Document.TextInput.CursorPos = Current.Document.TextInput.CursorPos + #paste - 1\\\
  2038.                         end,\\\
  2039.                         Keys = {\\\
  2040.                             keys.leftCtrl,\\\
  2041.                             keys.v\\\
  2042.                         },\\\
  2043.                         Enabled = function()\\\
  2044.                             return Current.Document ~= nil and (not Clipboard.isEmpty()) and Clipboard.Type == 'text'\\\
  2045.                         end\\\
  2046.                     },\\\
  2047.                     {\\\
  2048.                         Separator = true,   \\\
  2049.                     },\\\
  2050.                     {\\\
  2051.                         Title = 'Select All',\\\
  2052.                         Click = function()\\\
  2053.                             Current.Selection = {1, #Current.Document.TextInput.Value:gsub('\\\\n','')}\\\
  2054.                         end,\\\
  2055.                         Keys = {\\\
  2056.                             keys.leftCtrl,\\\
  2057.                             keys.a\\\
  2058.                         },\\\
  2059.                         Enabled = function()\\\
  2060.                             return Current.Document ~= nil\\\
  2061.                         end\\\
  2062.                     }\\\
  2063.                 }, self, true)\\\
  2064.             else\\\
  2065.                 Current.Menu = nil\\\
  2066.             end\\\
  2067.             return true \\\
  2068.         end, 'Edit', colours.lightGrey, false)\\\
  2069.     })\\\
  2070. end\\\
  2071. \\\
  2072. function LoadMenuBar()\\\
  2073.     Current.MenuBar = MenuBar:Initialise({\\\
  2074.         Button:Initialise(1, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
  2075.             if toggle then\\\
  2076.                 Menu:New(1, 2, {\\\
  2077.                     {\\\
  2078.                         Title = \\\"New...\\\",\\\
  2079.                         Click = function()\\\
  2080.                             Current.Document = Document:Initialise('')                          \\\
  2081.                         end,\\\
  2082.                         Keys = {\\\
  2083.                             keys.leftCtrl,\\\
  2084.                             keys.n\\\
  2085.                         }\\\
  2086.                     },\\\
  2087.                     {\\\
  2088.                         Title = 'Open...',\\\
  2089.                         Click = function()\\\
  2090.                             DisplayOpenDocumentWindow()\\\
  2091.                         end,\\\
  2092.                         Keys = {\\\
  2093.                             keys.leftCtrl,\\\
  2094.                             keys.o\\\
  2095.                         }\\\
  2096.                     },\\\
  2097.                     {\\\
  2098.                         Separator = true\\\
  2099.                     },\\\
  2100.                     {\\\
  2101.                         Title = 'Save...',\\\
  2102.                         Click = function()\\\
  2103.                             SaveDocument()\\\
  2104.                         end,\\\
  2105.                         Keys = {\\\
  2106.                             keys.leftCtrl,\\\
  2107.                             keys.s\\\
  2108.                         },\\\
  2109.                         Enabled = function()\\\
  2110.                             return Current.Document ~= nil\\\
  2111.                         end\\\
  2112.                     },\\\
  2113.                     {\\\
  2114.                         Separator = true\\\
  2115.                     },\\\
  2116.                     {\\\
  2117.                         Title = 'Print...',\\\
  2118.                         Click = function()\\\
  2119.                             PrintDocument()\\\
  2120.                         end,\\\
  2121.                         Keys = {\\\
  2122.                             keys.leftCtrl,\\\
  2123.                             keys.p\\\
  2124.                         },\\\
  2125.                         Enabled = function()\\\
  2126.                             return true\\\
  2127.                         end\\\
  2128.                     },\\\
  2129.                     {\\\
  2130.                         Separator = true\\\
  2131.                     },\\\
  2132.                     {\\\
  2133.                         Title = 'Quit',\\\
  2134.                         Click = function()\\\
  2135.                             if Close() and OneOS then\\\
  2136.                                 OneOS.Close()\\\
  2137.                             end\\\
  2138.                         end,\\\
  2139.                         Keys = {\\\
  2140.                             keys.leftCtrl,\\\
  2141.                             keys.q\\\
  2142.                         }\\\
  2143.                     },\\\
  2144.             --[[\\\
  2145.                     {\\\
  2146.                         Title = 'Save As...',\\\
  2147.                         Click = function()\\\
  2148. \\\
  2149.                         end\\\
  2150.                     }   \\\
  2151.             ]]--\\\
  2152.                 }, self, true)\\\
  2153.             else\\\
  2154.                 Current.Menu = nil\\\
  2155.             end\\\
  2156.             return true \\\
  2157.         end, 'File', colours.lightGrey, false),\\\
  2158.         Button:Initialise(7, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
  2159.             if not self.Toggle then\\\
  2160.                 Menu:New(7, 2, {\\\
  2161.             --[[\\\
  2162.                     {\\\
  2163.                         Title = \\\"Undo\\\",\\\
  2164.                         Click = function()\\\
  2165.                         end,\\\
  2166.                         Keys = {\\\
  2167.                             keys.leftCtrl,\\\
  2168.                             keys.z\\\
  2169.                         },\\\
  2170.                         Enabled = function()\\\
  2171.                             return false\\\
  2172.                         end\\\
  2173.                     },\\\
  2174.                     {\\\
  2175.                         Title = 'Redo',\\\
  2176.                         Click = function()\\\
  2177.                             \\\
  2178.                         end,\\\
  2179.                         Keys = {\\\
  2180.                             keys.leftCtrl,\\\
  2181.                             keys.y\\\
  2182.                         },\\\
  2183.                         Enabled = function()\\\
  2184.                             return false\\\
  2185.                         end\\\
  2186.                     },\\\
  2187.                     {\\\
  2188.                         Separator = true\\\
  2189.                     },\\\
  2190.             ]]--\\\
  2191.                     {\\\
  2192.                         Title = 'Cut',\\\
  2193.                         Click = function()\\\
  2194.                             Clipboard.Cut(Current.Document.TextInput:Extract(true), 'text')\\\
  2195.                         end,\\\
  2196.                         Keys = {\\\
  2197.                             keys.leftCtrl,\\\
  2198.                             keys.x\\\
  2199.                         },\\\
  2200.                         Enabled = function()\\\
  2201.                             return Current.Document ~= nil and Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil\\\
  2202.                         end\\\
  2203.                     },\\\
  2204.                     {\\\
  2205.                         Title = 'Copy',\\\
  2206.                         Click = function()\\\
  2207.                             Clipboard.Copy(Current.Document.TextInput:Extract(), 'text')\\\
  2208.                         end,\\\
  2209.                         Keys = {\\\
  2210.                             keys.leftCtrl,\\\
  2211.                             keys.c\\\
  2212.                         },\\\
  2213.                         Enabled = function()\\\
  2214.                             return Current.Document ~= nil and Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil\\\
  2215.                         end\\\
  2216.                     },\\\
  2217.                     {\\\
  2218.                         Title = 'Paste',\\\
  2219.                         Click = function()\\\
  2220.                             local paste = Clipboard.Paste()\\\
  2221.                             Current.Document.TextInput:Insert(paste)\\\
  2222.                             Current.Document.TextInput.CursorPos = Current.Document.TextInput.CursorPos + #paste - 1\\\
  2223.                         end,\\\
  2224.                         Keys = {\\\
  2225.                             keys.leftCtrl,\\\
  2226.                             keys.v\\\
  2227.                         },\\\
  2228.                         Enabled = function()\\\
  2229.                             return Current.Document ~= nil and (not Clipboard.isEmpty()) and Clipboard.Type == 'text'\\\
  2230.                         end\\\
  2231.                     },\\\
  2232.                     {\\\
  2233.                         Separator = true,   \\\
  2234.                     },\\\
  2235.                     {\\\
  2236.                         Title = 'Select All',\\\
  2237.                         Click = function()\\\
  2238.                             Current.Selection = {1, #Current.Document.TextInput.Value:gsub('\\\\n','')}\\\
  2239.                         end,\\\
  2240.                         Keys = {\\\
  2241.                             keys.leftCtrl,\\\
  2242.                             keys.a\\\
  2243.                         },\\\
  2244.                         Enabled = function()\\\
  2245.                             return Current.Document ~= nil\\\
  2246.                         end\\\
  2247.                     }\\\
  2248.                 }, self, true)\\\
  2249.             else\\\
  2250.                 Current.Menu = nil\\\
  2251.             end\\\
  2252.             return true \\\
  2253.         end, 'Edit', colours.lightGrey, false),\\\
  2254.         Button:Initialise(13, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
  2255.             if not self.Toggle then\\\
  2256.                 Menu:New(13, 2, {\\\
  2257.                     {\\\
  2258.                         Title = 'Red',\\\
  2259.                         Click = function(item)\\\
  2260.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2261.                         end,\\\
  2262.                         Colour = colours.red,\\\
  2263.                         Enabled = function()\\\
  2264.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2265.                         end\\\
  2266.                     },\\\
  2267.                     {\\\
  2268.                         Title = 'Orange',\\\
  2269.                         Click = function(item)\\\
  2270.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2271.                         end,\\\
  2272.                         Colour = colours.orange,\\\
  2273.                         Enabled = function()\\\
  2274.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2275.                         end\\\
  2276.                     },\\\
  2277.                     {\\\
  2278.                         Title = 'Yellow',\\\
  2279.                         Click = function(item)\\\
  2280.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2281.                         end,\\\
  2282.                         Colour = colours.yellow,\\\
  2283.                         Enabled = function()\\\
  2284.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2285.                         end\\\
  2286.                     },\\\
  2287.                     {\\\
  2288.                         Title = 'Pink',\\\
  2289.                         Click = function(item)\\\
  2290.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2291.                         end,\\\
  2292.                         Colour = colours.pink,\\\
  2293.                         Enabled = function()\\\
  2294.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2295.                         end\\\
  2296.                     },\\\
  2297.                     {\\\
  2298.                         Title = 'Magenta',\\\
  2299.                         Click = function(item)\\\
  2300.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2301.                         end,\\\
  2302.                         Colour = colours.magenta,\\\
  2303.                         Enabled = function()\\\
  2304.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2305.                         end\\\
  2306.                     },\\\
  2307.                     {\\\
  2308.                         Title = 'Purple',\\\
  2309.                         Click = function(item)\\\
  2310.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2311.                         end,\\\
  2312.                         Colour = colours.purple,\\\
  2313.                         Enabled = function()\\\
  2314.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2315.                         end\\\
  2316.                     },\\\
  2317.                     {\\\
  2318.                         Title = 'Light Blue',\\\
  2319.                         Click = function(item)\\\
  2320.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2321.                         end,\\\
  2322.                         Colour = colours.lightBlue,\\\
  2323.                         Enabled = function()\\\
  2324.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2325.                         end\\\
  2326.                     },\\\
  2327.                     {\\\
  2328.                         Title = 'Cyan',\\\
  2329.                         Click = function(item)\\\
  2330.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2331.                         end,\\\
  2332.                         Colour = colours.cyan,\\\
  2333.                         Enabled = function()\\\
  2334.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2335.                         end\\\
  2336.                     },\\\
  2337.                     {\\\
  2338.                         Title = 'Blue',\\\
  2339.                         Click = function(item)\\\
  2340.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2341.                         end,\\\
  2342.                         Colour = colours.blue,\\\
  2343.                         Enabled = function()\\\
  2344.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2345.                         end\\\
  2346.                     },\\\
  2347.                     {\\\
  2348.                         Title = 'Green',\\\
  2349.                         Click = function(item)\\\
  2350.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2351.                         end,\\\
  2352.                         Colour = colours.green,\\\
  2353.                         Enabled = function()\\\
  2354.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2355.                         end\\\
  2356.                     },\\\
  2357.                     {\\\
  2358.                         Title = 'Light Grey',\\\
  2359.                         Click = function(item)\\\
  2360.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2361.                         end,\\\
  2362.                         Colour = colours.lightGrey,\\\
  2363.                         Enabled = function()\\\
  2364.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2365.                         end\\\
  2366.                     },\\\
  2367.                     {\\\
  2368.                         Title = 'Grey',\\\
  2369.                         Click = function(item)\\\
  2370.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2371.                         end,\\\
  2372.                         Colour = colours.grey,\\\
  2373.                         Enabled = function()\\\
  2374.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2375.                         end\\\
  2376.                     },\\\
  2377.                     {\\\
  2378.                         Title = 'Black',\\\
  2379.                         Click = function(item)\\\
  2380.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2381.                         end,\\\
  2382.                         Colour = colours.black,\\\
  2383.                         Enabled = function()\\\
  2384.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2385.                         end\\\
  2386.                     },\\\
  2387.                     {\\\
  2388.                         Title = 'Brown',\\\
  2389.                         Click = function(item)\\\
  2390.                             Current.Document:SetSelectionColour(item.Colour)\\\
  2391.                         end,\\\
  2392.                         Colour = colours.brown,\\\
  2393.                         Enabled = function()\\\
  2394.                             return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
  2395.                         end\\\
  2396.                     }\\\
  2397.                 }, self, true)\\\
  2398.             else\\\
  2399.                 Current.Menu = nil\\\
  2400.             end\\\
  2401.             return true \\\
  2402.         end, 'Colour', colours.lightGrey, false)\\\
  2403.     })\\\
  2404. end\\\
  2405. \\\
  2406. function SplashScreen()\\\
  2407.     local w = colours.white\\\
  2408.     local b = colours.black\\\
  2409.     local u = colours.blue\\\
  2410.     local lb = colours.lightBlue\\\
  2411.     local splashIcon = {{w,w,w,b,w,w,w,b,w,w,w,},{w,w,w,b,w,w,w,b,w,w,w,},{w,w,w,b,u,u,u,b,w,w,w,},{w,b,b,u,u,u,u,u,b,b,w,},{b,u,u,lb,lb,u,u,u,u,u,b,},{b,u,lb,lb,u,u,u,u,u,u,b,},{b,u,lb,lb,u,u,u,u,u,u,b,},{b,u,u,u,u,u,u,u,u,u,b,},{w,b,b,b,b,b,b,b,b,b,w,},\\\
  2412.     [\\\"text\\\"]={{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\"I\\\",\\\"n\\\",\\\"k\\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\"b\\\",\\\"y\\\",\\\" \\\",\\\"o\\\",\\\"e\\\",\\\"e\\\",\\\"d\\\",\\\" \\\",\\\" \\\"},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},},\\\
  2413.     [\\\"textcol\\\"]={{w,w,w,w,w,w,w,w,w,w,w,},{w,w,w,w,w,w,w,w,w,w,w,},{w,w,w,w,w,w,w,w,w,w,w,},{w,w,w,w,w,w,w,w,w,w,w,},{w,w,w,w,w,w,w,w,w,w,w,},{w,w,w,w,w,w,w,w,w,w,w,},{w,w,w,w,w,w,w,w,w,w,w,},{lb,lb,lb,lb,lb,lb,lb,lb,lb,lb,lb,},{w,w,w,w,w,w,w,w,w,w,w,},},}\\\
  2414.     Drawing.Clear(colours.white)\\\
  2415.     Drawing.DrawImage((Drawing.Screen.Width - 11)/2, (Drawing.Screen.Height - 9)/2, splashIcon, 11, 9)\\\
  2416.     Drawing.DrawBuffer()\\\
  2417.     Drawing.Clear(colours.black)\\\
  2418.     parallel.waitForAny(function()sleep(1)end, function()os.pullEvent('mouse_click')end)\\\
  2419. end\\\
  2420. \\\
  2421. function Initialise(arg)\\\
  2422.     if OneOS then\\\
  2423.         fs = OneOS.FS\\\
  2424.     end\\\
  2425. \\\
  2426.     if not OneOS then\\\
  2427.         SplashScreen()\\\
  2428.     end\\\
  2429.     EventRegister('mouse_click', TryClick)\\\
  2430.     EventRegister('mouse_drag', function(event, side, x, y)TryClick(event, side, x, y, true)end)\\\
  2431.     EventRegister('mouse_scroll', Scroll)\\\
  2432.     EventRegister('key', HandleKey)\\\
  2433.     EventRegister('char', HandleKey)\\\
  2434.     EventRegister('timer', Timer)\\\
  2435.     EventRegister('terminate', function(event) if Close() then error( \\\"Terminated\\\", 0 ) end end)\\\
  2436.     \\\
  2437.     LoadMenuBar()\\\
  2438. \\\
  2439.     --Current.Document = Document:Initialise('abcdefghijklmnopqrtuvwxy')--'Hello everybody!')\\\
  2440.     if tArgs[1] then\\\
  2441.         if fs.exists(tArgs[1]) then\\\
  2442.             OpenDocument(tArgs[1])\\\
  2443.         else\\\
  2444.             --new\\\
  2445.         end\\\
  2446.     else\\\
  2447.         Current.Document = Document:Initialise('')--'Hello everybody!')\\\
  2448.     end\\\
  2449. \\\
  2450.     --[[\\\
  2451.     if arg and fs.exists(arg) then\\\
  2452.             OpenDocument(arg)\\\
  2453.         else\\\
  2454.             DisplayNewDocumentWindow()\\\
  2455.         end\\\
  2456.     ]]--\\\
  2457.     Draw()\\\
  2458. \\\
  2459.     EventHandler()\\\
  2460. end\\\
  2461. \\\
  2462. local isControlPushed = false\\\
  2463. controlPushedTimer = nil\\\
  2464. closeWindowTimer = nil\\\
  2465. function Timer(event, timer)\\\
  2466.     if timer == closeWindowTimer then\\\
  2467.         if Current.Window then\\\
  2468.             Current.Window:Close()\\\
  2469.         end\\\
  2470.         Draw()\\\
  2471.     elseif timer == controlPushedTimer then\\\
  2472.         isControlPushed = false\\\
  2473.     end\\\
  2474. end\\\
  2475. \\\
  2476. local ignoreNextChar = false\\\
  2477. function HandleKey(...)\\\
  2478.     local args = {...}\\\
  2479.     local event = args[1]\\\
  2480.     local keychar = args[2]\\\
  2481.                                                                                             --Mac left command character\\\
  2482.     if event == 'key' and keychar == keys.leftCtrl or keychar == keys.rightCtrl or keychar == 219 then\\\
  2483.         isControlPushed = true\\\
  2484.         controlPushedTimer = os.startTimer(0.5)\\\
  2485.     elseif isControlPushed then\\\
  2486.         if event == 'key' then\\\
  2487.             if CheckKeyboardShortcut(keychar) then\\\
  2488.                 isControlPushed = false\\\
  2489.                 ignoreNextChar = true\\\
  2490.             end\\\
  2491.         end\\\
  2492.     elseif ignoreNextChar then\\\
  2493.         ignoreNextChar = false\\\
  2494.     elseif Current.TextInput then\\\
  2495.         if event == 'char' then\\\
  2496.             Current.TextInput:Char(keychar)\\\
  2497.         elseif event == 'key' then\\\
  2498.             Current.TextInput:Key(keychar)\\\
  2499.         end\\\
  2500.     end\\\
  2501. end\\\
  2502. \\\
  2503. function CheckKeyboardShortcut(key)\\\
  2504.     local shortcuts = {}\\\
  2505.     shortcuts[keys.n] = function() Current.Document = Document:Initialise('') end\\\
  2506.     shortcuts[keys.o] = function() DisplayOpenDocumentWindow() end\\\
  2507.     shortcuts[keys.s] = function() if Current.Document ~= nil then SaveDocument() end end\\\
  2508.     shortcuts[keys.left] = function() if Current.TextInput then Current.TextInput:Key(keys.home) end end\\\
  2509.     shortcuts[keys.right] = function() if Current.TextInput then Current.TextInput:Key(keys[\\\"end\\\"]) end end\\\
  2510. --  shortcuts[keys.q] = function() DisplayOpenDocumentWindow() end\\\
  2511.     if Current.Document ~= nil then\\\
  2512.         shortcuts[keys.s] = function() SaveDocument() end\\\
  2513.         shortcuts[keys.p] = function() PrintDocument() end\\\
  2514.         if Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil then\\\
  2515.             shortcuts[keys.x] = function() Clipboard.Cut(Current.Document.TextInput:Extract(true), 'text') end\\\
  2516.             shortcuts[keys.c] = function() Clipboard.Copy(Current.Document.TextInput:Extract(), 'text') end\\\
  2517.         end\\\
  2518.         if (not Clipboard.isEmpty()) and Clipboard.Type == 'text' then\\\
  2519.             shortcuts[keys.v] = function() local paste = Clipboard.Paste()\\\
  2520.                                     Current.Document.TextInput:Insert(paste)\\\
  2521.                                     Current.Document.TextInput.CursorPos = Current.Document.TextInput.CursorPos + #paste - 1\\\
  2522.                                 end\\\
  2523.         end\\\
  2524.         shortcuts[keys.a] = function() Current.Selection = {1, #Current.Document.TextInput.Value:gsub('\\\\n','')} end\\\
  2525.     end\\\
  2526.                             \\\
  2527.     if shortcuts[key] then\\\
  2528.         shortcuts[key]()\\\
  2529.         Draw()\\\
  2530.         return true\\\
  2531.     else\\\
  2532.         return false\\\
  2533.     end\\\
  2534. end\\\
  2535. \\\
  2536. --[[\\\
  2537.     Check if the given object falls under the click coordinates\\\
  2538. ]]--\\\
  2539. function CheckClick(object, x, y)\\\
  2540.     if object.X <= x and object.Y <= y and object.X + object.Width > x and object.Y + object.Height > y then\\\
  2541.         return true\\\
  2542.     end\\\
  2543. end\\\
  2544. \\\
  2545. --[[\\\
  2546.     Attempt to clicka given object\\\
  2547. ]]--\\\
  2548. function DoClick(object, side, x, y, drag)\\\
  2549.     local obj = GetAbsolutePosition(object)\\\
  2550.     obj.Width = object.Width\\\
  2551.     obj.Height = object.Height\\\
  2552.     if object and CheckClick(obj, x, y) then\\\
  2553.         return object:Click(side, x - object.X + 1, y - object.Y + 1, drag)\\\
  2554.     end \\\
  2555. end\\\
  2556. \\\
  2557. --[[\\\
  2558.     Try to click at the given coordinates\\\
  2559. ]]--\\\
  2560. function TryClick(event, side, x, y, drag)\\\
  2561.     if Current.Menu then\\\
  2562.         if DoClick(Current.Menu, side, x, y, drag) then\\\
  2563.             Draw()\\\
  2564.             return\\\
  2565.         else\\\
  2566.             if Current.Menu.Owner and Current.Menu.Owner.Toggle then\\\
  2567.                 Current.Menu.Owner.Toggle = false\\\
  2568.             end\\\
  2569.             Current.Menu = nil\\\
  2570.             Draw()\\\
  2571.             return\\\
  2572.         end\\\
  2573.     elseif Current.Window then\\\
  2574.         if DoClick(Current.Window, side, x, y, drag) then\\\
  2575.             Draw()\\\
  2576.             return\\\
  2577.         else\\\
  2578.             Current.Window:Flash()\\\
  2579.             return\\\
  2580.         end\\\
  2581.     end\\\
  2582.     local interfaceElements = {}\\\
  2583. \\\
  2584.     table.insert(interfaceElements, Current.MenuBar)\\\
  2585.     table.insert(interfaceElements, Current.ScrollBar)\\\
  2586.     for i, page in ipairs(Current.Document.Pages) do\\\
  2587.         table.insert(interfaceElements, page)\\\
  2588.     end\\\
  2589. \\\
  2590.     for i, object in ipairs(interfaceElements) do\\\
  2591.         if DoClick(object, side, x, y, drag) then\\\
  2592.             Draw()\\\
  2593.             return\\\
  2594.         end     \\\
  2595.     end\\\
  2596.     Draw()\\\
  2597. end\\\
  2598. \\\
  2599. function Scroll(event, direction, x, y)\\\
  2600.     if Current.Window and Current.Window.OpenButton then\\\
  2601.         Current.Document.Scroll = Current.Document.Scroll + direction\\\
  2602.         if Current.Window.Scroll < 0 then\\\
  2603.             Current.Window.Scroll = 0\\\
  2604.         elseif Current.Window.Scroll > Current.Window.MaxScroll then\\\
  2605.             Current.Window.Scroll = Current.Window.MaxScroll\\\
  2606.         end\\\
  2607.         Draw()\\\
  2608.     elseif Current.ScrollBar then\\\
  2609.         if Current.ScrollBar:DoScroll(direction*2) then\\\
  2610.             Draw()\\\
  2611.         end\\\
  2612.     end\\\
  2613. end\\\
  2614. \\\
  2615. \\\
  2616. --[[\\\
  2617.     Registers functions to run on certain events\\\
  2618. ]]--\\\
  2619. function EventRegister(event, func)\\\
  2620.     if not Events[event] then\\\
  2621.         Events[event] = {}\\\
  2622.     end\\\
  2623. \\\
  2624.     table.insert(Events[event], func)\\\
  2625. end\\\
  2626. \\\
  2627. --[[\\\
  2628.     The main loop event handler, runs registered event functinos\\\
  2629. ]]--\\\
  2630. function EventHandler()\\\
  2631.     while true do\\\
  2632.         local event, arg1, arg2, arg3, arg4 = os.pullEventRaw()\\\
  2633.         if Events[event] then\\\
  2634.             for i, e in ipairs(Events[event]) do\\\
  2635.                 e(event, arg1, arg2, arg3, arg4)\\\
  2636.             end\\\
  2637.         end\\\
  2638.     end\\\
  2639. end\\\
  2640. \\\
  2641. \\\
  2642. local function Extension(path, addDot)\\\
  2643.     if not path then\\\
  2644.         return nil\\\
  2645.     elseif not string.find(fs.getName(path), '%.') then\\\
  2646.         if not addDot then\\\
  2647.             return fs.getName(path)\\\
  2648.         else\\\
  2649.             return ''\\\
  2650.         end\\\
  2651.     else\\\
  2652.         local _path = path\\\
  2653.         if path:sub(#path) == '/' then\\\
  2654.             _path = path:sub(1,#path-1)\\\
  2655.         end\\\
  2656.         local extension = _path:gmatch('%.[0-9a-z]+$')()\\\
  2657.         if extension then\\\
  2658.             extension = extension:sub(2)\\\
  2659.         else\\\
  2660.             --extension = nil\\\
  2661.             return ''\\\
  2662.         end\\\
  2663.         if addDot then\\\
  2664.             extension = '.'..extension\\\
  2665.         end\\\
  2666.         return extension:lower()\\\
  2667.     end\\\
  2668. end\\\
  2669. \\\
  2670. local RemoveExtension = function(path)\\\
  2671.     if path:sub(1,1) == '.' then\\\
  2672.         return path\\\
  2673.     end\\\
  2674.     local extension = Extension(path)\\\
  2675.     if extension == path then\\\
  2676.         return fs.getName(path)\\\
  2677.     end\\\
  2678.     return string.gsub(path, extension, ''):sub(1, -2)\\\
  2679. end\\\
  2680. \\\
  2681. local acknowledgedColour = false\\\
  2682. function PrintDocument()\\\
  2683.     if OneOS then\\\
  2684.         OneOS.LoadAPI('/System/API/Helpers.lua')\\\
  2685.         OneOS.LoadAPI('/System/API/Peripheral.lua')\\\
  2686.         OneOS.LoadAPI('/System/API/Printer.lua')\\\
  2687.     end\\\
  2688. \\\
  2689.     local doPrint = function()\\\
  2690.         local window = PrintDocumentWindow:Initialise():Show()\\\
  2691.     end\\\
  2692. \\\
  2693.     if Peripheral.GetPeripheral('printer') == nil then\\\
  2694.         ButtonDialougeWindow:Initialise('No Printer Found', 'Please place a printer next to your computer. Ensure you also insert dye (left slot) and paper (top slots)', 'Ok', nil, function(window, ok)\\\
  2695.             window:Close()\\\
  2696.         end):Show()\\\
  2697.     elseif not acknowledgedColour and FindColours(Current.Document.TextInput.Value) ~= 0 then\\\
  2698.         ButtonDialougeWindow:Initialise('Important', 'Due to the way printers work, you can\\\\'t print in more than one colour. The dye you use will be the colour of the text.', 'Ok', nil, function(window, ok)\\\
  2699.             acknowledgedColour = true\\\
  2700.             window:Close()\\\
  2701.             doPrint()\\\
  2702.         end):Show()\\\
  2703.     else\\\
  2704.         doPrint()\\\
  2705.     end\\\
  2706. end\\\
  2707. \\\
  2708. function SaveDocument()\\\
  2709.     local function save()\\\
  2710.         local h = fs.open(Current.Document.Path, 'w')\\\
  2711.         if h then\\\
  2712.             if Current.Document.Format == TextFormatPlainText then\\\
  2713.                 h.write(Current.Document.TextInput.Value)\\\
  2714.             else\\\
  2715.                 local lines = {}\\\
  2716.                 for p, page in ipairs(Current.Document.Pages) do\\\
  2717.                     for i, line in ipairs(page.Lines) do\\\
  2718.                         table.insert(lines, line)\\\
  2719.                     end\\\
  2720.                 end\\\
  2721.                 h.write(textutils.serialize(lines))\\\
  2722.             end\\\
  2723.             Current.Modified = false\\\
  2724.         else\\\
  2725.             ButtonDialougeWindow:Initialise('Error', 'An error occured while saving the file, try again.', 'Ok', nil, function(window, ok)\\\
  2726.                 window:Close()\\\
  2727.             end):Show()\\\
  2728.         end\\\
  2729.         h.close()\\\
  2730.     end\\\
  2731. \\\
  2732.     if not Current.Document.Path then\\\
  2733.         SaveDocumentWindow:Initialise(function(self, success, path)\\\
  2734.             self:Close()\\\
  2735.             if success then\\\
  2736.                 local extension = ''\\\
  2737.                 if Current.Document.Format == TextFormatPlainText then\\\
  2738.                     extension = '.txt'\\\
  2739.                 elseif Current.Document.Format == TextFormatInkText then\\\
  2740.                     extension = '.ink'\\\
  2741.                 end\\\
  2742.                 \\\
  2743.                 if path:sub(-4) ~= extension then\\\
  2744.                     path = path .. extension\\\
  2745.                 end\\\
  2746. \\\
  2747.                 Current.Document.Path = path\\\
  2748.                 Current.Document.Title = fs.getName(path)\\\
  2749.                 save()\\\
  2750.             end\\\
  2751.             if Current.Document then\\\
  2752.                 Current.TextInput = Current.Document.TextInput\\\
  2753.             end\\\
  2754.         end):Show()\\\
  2755.     else\\\
  2756.         save()\\\
  2757.     end\\\
  2758. end\\\
  2759. \\\
  2760. function DisplayOpenDocumentWindow()\\\
  2761.     OpenDocumentWindow:Initialise(function(self, success, path)\\\
  2762.         self:Close()\\\
  2763.         if success then\\\
  2764.             OpenDocument(path)\\\
  2765.         end\\\
  2766.     end):Show()\\\
  2767. end\\\
  2768. \\\
  2769. function OpenDocument(path)\\\
  2770.     Current.Selection = nil\\\
  2771.     local h = fs.open(path, 'r')\\\
  2772.     if h then\\\
  2773.         Current.Document = Document:Initialise(h.readAll(), RemoveExtension(fs.getName(path)), path)\\\
  2774.     else\\\
  2775.         ButtonDialougeWindow:Initialise('Error', 'An error occured while opening the file, try again.', 'Ok', nil, function(window, ok)\\\
  2776.             window:Close()\\\
  2777.             if Current.Document then\\\
  2778.                 Current.TextInput = Current.Document.TextInput\\\
  2779.             end\\\
  2780.         end):Show()\\\
  2781.     end\\\
  2782.     h.close()\\\
  2783. end\\\
  2784. \\\
  2785. local TidyPath = function(path)\\\
  2786.     path = '/'..path\\\
  2787.     local fs = fs\\\
  2788.     if OneOS then\\\
  2789.         fs = OneOS.FS\\\
  2790.     end\\\
  2791.     if fs.isDir(path) then\\\
  2792.         path = path .. '/'\\\
  2793.     end\\\
  2794. \\\
  2795.     path, n = path:gsub(\\\"//\\\", \\\"/\\\")\\\
  2796.     while n > 0 do\\\
  2797.         path, n = path:gsub(\\\"//\\\", \\\"/\\\")\\\
  2798.     end\\\
  2799.     return path\\\
  2800. end\\\
  2801. \\\
  2802. OpenDocumentWindow = {\\\
  2803.     X = 1,\\\
  2804.     Y = 1,\\\
  2805.     Width = 0,\\\
  2806.     Height = 0,\\\
  2807.     CursorPos = 1,\\\
  2808.     Visible = true,\\\
  2809.     Return = nil,\\\
  2810.     OpenButton = nil,\\\
  2811.     PathTextBox = nil,\\\
  2812.     CurrentDirectory = '/',\\\
  2813.     Scroll = 0,\\\
  2814.     MaxScroll = 0,\\\
  2815.     GoUpButton = nil,\\\
  2816.     SelectedFile = '',\\\
  2817.     Files = {},\\\
  2818.     Typed = false,\\\
  2819. \\\
  2820.     AbsolutePosition = function(self)\\\
  2821.         return {X = self.X, Y = self.Y}\\\
  2822.     end,\\\
  2823. \\\
  2824.     Draw = function(self)\\\
  2825.         if not self.Visible then\\\
  2826.             return\\\
  2827.         end\\\
  2828.         Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
  2829.         Drawing.DrawBlankArea(self.X, self.Y, self.Width, 3, colours.lightGrey)\\\
  2830.         Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-6, colours.white)\\\
  2831.         Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
  2832.         Drawing.DrawBlankArea(self.X, self.Y + self.Height - 5, self.Width, 5, colours.lightGrey)\\\
  2833.         self:DrawFiles()\\\
  2834. \\\
  2835.         if (fs.exists(self.PathTextBox.TextInput.Value)) or (self.SelectedFile and #self.SelectedFile > 0 and fs.exists(self.CurrentDirectory .. self.SelectedFile)) then\\\
  2836.             self.OpenButton.TextColour = colours.black\\\
  2837.         else\\\
  2838.             self.OpenButton.TextColour = colours.lightGrey\\\
  2839.         end\\\
  2840. \\\
  2841.         self.PathTextBox:Draw()\\\
  2842.         self.OpenButton:Draw()\\\
  2843.         self.CancelButton:Draw()\\\
  2844.         self.GoUpButton:Draw()\\\
  2845.     end,\\\
  2846. \\\
  2847.     DrawFiles = function(self)\\\
  2848.         for i, file in ipairs(self.Files) do\\\
  2849.             if i > self.Scroll and i - self.Scroll <= 11 then\\\
  2850.                 if file == self.SelectedFile then\\\
  2851.                     Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.white, colours.lightBlue)\\\
  2852.                 elseif string.find(file, '%.txt') or string.find(file, '%.text') or string.find(file, '%.ink') or fs.isDir(self.CurrentDirectory .. file) then\\\
  2853.                     Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.black, colours.white)\\\
  2854.                 else\\\
  2855.                     Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.grey, colours.white)\\\
  2856.                 end\\\
  2857.             end\\\
  2858.         end\\\
  2859.         self.MaxScroll = #self.Files - 11\\\
  2860.         if self.MaxScroll < 0 then\\\
  2861.             self.MaxScroll = 0\\\
  2862.         end\\\
  2863.     end,\\\
  2864. \\\
  2865.     Initialise = function(self, returnFunc)\\\
  2866.         local new = {}    -- the new instance\\\
  2867.         setmetatable( new, {__index = self} )\\\
  2868.         new.Width = 32\\\
  2869.         new.Height = 17\\\
  2870.         new.Return = returnFunc\\\
  2871.         new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
  2872.         new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
  2873.         new.Title = 'Open Document'\\\
  2874.         new.Visible = true\\\
  2875.         new.CurrentDirectory = '/'\\\
  2876.         new.SelectedFile = nil\\\
  2877.         if OneOS and fs.exists('/Desktop/Documents/') then\\\
  2878.             new.CurrentDirectory = '/Desktop/Documents/'\\\
  2879.         end\\\
  2880.         new.OpenButton = Button:Initialise(new.Width - 6, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
  2881.             if fs.exists(new.PathTextBox.TextInput.Value) and self.TextColour == colours.black and not fs.isDir(new.PathTextBox.TextInput.Value) then\\\
  2882.                 returnFunc(new, true, TidyPath(new.PathTextBox.TextInput.Value))\\\
  2883.             elseif new.SelectedFile and self.TextColour == colours.black and fs.isDir(new.CurrentDirectory .. new.SelectedFile) then\\\
  2884.                 new:GoToDirectory(new.CurrentDirectory .. new.SelectedFile)\\\
  2885.             elseif new.SelectedFile and self.TextColour == colours.black then\\\
  2886.                 returnFunc(new, true, TidyPath(new.CurrentDirectory .. '/' .. new.SelectedFile))\\\
  2887.             end\\\
  2888.         end, 'Open', colours.black)\\\
  2889.         new.CancelButton = Button:Initialise(new.Width - 15, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
  2890.             returnFunc(new, false)\\\
  2891.         end, 'Cancel', colours.black)\\\
  2892.         new.GoUpButton = Button:Initialise(2, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
  2893.             local folderName = fs.getName(new.CurrentDirectory)\\\
  2894.             local parentDirectory = new.CurrentDirectory:sub(1, #new.CurrentDirectory-#folderName-1)\\\
  2895.             new:GoToDirectory(parentDirectory)\\\
  2896.         end, 'Go Up', colours.black)\\\
  2897.         new.PathTextBox = TextBox:Initialise(2, new.Height - 3, new.Width - 2, 1, new, new.CurrentDirectory, colours.white, colours.black)\\\
  2898.         new:GoToDirectory(new.CurrentDirectory)\\\
  2899.         return new\\\
  2900.     end,\\\
  2901. \\\
  2902.     Show = function(self)\\\
  2903.         Current.Window = self\\\
  2904.         return self\\\
  2905.     end,\\\
  2906. \\\
  2907.     Close = function(self)\\\
  2908.         Current.Input = nil\\\
  2909.         Current.Window = nil\\\
  2910.         self = nil\\\
  2911.     end,\\\
  2912. \\\
  2913.     GoToDirectory = function(self, path)\\\
  2914.         path = TidyPath(path)\\\
  2915.         self.CurrentDirectory = path\\\
  2916.         self.Scroll = 0\\\
  2917.         self.SelectedFile = nil\\\
  2918.         self.Typed = false\\\
  2919.         self.PathTextBox.TextInput.Value = path\\\
  2920.         local fs = fs\\\
  2921.         if OneOS then\\\
  2922.             fs = OneOS.FS\\\
  2923.         end\\\
  2924.         self.Files = fs.list(self.CurrentDirectory)\\\
  2925.         Draw()\\\
  2926.     end,\\\
  2927. \\\
  2928.     Flash = function(self)\\\
  2929.         self.Visible = false\\\
  2930.         Draw()\\\
  2931.         sleep(0.15)\\\
  2932.         self.Visible = true\\\
  2933.         Draw()\\\
  2934.         sleep(0.15)\\\
  2935.         self.Visible = false\\\
  2936.         Draw()\\\
  2937.         sleep(0.15)\\\
  2938.         self.Visible = true\\\
  2939.         Draw()\\\
  2940.     end,\\\
  2941. \\\
  2942.     Click = function(self, side, x, y)\\\
  2943.         local items = {self.OpenButton, self.CancelButton, self.PathTextBox, self.GoUpButton}\\\
  2944.         local found = false\\\
  2945.         for i, v in ipairs(items) do\\\
  2946.             if CheckClick(v, x, y) then\\\
  2947.                 v:Click(side, x, y)\\\
  2948.                 found = true\\\
  2949.             end\\\
  2950.         end\\\
  2951. \\\
  2952.         if not found then\\\
  2953.             if y <= 12 then\\\
  2954.                 local fs = fs\\\
  2955.                 if OneOS then\\\
  2956.                     fs = OneOS.FS\\\
  2957.                 end\\\
  2958.                 self.SelectedFile = fs.list(self.CurrentDirectory)[y-1]\\\
  2959.                 self.PathTextBox.TextInput.Value = TidyPath(self.CurrentDirectory .. '/' .. self.SelectedFile)\\\
  2960.                 Draw()\\\
  2961.             end\\\
  2962.         end\\\
  2963.         return true\\\
  2964.     end\\\
  2965. }\\\
  2966. \\\
  2967. PrintDocumentWindow = {\\\
  2968.     X = 1,\\\
  2969.     Y = 1,\\\
  2970.     Width = 0,\\\
  2971.     Height = 0,\\\
  2972.     CursorPos = 1,\\\
  2973.     Visible = true,\\\
  2974.     Return = nil,\\\
  2975.     PrintButton = nil,\\\
  2976.     CopiesTextBox = nil,\\\
  2977.     Scroll = 0,\\\
  2978.     MaxScroll = 0,\\\
  2979.     PrinterSelectButton = nil,\\\
  2980.     Title = '',\\\
  2981.     Status = 0, --0 = neutral, 1 = good, -1 = error\\\
  2982.     StatusText = '',\\\
  2983.     SelectedPrinter = nil,\\\
  2984. \\\
  2985.     AbsolutePosition = function(self)\\\
  2986.         return {X = self.X, Y = self.Y}\\\
  2987.     end,\\\
  2988. \\\
  2989.     Draw = function(self)\\\
  2990.         if not self.Visible then\\\
  2991.             return\\\
  2992.         end\\\
  2993.         Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
  2994.         Drawing.DrawBlankArea(self.X, self.Y, self.Width, 1, colours.lightGrey)\\\
  2995.         Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-1, colours.white)\\\
  2996.         Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
  2997.         \\\
  2998.         self.PrinterSelectButton:Draw()\\\
  2999.         Drawing.DrawCharactersCenter(self.X,  self.Y + self.PrinterSelectButton.Y - 2, self.Width, 1, 'Printer', colours.black, colours.white)\\\
  3000.         Drawing.DrawCharacters(self.X + self.Width - 3, self.Y + self.PrinterSelectButton.Y - 1, '\\\\\\\\/', colours.black, colours.lightGrey)\\\
  3001.         Drawing.DrawCharacters(self.X + 1, self.Y + self.CopiesTextBox.Y - 1, 'Copies', colours.black, colours.white)\\\
  3002.         local statusColour = colours.grey\\\
  3003.         if self.Status == -1 then\\\
  3004.             statusColour = colours.red\\\
  3005.         elseif self.Status == 1 then\\\
  3006.             statusColour = colours.green\\\
  3007.         end\\\
  3008.         Drawing.DrawCharacters(self.X + 1, self.Y + self.CopiesTextBox.Y + 1, self.StatusText, statusColour, colours.white)\\\
  3009. \\\
  3010.         self.CopiesTextBox:Draw()\\\
  3011.         self.PrintButton:Draw()\\\
  3012.         self.CancelButton:Draw()\\\
  3013.     end,\\\
  3014. \\\
  3015.     Initialise = function(self)\\\
  3016.         local new = {}    -- the new instance\\\
  3017.         setmetatable( new, {__index = self} )\\\
  3018.         new.Width = 32\\\
  3019.         new.Height = 11\\\
  3020.         new.Return = returnFunc\\\
  3021.         new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
  3022.         new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
  3023.         new.Title = 'Print Document'\\\
  3024.         new.Visible = true\\\
  3025.         new.PrintButton = Button:Initialise(new.Width - 7, new.Height - 1, nil, nil, colours.lightGrey, new, function(self, side, x, y, toggle)\\\
  3026.             local doPrint = true\\\
  3027.             if new.SelectedPrinter == nil then\\\
  3028.                 local p = Peripheral.GetPeripheral('printer')\\\
  3029.                 if p then\\\
  3030.                     new.SelectedPrinter = p.Side\\\
  3031.                     new.PrinterSelectButton.Text = p.Fullname\\\
  3032.                 else\\\
  3033.                     new.StatusText = 'No Connected Printer'\\\
  3034.                     new.Status = -1\\\
  3035.                     doPrint = false\\\
  3036.                 end\\\
  3037.             end\\\
  3038.             if doPrint then\\\
  3039.                 local printer = Printer:Initialise(new.SelectedPrinter)\\\
  3040.                 local err = printer:PrintLines(Current.Document.Lines, Current.Document.Title, tonumber(new.CopiesTextBox.TextInput.Value))\\\
  3041.                 if not err then\\\
  3042.                     new.StatusText = 'Document Printed!'\\\
  3043.                     new.Status = 1\\\
  3044.                     closeWindowTimer = os.startTimer(1)\\\
  3045.                 else\\\
  3046.                     new.StatusText = err\\\
  3047.                     new.Status = -1\\\
  3048.                 end\\\
  3049.             end\\\
  3050.         end, 'Print', colours.black)\\\
  3051.         new.CancelButton = Button:Initialise(new.Width - 15, new.Height - 1, nil, nil, colours.lightGrey, new, function(self, side, x, y, toggle)\\\
  3052.             new:Close()\\\
  3053.             Draw()\\\
  3054.         end, 'Close', colours.black)\\\
  3055.         new.PrinterSelectButton = Button:Initialise(2, 4, new.Width - 2, nil, colours.lightGrey, new, function(self, side, x, y, toggle)\\\
  3056.             local printers = {\\\
  3057.                     {\\\
  3058.                         Title = \\\"Automatic\\\",\\\
  3059.                         Click = function()\\\
  3060.                             new.SelectedPrinter = nil\\\
  3061.                             new.PrinterSelectButton.Text = 'Automatic'\\\
  3062.                         end\\\
  3063.                     },\\\
  3064.                     {\\\
  3065.                         Separator = true\\\
  3066.                     }\\\
  3067.                 }\\\
  3068.             for i, p in ipairs(Peripheral.GetPeripherals('printer')) do\\\
  3069.                 table.insert(printers, {\\\
  3070.                     Title = p.Fullname,\\\
  3071.                     Click = function(self)\\\
  3072.                         new.SelectedPrinter = p.Side\\\
  3073.                         new.PrinterSelectButton.Text = p.Fullname\\\
  3074.                     end\\\
  3075.                 })\\\
  3076.             end\\\
  3077.             Current.Menu = Menu:New(x, y+4, printers, self, true)\\\
  3078.         end, 'Automatic', colours.black)\\\
  3079.         new.CopiesTextBox = TextBox:Initialise(9, 6, 4, 1, new, 1, colours.lightGrey, colours.black, nil, true)\\\
  3080.         Current.TextInput = new.CopiesTextBox.TextInput\\\
  3081.         new.StatusText = 'Waiting...'\\\
  3082.         new.Status = 0\\\
  3083.         return new\\\
  3084.     end,\\\
  3085. \\\
  3086.     Show = function(self)\\\
  3087.         Current.Window = self\\\
  3088.         return self\\\
  3089.     end,\\\
  3090. \\\
  3091.     Close = function(self)\\\
  3092.         Current.Input = nil\\\
  3093.         Current.Window = nil\\\
  3094.         self = nil\\\
  3095.     end,\\\
  3096. \\\
  3097.     Flash = function(self)\\\
  3098.         self.Visible = false\\\
  3099.         Draw()\\\
  3100.         sleep(0.15)\\\
  3101.         self.Visible = true\\\
  3102.         Draw()\\\
  3103.         sleep(0.15)\\\
  3104.         self.Visible = false\\\
  3105.         Draw()\\\
  3106.         sleep(0.15)\\\
  3107.         self.Visible = true\\\
  3108.         Draw()\\\
  3109.     end,\\\
  3110. \\\
  3111.     Click = function(self, side, x, y)\\\
  3112.         local items = {self.PrintButton, self.CancelButton, self.CopiesTextBox, self.PrinterSelectButton}\\\
  3113.         for i, v in ipairs(items) do\\\
  3114.             if CheckClick(v, x, y) then\\\
  3115.                 v:Click(side, x, y)\\\
  3116.             end\\\
  3117.         end\\\
  3118.         return true\\\
  3119.     end\\\
  3120. }\\\
  3121. \\\
  3122. SaveDocumentWindow = {\\\
  3123.     X = 1,\\\
  3124.     Y = 1,\\\
  3125.     Width = 0,\\\
  3126.     Height = 0,\\\
  3127.     CursorPos = 1,\\\
  3128.     Visible = true,\\\
  3129.     Return = nil,\\\
  3130.     SaveButton = nil,\\\
  3131.     PathTextBox = nil,\\\
  3132.     CurrentDirectory = '/',\\\
  3133.     Scroll = 0,\\\
  3134.     MaxScroll = 0,\\\
  3135.     ScrollBar = nil,\\\
  3136.     GoUpButton = nil,\\\
  3137.     Files = {},\\\
  3138.     Typed = false,\\\
  3139. \\\
  3140.     AbsolutePosition = function(self)\\\
  3141.         return {X = self.X, Y = self.Y}\\\
  3142.     end,\\\
  3143. \\\
  3144.     Draw = function(self)\\\
  3145.         if not self.Visible then\\\
  3146.             return\\\
  3147.         end\\\
  3148.         Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
  3149.         Drawing.DrawBlankArea(self.X, self.Y, self.Width, 3, colours.lightGrey)\\\
  3150.         Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-6, colours.white)\\\
  3151.         Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
  3152.         Drawing.DrawBlankArea(self.X, self.Y + self.Height - 5, self.Width, 5, colours.lightGrey)\\\
  3153.         Drawing.DrawCharacters(self.X + 1, self.Y + self.Height - 5, self.CurrentDirectory, colours.grey, colours.lightGrey)\\\
  3154.         self:DrawFiles()\\\
  3155. \\\
  3156.         if (self.PathTextBox.TextInput.Value) then\\\
  3157.             self.SaveButton.TextColour = colours.black\\\
  3158.         else\\\
  3159.             self.SaveButton.TextColour = colours.lightGrey\\\
  3160.         end\\\
  3161. \\\
  3162.         self.PathTextBox:Draw()\\\
  3163.         self.SaveButton:Draw()\\\
  3164.         self.CancelButton:Draw()\\\
  3165.         self.GoUpButton:Draw()\\\
  3166.     end,\\\
  3167. \\\
  3168.     DrawFiles = function(self)\\\
  3169.         for i, file in ipairs(self.Files) do\\\
  3170.             if i > self.Scroll and i - self.Scroll <= 10 then\\\
  3171.                 if file == self.SelectedFile then\\\
  3172.                     Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.white, colours.lightBlue)\\\
  3173.                 elseif fs.isDir(self.CurrentDirectory .. file) then\\\
  3174.                     Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.black, colours.white)\\\
  3175.                 else\\\
  3176.                     Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.lightGrey, colours.white)\\\
  3177.                 end\\\
  3178.             end\\\
  3179.         end\\\
  3180.         self.MaxScroll = #self.Files - 11\\\
  3181.         if self.MaxScroll < 0 then\\\
  3182.             self.MaxScroll = 0\\\
  3183.         end\\\
  3184.     end,\\\
  3185. \\\
  3186.     Initialise = function(self, returnFunc)\\\
  3187.         local new = {}    -- the new instance\\\
  3188.         setmetatable( new, {__index = self} )\\\
  3189.         new.Width = 32\\\
  3190.         new.Height = 16\\\
  3191.         new.Return = returnFunc\\\
  3192.         new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
  3193.         new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
  3194.         new.Title = 'Save Document'\\\
  3195.         new.Visible = true\\\
  3196.         new.CurrentDirectory = '/'\\\
  3197.         if OneOS and fs.exists('/Desktop/Documents/') then\\\
  3198.             new.CurrentDirectory = '/Desktop/Documents/'\\\
  3199.         end\\\
  3200.         new.SaveButton = Button:Initialise(new.Width - 6, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
  3201.             if self.TextColour == colours.black and not fs.isDir(new.CurrentDirectory ..'/' .. new.PathTextBox.TextInput.Value) then\\\
  3202.                 returnFunc(new, true, TidyPath(new.CurrentDirectory ..'/' .. new.PathTextBox.TextInput.Value))\\\
  3203.             elseif new.SelectedFile and self.TextColour == colours.black and fs.isDir(new.CurrentDirectory .. new.SelectedFile) then\\\
  3204.                 new:GoToDirectory(new.CurrentDirectory .. new.SelectedFile)\\\
  3205.             end\\\
  3206.         end, 'Save', colours.black)\\\
  3207.         new.CancelButton = Button:Initialise(new.Width - 15, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
  3208.             returnFunc(new, false)\\\
  3209.         end, 'Cancel', colours.black)\\\
  3210.         new.GoUpButton = Button:Initialise(2, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
  3211.             local folderName = fs.getName(new.CurrentDirectory)\\\
  3212.             local parentDirectory = new.CurrentDirectory:sub(1, #new.CurrentDirectory-#folderName-1)\\\
  3213.             new:GoToDirectory(parentDirectory)\\\
  3214.         end, 'Go Up', colours.black)\\\
  3215.         new.PathTextBox = TextBox:Initialise(2, new.Height - 3, new.Width - 2, 1, new, '', colours.white, colours.black, function(key)\\\
  3216.             if key == keys.enter then\\\
  3217.                 new.SaveButton:Click()\\\
  3218.             end\\\
  3219.         end)\\\
  3220.         new.PathTextBox.Placeholder = 'Document Name'\\\
  3221.         Current.TextInput = new.PathTextBox.TextInput\\\
  3222.         new:GoToDirectory(new.CurrentDirectory)\\\
  3223.         return new\\\
  3224.     end,\\\
  3225. \\\
  3226.     Show = function(self)\\\
  3227.         Current.Window = self\\\
  3228.         return self\\\
  3229.     end,\\\
  3230. \\\
  3231.     Close = function(self)\\\
  3232.         Current.Input = nil\\\
  3233.         Current.Window = nil\\\
  3234.         self = nil\\\
  3235.     end,\\\
  3236. \\\
  3237.     GoToDirectory = function(self, path)\\\
  3238.         path = TidyPath(path)\\\
  3239.         self.CurrentDirectory = path\\\
  3240.         self.Scroll = 0\\\
  3241.         self.Typed = false\\\
  3242.         local fs = fs\\\
  3243.         if OneOS then\\\
  3244.             fs = OneOS.FS\\\
  3245.         end\\\
  3246.         self.Files = fs.list(self.CurrentDirectory)\\\
  3247.         Draw()\\\
  3248.     end,\\\
  3249. \\\
  3250.     Flash = function(self)\\\
  3251.         self.Visible = false\\\
  3252.         Draw()\\\
  3253.         sleep(0.15)\\\
  3254.         self.Visible = true\\\
  3255.         Draw()\\\
  3256.         sleep(0.15)\\\
  3257.         self.Visible = false\\\
  3258.         Draw()\\\
  3259.         sleep(0.15)\\\
  3260.         self.Visible = true\\\
  3261.         Draw()\\\
  3262.     end,\\\
  3263. \\\
  3264.     Click = function(self, side, x, y)\\\
  3265.         local items = {self.SaveButton, self.CancelButton, self.PathTextBox, self.GoUpButton}\\\
  3266.         local found = false\\\
  3267.         for i, v in ipairs(items) do\\\
  3268.             if CheckClick(v, x, y) then\\\
  3269.                 v:Click(side, x, y)\\\
  3270.                 found = true\\\
  3271.             end\\\
  3272.         end\\\
  3273. \\\
  3274.         if not found then\\\
  3275.             if y <= 11 then\\\
  3276.                 local files = fs.list(self.CurrentDirectory)\\\
  3277.                 if files[y-1] then\\\
  3278.                     self:GoToDirectory(self.CurrentDirectory..files[y-1])\\\
  3279.                     Draw()\\\
  3280.                 end\\\
  3281.             end\\\
  3282.         end\\\
  3283.         return true\\\
  3284.     end\\\
  3285. }\\\
  3286. \\\
  3287. local WrapText = function(text, maxWidth)\\\
  3288.     local lines = {''}\\\
  3289.    for word, space in text:gmatch('(%S+)(%s*)') do\\\
  3290.            local temp = lines[#lines] .. word .. space:gsub('\\\\n','')\\\
  3291.            if #temp > maxWidth then\\\
  3292.                    table.insert(lines, '')\\\
  3293.            end\\\
  3294.            if space:find('\\\\n') then\\\
  3295.                    lines[#lines] = lines[#lines] .. word\\\
  3296.                    \\\
  3297.                    space = space:gsub('\\\\n', function()\\\
  3298.                            table.insert(lines, '')\\\
  3299.                            return ''\\\
  3300.                    end)\\\
  3301.            else\\\
  3302.                    lines[#lines] = lines[#lines] .. word .. space\\\
  3303.            end\\\
  3304.    end\\\
  3305.     return lines\\\
  3306. end\\\
  3307. \\\
  3308. ButtonDialougeWindow = {\\\
  3309.     X = 1,\\\
  3310.     Y = 1,\\\
  3311.     Width = 0,\\\
  3312.     Height = 0,\\\
  3313.     CursorPos = 1,\\\
  3314.     Visible = true,\\\
  3315.     CancelButton = nil,\\\
  3316.     OkButton = nil,\\\
  3317.     Lines = {},\\\
  3318. \\\
  3319.     AbsolutePosition = function(self)\\\
  3320.         return {X = self.X, Y = self.Y}\\\
  3321.     end,\\\
  3322. \\\
  3323.     Draw = function(self)\\\
  3324.         if not self.Visible then\\\
  3325.             return\\\
  3326.         end\\\
  3327.         Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
  3328.         Drawing.DrawBlankArea(self.X, self.Y, self.Width, 1, colours.lightGrey)\\\
  3329.         Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-1, colours.white)\\\
  3330.         Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
  3331. \\\
  3332.         for i, text in ipairs(self.Lines) do\\\
  3333.             Drawing.DrawCharacters(self.X + 1, self.Y + 1 + i, text, colours.black, colours.white)\\\
  3334.         end\\\
  3335. \\\
  3336.         self.OkButton:Draw()\\\
  3337.         if self.CancelButton then\\\
  3338.             self.CancelButton:Draw()\\\
  3339.         end\\\
  3340.     end,\\\
  3341. \\\
  3342.     Initialise = function(self, title, message, okText, cancelText, returnFunc)\\\
  3343.         local new = {}    -- the new instance\\\
  3344.         setmetatable( new, {__index = self} )\\\
  3345.         new.Width = 28\\\
  3346.         new.Lines = WrapText(message, new.Width - 2)\\\
  3347.         new.Height = 5 + #new.Lines\\\
  3348.         new.Return = returnFunc\\\
  3349.         new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
  3350.         new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
  3351.         new.Title = title\\\
  3352.         new.Visible = true\\\
  3353.         new.Visible = true\\\
  3354.         new.OkButton = Button:Initialise(new.Width - #okText - 2, new.Height - 1, nil, 1, nil, new, function()\\\
  3355.             returnFunc(new, true)\\\
  3356.         end, okText)\\\
  3357.         if cancelText then\\\
  3358.             new.CancelButton = Button:Initialise(new.Width - #okText - 2 - 1 - #cancelText - 2, new.Height - 1, nil, 1, nil, new, function()\\\
  3359.                 returnFunc(new, false)\\\
  3360.             end, cancelText)\\\
  3361.         end\\\
  3362. \\\
  3363.         return new\\\
  3364.     end,\\\
  3365. \\\
  3366.     Show = function(self)\\\
  3367.         Current.Window = self\\\
  3368.         return self\\\
  3369.     end,\\\
  3370. \\\
  3371.     Close = function(self)\\\
  3372.         Current.Window = nil\\\
  3373.         self = nil\\\
  3374.     end,\\\
  3375. \\\
  3376.     Flash = function(self)\\\
  3377.         self.Visible = false\\\
  3378.         Draw()\\\
  3379.         sleep(0.15)\\\
  3380.         self.Visible = true\\\
  3381.         Draw()\\\
  3382.         sleep(0.15)\\\
  3383.         self.Visible = false\\\
  3384.         Draw()\\\
  3385.         sleep(0.15)\\\
  3386.         self.Visible = true\\\
  3387.         Draw()\\\
  3388.     end,\\\
  3389. \\\
  3390.     Click = function(self, side, x, y)\\\
  3391.         local items = {self.OkButton, self.CancelButton}\\\
  3392.         local found = false\\\
  3393.         for i, v in ipairs(items) do\\\
  3394.             if CheckClick(v, x, y) then\\\
  3395.                 v:Click(side, x, y)\\\
  3396.                 found = true\\\
  3397.             end\\\
  3398.         end\\\
  3399.         return true\\\
  3400.     end\\\
  3401. }\\\
  3402. \\\
  3403. TextDialougeWindow = {\\\
  3404.     X = 1,\\\
  3405.     Y = 1,\\\
  3406.     Width = 0,\\\
  3407.     Height = 0,\\\
  3408.     CursorPos = 1,\\\
  3409.     Visible = true,\\\
  3410.     CancelButton = nil,\\\
  3411.     OkButton = nil,\\\
  3412.     Lines = {},\\\
  3413.     TextInput = nil,\\\
  3414. \\\
  3415.     AbsolutePosition = function(self)\\\
  3416.         return {X = self.X, Y = self.Y}\\\
  3417.     end,\\\
  3418. \\\
  3419.     Draw = function(self)\\\
  3420.         if not self.Visible then\\\
  3421.             return\\\
  3422.         end\\\
  3423.         Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
  3424.         Drawing.DrawBlankArea(self.X, self.Y, self.Width, 1, colours.lightGrey)\\\
  3425.         Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-1, colours.white)\\\
  3426.         Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
  3427. \\\
  3428.         for i, text in ipairs(self.Lines) do\\\
  3429.             Drawing.DrawCharacters(self.X + 1, self.Y + 1 + i, text, colours.black, colours.white)\\\
  3430.         end\\\
  3431. \\\
  3432. \\\
  3433.         Drawing.DrawBlankArea(self.X + 1, self.Y + self.Height - 4, self.Width - 2, 1, colours.lightGrey)\\\
  3434.         Drawing.DrawCharacters(self.X + 2, self.Y + self.Height - 4, self.TextInput.Value, colours.black, colours.lightGrey)\\\
  3435.         Current.CursorPos = {self.X + 2 + self.TextInput.CursorPos, self.Y + self.Height - 4}\\\
  3436.         Current.CursorColour = colours.black\\\
  3437. \\\
  3438.         self.OkButton:Draw()\\\
  3439.         if self.CancelButton then\\\
  3440.             self.CancelButton:Draw()\\\
  3441.         end\\\
  3442.     end,\\\
  3443. \\\
  3444.     Initialise = function(self, title, message, okText, cancelText, returnFunc, numerical)\\\
  3445.         local new = {}    -- the new instance\\\
  3446.         setmetatable( new, {__index = self} )\\\
  3447.         new.Width = 28\\\
  3448.         new.Lines = WrapText(message, new.Width - 2)\\\
  3449.         new.Height = 7 + #new.Lines\\\
  3450.         new.Return = returnFunc\\\
  3451.         new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
  3452.         new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
  3453.         new.Title = title\\\
  3454.         new.Visible = true\\\
  3455.         new.Visible = true\\\
  3456.         new.OkButton = Button:Initialise(new.Width - #okText - 2, new.Height - 1, nil, 1, nil, new, function()\\\
  3457.             if #new.TextInput.Value > 0 then\\\
  3458.                 returnFunc(new, true, new.TextInput.Value)\\\
  3459.             end\\\
  3460.         end, okText)\\\
  3461.         if cancelText then\\\
  3462.             new.CancelButton = Button:Initialise(new.Width - #okText - 2 - 1 - #cancelText - 2, new.Height - 1, nil, 1, nil, new, function()\\\
  3463.                 returnFunc(new, false)\\\
  3464.             end, cancelText)\\\
  3465.         end\\\
  3466.         new.TextInput = TextInput:Initialise('', function(enter)\\\
  3467.             if enter then\\\
  3468.                 new.OkButton:Click()\\\
  3469.             end\\\
  3470.             Draw()\\\
  3471.         end, numerical)\\\
  3472. \\\
  3473.         Current.Input = new.TextInput\\\
  3474. \\\
  3475.         return new\\\
  3476.     end,\\\
  3477. \\\
  3478.     Show = function(self)\\\
  3479.         Current.Window = self\\\
  3480.         return self\\\
  3481.     end,\\\
  3482. \\\
  3483.     Close = function(self)\\\
  3484.         Current.Window = nil\\\
  3485.         Current.Input = nil\\\
  3486.         self = nil\\\
  3487.     end,\\\
  3488. \\\
  3489.     Flash = function(self)\\\
  3490.         self.Visible = false\\\
  3491.         Draw()\\\
  3492.         sleep(0.15)\\\
  3493.         self.Visible = true\\\
  3494.         Draw()\\\
  3495.         sleep(0.15)\\\
  3496.         self.Visible = false\\\
  3497.         Draw()\\\
  3498.         sleep(0.15)\\\
  3499.         self.Visible = true\\\
  3500.         Draw()\\\
  3501.     end,\\\
  3502. \\\
  3503.     Click = function(self, side, x, y)\\\
  3504.         local items = {self.OkButton, self.CancelButton}\\\
  3505.         local found = false\\\
  3506.         for i, v in ipairs(items) do\\\
  3507.             if CheckClick(v, x, y) then\\\
  3508.                 v:Click(side, x, y)\\\
  3509.                 found = true\\\
  3510.             end\\\
  3511.         end\\\
  3512.         return true\\\
  3513.     end\\\
  3514. }\\\
  3515. \\\
  3516. function PrintCentered(text, y)\\\
  3517.    local w, h = term.getSize()\\\
  3518.    x = math.ceil(math.ceil((w / 2) - (#text / 2)), 0)+1\\\
  3519.    term.setCursorPos(x, y)\\\
  3520.    print(text)\\\
  3521. end\\\
  3522. \\\
  3523. function DoVanillaClose()\\\
  3524. shell.run(\\\"/system/apps/drawer\\\")\\\
  3525. end\\\
  3526. \\\
  3527. function Close()\\\
  3528.     if isQuitting or not Current.Document or not Current.Modified then\\\
  3529.         if not OneOS then\\\
  3530.             DoVanillaClose()\\\
  3531.         end\\\
  3532.         return true\\\
  3533.     else\\\
  3534.         local _w = ButtonDialougeWindow:Initialise('Quit Ink?', 'You have unsaved changes, do you want to quit anyway?', 'Quit', 'Cancel', function(window, success)\\\
  3535.             if success then\\\
  3536.                 if OneOS then\\\
  3537.                     OneOS.Close(true)\\\
  3538.                 else\\\
  3539.                     DoVanillaClose()\\\
  3540.                 end\\\
  3541.             end\\\
  3542.             window:Close()\\\
  3543.             Draw()\\\
  3544.         end):Show()\\\
  3545.         --it's hacky but it works\\\
  3546.         os.queueEvent('mouse_click', 1, _w.X, _w.Y)\\\
  3547.         return false\\\
  3548.     end\\\
  3549. end\\\
  3550. \\\
  3551. if OneOS then\\\
  3552.     OneOS.CanClose = function()\\\
  3553.         return Close()\\\
  3554.     end\\\
  3555. end\\\
  3556. \\\
  3557. Initialise()\",\
  3558.    path = \"/rootfs/apps/Ink.app/main\",\
  3559.  },\
  3560.  {\
  3561.    text = \" 0c-80-80-80-80-80\\\
  3562. 08-80I80n80k80-80\\\
  3563. 0c-80-80-80-80-80\\\
  3564. 08-80-80-80-80-80\",\
  3565.    path = \"/rootfs/apps/Ink.app/resources/icon.png\",\
  3566.  },\
  3567.  {\
  3568.    text = \"\\\
  3569. --  \\\
  3570. --  Lua IDE\\\
  3571. --  Made by GravityScore\\\
  3572. --  \\\
  3573. \\\
  3574. \\\
  3575. --  -------- Variables\\\
  3576. \\\
  3577. -- Version\\\
  3578. local version = \\\"1.0\\\"\\\
  3579. local args = {...}\\\
  3580. \\\
  3581. -- Editing\\\
  3582. local w, h = term.getSize()\\\
  3583. local tabWidth = 2\\\
  3584. \\\
  3585. local autosaveInterval = 20\\\
  3586. local allowEditorEvent = true\\\
  3587. local keyboardShortcutTimeout = 0.4\\\
  3588. \\\
  3589. -- Clipboard\\\
  3590. local clipboard = nil\\\
  3591. \\\
  3592. -- Theme\\\
  3593. local theme = {}\\\
  3594. \\\
  3595. -- Language\\\
  3596. local languages = {}\\\
  3597. local curLanguage = {}\\\
  3598. \\\
  3599. -- Events\\\
  3600. local event_distract = \\\"luaide_distractionEvent\\\"\\\
  3601. \\\
  3602. -- Locations\\\
  3603. local updateURL = \\\"https://raw.github.com/GravityScore/LuaIDE/master/luaide.lua\\\"\\\
  3604. local ideLocation = \\\"/\\\" .. shell.getRunningProgram()\\\
  3605. local themeLocation = \\\"/.LuaIDE-Theme\\\"\\\
  3606. \\\
  3607. local function isAdvanced() return term.isColor and term.isColor() end\\\
  3608. \\\
  3609. \\\
  3610. --  -------- Utilities\\\
  3611. \\\
  3612. local function modRead(properties)\\\
  3613.     local w, h = term.getSize()\\\
  3614.     local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil, \\\
  3615.         liveUpdates = nil, exitOnKey = nil}\\\
  3616.     if not properties then properties = {} end\\\
  3617.     for k, v in pairs(defaults) do if not properties[k] then properties[k] = v end end\\\
  3618.     if properties.replaceChar then properties.replaceChar = properties.replaceChar:sub(1, 1) end\\\
  3619.     if not properties.visibleLength then properties.visibleLength = w end\\\
  3620. \\\
  3621.     local sx, sy = term.getCursorPos()\\\
  3622.     local line = \\\"\\\"\\\
  3623.     local pos = 0\\\
  3624.     local historyPos = nil\\\
  3625. \\\
  3626.     local function redraw(repl)\\\
  3627.         local scroll = 0\\\
  3628.         if properties.visibleLength and sx + pos > properties.visibleLength + 1 then \\\
  3629.             scroll = (sx + pos) - (properties.visibleLength + 1)\\\
  3630.         end\\\
  3631. \\\
  3632.         term.setCursorPos(sx, sy)\\\
  3633.         local a = repl or properties.replaceChar\\\
  3634.         if a then term.write(string.rep(a, line:len() - scroll))\\\
  3635.         else term.write(line:sub(scroll + 1, -1)) end\\\
  3636.         term.setCursorPos(sx + pos - scroll, sy)\\\
  3637.     end\\\
  3638. \\\
  3639.     local function sendLiveUpdates(event, ...)\\\
  3640.         if type(properties.liveUpdates) == \\\"function\\\" then\\\
  3641.             local ox, oy = term.getCursorPos()\\\
  3642.             local a, data = properties.liveUpdates(line, event, ...)\\\
  3643.             if a == true and data == nil then\\\
  3644.                 term.setCursorBlink(false)\\\
  3645.                 return line\\\
  3646.             elseif a == true and data ~= nil then\\\
  3647.                 term.setCursorBlink(false)\\\
  3648.                 return data\\\
  3649.             end\\\
  3650.             term.setCursorPos(ox, oy)\\\
  3651.         end\\\
  3652.     end\\\
  3653. \\\
  3654.     term.setCursorBlink(true)\\\
  3655.     while true do\\\
  3656.         local e, but, x, y, p4, p5 = os.pullEvent()\\\
  3657. \\\
  3658.         if e == \\\"char\\\" then\\\
  3659.             local s = false\\\
  3660.             if properties.textLength and line:len() < properties.textLength then s = true\\\
  3661.             elseif not properties.textLength then s = true end\\\
  3662. \\\
  3663.             local canType = true\\\
  3664.             if not properties.grantPrint and properties.refusePrint then\\\
  3665.                 local canTypeKeys = {}\\\
  3666.                 if type(properties.refusePrint) == \\\"table\\\" then\\\
  3667.                     for _, v in pairs(properties.refusePrint) do\\\
  3668.                         table.insert(canTypeKeys, tostring(v):sub(1, 1))\\\
  3669.                     end\\\
  3670.                 elseif type(properties.refusePrint) == \\\"string\\\" then\\\
  3671.                     for char in properties.refusePrint:gmatch(\\\".\\\") do\\\
  3672.                         table.insert(canTypeKeys, char)\\\
  3673.                     end\\\
  3674.                 end\\\
  3675.                 for _, v in pairs(canTypeKeys) do if but == v then canType = false end end\\\
  3676.             elseif properties.grantPrint then\\\
  3677.                 canType = false\\\
  3678.                 local canTypeKeys = {}\\\
  3679.                 if type(properties.grantPrint) == \\\"table\\\" then\\\
  3680.                     for _, v in pairs(properties.grantPrint) do\\\
  3681.                         table.insert(canTypeKeys, tostring(v):sub(1, 1))\\\
  3682.                     end\\\
  3683.                 elseif type(properties.grantPrint) == \\\"string\\\" then\\\
  3684.                     for char in properties.grantPrint:gmatch(\\\".\\\") do\\\
  3685.                         table.insert(canTypeKeys, char)\\\
  3686.                     end\\\
  3687.                 end\\\
  3688.                 for _, v in pairs(canTypeKeys) do if but == v then canType = true end end\\\
  3689.             end\\\
  3690. \\\
  3691.             if s and canType then\\\
  3692.                 line = line:sub(1, pos) .. but .. line:sub(pos + 1, -1)\\\
  3693.                 pos = pos + 1\\\
  3694.                 redraw()\\\
  3695.             end\\\
  3696.         elseif e == \\\"key\\\" then\\\
  3697.             if but == keys.enter then break\\\
  3698.             elseif but == keys.left then if pos > 0 then pos = pos - 1 redraw() end\\\
  3699.             elseif but == keys.right then if pos < line:len() then pos = pos + 1 redraw() end\\\
  3700.             elseif (but == keys.up or but == keys.down) and properties.history then\\\
  3701.                 redraw(\\\" \\\")\\\
  3702.                 if but == keys.up then\\\
  3703.                     if historyPos == nil and #properties.history > 0 then \\\
  3704.                         historyPos = #properties.history\\\
  3705.                     elseif historyPos > 1 then \\\
  3706.                         historyPos = historyPos - 1\\\
  3707.                     end\\\
  3708.                 elseif but == keys.down then\\\
  3709.                     if historyPos == #properties.history then historyPos = nil\\\
  3710.                     elseif historyPos ~= nil then historyPos = historyPos + 1 end\\\
  3711.                 end\\\
  3712. \\\
  3713.                 if properties.history and historyPos then\\\
  3714.                     line = properties.history[historyPos]\\\
  3715.                     pos = line:len()\\\
  3716.                 else\\\
  3717.                     line = \\\"\\\"\\\
  3718.                     pos = 0\\\
  3719.                 end\\\
  3720. \\\
  3721.                 redraw()\\\
  3722.                 local a = sendLiveUpdates(\\\"history\\\")\\\
  3723.                 if a then return a end\\\
  3724.             elseif but == keys.backspace and pos > 0 then\\\
  3725.                 redraw(\\\" \\\")\\\
  3726.                 line = line:sub(1, pos - 1) .. line:sub(pos + 1, -1)\\\
  3727.                 pos = pos - 1\\\
  3728.                 redraw()\\\
  3729.                 local a = sendLiveUpdates(\\\"delete\\\")\\\
  3730.                 if a then return a end\\\
  3731.             elseif but == keys.home then\\\
  3732.                 pos = 0\\\
  3733.                 redraw()\\\
  3734.             elseif but == keys.delete and pos < line:len() then\\\
  3735.                 redraw(\\\" \\\")\\\
  3736.                 line = line:sub(1, pos) .. line:sub(pos + 2, -1)\\\
  3737.                 redraw()\\\
  3738.                 local a = sendLiveUpdates(\\\"delete\\\")\\\
  3739.                 if a then return a end\\\
  3740.             elseif but == keys[\\\"end\\\"] then\\\
  3741.                 pos = line:len()\\\
  3742.                 redraw()\\\
  3743.             elseif properties.exitOnKey then \\\
  3744.                 if but == properties.exitOnKey or (properties.exitOnKey == \\\"control\\\" and \\\
  3745.                         (but == 29 or but == 157)) then \\\
  3746.                     term.setCursorBlink(false)\\\
  3747.                     return nil\\\
  3748.                 end\\\
  3749.             end\\\
  3750.         end\\\
  3751.         local a = sendLiveUpdates(e, but, x, y, p4, p5)\\\
  3752.         if a then return a end\\\
  3753.     end\\\
  3754. \\\
  3755.     term.setCursorBlink(false)\\\
  3756.     if line ~= nil then line = line:gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\") end\\\
  3757.     return line\\\
  3758. end\\\
  3759. \\\
  3760. \\\
  3761. --  -------- Themes\\\
  3762. \\\
  3763. local defaultTheme = {\\\
  3764.     background = \\\"gray\\\",\\\
  3765.     backgroundHighlight = \\\"lightGray\\\",\\\
  3766.     prompt = \\\"cyan\\\",\\\
  3767.     promptHighlight = \\\"lightBlue\\\",\\\
  3768.     err = \\\"red\\\",\\\
  3769.     errHighlight = \\\"pink\\\",\\\
  3770. \\\
  3771.     editorBackground = \\\"gray\\\",\\\
  3772.     editorLineHightlight = \\\"lightBlue\\\",\\\
  3773.     editorLineNumbers = \\\"gray\\\",\\\
  3774.     editorLineNumbersHighlight = \\\"lightGray\\\",\\\
  3775.     editorError = \\\"pink\\\",\\\
  3776.     editorErrorHighlight = \\\"red\\\",\\\
  3777. \\\
  3778.     textColor = \\\"white\\\",\\\
  3779.     conditional = \\\"yellow\\\",\\\
  3780.     constant = \\\"orange\\\",\\\
  3781.     [\\\"function\\\"] = \\\"magenta\\\",\\\
  3782.     string = \\\"red\\\",\\\
  3783.     comment = \\\"lime\\\"\\\
  3784. }\\\
  3785. \\\
  3786. local normalTheme = {\\\
  3787.     background = \\\"black\\\",\\\
  3788.     backgroundHighlight = \\\"black\\\",\\\
  3789.     prompt = \\\"black\\\",\\\
  3790.     promptHighlight = \\\"black\\\",\\\
  3791.     err = \\\"black\\\",\\\
  3792.     errHighlight = \\\"black\\\",\\\
  3793. \\\
  3794.     editorBackground = \\\"black\\\",\\\
  3795.     editorLineHightlight = \\\"black\\\",\\\
  3796.     editorLineNumbers = \\\"black\\\",\\\
  3797.     editorLineNumbersHighlight = \\\"white\\\",\\\
  3798.     editorError = \\\"black\\\",\\\
  3799.     editorErrorHighlight = \\\"black\\\",\\\
  3800. \\\
  3801.     textColor = \\\"white\\\",\\\
  3802.     conditional = \\\"white\\\",\\\
  3803.     constant = \\\"white\\\",\\\
  3804.     [\\\"function\\\"] = \\\"white\\\",\\\
  3805.     string = \\\"white\\\",\\\
  3806.     comment = \\\"white\\\"\\\
  3807. }\\\
  3808. \\\
  3809. local availableThemes = {\\\
  3810.     {\\\"Water (Default)\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/default.txt\\\"},\\\
  3811.     {\\\"Fire\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/fire.txt\\\"},\\\
  3812.     {\\\"Sublime Text 2\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/st2.txt\\\"},\\\
  3813.     {\\\"Midnight\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/midnight.txt\\\"},\\\
  3814.     {\\\"TheOriginalBIT\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/bit.txt\\\"},\\\
  3815.     {\\\"Superaxander\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/superaxander.txt\\\"},\\\
  3816.     {\\\"Forest\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/forest.txt\\\"},\\\
  3817.     {\\\"Night\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/night.txt\\\"},\\\
  3818.     {\\\"Original\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/original.txt\\\"},\\\
  3819. }\\\
  3820. \\\
  3821. local function loadTheme(path)\\\
  3822.     local f = io.open(path)\\\
  3823.     local l = f:read(\\\"*l\\\")\\\
  3824.     local config = {}\\\
  3825.     while l ~= nil do\\\
  3826.         local k, v = string.match(l, \\\"^(%a+)=(%a+)\\\")\\\
  3827.         if k and v then config[k] = v end\\\
  3828.         l = f:read(\\\"*l\\\")\\\
  3829.     end\\\
  3830.     f:close()\\\
  3831.     return config\\\
  3832. end\\\
  3833. \\\
  3834. -- Load Theme\\\
  3835. if isAdvanced() then theme = defaultTheme\\\
  3836. else theme = normalTheme end\\\
  3837. \\\
  3838. \\\
  3839. --  -------- Drawing\\\
  3840. \\\
  3841. local function centerPrint(text, ny)\\\
  3842.     if type(text) == \\\"table\\\" then for _, v in pairs(text) do centerPrint(v) end\\\
  3843.     else\\\
  3844.         local x, y = term.getCursorPos()\\\
  3845.         local w, h = term.getSize()\\\
  3846.         term.setCursorPos(w/2 - text:len()/2 + (#text % 2 == 0 and 1 or 0), ny or y)\\\
  3847.         print(text)\\\
  3848.     end\\\
  3849. end\\\
  3850. \\\
  3851. local function title(t)\\\
  3852.     term.setTextColor(colors[theme.textColor])\\\
  3853.     term.setBackgroundColor(colors[theme.background])\\\
  3854.     term.clear()\\\
  3855. \\\
  3856.     term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
  3857.     for i = 2, 4 do term.setCursorPos(1, i) term.clearLine() end\\\
  3858.     term.setCursorPos(3, 3)\\\
  3859.     term.write(t)\\\
  3860. end\\\
  3861. \\\
  3862. local function centerRead(wid, begt)\\\
  3863.     local function liveUpdate(line, e, but, x, y, p4, p5)\\\
  3864.         if isAdvanced() and e == \\\"mouse_click\\\" and x >= w/2 - wid/2 and x <= w/2 - wid/2 + 10 \\\
  3865.                 and y >= 13 and y <= 15 then\\\
  3866.             return true, \\\"\\\"\\\
  3867.         end\\\
  3868.     end\\\
  3869. \\\
  3870.     if not begt then begt = \\\"\\\" end\\\
  3871.     term.setTextColor(colors[theme.textColor])\\\
  3872.     term.setBackgroundColor(colors[theme.promptHighlight])\\\
  3873.     for i = 8, 10 do\\\
  3874.         term.setCursorPos(w/2 - wid/2, i)\\\
  3875.         term.write(string.rep(\\\" \\\", wid))\\\
  3876.     end\\\
  3877. \\\
  3878.     if isAdvanced() then\\\
  3879.         term.setBackgroundColor(colors[theme.errHighlight])\\\
  3880.         for i = 13, 15 do\\\
  3881.             term.setCursorPos(w/2 - wid/2 + 1, i)\\\
  3882.             term.write(string.rep(\\\" \\\", 10))\\\
  3883.         end\\\
  3884.         term.setCursorPos(w/2 - wid/2 + 2, 14)\\\
  3885.         term.write(\\\"> Cancel\\\")\\\
  3886.     end\\\
  3887. \\\
  3888.     term.setBackgroundColor(colors[theme.promptHighlight])\\\
  3889.     term.setCursorPos(w/2 - wid/2 + 1, 9)\\\
  3890.     term.write(\\\"> \\\" .. begt)\\\
  3891.     return modRead({visibleLength = w/2 + wid/2, liveUpdates = liveUpdate})\\\
  3892. end\\\
  3893. \\\
  3894. \\\
  3895. --  -------- Prompt\\\
  3896. \\\
  3897. local function prompt(list, dir, isGrid)\\\
  3898.     local function draw(sel)\\\
  3899.         for i, v in ipairs(list) do\\\
  3900.             if i == sel then term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\\\
  3901.             else term.setBackgroundColor(v.bg or colors[theme.prompt]) end\\\
  3902.             term.setTextColor(v.tc or colors[theme.textColor])\\\
  3903.             for i = -1, 1 do\\\
  3904.                 term.setCursorPos(v[2], v[3] + i)\\\
  3905.                 term.write(string.rep(\\\" \\\", v[1]:len() + 4))\\\
  3906.             end\\\
  3907. \\\
  3908.             term.setCursorPos(v[2], v[3])\\\
  3909.             if i == sel then\\\
  3910.                 term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\\\
  3911.                 term.write(\\\" > \\\")\\\
  3912.             else term.write(\\\" - \\\") end\\\
  3913.             term.write(v[1] .. \\\" \\\")\\\
  3914.         end\\\
  3915.     end\\\
  3916. \\\
  3917.     local key1 = dir == \\\"horizontal\\\" and 203 or 200\\\
  3918.     local key2 = dir == \\\"horizontal\\\" and 205 or 208\\\
  3919.     local sel = 1\\\
  3920.     draw(sel)\\\
  3921. \\\
  3922.     while true do\\\
  3923.         local e, but, x, y = os.pullEvent()\\\
  3924.         if e == \\\"key\\\" and but == 28 then\\\
  3925.             return list[sel][1]\\\
  3926.         elseif e == \\\"key\\\" and but == key1 and sel > 1 then\\\
  3927.             sel = sel - 1\\\
  3928.             draw(sel)\\\
  3929.         elseif e == \\\"key\\\" and but == key2 and ((err == true and sel < #list - 1) or (sel < #list)) then\\\
  3930.             sel = sel + 1\\\
  3931.             draw(sel)\\\
  3932.         elseif isGrid and e == \\\"key\\\" and but == 203 and sel > 2 then\\\
  3933.             sel = sel - 2\\\
  3934.             draw(sel)\\\
  3935.         elseif isGrid and e == \\\"key\\\" and but == 205 and sel < 3 then\\\
  3936.             sel = sel + 2\\\
  3937.             draw(sel)\\\
  3938.         elseif e == \\\"mouse_click\\\" then\\\
  3939.             for i, v in ipairs(list) do\\\
  3940.                 if x >= v[2] - 1 and x <= v[2] + v[1]:len() + 3 and y >= v[3] - 1 and y <= v[3] + 1 then\\\
  3941.                     return list[i][1]\\\
  3942.                 end\\\
  3943.             end\\\
  3944.         end\\\
  3945.     end\\\
  3946. end\\\
  3947. \\\
  3948. local function scrollingPrompt(list)\\\
  3949.     local function draw(items, sel, loc)\\\
  3950.         for i, v in ipairs(items) do\\\
  3951.             local bg = colors[theme.prompt]\\\
  3952.             local bghigh = colors[theme.promptHighlight]\\\
  3953.             if v:find(\\\"Back\\\") or v:find(\\\"Return\\\") then\\\
  3954.                 bg = colors[theme.err]\\\
  3955.                 bghigh = colors[theme.errHighlight]\\\
  3956.             end\\\
  3957. \\\
  3958.             if i == sel then term.setBackgroundColor(bghigh)\\\
  3959.             else term.setBackgroundColor(bg) end\\\
  3960.             term.setTextColor(colors[theme.textColor])\\\
  3961.             for x = -1, 1 do\\\
  3962.                 term.setCursorPos(3, (i * 4) + x + 4)\\\
  3963.                 term.write(string.rep(\\\" \\\", w - 13))\\\
  3964.             end\\\
  3965. \\\
  3966.             term.setCursorPos(3, i * 4 + 4)\\\
  3967.             if i == sel then\\\
  3968.                 term.setBackgroundColor(bghigh)\\\
  3969.                 term.write(\\\" > \\\")\\\
  3970.             else term.write(\\\" - \\\") end\\\
  3971.             term.write(v .. \\\" \\\")\\\
  3972.         end\\\
  3973.     end\\\
  3974. \\\
  3975.     local function updateDisplayList(items, loc, len)\\\
  3976.         local ret = {}\\\
  3977.         for i = 1, len do\\\
  3978.             local item = items[i + loc - 1]\\\
  3979.             if item then table.insert(ret, item) end\\\
  3980.         end\\\
  3981.         return ret\\\
  3982.     end\\\
  3983. \\\
  3984.     -- Variables\\\
  3985.     local sel = 1\\\
  3986.     local loc = 1\\\
  3987.     local len = 3\\\
  3988.     local disList = updateDisplayList(list, loc, len)\\\
  3989.     draw(disList, sel, loc)\\\
  3990. \\\
  3991.     -- Loop\\\
  3992.     while true do\\\
  3993.         local e, key, x, y = os.pullEvent()\\\
  3994. \\\
  3995.         if e == \\\"mouse_click\\\" then\\\
  3996.             for i, v in ipairs(disList) do\\\
  3997.                 if x >= 3 and x <= w - 11 and y >= i * 4 + 3 and y <= i * 4 + 5 then return v end\\\
  3998.             end\\\
  3999.         elseif e == \\\"key\\\" and key == 200 then\\\
  4000.             if sel > 1 then\\\
  4001.                 sel = sel - 1\\\
  4002.                 draw(disList, sel, loc)\\\
  4003.             elseif loc > 1 then\\\
  4004.                 loc = loc - 1\\\
  4005.                 disList = updateDisplayList(list, loc, len)\\\
  4006.                 draw(disList, sel, loc)\\\
  4007.             end\\\
  4008.         elseif e == \\\"key\\\" and key == 208 then\\\
  4009.             if sel < len then\\\
  4010.                 sel = sel + 1\\\
  4011.                 draw(disList, sel, loc)\\\
  4012.             elseif loc + len - 1 < #list then\\\
  4013.                 loc = loc + 1\\\
  4014.                 disList = updateDisplayList(list, loc, len)\\\
  4015.                 draw(disList, sel, loc)\\\
  4016.             end\\\
  4017.         elseif e == \\\"mouse_scroll\\\" then\\\
  4018.             os.queueEvent(\\\"key\\\", key == -1 and 200 or 208)\\\
  4019.         elseif e == \\\"key\\\" and key == 28 then\\\
  4020.             return disList[sel]\\\
  4021.         end\\\
  4022.     end\\\
  4023. end\\\
  4024. \\\
  4025. function monitorKeyboardShortcuts()\\\
  4026.     local ta, tb = nil, nil\\\
  4027.     local allowChar = false\\\
  4028.     local shiftPressed = false\\\
  4029.     while true do\\\
  4030.         local event, char = os.pullEvent()\\\
  4031.         if event == \\\"key\\\" and (char == 42 or char == 52) then\\\
  4032.             shiftPressed = true\\\
  4033.             tb = os.startTimer(keyboardShortcutTimeout)\\\
  4034.         elseif event == \\\"key\\\" and (char == 29 or char == 157 or char == 219 or char == 220) then\\\
  4035.             allowEditorEvent = false\\\
  4036.             allowChar = true\\\
  4037.             ta = os.startTimer(keyboardShortcutTimeout)\\\
  4038.         elseif event == \\\"key\\\" and allowChar then\\\
  4039.             local name = nil\\\
  4040.             for k, v in pairs(keys) do\\\
  4041.                 if v == char then\\\
  4042.                     if shiftPressed then os.queueEvent(\\\"shortcut\\\", \\\"ctrl shift\\\", k:lower())\\\
  4043.                     else os.queueEvent(\\\"shortcut\\\", \\\"ctrl\\\", k:lower()) end\\\
  4044.                     sleep(0.005)\\\
  4045.                     allowEditorEvent = true\\\
  4046.                 end\\\
  4047.             end\\\
  4048.             if shiftPressed then os.queueEvent(\\\"shortcut\\\", \\\"ctrl shift\\\", char)\\\
  4049.             else os.queueEvent(\\\"shortcut\\\", \\\"ctrl\\\", char) end\\\
  4050.         elseif event == \\\"timer\\\" and char == ta then\\\
  4051.             allowEditorEvent = true\\\
  4052.             allowChar = false\\\
  4053.         elseif event == \\\"timer\\\" and char == tb then\\\
  4054.             shiftPressed = false\\\
  4055.         end\\\
  4056.     end\\\
  4057. end\\\
  4058. \\\
  4059. \\\
  4060. --  -------- Saving and Loading\\\
  4061. \\\
  4062. local function download(url, path)\\\
  4063.     for i = 1, 3 do\\\
  4064.         local response = http.get(url)\\\
  4065.         if response then\\\
  4066.             local data = response.readAll()\\\
  4067.             response.close()\\\
  4068.             if path then\\\
  4069.                 local f = io.open(path, \\\"w\\\")\\\
  4070.                 f:write(data)\\\
  4071.                 f:close()\\\
  4072.             end\\\
  4073.             return true\\\
  4074.         end\\\
  4075.     end\\\
  4076. \\\
  4077.     return false\\\
  4078. end\\\
  4079. \\\
  4080. local function saveFile(path, lines)\\\
  4081.     local dir = path:sub(1, path:len() - fs.getName(path):len())\\\
  4082.     if not fs.exists(dir) then fs.makeDir(dir) end\\\
  4083.     if not fs.isDir(path) and not fs.isReadOnly(path) then\\\
  4084.         local a = \\\"\\\"\\\
  4085.         for _, v in pairs(lines) do a = a .. v .. \\\"\\\\n\\\" end\\\
  4086. \\\
  4087.         local f = io.open(path, \\\"w\\\")\\\
  4088.         f:write(a)\\\
  4089.         f:close()\\\
  4090.         return true\\\
  4091.     else return false end\\\
  4092. end\\\
  4093. \\\
  4094. local function loadFile(path)\\\
  4095.     if not fs.exists(path) then\\\
  4096.         local dir = path:sub(1, path:len() - fs.getName(path):len())\\\
  4097.         if not fs.exists(dir) then fs.makeDir(dir) end\\\
  4098.         local f = io.open(path, \\\"w\\\")\\\
  4099.         f:write(\\\"\\\")\\\
  4100.         f:close()\\\
  4101.     end\\\
  4102. \\\
  4103.     local l = {}\\\
  4104.     if fs.exists(path) and not fs.isDir(path) then\\\
  4105.         local f = io.open(path, \\\"r\\\")\\\
  4106.         if f then\\\
  4107.             local a = f:read(\\\"*l\\\")\\\
  4108.             while a do\\\
  4109.                 table.insert(l, a)\\\
  4110.                 a = f:read(\\\"*l\\\")\\\
  4111.             end\\\
  4112.             f:close()\\\
  4113.         end\\\
  4114.     else return nil end\\\
  4115. \\\
  4116.     if #l < 1 then table.insert(l, \\\"\\\") end\\\
  4117.     return l\\\
  4118. end\\\
  4119. \\\
  4120. \\\
  4121. --  -------- Languages\\\
  4122. \\\
  4123. languages.lua = {}\\\
  4124. languages.brainfuck = {}\\\
  4125. languages.none = {}\\\
  4126. \\\
  4127. --  Lua\\\
  4128. \\\
  4129. languages.lua.helpTips = {\\\
  4130.     \\\"A function you tried to call doesn't exist.\\\",\\\
  4131.     \\\"You made a typo.\\\",\\\
  4132.     \\\"The index of an array is nil.\\\",\\\
  4133.     \\\"The wrong variable type was passed.\\\",\\\
  4134.     \\\"A function/variable doesn't exist.\\\",\\\
  4135.     \\\"You missed an 'end'.\\\",\\\
  4136.     \\\"You missed a 'then'.\\\",\\\
  4137.     \\\"You declared a variable incorrectly.\\\",\\\
  4138.     \\\"One of your variables is mysteriously nil.\\\"\\\
  4139. }\\\
  4140. \\\
  4141. languages.lua.defaultHelpTips = {\\\
  4142.     2, 5\\\
  4143. }\\\
  4144. \\\
  4145. languages.lua.errors = {\\\
  4146.     [\\\"Attempt to call nil.\\\"] = {1, 2},\\\
  4147.     [\\\"Attempt to index nil.\\\"] = {3, 2},\\\
  4148.     [\\\".+ expected, got .+\\\"] = {4, 2, 9},\\\
  4149.     [\\\"'end' expected\\\"] = {6, 2},\\\
  4150.     [\\\"'then' expected\\\"] = {7, 2},\\\
  4151.     [\\\"'=' expected\\\"] = {8, 2}\\\
  4152. }\\\
  4153. \\\
  4154. languages.lua.keywords = {\\\
  4155.     [\\\"and\\\"] = \\\"conditional\\\",\\\
  4156.     [\\\"break\\\"] = \\\"conditional\\\",\\\
  4157.     [\\\"do\\\"] = \\\"conditional\\\",\\\
  4158.     [\\\"else\\\"] = \\\"conditional\\\",\\\
  4159.     [\\\"elseif\\\"] = \\\"conditional\\\",\\\
  4160.     [\\\"end\\\"] = \\\"conditional\\\",\\\
  4161.     [\\\"for\\\"] = \\\"conditional\\\",\\\
  4162.     [\\\"function\\\"] = \\\"conditional\\\",\\\
  4163.     [\\\"if\\\"] = \\\"conditional\\\",\\\
  4164.     [\\\"in\\\"] = \\\"conditional\\\",\\\
  4165.     [\\\"local\\\"] = \\\"conditional\\\",\\\
  4166.     [\\\"not\\\"] = \\\"conditional\\\",\\\
  4167.     [\\\"or\\\"] = \\\"conditional\\\",\\\
  4168.     [\\\"repeat\\\"] = \\\"conditional\\\",\\\
  4169.     [\\\"return\\\"] = \\\"conditional\\\",\\\
  4170.     [\\\"then\\\"] = \\\"conditional\\\",\\\
  4171.     [\\\"until\\\"] = \\\"conditional\\\",\\\
  4172.     [\\\"while\\\"] = \\\"conditional\\\",\\\
  4173. \\\
  4174.     [\\\"true\\\"] = \\\"constant\\\",\\\
  4175.     [\\\"false\\\"] = \\\"constant\\\",\\\
  4176.     [\\\"nil\\\"] = \\\"constant\\\",\\\
  4177. \\\
  4178.     [\\\"print\\\"] = \\\"function\\\",\\\
  4179.     [\\\"write\\\"] = \\\"function\\\",\\\
  4180.     [\\\"sleep\\\"] = \\\"function\\\",\\\
  4181.     [\\\"pairs\\\"] = \\\"function\\\",\\\
  4182.     [\\\"ipairs\\\"] = \\\"function\\\",\\\
  4183.     [\\\"loadstring\\\"] = \\\"function\\\",\\\
  4184.     [\\\"loadfile\\\"] = \\\"function\\\",\\\
  4185.     [\\\"dofile\\\"] = \\\"function\\\",\\\
  4186.     [\\\"rawset\\\"] = \\\"function\\\",\\\
  4187.     [\\\"rawget\\\"] = \\\"function\\\",\\\
  4188.     [\\\"setfenv\\\"] = \\\"function\\\",\\\
  4189.     [\\\"getfenv\\\"] = \\\"function\\\",\\\
  4190. }\\\
  4191. \\\
  4192. languages.lua.parseError = function(e)\\\
  4193.     local ret = {filename = \\\"unknown\\\", line = -1, display = \\\"Unknown!\\\", err = \\\"\\\"}\\\
  4194.     if e and e ~= \\\"\\\" then\\\
  4195.         ret.err = e\\\
  4196.         if e:find(\\\":\\\") then\\\
  4197.             ret.filename = e:sub(1, e:find(\\\":\\\") - 1):gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\")\\\
  4198.             -- The \\\"\\\" is needed to circumvent a CC bug\\\
  4199.             e = (e:sub(e:find(\\\":\\\") + 1) .. \\\"\\\"):gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\")\\\
  4200.             if e:find(\\\":\\\") then\\\
  4201.                 ret.line = e:sub(1, e:find(\\\":\\\") - 1)\\\
  4202.                 e = e:sub(e:find(\\\":\\\") + 2):gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\") .. \\\"\\\"\\\
  4203.             end\\\
  4204.         end\\\
  4205.         ret.display = e:sub(1, 1):upper() .. e:sub(2, -1) .. \\\".\\\"\\\
  4206.     end\\\
  4207. \\\
  4208.     return ret\\\
  4209. end\\\
  4210. \\\
  4211. languages.lua.getCompilerErrors = function(code)\\\
  4212.     code = \\\"local function ee65da6af1cb6f63fee9a081246f2fd92b36ef2(...)\\\\n\\\\n\\\" .. code .. \\\"\\\\n\\\\nend\\\"\\\
  4213.     local fn, err = loadstring(code)\\\
  4214.     if not err then\\\
  4215.         local _, e = pcall(fn)\\\
  4216.         if e then err = e end\\\
  4217.     end\\\
  4218. \\\
  4219.     if err then\\\
  4220.         local a = err:find(\\\"]\\\", 1, true)\\\
  4221.         if a then err = \\\"string\\\" .. err:sub(a + 1, -1) end\\\
  4222.         local ret = languages.lua.parseError(err)\\\
  4223.         if tonumber(ret.line) then ret.line = tonumber(ret.line) end\\\
  4224.         return ret\\\
  4225.     else return languages.lua.parseError(nil) end\\\
  4226. end\\\
  4227. \\\
  4228. languages.lua.run = function(path, ar)\\\
  4229.     local fn, err = loadfile(path)\\\
  4230.     setfenv(fn, getfenv())\\\
  4231.     if not err then\\\
  4232.         _, err = pcall(function() fn(unpack(ar)) end)\\\
  4233.     end\\\
  4234.     return err\\\
  4235. end\\\
  4236. \\\
  4237. \\\
  4238. --  Brainfuck\\\
  4239. \\\
  4240. languages.brainfuck.helpTips = {\\\
  4241.     \\\"Well idk...\\\",\\\
  4242.     \\\"Isn't this the whole point of the language?\\\",\\\
  4243.     \\\"Ya know... Not being able to debug it?\\\",\\\
  4244.     \\\"You made a typo.\\\"\\\
  4245. }\\\
  4246. \\\
  4247. languages.brainfuck.defaultHelpTips = {\\\
  4248.     1, 2, 3\\\
  4249. }\\\
  4250. \\\
  4251. languages.brainfuck.errors = {\\\
  4252.     [\\\"No matching '['\\\"] = {1, 2, 3, 4}\\\
  4253. }\\\
  4254. \\\
  4255. languages.brainfuck.keywords = {}\\\
  4256. \\\
  4257. languages.brainfuck.parseError = function(e)\\\
  4258.     local ret = {filename = \\\"unknown\\\", line = -1, display = \\\"Unknown!\\\", err = \\\"\\\"}\\\
  4259.     if e and e ~= \\\"\\\" then\\\
  4260.         ret.err = e\\\
  4261.         ret.line = e:sub(1, e:find(\\\":\\\") - 1)\\\
  4262.         e = e:sub(e:find(\\\":\\\") + 2):gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\") .. \\\"\\\"\\\
  4263.         ret.display = e:sub(1, 1):upper() .. e:sub(2, -1) .. \\\".\\\"\\\
  4264.     end\\\
  4265. \\\
  4266.     return ret\\\
  4267. end\\\
  4268. \\\
  4269. languages.brainfuck.mapLoops = function(code)\\\
  4270.     -- Map loops\\\
  4271.     local loopLocations = {}\\\
  4272.     local loc = 1\\\
  4273.     local line = 1\\\
  4274.     for let in string.gmatch(code, \\\".\\\") do\\\
  4275.         if let == \\\"[\\\" then\\\
  4276.             loopLocations[loc] = true\\\
  4277.         elseif let == \\\"]\\\" then\\\
  4278.             local found = false\\\
  4279.             for i = loc, 1, -1 do \\\
  4280.                 if loopLocations[i] == true then\\\
  4281.                     loopLocations[i] = loc\\\
  4282.                     found = true\\\
  4283.                 end\\\
  4284.             end\\\
  4285. \\\
  4286.             if not found then\\\
  4287.                 return line .. \\\": No matching '['\\\"\\\
  4288.             end\\\
  4289.         end\\\
  4290. \\\
  4291.         if let == \\\"\\\\n\\\" then line = line + 1 end\\\
  4292.         loc = loc + 1\\\
  4293.     end\\\
  4294.     return loopLocations\\\
  4295. end\\\
  4296. \\\
  4297. languages.brainfuck.getCompilerErrors = function(code)\\\
  4298.     local a = languages.brainfuck.mapLoops(code)\\\
  4299.     if type(a) == \\\"string\\\" then return languages.brainfuck.parseError(a)\\\
  4300.     else return languages.brainfuck.parseError(nil) end\\\
  4301. end\\\
  4302. \\\
  4303. languages.brainfuck.run = function(path)\\\
  4304.     -- Read from file\\\
  4305.     local f = io.open(path, \\\"r\\\")\\\
  4306.     local content = f:read(\\\"*a\\\")\\\
  4307.     f:close()\\\
  4308. \\\
  4309.     -- Define environment\\\
  4310.     local dataCells = {}\\\
  4311.     local dataPointer = 1\\\
  4312.     local instructionPointer = 1\\\
  4313. \\\
  4314.     -- Map loops\\\
  4315.     local loopLocations = languages.brainfuck.mapLoops(content)\\\
  4316.     if type(loopLocations) == \\\"string\\\" then return loopLocations end\\\
  4317. \\\
  4318.     -- Execute code\\\
  4319.     while true do\\\
  4320.         local let = content:sub(instructionPointer, instructionPointer)\\\
  4321. \\\
  4322.         if let == \\\">\\\" then\\\
  4323.             dataPointer = dataPointer + 1\\\
  4324.             if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
  4325.         elseif let == \\\"<\\\" then\\\
  4326.             if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
  4327.             dataPointer = dataPointer - 1\\\
  4328.             if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
  4329.         elseif let == \\\"+\\\" then\\\
  4330.             if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
  4331.             dataCells[tostring(dataPointer)] = dataCells[tostring(dataPointer)] + 1\\\
  4332.         elseif let == \\\"-\\\" then\\\
  4333.             if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
  4334.             dataCells[tostring(dataPointer)] = dataCells[tostring(dataPointer)] - 1\\\
  4335.         elseif let == \\\".\\\" then\\\
  4336.             if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
  4337.             if term.getCursorPos() >= w then print(\\\"\\\") end\\\
  4338.             write(string.char(math.max(1, dataCells[tostring(dataPointer)])))\\\
  4339.         elseif let == \\\",\\\" then\\\
  4340.             if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
  4341.             term.setCursorBlink(true)\\\
  4342.             local e, but = os.pullEvent(\\\"char\\\")\\\
  4343.             term.setCursorBlink(false)\\\
  4344.             dataCells[tostring(dataPointer)] = string.byte(but)\\\
  4345.             if term.getCursorPos() >= w then print(\\\"\\\") end\\\
  4346.             write(but)\\\
  4347.         elseif let == \\\"/\\\" then\\\
  4348.             if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
  4349.             if term.getCursorPos() >= w then print(\\\"\\\") end\\\
  4350.             write(dataCells[tostring(dataPointer)])\\\
  4351.         elseif let == \\\"[\\\" then\\\
  4352.             if dataCells[tostring(dataPointer)] == 0 then\\\
  4353.                 for k, v in pairs(loopLocations) do\\\
  4354.                     if k == instructionPointer then instructionPointer = v end\\\
  4355.                 end\\\
  4356.             end\\\
  4357.         elseif let == \\\"]\\\" then\\\
  4358.             for k, v in pairs(loopLocations) do\\\
  4359.                 if v == instructionPointer then instructionPointer = k - 1 end\\\
  4360.             end\\\
  4361.         end\\\
  4362. \\\
  4363.         instructionPointer = instructionPointer + 1\\\
  4364.         if instructionPointer > content:len() then print(\\\"\\\") break end\\\
  4365.     end\\\
  4366. end\\\
  4367. \\\
  4368. --  None\\\
  4369. \\\
  4370. languages.none.helpTips = {}\\\
  4371. languages.none.defaultHelpTips = {}\\\
  4372. languages.none.errors = {}\\\
  4373. languages.none.keywords = {}\\\
  4374. \\\
  4375. languages.none.parseError = function(err)\\\
  4376.     return {filename = \\\"\\\", line = -1, display = \\\"\\\", err = \\\"\\\"}\\\
  4377. end\\\
  4378. \\\
  4379. languages.none.getCompilerErrors = function(code)\\\
  4380.     return languages.none.parseError(nil)\\\
  4381. end\\\
  4382. \\\
  4383. languages.none.run = function(path) end\\\
  4384. \\\
  4385. \\\
  4386. -- Load language\\\
  4387. curLanguage = languages.lua\\\
  4388. \\\
  4389. \\\
  4390. --  -------- Run GUI\\\
  4391. \\\
  4392. local function viewErrorHelp(e)\\\
  4393.     title(\\\"LuaIDE - Error Help\\\")\\\
  4394. \\\
  4395.     local tips = nil\\\
  4396.     for k, v in pairs(curLanguage.errors) do\\\
  4397.         if e.display:find(k) then tips = v break end\\\
  4398.     end\\\
  4399. \\\
  4400.     term.setBackgroundColor(colors[theme.err])\\\
  4401.     for i = 6, 8 do\\\
  4402.         term.setCursorPos(5, i)\\\
  4403.         term.write(string.rep(\\\" \\\", 35))\\\
  4404.     end\\\
  4405. \\\
  4406.     term.setBackgroundColor(colors[theme.prompt])\\\
  4407.     for i = 10, 18 do\\\
  4408.         term.setCursorPos(5, i)\\\
  4409.         term.write(string.rep(\\\" \\\", 46))\\\
  4410.     end\\\
  4411. \\\
  4412.     if tips then\\\
  4413.         term.setBackgroundColor(colors[theme.err])\\\
  4414.         term.setCursorPos(6, 7)\\\
  4415.         term.write(\\\"Error Help\\\")\\\
  4416. \\\
  4417.         term.setBackgroundColor(colors[theme.prompt])\\\
  4418.         for i, v in ipairs(tips) do\\\
  4419.             term.setCursorPos(7, i + 10)\\\
  4420.             term.write(\\\"- \\\" .. curLanguage.helpTips[v])\\\
  4421.         end\\\
  4422.     else\\\
  4423.         term.setBackgroundColor(colors[theme.err])\\\
  4424.         term.setCursorPos(6, 7)\\\
  4425.         term.write(\\\"No Error Tips Available!\\\")\\\
  4426. \\\
  4427.         term.setBackgroundColor(colors[theme.prompt])\\\
  4428.         term.setCursorPos(6, 11)\\\
  4429.         term.write(\\\"There are no error tips available, but\\\")\\\
  4430.         term.setCursorPos(6, 12)\\\
  4431.         term.write(\\\"you could see if it was any of these:\\\")\\\
  4432. \\\
  4433.         for i, v in ipairs(curLanguage.defaultHelpTips) do\\\
  4434.             term.setCursorPos(7, i + 12)\\\
  4435.             term.write(\\\"- \\\" .. curLanguage.helpTips[v])\\\
  4436.         end\\\
  4437.     end\\\
  4438. \\\
  4439.     prompt({{\\\"Back\\\", w - 8, 7}}, \\\"horizontal\\\")\\\
  4440. end\\\
  4441. \\\
  4442. local function run(path, lines, useArgs)\\\
  4443.     local ar = {}\\\
  4444.     if useArgs then\\\
  4445.         title(\\\"LuaIDE - Run \\\" .. fs.getName(path))\\\
  4446.         local s = centerRead(w - 13, fs.getName(path) .. \\\" \\\")\\\
  4447.         for m in string.gmatch(s, \\\"[^ \\\\t]+\\\") do ar[#ar + 1] = m:gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\") end\\\
  4448.     end\\\
  4449.     \\\
  4450.     saveFile(path, lines)\\\
  4451.     term.setCursorBlink(false)\\\
  4452.     term.setBackgroundColor(colors.black)\\\
  4453.     term.setTextColor(colors.white)\\\
  4454.     term.clear()\\\
  4455.     term.setCursorPos(1, 1)\\\
  4456.     local err = curLanguage.run(path, ar)\\\
  4457. \\\
  4458.     term.setBackgroundColor(colors.black)\\\
  4459.     print(\\\"\\\\n\\\")\\\
  4460.     if err then\\\
  4461.         if isAdvanced() then term.setTextColor(colors.red) end\\\
  4462.         centerPrint(\\\"The program has crashed!\\\")\\\
  4463.     end\\\
  4464.     term.setTextColor(colors.white)\\\
  4465.     centerPrint(\\\"Press any key to return to LuaIDE...\\\")\\\
  4466.     while true do\\\
  4467.         local e = os.pullEvent()\\\
  4468.         if e == \\\"key\\\" then break end\\\
  4469.     end\\\
  4470. \\\
  4471.     -- To prevent key from showing up in editor\\\
  4472.     os.queueEvent(event_distract)\\\
  4473.     os.pullEvent()\\\
  4474. \\\
  4475.     if err then\\\
  4476.         if curLanguage == languages.lua and err:find(\\\"]\\\") then\\\
  4477.             err = fs.getName(path) .. err:sub(err:find(\\\"]\\\", 1, true) + 1, -1)\\\
  4478.         end\\\
  4479. \\\
  4480.         while true do\\\
  4481.             title(\\\"LuaIDE - Error!\\\")\\\
  4482. \\\
  4483.             term.setBackgroundColor(colors[theme.err])\\\
  4484.             for i = 6, 8 do\\\
  4485.                 term.setCursorPos(3, i)\\\
  4486.                 term.write(string.rep(\\\" \\\", w - 5))\\\
  4487.             end\\\
  4488.             term.setCursorPos(4, 7)\\\
  4489.             term.write(\\\"The program has crashed!\\\")\\\
  4490. \\\
  4491.             term.setBackgroundColor(colors[theme.prompt])\\\
  4492.             for i = 10, 14 do\\\
  4493.                 term.setCursorPos(3, i)\\\
  4494.                 term.write(string.rep(\\\" \\\", w - 5))\\\
  4495.             end\\\
  4496. \\\
  4497.             local formattedErr = curLanguage.parseError(err)\\\
  4498.             term.setCursorPos(4, 11)\\\
  4499.             term.write(\\\"Line: \\\" .. formattedErr.line)\\\
  4500.             term.setCursorPos(4, 12)\\\
  4501.             term.write(\\\"Error:\\\")\\\
  4502.             term.setCursorPos(5, 13)\\\
  4503. \\\
  4504.             local a = formattedErr.display\\\
  4505.             local b = nil\\\
  4506.             if a:len() > w - 8 then\\\
  4507.                 for i = a:len(), 1, -1 do\\\
  4508.                     if a:sub(i, i) == \\\" \\\" then\\\
  4509.                         b = a:sub(i + 1, -1)\\\
  4510.                         a = a:sub(1, i)\\\
  4511.                         break\\\
  4512.                     end\\\
  4513.                 end\\\
  4514.             end\\\
  4515. \\\
  4516.             term.write(a)\\\
  4517.             if b then\\\
  4518.                 term.setCursorPos(5, 14)\\\
  4519.                 term.write(b)\\\
  4520.             end\\\
  4521.             \\\
  4522.             local opt = prompt({{\\\"Error Help\\\", w/2 - 15, 17}, {\\\"Go To Line\\\", w/2 + 2, 17}},\\\
  4523.                 \\\"horizontal\\\")\\\
  4524.             if opt == \\\"Error Help\\\" then\\\
  4525.                 viewErrorHelp(formattedErr)\\\
  4526.             elseif opt == \\\"Go To Line\\\" then\\\
  4527.                 -- To prevent key from showing up in editor\\\
  4528.                 os.queueEvent(event_distract)\\\
  4529.                 os.pullEvent()\\\
  4530. \\\
  4531.                 return \\\"go to\\\", tonumber(formattedErr.line)\\\
  4532.             end\\\
  4533.         end\\\
  4534.     end\\\
  4535. end\\\
  4536. \\\
  4537. \\\
  4538. --  -------- Functions\\\
  4539. \\\
  4540. local function goto()\\\
  4541.     term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
  4542.     term.setCursorPos(2, 1)\\\
  4543.     term.clearLine()\\\
  4544.     term.write(\\\"Line: \\\")\\\
  4545.     local line = modRead({visibleLength = w - 2})\\\
  4546. \\\
  4547.     local num = tonumber(line)\\\
  4548.     if num and num > 0 then return num\\\
  4549.     else\\\
  4550.         term.setCursorPos(2, 1)\\\
  4551.         term.clearLine()\\\
  4552.         term.write(\\\"Not a line number!\\\")\\\
  4553.         sleep(1.6)\\\
  4554.         return nil\\\
  4555.     end\\\
  4556. end\\\
  4557. \\\
  4558. local function setsyntax()\\\
  4559.     local opts = {\\\
  4560.         \\\"[Lua]   Brainfuck    None \\\",\\\
  4561.         \\\" Lua   [Brainfuck]   None \\\",\\\
  4562.         \\\" Lua    Brainfuck   [None]\\\"\\\
  4563.     }\\\
  4564.     local sel = 1\\\
  4565. \\\
  4566.     term.setCursorBlink(false)\\\
  4567.     term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
  4568.     term.setCursorPos(2, 1)\\\
  4569.     term.clearLine()\\\
  4570.     term.write(opts[sel])\\\
  4571.     while true do\\\
  4572.         local e, but, x, y = os.pullEvent(\\\"key\\\")\\\
  4573.         if but == 203 then\\\
  4574.             sel = math.max(1, sel - 1)\\\
  4575.             term.setCursorPos(2, 1)\\\
  4576.             term.clearLine()\\\
  4577.             term.write(opts[sel])\\\
  4578.         elseif but == 205 then\\\
  4579.             sel = math.min(#opts, sel + 1)\\\
  4580.             term.setCursorPos(2, 1)\\\
  4581.             term.clearLine()\\\
  4582.             term.write(opts[sel])\\\
  4583.         elseif but == 28 then\\\
  4584.             if sel == 1 then curLanguage = languages.lua\\\
  4585.             elseif sel == 2 then curLanguage = languages.brainfuck\\\
  4586.             elseif sel == 3 then curLanguage = languages.none end\\\
  4587.             term.setCursorBlink(true)\\\
  4588.             return\\\
  4589.         end\\\
  4590.     end\\\
  4591. end\\\
  4592. \\\
  4593. \\\
  4594. --  -------- Re-Indenting\\\
  4595. \\\
  4596. local tabWidth = 2\\\
  4597. \\\
  4598. local comments = {}\\\
  4599. local strings = {}\\\
  4600. \\\
  4601. local increment = {\\\
  4602.     \\\"if%s+.+%s+then%s*$\\\",\\\
  4603.     \\\"for%s+.+%s+do%s*$\\\",\\\
  4604.     \\\"while%s+.+%s+do%s*$\\\",\\\
  4605.     \\\"repeat%s*$\\\",\\\
  4606.     \\\"function%s+[a-zA-Z_0-9]\\\\(.*\\\\)%s*$\\\"\\\
  4607. }\\\
  4608. \\\
  4609. local decrement = {\\\
  4610.     \\\"end\\\",\\\
  4611.     \\\"until%s+.+\\\"\\\
  4612. }\\\
  4613. \\\
  4614. local special = {\\\
  4615.     \\\"else%s*$\\\",\\\
  4616.     \\\"elseif%s+.+%s+then%s*$\\\"\\\
  4617. }\\\
  4618. \\\
  4619. local function check(func)\\\
  4620.     for _, v in pairs(func) do\\\
  4621.         local cLineStart = v[\\\"lineStart\\\"]\\\
  4622.         local cLineEnd = v[\\\"lineEnd\\\"]\\\
  4623.         local cCharStart = v[\\\"charStart\\\"]\\\
  4624.         local cCharEnd = v[\\\"charEnd\\\"]\\\
  4625. \\\
  4626.         if line >= cLineStart and line <= cLineEnd then\\\
  4627.             if line == cLineStart then return cCharStart < charNumb\\\
  4628.             elseif line == cLineEnd then return cCharEnd > charNumb\\\
  4629.             else return true end\\\
  4630.         end\\\
  4631.     end\\\
  4632. end\\\
  4633. \\\
  4634. local function isIn(line, loc)\\\
  4635.     if check(comments) then return true end\\\
  4636.     if check(strings) then return true end\\\
  4637.     return false\\\
  4638. end\\\
  4639. \\\
  4640. local function setComment(ls, le, cs, ce)\\\
  4641.     comments[#comments + 1] = {}\\\
  4642.     comments[#comments].lineStart = ls\\\
  4643.     comments[#comments].lineEnd = le\\\
  4644.     comments[#comments].charStart = cs\\\
  4645.     comments[#comments].charEnd = ce\\\
  4646. end\\\
  4647. \\\
  4648. local function setString(ls, le, cs, ce)\\\
  4649.     strings[#strings + 1] = {}\\\
  4650.     strings[#strings].lineStart = ls\\\
  4651.     strings[#strings].lineEnd = le\\\
  4652.     strings[#strings].charStart = cs\\\
  4653.     strings[#strings].charEnd = ce\\\
  4654. end\\\
  4655. \\\
  4656. local function map(contents)\\\
  4657.     local inCom = false\\\
  4658.     local inStr = false\\\
  4659. \\\
  4660.     for i = 1, #contents do\\\
  4661.         if content[i]:find(\\\"%-%-%[%[\\\") and not inStr and not inCom then\\\
  4662.             local cStart = content[i]:find(\\\"%-%-%[%[\\\")\\\
  4663.             setComment(i, nil, cStart, nil)\\\
  4664.             inCom = true\\\
  4665.         elseif content[i]:find(\\\"%-%-%[=%[\\\") and not inStr and not inCom then\\\
  4666.             local cStart = content[i]:find(\\\"%-%-%[=%[\\\")\\\
  4667.             setComment(i, nil, cStart, nil)\\\
  4668.             inCom = true\\\
  4669.         elseif content[i]:find(\\\"%[%[\\\") and not inStr and not inCom then\\\
  4670.             local cStart = content[i]:find(\\\"%[%[\\\")\\\
  4671.             setString(i, nil, cStart, nil)\\\
  4672.             inStr = true\\\
  4673.         elseif content[i]:find(\\\"%[=%[\\\") and not inStr and not inCom then\\\
  4674.             local cStart = content[i]:find(\\\"%[=%[\\\")\\\
  4675.             setString(i, nil, cStart, nil)\\\
  4676.             inStr = true\\\
  4677.         end\\\
  4678. \\\
  4679.         if content[i]:find(\\\"%]%]\\\") and inStr and not inCom then\\\
  4680.             local cStart, cEnd = content[i]:find(\\\"%]%]\\\")\\\
  4681.             strings[#strings].lineEnd = i\\\
  4682.             strings[#strings].charEnd = cEnd\\\
  4683.             inStr = false\\\
  4684.         elseif content[i]:find(\\\"%]=%]\\\") and inStr and not inCom then\\\
  4685.             local cStart, cEnd = content[i]:find(\\\"%]=%]\\\")\\\
  4686.             strings[#strings].lineEnd = i\\\
  4687.             strings[#strings].charEnd = cEnd\\\
  4688.             inStr = false\\\
  4689.         end\\\
  4690. \\\
  4691.         if content[i]:find(\\\"%]%]\\\") and not inStr and inCom then\\\
  4692.             local cStart, cEnd = content[i]:find(\\\"%]%]\\\")\\\
  4693.             comments[#comments].lineEnd = i\\\
  4694.             comments[#comments].charEnd = cEnd\\\
  4695.             inCom = false\\\
  4696.         elseif content[i]:find(\\\"%]=%]\\\") and not inStr and inCom then\\\
  4697.             local cStart, cEnd = content[i]:find(\\\"%]=%]\\\")\\\
  4698.             comments[#comments].lineEnd = i\\\
  4699.             comments[#comments].charEnd = cEnd\\\
  4700.             inCom = false\\\
  4701.         end\\\
  4702. \\\
  4703.         if content[i]:find(\\\"%-%-\\\") and not inStr and not inCom then\\\
  4704.             local cStart = content[i]:find(\\\"%-%-\\\")\\\
  4705.             setComment(i, i, cStart, -1)\\\
  4706.         elseif content[i]:find(\\\"'\\\") and not inStr and not inCom then\\\
  4707.             local cStart, cEnd = content[i]:find(\\\"'\\\")\\\
  4708.             local nextChar = content[i]:sub(cEnd + 1, string.len(content[i]))\\\
  4709.             local _, cEnd = nextChar:find(\\\"'\\\")\\\
  4710.             setString(i, i, cStart, cEnd)\\\
  4711.         elseif content[i]:find('\\\"') and not inStr and not inCom then\\\
  4712.             local cStart, cEnd = content[i]:find('\\\"')\\\
  4713.             local nextChar = content[i]:sub(cEnd + 1, string.len(content[i]))\\\
  4714.             local _, cEnd = nextChar:find('\\\"')\\\
  4715.             setString(i, i, cStart, cEnd)\\\
  4716.         end\\\
  4717.     end\\\
  4718. end\\\
  4719. \\\
  4720. local function reindent(contents)\\\
  4721.     local err = nil\\\
  4722.     if curLanguage ~= languages.lua then\\\
  4723.         err = \\\"Cannot indent languages other than Lua!\\\"\\\
  4724.     elseif curLanguage.getCompilerErrors(table.concat(contents, \\\"\\\\n\\\")).line ~= -1 then\\\
  4725.         err = \\\"Cannot indent a program with errors!\\\"\\\
  4726.     end\\\
  4727. \\\
  4728.     if err then\\\
  4729.         term.setCursorBlink(false)\\\
  4730.         term.setCursorPos(2, 1)\\\
  4731.         term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
  4732.         term.clearLine()\\\
  4733.         term.write(err)\\\
  4734.         sleep(1.6)\\\
  4735.         return contents\\\
  4736.     end\\\
  4737. \\\
  4738.     local new = {}\\\
  4739.     local level = 0\\\
  4740.     for k, v in pairs(contents) do\\\
  4741.         local incrLevel = false\\\
  4742.         local foundIncr = false\\\
  4743.         for _, incr in pairs(increment) do\\\
  4744.             if v:find(incr) and not isIn(k, v:find(incr)) then\\\
  4745.                 incrLevel = true\\\
  4746.             end\\\
  4747.             if v:find(incr:sub(1, -2)) and not isIn(k, v:find(incr)) then\\\
  4748.                 foundIncr = true\\\
  4749.             end\\\
  4750.         end\\\
  4751. \\\
  4752.         local decrLevel = false\\\
  4753.         if not incrLevel then\\\
  4754.             for _, decr in pairs(decrement) do\\\
  4755.                 if v:find(decr) and not isIn(k, v:find(decr)) and not foundIncr then\\\
  4756.                     level = math.max(0, level - 1)\\\
  4757.                     decrLevel = true\\\
  4758.                 end\\\
  4759.             end\\\
  4760.         end\\\
  4761. \\\
  4762.         if not decrLevel then\\\
  4763.             for _, sp in pairs(special) do\\\
  4764.                 if v:find(sp) and not isIn(k, v:find(sp)) then\\\
  4765.                     incrLevel = true\\\
  4766.                     level = math.max(0, level - 1)\\\
  4767.                 end\\\
  4768.             end\\\
  4769.         end\\\
  4770. \\\
  4771.         new[k] = string.rep(\\\" \\\", level * tabWidth) .. v\\\
  4772.         if incrLevel then level = level + 1 end\\\
  4773.     end\\\
  4774. \\\
  4775.     return new\\\
  4776. end\\\
  4777. \\\
  4778. \\\
  4779. --  -------- Menu\\\
  4780. \\\
  4781. local menu = {\\\
  4782.     [1] = {\\\"File\\\",\\\
  4783. --      \\\"About\\\",\\\
  4784. --      \\\"Settings\\\",\\\
  4785. --      \\\"\\\",\\\
  4786.         \\\"New File  ^+N\\\",\\\
  4787.         \\\"Open File ^+O\\\",\\\
  4788.         \\\"Save File ^+S\\\",\\\
  4789.         \\\"Close     ^+W\\\",\\\
  4790.         \\\"Print     ^+P\\\",\\\
  4791.         \\\"Quit      ^+Q\\\"\\\
  4792.     }, [2] = {\\\"Edit\\\",\\\
  4793.         \\\"Cut Line   ^+X\\\",\\\
  4794.         \\\"Copy Line  ^+C\\\",\\\
  4795.         \\\"Paste Line ^+V\\\",\\\
  4796.         \\\"Delete Line\\\",\\\
  4797.         \\\"Clear Line\\\"\\\
  4798.     }, [3] = {\\\"Functions\\\",\\\
  4799.         \\\"Go To Line    ^+G\\\",\\\
  4800.         \\\"Re-Indent     ^+I\\\",\\\
  4801.         \\\"Set Syntax    ^+E\\\",\\\
  4802.         \\\"Start of Line ^+<\\\",\\\
  4803.         \\\"End of Line   ^+>\\\"\\\
  4804.     }, [4] = {\\\"Run\\\",\\\
  4805.         \\\"Run Program       ^+R\\\",\\\
  4806.         \\\"Run w/ Args ^+Shift+R\\\"\\\
  4807.     }\\\
  4808. }\\\
  4809. \\\
  4810. local shortcuts = {\\\
  4811.     -- File\\\
  4812.     [\\\"ctrl n\\\"] = \\\"New File  ^+N\\\",\\\
  4813.     [\\\"ctrl o\\\"] = \\\"Open File ^+O\\\",\\\
  4814.     [\\\"ctrl s\\\"] = \\\"Save File ^+S\\\",\\\
  4815.     [\\\"ctrl w\\\"] = \\\"Close     ^+W\\\",\\\
  4816.     [\\\"ctrl p\\\"] = \\\"Print     ^+P\\\",\\\
  4817.     [\\\"ctrl q\\\"] = \\\"Quit      ^+Q\\\",\\\
  4818. \\\
  4819.     -- Edit\\\
  4820.     [\\\"ctrl x\\\"] = \\\"Cut Line   ^+X\\\",\\\
  4821.     [\\\"ctrl c\\\"] = \\\"Copy Line  ^+C\\\",\\\
  4822.     [\\\"ctrl v\\\"] = \\\"Paste Line ^+V\\\",\\\
  4823. \\\
  4824.     -- Functions\\\
  4825.     [\\\"ctrl g\\\"] = \\\"Go To Line    ^+G\\\",\\\
  4826.     [\\\"ctrl i\\\"] = \\\"Re-Indent     ^+I\\\",\\\
  4827.     [\\\"ctrl e\\\"] = \\\"Set Syntax    ^+E\\\",\\\
  4828.     [\\\"ctrl 203\\\"] = \\\"Start of Line ^+<\\\",\\\
  4829.     [\\\"ctrl 205\\\"] = \\\"End of Line   ^+>\\\",\\\
  4830. \\\
  4831.     -- Run\\\
  4832.     [\\\"ctrl r\\\"] = \\\"Run Program       ^+R\\\",\\\
  4833.     [\\\"ctrl shift r\\\"] = \\\"Run w/ Args ^+Shift+R\\\"\\\
  4834. }\\\
  4835. \\\
  4836. local menuFunctions = {\\\
  4837.     -- File\\\
  4838. --  [\\\"About\\\"] = function() end,\\\
  4839. --  [\\\"Settings\\\"] = function() end,\\\
  4840.     [\\\"New File  ^+N\\\"] = function(path, lines) saveFile(path, lines) return \\\"new\\\" end,\\\
  4841.     [\\\"Open File ^+O\\\"] = function(path, lines) saveFile(path, lines) return \\\"open\\\" end,\\\
  4842.     [\\\"Save File ^+S\\\"] = function(path, lines) saveFile(path, lines) end,\\\
  4843.     [\\\"Close     ^+W\\\"] = function(path, lines) saveFile(path, lines) return \\\"menu\\\" end,\\\
  4844.     [\\\"Print     ^+P\\\"] = function(path, lines) saveFile(path, lines) return nil end,\\\
  4845.     [\\\"Quit      ^+Q\\\"] = function(path, lines) saveFile(path, lines) return \\\"exit\\\" end,\\\
  4846. \\\
  4847.     -- Edit\\\
  4848.     [\\\"Cut Line   ^+X\\\"] = function(path, lines, y)\\\
  4849.         clipboard = lines[y] table.remove(lines, y) return nil, lines end,\\\
  4850.     [\\\"Copy Line  ^+C\\\"] = function(path, lines, y) clipboard = lines[y] end,\\\
  4851.     [\\\"Paste Line ^+V\\\"] = function(path, lines, y)\\\
  4852.         if clipboard then table.insert(lines, y, clipboard) end return nil, lines end,\\\
  4853.     [\\\"Delete Line\\\"] = function(path, lines, y) table.remove(lines, y) return nil, lines end,\\\
  4854.     [\\\"Clear Line\\\"] = function(path, lines, y) lines[y] = \\\"\\\" return nil, lines, \\\"cursor\\\" end,\\\
  4855. \\\
  4856.     -- Functions\\\
  4857.     [\\\"Go To Line    ^+G\\\"] = function() return nil, \\\"go to\\\", goto() end,\\\
  4858.     [\\\"Re-Indent     ^+I\\\"] = function(path, lines)\\\
  4859.         local a = reindent(lines) saveFile(path, lines) return nil, a\\\
  4860.     end,\\\
  4861.     [\\\"Set Syntax    ^+E\\\"] = function(path, lines)\\\
  4862.         setsyntax()\\\
  4863.         if curLanguage == languages.brainfuck and lines[1] ~= \\\"-- Syntax: Brainfuck\\\" then\\\
  4864.             table.insert(lines, 1, \\\"-- Syntax: Brainfuck\\\")\\\
  4865.             return nil, lines\\\
  4866.         end\\\
  4867.     end,\\\
  4868.     [\\\"Start of Line ^+<\\\"] = function() os.queueEvent(\\\"key\\\", 199) end,\\\
  4869.     [\\\"End of Line   ^+>\\\"] = function() os.queueEvent(\\\"key\\\", 207) end,\\\
  4870. \\\
  4871.     -- Run\\\
  4872.     [\\\"Run Program       ^+R\\\"] = function(path, lines)\\\
  4873.         saveFile(path, lines)\\\
  4874.         return nil, run(path, lines, false)\\\
  4875.     end,\\\
  4876.     [\\\"Run w/ Args ^+Shift+R\\\"] = function(path, lines)\\\
  4877.         saveFile(path, lines)\\\
  4878.         return nil, run(path, lines, true)\\\
  4879.     end,\\\
  4880. }\\\
  4881. \\\
  4882. local function drawMenu(open)\\\
  4883.     term.setCursorPos(1, 1)\\\
  4884.     term.setTextColor(colors[theme.textColor])\\\
  4885.     term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
  4886.     term.clearLine()\\\
  4887.     local curX = 0\\\
  4888.     for _, v in pairs(menu) do\\\
  4889.         term.setCursorPos(3 + curX, 1)\\\
  4890.         term.write(v[1])\\\
  4891.         curX = curX + v[1]:len() + 3\\\
  4892.     end\\\
  4893. \\\
  4894.     if open then\\\
  4895.         local it = {}\\\
  4896.         local x = 1\\\
  4897.         for _, v in pairs(menu) do\\\
  4898.             if open == v[1] then\\\
  4899.                 it = v\\\
  4900.                 break\\\
  4901.             end\\\
  4902.             x = x + v[1]:len() + 3\\\
  4903.         end\\\
  4904.         x = x + 1\\\
  4905. \\\
  4906.         local items = {}\\\
  4907.         for i = 2, #it do\\\
  4908.             table.insert(items, it[i])\\\
  4909.         end\\\
  4910. \\\
  4911.         local len = 1\\\
  4912.         for _, v in pairs(items) do if v:len() + 2 > len then len = v:len() + 2 end end\\\
  4913. \\\
  4914.         for i, v in ipairs(items) do\\\
  4915.             term.setCursorPos(x, i + 1)\\\
  4916.             term.write(string.rep(\\\" \\\", len))\\\
  4917.             term.setCursorPos(x + 1, i + 1)\\\
  4918.             term.write(v)\\\
  4919.         end\\\
  4920.         term.setCursorPos(x, #items + 2)\\\
  4921.         term.write(string.rep(\\\" \\\", len))\\\
  4922.         return items, len\\\
  4923.     end\\\
  4924. end\\\
  4925. \\\
  4926. local function triggerMenu(cx, cy)\\\
  4927.     -- Determine clicked menu\\\
  4928.     local curX = 0\\\
  4929.     local open = nil\\\
  4930.     for _, v in pairs(menu) do\\\
  4931.         if cx >= curX + 3 and cx <= curX + v[1]:len() + 2 then\\\
  4932.             open = v[1]\\\
  4933.             break\\\
  4934.         end\\\
  4935.         curX = curX + v[1]:len() + 3\\\
  4936.     end\\\
  4937.     local menux = curX + 2\\\
  4938.     if not open then return false end\\\
  4939. \\\
  4940.     -- Flash menu item\\\
  4941.     term.setCursorBlink(false)\\\
  4942.     term.setCursorPos(menux, 1)\\\
  4943.     term.setBackgroundColor(colors[theme.background])\\\
  4944.     term.write(string.rep(\\\" \\\", open:len() + 2))\\\
  4945.     term.setCursorPos(menux + 1, 1)\\\
  4946.     term.write(open)\\\
  4947.     sleep(0.1)\\\
  4948.     local items, len = drawMenu(open)\\\
  4949. \\\
  4950.     local ret = true\\\
  4951. \\\
  4952.     -- Pull events on menu\\\
  4953.     local ox, oy = term.getCursorPos()\\\
  4954.     while type(ret) ~= \\\"string\\\" do\\\
  4955.         local e, but, x, y = os.pullEvent()\\\
  4956.         if e == \\\"mouse_click\\\" then\\\
  4957.             -- If clicked outside menu\\\
  4958.             if x < menux - 1 or x > menux + len - 1 then break\\\
  4959.             elseif y > #items + 2 then break\\\
  4960.             elseif y == 1 then break end\\\
  4961. \\\
  4962.             for i, v in ipairs(items) do\\\
  4963.                 if y == i + 1 and x >= menux and x <= menux + len - 2 then\\\
  4964.                     -- Flash when clicked\\\
  4965.                     term.setCursorPos(menux, y)\\\
  4966.                     term.setBackgroundColor(colors[theme.background])\\\
  4967.                     term.write(string.rep(\\\" \\\", len))\\\
  4968.                     term.setCursorPos(menux + 1, y)\\\
  4969.                     term.write(v)\\\
  4970.                     sleep(0.1)\\\
  4971.                     drawMenu(open)\\\
  4972. \\\
  4973.                     -- Return item\\\
  4974.                     ret = v\\\
  4975.                     break\\\
  4976.                 end\\\
  4977.             end\\\
  4978.         end\\\
  4979.     end\\\
  4980. \\\
  4981.     term.setCursorPos(ox, oy)\\\
  4982.     term.setCursorBlink(true)\\\
  4983.     return ret\\\
  4984. end\\\
  4985. \\\
  4986. \\\
  4987. --  -------- Editing\\\
  4988. \\\
  4989. local standardsCompletions = {\\\
  4990.     \\\"if%s+.+%s+then%s*$\\\",\\\
  4991.     \\\"for%s+.+%s+do%s*$\\\",\\\
  4992.     \\\"while%s+.+%s+do%s*$\\\",\\\
  4993.     \\\"repeat%s*$\\\",\\\
  4994.     \\\"function%s+[a-zA-Z_0-9]?\\\\(.*\\\\)%s*$\\\",\\\
  4995.     \\\"=%s*function%s*\\\\(.*\\\\)%s*$\\\",\\\
  4996.     \\\"else%s*$\\\",\\\
  4997.     \\\"elseif%s+.+%s+then%s*$\\\"\\\
  4998. }\\\
  4999. \\\
  5000. local liveCompletions = {\\\
  5001.     [\\\"(\\\"] = \\\")\\\",\\\
  5002.     [\\\"{\\\"] = \\\"}\\\",\\\
  5003.     [\\\"[\\\"] = \\\"]\\\",\\\
  5004.     [\\\"\\\\\\\"\\\"] = \\\"\\\\\\\"\\\",\\\
  5005.     [\\\"'\\\"] = \\\"'\\\",\\\
  5006. }\\\
  5007. \\\
  5008. local x, y = 0, 0\\\
  5009. local edw, edh = 0, h - 1\\\
  5010. local offx, offy = 0, 1\\\
  5011. local scrollx, scrolly = 0, 0\\\
  5012. local lines = {}\\\
  5013. local liveErr = curLanguage.parseError(nil)\\\
  5014. local displayCode = true\\\
  5015. local lastEventClock = os.clock()\\\
  5016. \\\
  5017. local function attemptToHighlight(line, regex, col)\\\
  5018.     local match = string.match(line, regex)\\\
  5019.     if match then\\\
  5020.         if type(col) == \\\"number\\\" then term.setTextColor(col)\\\
  5021.         elseif type(col) == \\\"function\\\" then term.setTextColor(col(match)) end\\\
  5022.         term.write(match)\\\
  5023.         term.setTextColor(colors[theme.textColor])\\\
  5024.         return line:sub(match:len() + 1, -1)\\\
  5025.     end\\\
  5026.     return nil\\\
  5027. end\\\
  5028. \\\
  5029. local function writeHighlighted(line)\\\
  5030.     if curLanguage == languages.lua then\\\
  5031.         while line:len() > 0 do \\\
  5032.             line = attemptToHighlight(line, \\\"^%-%-%[%[.-%]%]\\\", colors[theme.comment]) or\\\
  5033.                 attemptToHighlight(line, \\\"^%-%-.*\\\", colors[theme.comment]) or\\\
  5034.                 attemptToHighlight(line, \\\"^\\\\\\\".*[^\\\\\\\\]\\\\\\\"\\\", colors[theme.string]) or\\\
  5035.                 attemptToHighlight(line, \\\"^\\\\'.*[^\\\\\\\\]\\\\'\\\", colors[theme.string]) or\\\
  5036.                 attemptToHighlight(line, \\\"^%[%[.-%]%]\\\", colors[theme.string]) or\\\
  5037.                 attemptToHighlight(line, \\\"^[%w_]+\\\", function(match)\\\
  5038.                     if curLanguage.keywords[match] then\\\
  5039.                         return colors[theme[curLanguage.keywords[match]]]\\\
  5040.                     end\\\
  5041.                     return colors[theme.textColor]\\\
  5042.                 end) or\\\
  5043.                 attemptToHighlight(line, \\\"^[^%w_]\\\", colors[theme.textColor])\\\
  5044.         end\\\
  5045.     else term.write(line) end\\\
  5046. end\\\
  5047. \\\
  5048. local function draw()\\\
  5049.     -- Menu\\\
  5050.     term.setTextColor(colors[theme.textColor])\\\
  5051.     term.setBackgroundColor(colors[theme.editorBackground])\\\
  5052.     term.clear()\\\
  5053.     drawMenu()\\\
  5054. \\\
  5055.     -- Line numbers\\\
  5056.     offx, offy = tostring(#lines):len() + 1, 1\\\
  5057.     edw, edh = w - offx, h - 1\\\
  5058. \\\
  5059.     -- Draw text\\\
  5060.     for i = 1, edh do\\\
  5061.         local a = lines[scrolly + i]\\\
  5062.         if a then\\\
  5063.             local ln = string.rep(\\\" \\\", offx - 1 - tostring(scrolly + i):len()) .. tostring(scrolly + i) \\\
  5064.             local l = a:sub(scrollx + 1, edw + scrollx + 1)\\\
  5065.             ln = ln .. \\\":\\\"\\\
  5066. \\\
  5067.             if liveErr.line == scrolly + i then ln = string.rep(\\\" \\\", offx - 2) .. \\\"!:\\\" end\\\
  5068. \\\
  5069.             term.setCursorPos(1, i + offy)\\\
  5070.             term.setBackgroundColor(colors[theme.editorBackground])\\\
  5071.             if scrolly + i == y then\\\
  5072.                 if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\\\
  5073.                     term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
  5074.                 else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\\\
  5075.                 term.clearLine()\\\
  5076.             elseif scrolly + i == liveErr.line then\\\
  5077.                 term.setBackgroundColor(colors[theme.editorError])\\\
  5078.                 term.clearLine()\\\
  5079.             end\\\
  5080. \\\
  5081.             term.setCursorPos(1 - scrollx + offx, i + offy)\\\
  5082.             if scrolly + i == y then\\\
  5083.                 if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\\\
  5084.                     term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
  5085.                 else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\\\
  5086.             elseif scrolly + i == liveErr.line then term.setBackgroundColor(colors[theme.editorError])\\\
  5087.             else term.setBackgroundColor(colors[theme.editorBackground]) end\\\
  5088.             if scrolly + i == liveErr.line then\\\
  5089.                 if displayCode then term.write(a)\\\
  5090.                 else term.write(liveErr.display) end\\\
  5091.             else writeHighlighted(a) end\\\
  5092. \\\
  5093.             term.setCursorPos(1, i + offy)\\\
  5094.             if scrolly + i == y then\\\
  5095.                 if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\\\
  5096.                     term.setBackgroundColor(colors[theme.editorError])\\\
  5097.                 else term.setBackgroundColor(colors[theme.editorLineNumbersHighlight]) end\\\
  5098.             elseif scrolly + i == liveErr.line then\\\
  5099.                 term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
  5100.             else term.setBackgroundColor(colors[theme.editorLineNumbers]) end\\\
  5101.             term.write(ln)\\\
  5102.         end\\\
  5103.     end\\\
  5104.     term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
  5105. end\\\
  5106. \\\
  5107. local function drawLine(...)\\\
  5108.     local ls = {...}\\\
  5109.     offx = tostring(#lines):len() + 1\\\
  5110.     for _, ly in pairs(ls) do\\\
  5111.         local a = lines[ly]\\\
  5112.         if a then\\\
  5113.             local ln = string.rep(\\\" \\\", offx - 1 - tostring(ly):len()) .. tostring(ly) \\\
  5114.             local l = a:sub(scrollx + 1, edw + scrollx + 1)\\\
  5115.             ln = ln .. \\\":\\\"\\\
  5116. \\\
  5117.             if liveErr.line == ly then ln = string.rep(\\\" \\\", offx - 2) .. \\\"!:\\\" end\\\
  5118. \\\
  5119.             term.setCursorPos(1, (ly - scrolly) + offy)\\\
  5120.             term.setBackgroundColor(colors[theme.editorBackground])\\\
  5121.             if ly == y then\\\
  5122.                 if ly == liveErr.line and os.clock() - lastEventClock > 3 then\\\
  5123.                     term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
  5124.                 else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\\\
  5125.             elseif ly == liveErr.line then\\\
  5126.                 term.setBackgroundColor(colors[theme.editorError])\\\
  5127.             end\\\
  5128.             term.clearLine()\\\
  5129. \\\
  5130.             term.setCursorPos(1 - scrollx + offx, (ly - scrolly) + offy)\\\
  5131.             if ly == y then\\\
  5132.                 if ly == liveErr.line and os.clock() - lastEventClock > 3 then\\\
  5133.                     term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
  5134.                 else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\\\
  5135.             elseif ly == liveErr.line then term.setBackgroundColor(colors[theme.editorError])\\\
  5136.             else term.setBackgroundColor(colors[theme.editorBackground]) end\\\
  5137.             if ly == liveErr.line then\\\
  5138.                 if displayCode then term.write(a)\\\
  5139.                 else term.write(liveErr.display) end\\\
  5140.             else writeHighlighted(a) end\\\
  5141. \\\
  5142.             term.setCursorPos(1, (ly - scrolly) + offy)\\\
  5143.             if ly == y then\\\
  5144.                 if ly == liveErr.line and os.clock() - lastEventClock > 3 then\\\
  5145.                     term.setBackgroundColor(colors[theme.editorError])\\\
  5146.                 else term.setBackgroundColor(colors[theme.editorLineNumbersHighlight]) end\\\
  5147.             elseif ly == liveErr.line then\\\
  5148.                 term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
  5149.             else term.setBackgroundColor(colors[theme.editorLineNumbers]) end\\\
  5150.             term.write(ln)\\\
  5151.         end\\\
  5152.     end\\\
  5153.     term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
  5154. end\\\
  5155. \\\
  5156. local function cursorLoc(x, y, force)\\\
  5157.     local sx, sy = x - scrollx, y - scrolly\\\
  5158.     local redraw = false\\\
  5159.     if sx < 1 then\\\
  5160.         scrollx = x - 1\\\
  5161.         sx = 1\\\
  5162.         redraw = true\\\
  5163.     elseif sx > edw then\\\
  5164.         scrollx = x - edw\\\
  5165.         sx = edw\\\
  5166.         redraw = true\\\
  5167.     end if sy < 1 then\\\
  5168.         scrolly = y - 1\\\
  5169.         sy = 1\\\
  5170.         redraw = true\\\
  5171.     elseif sy > edh then\\\
  5172.         scrolly = y - edh\\\
  5173.         sy = edh\\\
  5174.         redraw = true\\\
  5175.     end if redraw or force then draw() end\\\
  5176.     term.setCursorPos(sx + offx, sy + offy)\\\
  5177. end\\\
  5178. \\\
  5179. local function executeMenuItem(a, path)\\\
  5180.     if type(a) == \\\"string\\\" and menuFunctions[a] then\\\
  5181.         local opt, nl, gtln = menuFunctions[a](path, lines, y)\\\
  5182.         if type(opt) == \\\"string\\\" then term.setCursorBlink(false) return opt end\\\
  5183.         if type(nl) == \\\"table\\\" then\\\
  5184.             if #lines < 1 then table.insert(lines, \\\"\\\") end\\\
  5185.             y = math.min(y, #lines)\\\
  5186.             x = math.min(x, lines[y]:len() + 1)\\\
  5187.             lines = nl\\\
  5188.         elseif type(nl) == \\\"string\\\" then\\\
  5189.             if nl == \\\"go to\\\" and gtln then\\\
  5190.                 x, y = 1, math.min(#lines, gtln)\\\
  5191.                 cursorLoc(x, y)\\\
  5192.             end\\\
  5193.         end\\\
  5194.     end\\\
  5195.     term.setCursorBlink(true)\\\
  5196.     draw()\\\
  5197.     term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
  5198. end\\\
  5199. \\\
  5200. local function edit(path)\\\
  5201.     -- Variables\\\
  5202.     x, y = 1, 1\\\
  5203.     offx, offy = 0, 1\\\
  5204.     scrollx, scrolly = 0, 0\\\
  5205.     lines = loadFile(path)\\\
  5206.     if not lines then return \\\"menu\\\" end\\\
  5207. \\\
  5208.     -- Enable brainfuck\\\
  5209.     if lines[1] == \\\"-- Syntax: Brainfuck\\\" then\\\
  5210.         curLanguage = languages.brainfuck\\\
  5211.     end\\\
  5212. \\\
  5213.     -- Clocks\\\
  5214.     local autosaveClock = os.clock()\\\
  5215.     local scrollClock = os.clock() -- To prevent redraw flicker\\\
  5216.     local liveErrorClock = os.clock()\\\
  5217.     local hasScrolled = false\\\
  5218. \\\
  5219.     -- Draw\\\
  5220.     draw()\\\
  5221.     term.setCursorPos(x + offx, y + offy)\\\
  5222.     term.setCursorBlink(true)\\\
  5223.     \\\
  5224.     -- Main loop\\\
  5225.     local tid = os.startTimer(3)\\\
  5226.     while true do\\\
  5227.         local e, key, cx, cy = os.pullEvent()\\\
  5228.         if e == \\\"key\\\" and allowEditorEvent then\\\
  5229.             if key == 200 and y > 1 then\\\
  5230.                 -- Up\\\
  5231.                 x, y = math.min(x, lines[y - 1]:len() + 1), y - 1\\\
  5232.                 drawLine(y, y + 1)\\\
  5233.                 cursorLoc(x, y)\\\
  5234.             elseif key == 208 and y < #lines then\\\
  5235.                 -- Down\\\
  5236.                 x, y = math.min(x, lines[y + 1]:len() + 1), y + 1\\\
  5237.                 drawLine(y, y - 1)\\\
  5238.                 cursorLoc(x, y)\\\
  5239.             elseif key == 203 and x > 1 then\\\
  5240.                 -- Left\\\
  5241.                 x = x - 1\\\
  5242.                 local force = false\\\
  5243.                 if y - scrolly + offy < offy + 1 then force = true end\\\
  5244.                 cursorLoc(x, y, force)\\\
  5245.             elseif key == 205 and x < lines[y]:len() + 1 then\\\
  5246.                 -- Right\\\
  5247.                 x = x + 1\\\
  5248.                 local force = false\\\
  5249.                 if y - scrolly + offy < offy + 1 then force = true end\\\
  5250.                 cursorLoc(x, y, force)\\\
  5251.             elseif (key == 28 or key == 156) and (displayCode and true or y + scrolly - 1 ==\\\
  5252.                     liveErr.line) then\\\
  5253.                 -- Enter\\\
  5254.                 local f = nil\\\
  5255.                 for _, v in pairs(standardsCompletions) do\\\
  5256.                     if lines[y]:find(v) then f = v end\\\
  5257.                 end\\\
  5258. \\\
  5259.                 local _, spaces = lines[y]:find(\\\"^[ ]+\\\")\\\
  5260.                 if not spaces then spaces = 0 end\\\
  5261.                 if f then\\\
  5262.                     table.insert(lines, y + 1, string.rep(\\\" \\\", spaces + 2))\\\
  5263.                     if not f:find(\\\"else\\\", 1, true) and not f:find(\\\"elseif\\\", 1, true) then\\\
  5264.                         table.insert(lines, y + 2, string.rep(\\\" \\\", spaces) .. \\\
  5265.                             (f:find(\\\"repeat\\\", 1, true) and \\\"until \\\" or f:find(\\\"{\\\", 1, true) and \\\"}\\\" or \\\
  5266.                             \\\"end\\\"))\\\
  5267.                     end\\\
  5268.                     x, y = spaces + 3, y + 1\\\
  5269.                     cursorLoc(x, y, true)\\\
  5270.                 else\\\
  5271.                     local oldLine = lines[y]\\\
  5272. \\\
  5273.                     lines[y] = lines[y]:sub(1, x - 1)\\\
  5274.                     table.insert(lines, y + 1, string.rep(\\\" \\\", spaces) .. oldLine:sub(x, -1))\\\
  5275. \\\
  5276.                     x, y = spaces + 1, y + 1\\\
  5277.                     cursorLoc(x, y, true)\\\
  5278.                 end\\\
  5279.             elseif key == 14 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\\\
  5280.                 -- Backspace\\\
  5281.                 if x > 1 then\\\
  5282.                     local f = false\\\
  5283.                     for k, v in pairs(liveCompletions) do\\\
  5284.                         if lines[y]:sub(x - 1, x - 1) == k then f = true end\\\
  5285.                     end\\\
  5286. \\\
  5287.                     lines[y] = lines[y]:sub(1, x - 2) .. lines[y]:sub(x + (f and 1 or 0), -1)\\\
  5288.                     drawLine(y)\\\
  5289.                     x = x - 1\\\
  5290.                     cursorLoc(x, y)\\\
  5291.                 elseif y > 1 then\\\
  5292.                     local prevLen = lines[y - 1]:len() + 1\\\
  5293.                     lines[y - 1] = lines[y - 1] .. lines[y]\\\
  5294.                     table.remove(lines, y)\\\
  5295.                     x, y = prevLen, y - 1\\\
  5296.                     cursorLoc(x, y, true)\\\
  5297.                 end\\\
  5298.             elseif key == 199 then\\\
  5299.                 -- Home\\\
  5300.                 x = 1\\\
  5301.                 local force = false\\\
  5302.                 if y - scrolly + offy < offy + 1 then force = true end\\\
  5303.                 cursorLoc(x, y, force)\\\
  5304.             elseif key == 207 then\\\
  5305.                 -- End\\\
  5306.                 x = lines[y]:len() + 1\\\
  5307.                 local force = false\\\
  5308.                 if y - scrolly + offy < offy + 1 then force = true end\\\
  5309.                 cursorLoc(x, y, force)\\\
  5310.             elseif key == 211 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\\\
  5311.                 -- Forward Delete\\\
  5312.                 if x < lines[y]:len() + 1 then\\\
  5313.                     lines[y] = lines[y]:sub(1, x - 1) .. lines[y]:sub(x + 1)\\\
  5314.                     local force = false\\\
  5315.                     if y - scrolly + offy < offy + 1 then force = true end\\\
  5316.                     drawLine(y)\\\
  5317.                     cursorLoc(x, y, force)\\\
  5318.                 elseif y < #lines then\\\
  5319.                     lines[y] = lines[y] .. lines[y + 1]\\\
  5320.                     table.remove(lines, y + 1)\\\
  5321.                     draw()\\\
  5322.                     cursorLoc(x, y)\\\
  5323.                 end\\\
  5324.             elseif key == 15 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\\\
  5325.                 -- Tab\\\
  5326.                 lines[y] = string.rep(\\\" \\\", tabWidth) .. lines[y]\\\
  5327.                 x = x + 2\\\
  5328.                 local force = false\\\
  5329.                 if y - scrolly + offy < offy + 1 then force = true end\\\
  5330.                 drawLine(y)\\\
  5331.                 cursorLoc(x, y, force)\\\
  5332.             elseif key == 201 then\\\
  5333.                 -- Page up\\\
  5334.                 y = math.min(math.max(y - edh, 1), #lines)\\\
  5335.                 x = math.min(lines[y]:len() + 1, x)\\\
  5336.                 cursorLoc(x, y, true)\\\
  5337.             elseif key == 209 then\\\
  5338.                 -- Page down\\\
  5339.                 y = math.min(math.max(y + edh, 1), #lines)\\\
  5340.                 x = math.min(lines[y]:len() + 1, x)\\\
  5341.                 cursorLoc(x, y, true)\\\
  5342.             end\\\
  5343.         elseif e == \\\"char\\\" and allowEditorEvent and (displayCode and true or \\\
  5344.                 y + scrolly - 1 == liveErr.line) then\\\
  5345.             local shouldIgnore = false\\\
  5346.             for k, v in pairs(liveCompletions) do\\\
  5347.                 if key == v and lines[y]:find(k, 1, true) and lines[y]:sub(x, x) == v then\\\
  5348.                     shouldIgnore = true\\\
  5349.                 end\\\
  5350.             end\\\
  5351. \\\
  5352.             local addOne = false\\\
  5353.             if not shouldIgnore then\\\
  5354.                 for k, v in pairs(liveCompletions) do\\\
  5355.                     if key == k and lines[y]:sub(x, x) ~= k then key = key .. v addOne = true end\\\
  5356.                 end\\\
  5357.                 lines[y] = lines[y]:sub(1, x - 1) .. key .. lines[y]:sub(x, -1)\\\
  5358.             end\\\
  5359. \\\
  5360.             x = x + (addOne and 1 or key:len())\\\
  5361.             local force = false\\\
  5362.             if y - scrolly + offy < offy + 1 then force = true end\\\
  5363.             drawLine(y)\\\
  5364.             cursorLoc(x, y, force)\\\
  5365.         elseif e == \\\"mouse_click\\\" and key == 1 then\\\
  5366.             if cy > 1 then\\\
  5367.                 if cx <= offx and cy - offy == liveErr.line - scrolly then\\\
  5368.                     displayCode = not displayCode\\\
  5369.                     drawLine(liveErr.line)\\\
  5370.                 else\\\
  5371.                     local oldy = y\\\
  5372.                     y = math.min(math.max(scrolly + cy - offy, 1), #lines)\\\
  5373.                     x = math.min(math.max(scrollx + cx - offx, 1), lines[y]:len() + 1)\\\
  5374.                     if oldy ~= y then drawLine(oldy, y) end\\\
  5375.                     cursorLoc(x, y)\\\
  5376.                 end\\\
  5377.             else\\\
  5378.                 local a = triggerMenu(cx, cy)\\\
  5379.                 if a then\\\
  5380.                     local opt = executeMenuItem(a, path)\\\
  5381.                     if opt then return opt end\\\
  5382.                 end\\\
  5383.             end\\\
  5384.         elseif e == \\\"shortcut\\\" then\\\
  5385.             local a = shortcuts[key .. \\\" \\\" .. cx]\\\
  5386.             if a then\\\
  5387.                 local parent = nil\\\
  5388.                 local curx = 0\\\
  5389.                 for i, mv in ipairs(menu) do\\\
  5390.                     for _, iv in pairs(mv) do\\\
  5391.                         if iv == a then\\\
  5392.                             parent = menu[i][1]\\\
  5393.                             break\\\
  5394.                         end\\\
  5395.                     end\\\
  5396.                     if parent then break end\\\
  5397.                     curx = curx + mv[1]:len() + 3\\\
  5398.                 end\\\
  5399.                 local menux = curx + 2\\\
  5400. \\\
  5401.                 -- Flash menu item\\\
  5402.                 term.setCursorBlink(false)\\\
  5403.                 term.setCursorPos(menux, 1)\\\
  5404.                 term.setBackgroundColor(colors[theme.background])\\\
  5405.                 term.write(string.rep(\\\" \\\", parent:len() + 2))\\\
  5406.                 term.setCursorPos(menux + 1, 1)\\\
  5407.                 term.write(parent)\\\
  5408.                 sleep(0.1)\\\
  5409.                 drawMenu()\\\
  5410. \\\
  5411.                 -- Execute item\\\
  5412.                 local opt = executeMenuItem(a, path)\\\
  5413.                 if opt then return opt end\\\
  5414.             end\\\
  5415.         elseif e == \\\"mouse_scroll\\\" then\\\
  5416.             if key == -1 and scrolly > 0 then\\\
  5417.                 scrolly = scrolly - 1\\\
  5418.                 if os.clock() - scrollClock > 0.0005 then\\\
  5419.                     draw()\\\
  5420.                     term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
  5421.                 end\\\
  5422.                 scrollClock = os.clock()\\\
  5423.                 hasScrolled = true\\\
  5424.             elseif key == 1 and scrolly < #lines - edh then\\\
  5425.                 scrolly = scrolly + 1\\\
  5426.                 if os.clock() - scrollClock > 0.0005 then\\\
  5427.                     draw()\\\
  5428.                     term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
  5429.                 end\\\
  5430.                 scrollClock = os.clock()\\\
  5431.                 hasScrolled = true\\\
  5432.             end\\\
  5433.         elseif e == \\\"timer\\\" and key == tid then\\\
  5434.             drawLine(y)\\\
  5435.             tid = os.startTimer(3)\\\
  5436.         end\\\
  5437. \\\
  5438.         -- Draw\\\
  5439.         if hasScrolled and os.clock() - scrollClock > 0.1 then\\\
  5440.             draw()\\\
  5441.             term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
  5442.             hasScrolled = false\\\
  5443.         end\\\
  5444. \\\
  5445.         -- Autosave\\\
  5446.         if os.clock() - autosaveClock > autosaveInterval then\\\
  5447.             saveFile(path, lines)\\\
  5448.             autosaveClock = os.clock()\\\
  5449.         end\\\
  5450. \\\
  5451.         -- Errors\\\
  5452.         if os.clock() - liveErrorClock > 1 then\\\
  5453.             local prevLiveErr = liveErr\\\
  5454.             liveErr = curLanguage.parseError(nil)\\\
  5455.             local code = \\\"\\\"\\\
  5456.             for _, v in pairs(lines) do code = code .. v .. \\\"\\\\n\\\" end\\\
  5457. \\\
  5458.             liveErr = curLanguage.getCompilerErrors(code)\\\
  5459.             liveErr.line = math.min(liveErr.line - 2, #lines)\\\
  5460.             if liveErr ~= prevLiveErr then draw() end\\\
  5461.             liveErrorClock = os.clock()\\\
  5462.         end\\\
  5463.     end\\\
  5464. \\\
  5465.     return \\\"menu\\\"\\\
  5466. end\\\
  5467. \\\
  5468. \\\
  5469. --  -------- Open File\\\
  5470. \\\
  5471. local function newFile()\\\
  5472.     local wid = w - 13\\\
  5473. \\\
  5474.     -- Get name\\\
  5475.     title(\\\"Lua IDE - New File\\\")\\\
  5476.     local name = centerRead(wid, \\\"/\\\")\\\
  5477.     if not name or name == \\\"\\\" then return \\\"menu\\\" end\\\
  5478.     name = \\\"/\\\" .. name\\\
  5479. \\\
  5480.     -- Clear\\\
  5481.     title(\\\"Lua IDE - New File\\\")\\\
  5482.     term.setTextColor(colors[theme.textColor])\\\
  5483.     term.setBackgroundColor(colors[theme.promptHighlight])\\\
  5484.     for i = 8, 10 do\\\
  5485.         term.setCursorPos(w/2 - wid/2, i)\\\
  5486.         term.write(string.rep(\\\" \\\", wid))\\\
  5487.     end\\\
  5488.     term.setCursorPos(1, 9)\\\
  5489.     if fs.isDir(name) then\\\
  5490.         centerPrint(\\\"Cannot Edit a Directory!\\\")\\\
  5491.         sleep(1.6)\\\
  5492.         return \\\"menu\\\"\\\
  5493.     elseif fs.exists(name) then\\\
  5494.         centerPrint(\\\"File Already Exists!\\\")\\\
  5495.         local opt = prompt({{\\\"Open\\\", w/2 - 9, 14}, {\\\"Cancel\\\", w/2 + 2, 14}}, \\\"horizontal\\\")\\\
  5496.         if opt == \\\"Open\\\" then return \\\"edit\\\", name\\\
  5497.         elseif opt == \\\"Cancel\\\" then return \\\"menu\\\" end\\\
  5498.     else return \\\"edit\\\", name end\\\
  5499. end\\\
  5500. \\\
  5501. local function openFile()\\\
  5502.     local wid = w - 13\\\
  5503. \\\
  5504.     -- Get name\\\
  5505.     title(\\\"Lua IDE - Open File\\\")\\\
  5506.     local name = centerRead(wid, \\\"/\\\")\\\
  5507.     if not name or name == \\\"\\\" then return \\\"menu\\\" end\\\
  5508.     name = \\\"/\\\" .. name\\\
  5509. \\\
  5510.     -- Clear\\\
  5511.     title(\\\"Lua IDE - New File\\\")\\\
  5512.     term.setTextColor(colors[theme.textColor])\\\
  5513.     term.setBackgroundColor(colors[theme.promptHighlight])\\\
  5514.     for i = 8, 10 do\\\
  5515.         term.setCursorPos(w/2 - wid/2, i)\\\
  5516.         term.write(string.rep(\\\" \\\", wid))\\\
  5517.     end\\\
  5518.     term.setCursorPos(1, 9)\\\
  5519.     if fs.isDir(name) then\\\
  5520.         centerPrint(\\\"Cannot Open a Directory!\\\")\\\
  5521.         sleep(1.6)\\\
  5522.         return \\\"menu\\\"\\\
  5523.     elseif not fs.exists(name) then\\\
  5524.         centerPrint(\\\"File Doesn't Exist!\\\")\\\
  5525.         local opt = prompt({{\\\"Create\\\", w/2 - 11, 14}, {\\\"Cancel\\\", w/2 + 2, 14}}, \\\"horizontal\\\")\\\
  5526.         if opt == \\\"Create\\\" then return \\\"edit\\\", name\\\
  5527.         elseif opt == \\\"Cancel\\\" then return \\\"menu\\\" end\\\
  5528.     else return \\\"edit\\\", name end\\\
  5529. end\\\
  5530. \\\
  5531. \\\
  5532. --  -------- Settings\\\
  5533. \\\
  5534. local function update()\\\
  5535.     local function draw(status)\\\
  5536.         title(\\\"LuaIDE - Update\\\")\\\
  5537.         term.setBackgroundColor(colors[theme.prompt])\\\
  5538.         term.setTextColor(colors[theme.textColor])\\\
  5539.         for i = 8, 10 do\\\
  5540.             term.setCursorPos(w/2 - (status:len() + 4), i)\\\
  5541.             write(string.rep(\\\" \\\", status:len() + 4))\\\
  5542.         end\\\
  5543.         term.setCursorPos(w/2 - (status:len() + 4), 9)\\\
  5544.         term.write(\\\" - \\\" .. status .. \\\" \\\")\\\
  5545. \\\
  5546.         term.setBackgroundColor(colors[theme.errHighlight])\\\
  5547.         for i = 8, 10 do\\\
  5548.             term.setCursorPos(w/2 + 2, i)\\\
  5549.             term.write(string.rep(\\\" \\\", 10))\\\
  5550.         end\\\
  5551.         term.setCursorPos(w/2 + 2, 9)\\\
  5552.         term.write(\\\" > Cancel \\\")\\\
  5553.     end\\\
  5554. \\\
  5555.     if not http then\\\
  5556.         draw(\\\"HTTP API Disabled!\\\")\\\
  5557.         sleep(1.6)\\\
  5558.         return \\\"settings\\\"\\\
  5559.     end\\\
  5560. \\\
  5561.     draw(\\\"Updating...\\\")\\\
  5562.     local tID = os.startTimer(10)\\\
  5563.     http.request(updateURL)\\\
  5564.     while true do\\\
  5565.         local e, but, x, y = os.pullEvent()\\\
  5566.         if (e == \\\"key\\\" and but == 28) or\\\
  5567.                 (e == \\\"mouse_click\\\" and x >= w/2 + 2 and x <= w/2 + 12 and y == 9) then\\\
  5568.             draw(\\\"Cancelled\\\")\\\
  5569.             sleep(1.6)\\\
  5570.             break\\\
  5571.         elseif e == \\\"http_success\\\" and but == updateURL then\\\
  5572.             local new = x.readAll()\\\
  5573.             local curf = io.open(ideLocation, \\\"r\\\")\\\
  5574.             local cur = curf:read(\\\"*a\\\")\\\
  5575.             curf:close()\\\
  5576. \\\
  5577.             if cur ~= new then\\\
  5578.                 draw(\\\"Update Found\\\")\\\
  5579.                 sleep(1.6)\\\
  5580.                 local f = io.open(ideLocation, \\\"w\\\")\\\
  5581.                 f:write(new)\\\
  5582.                 f:close()\\\
  5583. \\\
  5584.                 draw(\\\"Click to Exit\\\")\\\
  5585.                 while true do\\\
  5586.                     local e = os.pullEvent()\\\
  5587.                     if e == \\\"mouse_click\\\" or (not isAdvanced() and e == \\\"key\\\") then break end\\\
  5588.                 end\\\
  5589.                 return \\\"exit\\\"\\\
  5590.             else\\\
  5591.                 draw(\\\"No Updates Found!\\\")\\\
  5592.                 sleep(1.6)\\\
  5593.                 break\\\
  5594.             end\\\
  5595.         elseif e == \\\"http_failure\\\" or (e == \\\"timer\\\" and but == tID) then\\\
  5596.             draw(\\\"Update Failed!\\\")\\\
  5597.             sleep(1.6)\\\
  5598.             break\\\
  5599.         end\\\
  5600.     end\\\
  5601. \\\
  5602.     return \\\"settings\\\"\\\
  5603. end\\\
  5604. \\\
  5605. local function changeTheme()\\\
  5606.     title(\\\"LuaIDE - Theme\\\")\\\
  5607. \\\
  5608.     if isAdvanced() then\\\
  5609.         local disThemes = {\\\"Back\\\"}\\\
  5610.         for _, v in pairs(availableThemes) do table.insert(disThemes, v[1]) end\\\
  5611.         local t = scrollingPrompt(disThemes)\\\
  5612.         local url = nil\\\
  5613.         for _, v in pairs(availableThemes) do if v[1] == t then url = v[2] end end\\\
  5614. \\\
  5615.         if not url then return \\\"settings\\\" end\\\
  5616.         if t == \\\"Dawn (Default)\\\" then\\\
  5617.             term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
  5618.             term.setCursorPos(3, 3)\\\
  5619.             term.clearLine()\\\
  5620.             term.write(\\\"LuaIDE - Loaded Theme!\\\")\\\
  5621.             sleep(1.6)\\\
  5622. \\\
  5623.             fs.delete(themeLocation)\\\
  5624.             theme = defaultTheme\\\
  5625.             return \\\"menu\\\"\\\
  5626.         end\\\
  5627. \\\
  5628.         term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
  5629.         term.setCursorPos(3, 3)\\\
  5630.         term.clearLine()\\\
  5631.         term.write(\\\"LuaIDE - Downloading...\\\")\\\
  5632. \\\
  5633.         fs.delete(\\\"/.LuaIDE_temp_theme_file\\\")\\\
  5634.         download(url, \\\"/.LuaIDE_temp_theme_file\\\")\\\
  5635.         local a = loadTheme(\\\"/.LuaIDE_temp_theme_file\\\")\\\
  5636. \\\
  5637.         term.setCursorPos(3, 3)\\\
  5638.         term.clearLine()\\\
  5639.         if a then\\\
  5640.             term.write(\\\"LuaIDE - Loaded Theme!\\\")\\\
  5641.             fs.delete(themeLocation)\\\
  5642.             fs.move(\\\"/.LuaIDE_temp_theme_file\\\", themeLocation)\\\
  5643.             theme = a\\\
  5644.             sleep(1.6)\\\
  5645.             return \\\"menu\\\"\\\
  5646.         end\\\
  5647.         \\\
  5648.         term.write(\\\"LuaIDE - Could Not Load Theme!\\\")\\\
  5649.         fs.delete(\\\"/.LuaIDE_temp_theme_file\\\")\\\
  5650.         sleep(1.6)\\\
  5651.         return \\\"settings\\\"\\\
  5652.     else\\\
  5653.         term.setCursorPos(1, 8)\\\
  5654.         centerPrint(\\\"Themes are not available on\\\")\\\
  5655.         centerPrint(\\\"normal computers!\\\")\\\
  5656.     end\\\
  5657. end\\\
  5658. \\\
  5659. local function settings()\\\
  5660.     title(\\\"LuaIDE - Settings\\\")\\\
  5661. \\\
  5662.     local opt = prompt({{\\\"Change Theme\\\", w/2 - 17, 8}, {\\\"Return to Menu\\\", w/2 - 22, 13},\\\
  5663.         {\\\"Check for Updates\\\", w/2 + 2, 8}, {\\\"Exit IDE\\\", w/2 + 2, 13, bg = colors[theme.err], \\\
  5664.         highlight = colors[theme.errHighlight]}}, \\\"vertical\\\", true)\\\
  5665.     if opt == \\\"Change Theme\\\" then return changeTheme()\\\
  5666.     elseif opt == \\\"Check for Updates\\\" then return update()\\\
  5667.     elseif opt == \\\"Return to Menu\\\" then return \\\"menu\\\"\\\
  5668.     elseif opt == \\\"Exit IDE\\\" then return \\\"exit\\\" end\\\
  5669. end\\\
  5670. \\\
  5671. \\\
  5672. --  -------- Menu\\\
  5673. \\\
  5674. local function menu()\\\
  5675.     title(\\\"Welcome to LuaIDE \\\" .. version)\\\
  5676. \\\
  5677.     local opt = prompt({{\\\"New File\\\", w/2 - 13, 8}, {\\\"Open File\\\", w/2 - 14, 13},\\\
  5678.         {\\\"Settings\\\", w/2 + 2, 8}, {\\\"Exit IDE\\\", w/2 + 2, 13, bg = colors[theme.err],\\\
  5679.         highlight = colors[theme.errHighlight]}}, \\\"vertical\\\", true)\\\
  5680.     if opt == \\\"New File\\\" then return \\\"new\\\"\\\
  5681.     elseif opt == \\\"Open File\\\" then return \\\"open\\\"\\\
  5682.     elseif opt == \\\"Settings\\\" then return \\\"settings\\\"\\\
  5683.     elseif opt == \\\"Exit IDE\\\" then return \\\"exit\\\" end\\\
  5684. end\\\
  5685. \\\
  5686. \\\
  5687. --  -------- Main\\\
  5688. \\\
  5689. local function main(arguments)\\\
  5690.     local opt, data = \\\"menu\\\", nil\\\
  5691. \\\
  5692.     -- Check arguments\\\
  5693.     if type(arguments) == \\\"table\\\" and #arguments > 0 then\\\
  5694.         local f = \\\"/\\\" .. shell.resolve(arguments[1])\\\
  5695.         if fs.isDir(f) then print(\\\"Cannot edit a directory.\\\") end\\\
  5696.         opt, data = \\\"edit\\\", f\\\
  5697.     end\\\
  5698. \\\
  5699.     -- Main run loop\\\
  5700.     while true do\\\
  5701.         -- Menu\\\
  5702.         if opt == \\\"menu\\\" then opt = menu() end\\\
  5703. \\\
  5704.         -- Other\\\
  5705.         if opt == \\\"new\\\" then opt, data = newFile()\\\
  5706.         elseif opt == \\\"open\\\" then opt, data = openFile()\\\
  5707.         elseif opt == \\\"settings\\\" then opt = settings()\\\
  5708.         end if opt == \\\"exit\\\" then break end\\\
  5709. \\\
  5710.         -- Edit\\\
  5711.         if opt == \\\"edit\\\" and data then opt = edit(data) end\\\
  5712.     end\\\
  5713. end\\\
  5714. \\\
  5715. -- Load Theme\\\
  5716. if fs.exists(themeLocation) then theme = loadTheme(themeLocation) end\\\
  5717. if not theme and isAdvanced() then theme = defaultTheme\\\
  5718. elseif not theme then theme = normalTheme end\\\
  5719. \\\
  5720. -- Run\\\
  5721. local _, err = pcall(function()\\\
  5722.     parallel.waitForAny(function() main(args) end, monitorKeyboardShortcuts)\\\
  5723. end)\\\
  5724. \\\
  5725. -- Catch errors\\\
  5726. if err and not err:find(\\\"Terminated\\\") then\\\
  5727.     term.setCursorBlink(false)\\\
  5728.     title(\\\"LuaIDE - Crash! D:\\\")\\\
  5729. \\\
  5730.     term.setBackgroundColor(colors[theme.err])\\\
  5731.     for i = 6, 8 do\\\
  5732.         term.setCursorPos(5, i)\\\
  5733.         term.write(string.rep(\\\" \\\", 36))\\\
  5734.     end\\\
  5735.     term.setCursorPos(6, 7)\\\
  5736.     term.write(\\\"LuaIDE Has Crashed! D:\\\")\\\
  5737. \\\
  5738.     term.setBackgroundColor(colors[theme.background])\\\
  5739.     term.setCursorPos(2, 10)\\\
  5740.     print(err)\\\
  5741. \\\
  5742.     term.setBackgroundColor(colors[theme.prompt])\\\
  5743.     local _, cy = term.getCursorPos()\\\
  5744.     for i = cy + 1, cy + 4 do\\\
  5745.         term.setCursorPos(5, i)\\\
  5746.         term.write(string.rep(\\\" \\\", 36))\\\
  5747.     end\\\
  5748.     term.setCursorPos(6, cy + 2)\\\
  5749.     term.write(\\\"Please report this error to\\\")\\\
  5750.     term.setCursorPos(6, cy + 3)\\\
  5751.     term.write(\\\"GravityScore! \\\")\\\
  5752.     \\\
  5753.     term.setBackgroundColor(colors[theme.background])\\\
  5754.     if isAdvanced() then centerPrint(\\\"Click to Exit...\\\", h - 1)\\\
  5755.     else centerPrint(\\\"Press Any Key to Exit...\\\", h - 1) end\\\
  5756.     while true do\\\
  5757.         local e = os.pullEvent()\\\
  5758.         if e == \\\"mouse_click\\\" or (not isAdvanced() and e == \\\"key\\\") then break end\\\
  5759.     end\\\
  5760. \\\
  5761.     -- Prevent key from being shown\\\
  5762.     os.queueEvent(event_distract)\\\
  5763.     os.pullEvent()\\\
  5764. end\\\
  5765. \\\
  5766. -- Exit\\\
  5767. term.setBackgroundColor(colors.black)\\\
  5768. term.setTextColor(colors.white)\\\
  5769. term.clear()\\\
  5770. term.setCursorPos(1, 1)\\\
  5771. centerPrint(\\\"Thank You for Using Lua IDE \\\" .. version)\\\
  5772. centerPrint(\\\"Made by GravityScore\\\")\",\
  5773.    path = \"/rootfs/apps/LuaIDE.app/main\",\
  5774.  },\
  5775.  {\
  5776.    text = \" 37L37u37a37 37 37\\\
  5777. 37 37Ie7De7Ee7 37\\\
  5778. b7Gb7Sb7 b7 b7 b7\\\
  5779. b7 b7 b7 b7 b7 b7\",\
  5780.    path = \"/rootfs/apps/LuaIDE.app/resources/icon.png\",\
  5781.  },\
  5782.  {\
  5783.    text = \"-----------------------ВСЯКпЕ ПОЛЕЗНОСТп----------------------\\\
  5784. if not term.isColor() then error(\\\"This program will work only on advanced computer.\\\") end\\\
  5785. local Args = {...}\\\
  5786. os.loadAPI(\\\"System/api/context\\\")\\\
  5787. os.loadAPI(\\\"System/api/image\\\")\\\
  5788. os.loadAPI(\\\"System/api/filemanager\\\")\\\
  5789. os.loadAPI(\\\"System/api/windows\\\")\\\
  5790. \\\
  5791. ----------------------ОБЪЯВЛЕНпЕ ПЕРЕМЕННЫХ----------------------\\\
  5792. local xSize, ySize = term.getSize()\\\
  5793. \\\
  5794. --СУПЕР-ОПпЗДОХУЕННЫЙ АЛГОРпТМ СОЗДАНпЯ ОКОН - САМ УЖЕ СМУТНО ПОНпМАЮ, КАК ОНО РАБОТАЕТ, НО РАБОТАЕТ НОРМ\\\
  5795. --СОЗДАНпЕ ОКНА ОТ ТЕКУЩЕГО ТЕРМпНАЛА ЧпСТО ДЛЯ СОЗДАНпЯ ПЕРЕМЕННОЙ DEFAULTTERM\\\
  5796. local windowForDrawing = window.create(term.current(), 3, 2, xSize-12, ySize-1,true)\\\
  5797. local defaultTerm = term.redirect(windowForDrawing)\\\
  5798. --ВОССТАНОВЛЕНпЕ СТАНДАРТНОГО СОСТОЯНпЯ TERM\\\
  5799. term.redirect(term.native())\\\
  5800. --СОЗДАНпЕ ОКНА ДЛЯ РАБОТЫ С РпСУНКОМ, ФпНАЛ\\\
  5801. windowForDrawing = window.create(term.native(), 3, 2, xSize-12, ySize-1,true)\\\
  5802. \\\
  5803. --МАССпВЫ ОБЪЕКТОВ\\\
  5804. local Obj = {}\\\
  5805. local ObjColor = {}\\\
  5806. \\\
  5807. --ВСЯКАЯ ХУЙНЯ С ПАРАМЕТРАМп СОЗДАВАЕМОГО пЗОБРАЖЕНпЯ\\\
  5808. local imageSizeX = 36\\\
  5809. local imageSizeY = 15\\\
  5810. local transparentSymbol = \\\"+\\\"\\\
  5811. local displayImageFromX = 4\\\
  5812. local displayImageFromY = 3\\\
  5813. local displayImageEndX = displayImageFromX + imageSizeX - 1\\\
  5814. local displayImageEndY = displayImageFromY + imageSizeY - 1\\\
  5815. \\\
  5816. --МАСпВ СОКРАЩЕННЫХ В ОДпН СпМВОЛ ЦВЕТОВ ДЛЯ СОХРАНЕНпЯ пЗОБРАЖЕНпЯ В ФАЙЛ\\\
  5817. local Colors = {\\\
  5818.     [\\\"0\\\"] = 1,\\\
  5819.     [\\\"1\\\"] = 2,\\\
  5820.     [\\\"2\\\"] = 4,\\\
  5821.     [\\\"3\\\"] = 8,\\\
  5822.     [\\\"4\\\"] = 16,\\\
  5823.     [\\\"5\\\"] = 32,\\\
  5824.     [\\\"6\\\"] = 64,\\\
  5825.     [\\\"7\\\"] = 128,\\\
  5826.     [\\\"8\\\"] = 256,\\\
  5827.     [\\\"9\\\"] = 512,\\\
  5828.     [\\\"a\\\"] = 1024,\\\
  5829.     [\\\"b\\\"] = 2048,\\\
  5830.     [\\\"c\\\"] = 4096,\\\
  5831.     [\\\"d\\\"] = 8192,\\\
  5832.     [\\\"e\\\"] = 16384,\\\
  5833.     [\\\"f\\\"] = 32768\\\
  5834. }\\\
  5835. \\\
  5836. --МАССпВ СООТВЕТСТВпЯ ЦВЕТА НА ЭКРАНЕ БЛОКУ В МпРЕ МАЙНА\\\
  5837. local Blocks = {\\\
  5838.     [1] = {[\\\"id\\\"]=\\\"quartz_block\\\",[\\\"data\\\"]=\\\"0\\\"},\\\
  5839.     [2] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"1\\\"},\\\
  5840.     [4] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"2\\\"},\\\
  5841.     [8] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"3\\\"},\\\
  5842.     [16] = {[\\\"id\\\"]=\\\"gold_block\\\",[\\\"data\\\"]=\\\"0\\\"},\\\
  5843.     [32] = {[\\\"id\\\"]=\\\"emerald_block\\\",[\\\"data\\\"]=\\\"0\\\"},\\\
  5844.     [64] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"6\\\"},\\\
  5845.     [128] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"7\\\"},\\\
  5846.     [256] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"8\\\"},\\\
  5847.     [512] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"9\\\"},\\\
  5848.     [1024] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"10\\\"},\\\
  5849.     [2048] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"11\\\"},\\\
  5850.     [4096] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"12\\\"},\\\
  5851.     [8192] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"13\\\"},\\\
  5852.     [16384] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"14\\\"},\\\
  5853.     [32768] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"15\\\"}\\\
  5854. }\\\
  5855. \\\
  5856. --МАССпВ ПпКСЕЛЕЙ НА ЭКРАНЕ\\\
  5857. local Pixels = {}\\\
  5858. \\\
  5859. --ВСЯКАЯ ХУЙНЯ, КАСАЮЩАЯСЯ пНСТРУМЕНТОВ, ЦВЕТОВ п ПРОЧЕГО\\\
  5860. local currentInstrument = \\\"B\\\"\\\
  5861. local currentTextColor = colors.white\\\
  5862. local currentBackColor = colors.black\\\
  5863. local currentSymbol = \\\" \\\"\\\
  5864. \\\
  5865. --ВСЯКАЯ ХУЙНЯ ПРО КОМАНДНЫЕ БЛОКп\\\
  5866. local CommandBlockIsActive = false\\\
  5867. local commandBlockAttachedAt = \\\"\\\"\\\
  5868. local CommandBlock = {}\\\
  5869. \\\
  5870. --ГОВНЕЦО ДЛЯ ФАСТ СЕЙВА ФАЙЛпКОВ\\\
  5871. local fastFileMode = false\\\
  5872. local fastFilePath = nil\\\
  5873. \\\
  5874. local pathForFastSaving = nil\\\
  5875. \\\
  5876. ------------------------ОБЪЯВЛЕНпЕ ФУНКЦпЙ-----------------------\\\
  5877. \\\
  5878. --ПОпСК ПЕРпФЕРпп В ВпДЕ КОМАНДНОГО БЛОКА. ЕСЛп НЕ НАХОДпТ, ТО NIL\\\
  5879. function findCommandBlock()\\\
  5880.     local PeriList = peripheral.getNames()\\\
  5881.     for i=1,#PeriList do\\\
  5882.         if peripheral.getType(PeriList[i]) == \\\"command\\\" then\\\
  5883.             return PeriList[i]\\\
  5884.         end\\\
  5885.     end\\\
  5886. end\\\
  5887. \\\
  5888. --УСТАНОВКА п ЗАПУСК КОМАНДЫ В КОМАНДНЫЙ БЛОК\\\
  5889. local function cb(command)\\\
  5890.     CommandBlock.setCommand(command)\\\
  5891.     CommandBlock.runCommand()\\\
  5892. end\\\
  5893. \\\
  5894. --УСТАНОВКА БЛОКА В МпРЕ МАЙНА ПО КООРДпНАТАМ\\\
  5895. local function setBlock(x,y,id,data)\\\
  5896.     cb(\\\"/setblock ~\\\"..(x-math.floor(imageSizeX/2))..\\\" ~\\\"..(ySize+3-y)..\\\" ~0 minecraft:\\\"..id..\\\" \\\"..data)\\\
  5897. end\\\
  5898. \\\
  5899. --ОЧпСТКА ВСЕХ НАРпСОВАННЫХ БЛОКОВ В МпРЕ МАЙНА\\\
  5900. local function clearAll()\\\
  5901.     for x=1,xSize do\\\
  5902.         for y=1,ySize do\\\
  5903.             setBlock(x,y,\\\"air\\\",\\\"0\\\")\\\
  5904.         end\\\
  5905.     end\\\
  5906. end\\\
  5907. \\\
  5908. local function changeDisplayImageFromParameters(x,y)\\\
  5909.     displayImageFromX = x\\\
  5910.     displayImageFromY = y\\\
  5911.     displayImageEndX = displayImageFromX + imageSizeX - 1\\\
  5912.     displayImageEndY = displayImageFromY + imageSizeY - 1\\\
  5913. end\\\
  5914. \\\
  5915. --СОЗДАНпЕ ОБЪЕКТОВ КНОПОК\\\
  5916. local function newObj(name,x1,y1,width,height)\\\
  5917.     Obj[name]={}\\\
  5918.     Obj[name][\\\"x1\\\"]=x1\\\
  5919.     Obj[name][\\\"y1\\\"]=y1\\\
  5920.     Obj[name][\\\"x2\\\"]=x1+width-1\\\
  5921.     Obj[name][\\\"y2\\\"]=y1+height-1\\\
  5922. end\\\
  5923. \\\
  5924. --СОЗДАНпЕ ОБЪЕКТА ЦВЕТОВ\\\
  5925. local function newObjColor(name,x1,y1,width)\\\
  5926.     ObjColor[name]={}\\\
  5927.     ObjColor[name][\\\"x1\\\"]=x1\\\
  5928.     ObjColor[name][\\\"y1\\\"]=y1\\\
  5929.     ObjColor[name][\\\"x2\\\"]=x1+width-1\\\
  5930. end\\\
  5931. \\\
  5932. --ПРОСТОЕ ОТОБРАЖЕНпЕ ТЕКСТА ПО КООРДпНАТАМ\\\
  5933. local function usualText(x,y,text)\\\
  5934.     term.setCursorPos(x,y)\\\
  5935.     term.write(text)\\\
  5936. end\\\
  5937. \\\
  5938. --УНпВЕРСАЛЬНАЯ ФУНКЦпЯ ДЛЯ ОТОБРАЖЕНпЯ ТЕКСТА ПО ЦЕНТРУ ЭКРАНА\\\
  5939. local function centerText(how,coord,text,textColor,backColor)\\\
  5940.     term.setTextColor(textColor)\\\
  5941.     term.setBackgroundColor(backColor)\\\
  5942.     if how == \\\"xy\\\" then\\\
  5943.         term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2))\\\
  5944.     elseif how == \\\"x\\\" then\\\
  5945.         term.setCursorPos(math.floor(xSize/2-#text/2),coord)\\\
  5946.     elseif how == \\\"y\\\" then\\\
  5947.         term.setCursorPos(coord,math.floor(ySize/2))\\\
  5948.     end\\\
  5949.     term.write(text)\\\
  5950. end\\\
  5951. \\\
  5952. --РпСОВАНпЕ КВАДРАТА С ЗАЛпВКОЙ\\\
  5953. local function square(x1,y1,width,height,color)\\\
  5954.     local string = string.rep(\\\" \\\",width)\\\
  5955.     term.setBackgroundColor(color)\\\
  5956.     for y=y1,(y1+height-1) do\\\
  5957.         usualText(x1,y,string)\\\
  5958.     end\\\
  5959. end\\\
  5960. \\\
  5961. --ЗАЛпВКА ЭКРАНА ЦВЕТОМ\\\
  5962. local function clearScreen(color)\\\
  5963.     term.setBackgroundColor(color)\\\
  5964.     term.clear()\\\
  5965. end\\\
  5966. \\\
  5967. --ПЛАВНОЕ ВКЛЮЧЕНпЕ ЭКРАНА\\\
  5968. local function fadeIn(time)\\\
  5969.     clearScreen(colors.gray)\\\
  5970.     sleep(time)\\\
  5971.     clearScreen(colors.lightGray)\\\
  5972.     sleep(time)\\\
  5973.     clearScreen(colors.white)\\\
  5974.     sleep(time)\\\
  5975. end\\\
  5976. \\\
  5977. --ПЛАВНОЕ ЗАТУХАНпЕ ЭКРАНА\\\
  5978. local function fadeOut(time)\\\
  5979.     clearScreen(colors.lightGray)\\\
  5980.     sleep(time)\\\
  5981.     clearScreen(colors.gray)\\\
  5982.     sleep(time)\\\
  5983.     clearScreen(colors.black)\\\
  5984.     sleep(time)\\\
  5985.     term.setCursorPos(1,1)\\\
  5986.     term.setTextColor(colors.white)\\\
  5987. end\\\
  5988. \\\
  5989. --ОТРпСОВКА ВЕРХНЕГО ТУЛБАРА\\\
  5990. local function topBar()\\\
  5991.     local function topBarButton(x,y,text)\\\
  5992.         usualText(x,y,text)\\\
  5993.         newObj(text,x,y,#text,1)\\\
  5994.     end\\\
  5995. \\\
  5996.     for i=1,xSize do\\\
  5997.         paintutils.drawPixel(i,1,colors.gray)\\\
  5998.     end\\\
  5999. \\\
  6000.     term.setTextColor(colors.lightGray)\\\
  6001.     topBarButton(1,1,\\\"File\\\")\\\
  6002.     topBarButton(Obj[\\\"File\\\"][\\\"x2\\\"]+3,1,\\\"Edit\\\")\\\
  6003.     topBarButton(Obj[\\\"Edit\\\"][\\\"x2\\\"]+3,1,\\\"Quit\\\")\\\
  6004. end\\\
  6005. \\\
  6006. --ОТРпСОВКА ВЫБРАННОГО ЦВЕТА п СпМВОЛА НА ЛЕВОМ ТУЛБАРЕ\\\
  6007. local function leftBarColorBar()\\\
  6008.     square(1,ySize-2,2,2,currentTextColor)\\\
  6009.     paintutils.drawPixel(1,ySize-2,currentBackColor)\\\
  6010.     term.setTextColor(currentTextColor)\\\
  6011.     term.setCursorPos(1,ySize-2)\\\
  6012.     term.write(currentSymbol)\\\
  6013. end\\\
  6014. \\\
  6015. --ОТРпСОВКА КНОПОК НА ЛЕВОМ ТУЛБАРЕ\\\
  6016. local function leftBarButton(x,y,symbol)\\\
  6017.     if currentInstrument == symbol then\\\
  6018.         term.setTextColor(colors.white)\\\
  6019.         square(x,y,2,2,colors.blue)\\\
  6020.     else\\\
  6021.         term.setTextColor(colors.gray)\\\
  6022.         square(x,y,2,2,colors.black)\\\
  6023.     end\\\
  6024.     usualText(x,y+1,symbol)\\\
  6025.     newObj(symbol,x,y,2,2)\\\
  6026. end\\\
  6027. \\\
  6028. --ОТРпСОВКА КАСТОМНЫХ КНОПОК НА ЛЕВОМ ТУЛБАРЕ\\\
  6029. local function leftBarButtonPersonal(x,y,symbol,colorOfButton,colorOfText)\\\
  6030.     term.setTextColor(colorOfText)\\\
  6031.     square(x,y,2,2,colorOfButton)\\\
  6032.     usualText(x,y+1,symbol)\\\
  6033.     newObj(symbol,x,y,2,2)\\\
  6034. end\\\
  6035. \\\
  6036. --ОТРпСОВКА ЛЕВОГО ТУЛБАРА\\\
  6037. local function leftBar(activeInstrument)\\\
  6038.     square(1,2,2,ySize-1,colors.gray)\\\
  6039.     leftBarButton(1,2,\\\"M\\\")\\\
  6040.     leftBarButton(1,5,\\\"B\\\")\\\
  6041.     leftBarButton(1,8,\\\"E\\\")\\\
  6042.     leftBarButton(1,11,\\\"F\\\")\\\
  6043.     if CommandBlockIsActive then\\\
  6044.         leftBarButtonPersonal(1,14,\\\"CB\\\",colors.green,colors.white)\\\
  6045.     else\\\
  6046.         leftBarButtonPersonal(1,14,\\\"CB\\\",colors.black,colors.gray)\\\
  6047.     end\\\
  6048.     leftBarColorBar()\\\
  6049. end\\\
  6050. \\\
  6051. --ОТРпСОВКА ПРАВОГО ТУЛБАРА\\\
  6052. local function rightBar()\\\
  6053.     --НАРпСОВАТЬ КВАДРАТпК С УКАЗАННЫМ ЦВЕТОМ (ДЛЯ ПАЛпТРЫ)\\\
  6054.     local function drawColor(x,y,color)\\\
  6055.         for i=x,(x+1) do\\\
  6056.             paintutils.drawPixel(i,y,color)\\\
  6057.             newObjColor(color,x,y,2)\\\
  6058.         end\\\
  6059.     end\\\
  6060. \\\
  6061.     square(xSize-9,2,10,ySize-1,colors.gray)\\\
  6062. \\\
  6063.     for i=(xSize-9),xSize do\\\
  6064.         paintutils.drawPixel(i,2,colors.black)\\\
  6065.     end\\\
  6066.     term.setTextColor(colors.lightGray)\\\
  6067.     usualText(xSize-8,2,\\\"Colors\\\")\\\
  6068. \\\
  6069.     --for i=(xSize-9),xSize do\\\
  6070.     --  paintutils.drawPixel(i,9,colors.black)\\\
  6071.     --end\\\
  6072.     --term.setTextColor(colors.lightGray)\\\
  6073.     --usualText(xSize-8,9,\\\"Layers\\\")\\\
  6074.     \\\
  6075.     --САМАЯ БОЛЬШАЯ ЖОПА, ОТОБРАЖЕНпЕ ЦВЕТОВОЙ ПАЛпТРЫ\\\
  6076.     local startXColor = 0\\\
  6077.     local startYColor = 0\\\
  6078.     for i=0,3 do\\\
  6079.         startXColor = xSize-8+i*2\\\
  6080.         startYColor = 4\\\
  6081.         drawColor(startXColor,startYColor,2^i)\\\
  6082.         newObjColor(2^i,startXColor,startYColor,2)\\\
  6083.     end\\\
  6084.     for i=4,7 do\\\
  6085.         startXColor = xSize-8+(i-4)*2\\\
  6086.         startYColor = 5\\\
  6087.         drawColor(startXColor,startYColor,2^i)\\\
  6088.         newObjColor(2^i,startXColor,startYColor,2)\\\
  6089.     end\\\
  6090.     for i=8,11 do\\\
  6091.         startXColor = xSize-8+(i-8)*2\\\
  6092.         startYColor = 6\\\
  6093.         drawColor(startXColor,startYColor,2^i)\\\
  6094.         newObjColor(2^i,startXColor,startYColor,2)\\\
  6095.     end\\\
  6096.     for i=12,15 do\\\
  6097.         startXColor = xSize-8+(i-12)*2\\\
  6098.         startYColor = 7\\\
  6099.         drawColor(startXColor,startYColor,2^i)\\\
  6100.         newObjColor(2^i,startXColor,startYColor,2)\\\
  6101.     end\\\
  6102. end\\\
  6103. \\\
  6104. --ОТРпСОВКА РпСОВАЛЬНОЙ ЗОНЫ п САМОГО пЗОБРАЖЕНпЯ пЗ ПАМЯТп ПО МАССпВУ PIXELS\\\
  6105. local function drawingArea()\\\
  6106. \\\
  6107.     --ПЕРЕАДРЕСАЦпЯ С TERM НА СОЗДАННОЕ ОКНО\\\
  6108.     term.redirect(windowForDrawing)\\\
  6109. \\\
  6110.     --ФУНКЦпЯ РпСОВАНпЯ \\\"ПРОЗРАЧНОЙ ЗОНЫ\\\" В ВпДЕ СпМВОЛОВ ПРОЗРАЧНОСТп, УКАЗАННЫХ РАНЕЕ\\\
  6111.     local function cresti(x1,y1,width,height,color)\\\
  6112.         local string = string.rep(transparentSymbol,width)\\\
  6113.         term.setBackgroundColor(color)\\\
  6114.         term.setTextColor(colors.lightGray)\\\
  6115.         for y=y1,(y1+height-1) do\\\
  6116.             usualText(x1,y,string)\\\
  6117.         end\\\
  6118.     end\\\
  6119. \\\
  6120.     --СМЕЩЕНпЕ ПО КООРДпНАТАМ ДЛЯ СТАРТОВОГО ОКНА\\\
  6121.     local smeshenieX = 2\\\
  6122.     local smeshenieY = 1\\\
  6123. \\\
  6124.     --РпСОВАНпЕ БЕЛОЙ ПОДЛОЖКп п СпМВОЛОВ ПРОЗРАЧНОСТп (ТпПА ПРОЗРАЧНЫЙ ФОН)\\\
  6125.     square(1,1,xSize-12,ySize-1,colors.lightGray)\\\
  6126.     cresti(displayImageFromX-smeshenieX,displayImageFromY-smeshenieY,imageSizeX,imageSizeY,colors.white)\\\
  6127. \\\
  6128.     --РпСОВАНпЕ \\\"ТЕНп\\\" пЗОБРАЖЕНпЯ\\\
  6129.     for i=1,imageSizeY do\\\
  6130.         paintutils.drawPixel(displayImageFromX+imageSizeX-smeshenieX,displayImageFromY+i-smeshenieY,colors.gray)\\\
  6131.     end\\\
  6132.     square(displayImageFromX+1-smeshenieX,displayImageFromY+imageSizeY-smeshenieY,imageSizeX,1,colors.gray)\\\
  6133. \\\
  6134.     --РпСОВАНпЕ САМОГО пЗОБРАЖЕНпЯ пЗ ПАМЯТп\\\
  6135.     for y=1,#Pixels do\\\
  6136.         for x=1,#Pixels[y] do\\\
  6137.             if Pixels[y][x][\\\"symbol\\\"] ~= \\\"#\\\" then\\\
  6138.                 term.setTextColor(Pixels[y][x][\\\"textColor\\\"])\\\
  6139.                 term.setBackgroundColor(Pixels[y][x][\\\"backColor\\\"])\\\
  6140.                 term.setCursorPos(displayImageFromX+x-1-smeshenieX,displayImageFromY+y-1-smeshenieY)\\\
  6141.                 term.write(Pixels[y][x][\\\"symbol\\\"])\\\
  6142.             end\\\
  6143.         end\\\
  6144.     end\\\
  6145. \\\
  6146.     --ПЕРЕАДРЕСАЦпЯ ОБРАТНО НА СТАНДАРТНЫЙ TERM\\\
  6147.     term.redirect(term.native())\\\
  6148. end\\\
  6149. \\\
  6150. --ОТРпСОВКА ВСЕГО пНТЕРФЕЙСА\\\
  6151. local function drawAllGui()\\\
  6152.     drawingArea()\\\
  6153.     topBar()\\\
  6154.     leftBar(currentInstrument)\\\
  6155.     rightBar()\\\
  6156. end\\\
  6157. \\\
  6158. --пЗМЕНЕНпЕ ПАРАМЕТРОВ РАЗМЕРА пЗОБРАЖЕНпЯ В ПАМЯТп\\\
  6159. local function changeImageSizeInMemory(width,height)\\\
  6160.     imageSizeX = width\\\
  6161.     imageSizeY = height\\\
  6162.     displayImageEndX = displayImageFromX + imageSizeX - 1\\\
  6163.     displayImageEndY = displayImageFromY + imageSizeY - 1\\\
  6164. end\\\
  6165. \\\
  6166. --СОЗДАНпЕ НОВОГО ФАЙЛА В ПАМЯТп п ЗАПОЛНЕНпЕ МАССпВА PIXELS ПУСТЫМп ЗНАЧЕНпЯМп\\\
  6167. local function newFile(override)\\\
  6168.     Pixels = {}\\\
  6169. \\\
  6170.     local loadData = nil\\\
  6171.     if override == nil then\\\
  6172.         loadData = windows.input(math.floor(xSize/2-14),math.floor(ySize/2-3),\\\"New file\\\",12,{\\\"Width\\\",\\\"\\\"},{\\\"Height\\\",\\\"\\\"})\\\
  6173.         changeImageSizeInMemory(loadData[1],loadData[2])\\\
  6174.     end\\\
  6175.     \\\
  6176.     for y=1,imageSizeY do\\\
  6177.         Pixels[y] = {}\\\
  6178.         for x=1,imageSizeX do\\\
  6179.             Pixels[y][x] = {}\\\
  6180.             Pixels[y][x][\\\"symbol\\\"] = \\\"#\\\"\\\
  6181.             Pixels[y][x][\\\"textColor\\\"] = \\\"0\\\"\\\
  6182.             Pixels[y][x][\\\"backColor\\\"] = \\\"0\\\"\\\
  6183.         end\\\
  6184.     end\\\
  6185. \\\
  6186.     displayImageFromX = 4\\\
  6187.     displayImageFromY = 3\\\
  6188. end\\\
  6189. \\\
  6190. --КОНВЕРТАЦпЯ пЗ ЦВЕТОВ, ПОНЯТНЫХ КК, В ЦВЕТА, ПОНЯТНЫЕ МОЕЙ ПРОГЕ, п НАОБОРОТ\\\
  6191. local function convert(mode,color)\\\
  6192.     if mode == \\\"from cc\\\" then\\\
  6193.         for key,value in pairs(Colors) do\\\
  6194.             if color == value then\\\
  6195.                 return key\\\
  6196.             end\\\
  6197.         end\\\
  6198.     else\\\
  6199.         if color == \\\"#\\\" then\\\
  6200.             return \\\"0\\\"\\\
  6201.         else\\\
  6202.             return Colors[color]\\\
  6203.         end\\\
  6204.     end\\\
  6205. end\\\
  6206. \\\
  6207. --СОХРАНЕНпЕ МАССпВА PIXELS В ФАЙЛ\\\
  6208. local function save(path)\\\
  6209.     local file = fs.open(path,\\\"w\\\")\\\
  6210.     for j=1,#Pixels do\\\
  6211.         local line = \\\"\\\"\\\
  6212.         for i=1,#Pixels[j] do\\\
  6213.             if Pixels[j][i][\\\"symbol\\\"] == \\\"#\\\" and Pixels[j][i][\\\"textColor\\\"] == \\\"0\\\" and Pixels[j][i][\\\"backColor\\\"] == \\\"0\\\" then\\\
  6214.                 line = line..\\\"#\\\"..\\\"#\\\"..\\\"#\\\"\\\
  6215.             else\\\
  6216.                 line = line..Pixels[j][i][\\\"symbol\\\"]..convert(\\\"from cc\\\",Pixels[j][i][\\\"textColor\\\"])..convert(\\\"from cc\\\",Pixels[j][i][\\\"backColor\\\"])\\\
  6217.             end\\\
  6218.         end\\\
  6219.         file.writeLine(line)\\\
  6220.     end\\\
  6221.     file.close()\\\
  6222. end\\\
  6223. \\\
  6224. --ЗАГРУЗКА ДАННЫХ пЗ СУЩЕСТВУЮЩЕГО ФАЙЛА В МАССпВ PIXELS\\\
  6225. local function load(path)\\\
  6226.     Pixels = {}\\\
  6227.     local file = fs.open(path,\\\"r\\\")\\\
  6228.     local lineCounter = 1\\\
  6229.     while true do\\\
  6230.         local line = file.readLine()\\\
  6231.         Pixels[lineCounter]={}\\\
  6232.         if line ~= \\\"\\\" and line ~= nil then\\\
  6233.             for i=1,#line,3 do\\\
  6234.                 local posX = (i+2)/3\\\
  6235.                 Pixels[lineCounter][posX]={}\\\
  6236.                 Pixels[lineCounter][posX][\\\"symbol\\\"] = string.sub(line,i,i)\\\
  6237.                 Pixels[lineCounter][posX][\\\"textColor\\\"] = convert(\\\"to cc\\\",string.sub(line,i+1,i+1))\\\
  6238.                 Pixels[lineCounter][posX][\\\"backColor\\\"] = convert(\\\"to cc\\\",string.sub(line,i+2,i+2))\\\
  6239.                 if CommandBlockIsActive then\\\
  6240.                     if Pixels[lineCounter][posX][\\\"backColor\\\"] ~= \\\"0\\\" then\\\
  6241.                         setBlock(posX,lineCounter,Blocks[convert(\\\"to cc\\\",string.sub(line,i+2,i+2))][\\\"id\\\"],Blocks[convert(\\\"to cc\\\",string.sub(line,i+2,i+2))][\\\"data\\\"])\\\
  6242.                     end\\\
  6243.                 end\\\
  6244.             end\\\
  6245.             lineCounter = lineCounter + 1\\\
  6246.         else\\\
  6247.             break\\\
  6248.         end\\\
  6249.     end\\\
  6250. \\\
  6251.     changeImageSizeInMemory(#Pixels[1],lineCounter-1)\\\
  6252.     file.close()\\\
  6253. end\\\
  6254. \\\
  6255. local function moveImage(direction)\\\
  6256.     if direction == \\\"up\\\" then\\\
  6257.         if displayImageEndY > ySize-2 then\\\
  6258.             changeDisplayImageFromParameters(displayImageFromX,displayImageFromY-1)\\\
  6259.             drawingArea()\\\
  6260.         end\\\
  6261.     elseif direction == \\\"down\\\" then\\\
  6262.         if displayImageFromY < 3 then\\\
  6263.             changeDisplayImageFromParameters(displayImageFromX,displayImageFromY+1)\\\
  6264.             drawingArea()\\\
  6265.         end\\\
  6266.     elseif direction == \\\"left\\\" then\\\
  6267.         if displayImageEndX > xSize-12 then\\\
  6268.             changeDisplayImageFromParameters(displayImageFromX-1,displayImageFromY)\\\
  6269.             drawingArea()\\\
  6270.         end\\\
  6271.     elseif direction == \\\"right\\\" then\\\
  6272.         if displayImageFromX < 4 then\\\
  6273.             changeDisplayImageFromParameters(displayImageFromX+1,displayImageFromY)\\\
  6274.             drawingArea()\\\
  6275.         end\\\
  6276.     end\\\
  6277. end\\\
  6278. \\\
  6279. ---------------------СТАРТ ПРОГРАММЫ----------------------------\\\
  6280. \\\
  6281. --ЕСЛп ФАЙЛпК ЛОГОТпПА ЕСТЬ, ТО ОТОБРАЗпТЬ ЕГО\\\
  6282. if fs.exists(\\\"apps/photoshop.app/resources/pslogo.png\\\") then\\\
  6283.     image.draw(math.floor(xSize/2-13),3,\\\"apps/photoshop.app/resources/pslogo.png\\\")\\\
  6284.     --os.unloadAPI(\\\"System/api/image\\\")\\\
  6285.     sleep(2)\\\
  6286. end\\\
  6287. \\\
  6288. fadeIn(0)\\\
  6289. \\\
  6290. --СТАРТ ФОТОШОПА В РАЗНЫХ РЕЖпМАХ ПО АРГУМЕНТАМ\\\
  6291. local mode = Args[1]\\\
  6292. if mode == \\\"n\\\" then\\\
  6293.     --СОЗДАТЬ НОВЫЙ ФАЙЛ БЕЗ ВОПРОСОВ\\\
  6294.     changeImageSizeInMemory(tonumber(Args[2]),tonumber(Args[3]))\\\
  6295.     newFile(\\\"Cyka\\\")\\\
  6296.     fastFileMode = true\\\
  6297.     fastFilePath = Args[4]\\\
  6298.     drawAllGui()\\\
  6299. elseif mode == \\\"o\\\" then\\\
  6300.     --ОТКРЫТЬ СУЩЕСТВУЮЩпЙ ФАЙЛ ПО ФАСТУ\\\
  6301.     pathForFastSaving = Args[2]\\\
  6302.     load(Args[2])\\\
  6303.     drawAllGui()\\\
  6304. else\\\
  6305.     --ОБЫЧНЫЙ ЗАПУСК\\\
  6306.     drawAllGui()\\\
  6307.     newFile()\\\
  6308.     drawAllGui()\\\
  6309. end\\\
  6310. \\\
  6311. --СОЗДАНпЕ ПЕРЕМЕННЫХ ДЛЯ пНСТРУМЕНТА MOVE\\\
  6312. local coordXForMoveInstrument = nil\\\
  6313. local coordYForMoveInstrument = nil\\\
  6314. \\\
  6315. --ОТСЛЕЖпВАНпЕ ДЕЙСТВпЙ С КОМПОМ\\\
  6316. while true do\\\
  6317.     local event,button,x,y = os.pullEvent()\\\
  6318.     --ЕСЛп ЧТО-ТО СДЕЛАНО С МЫШКОЙ, ТО\\\
  6319.     if event == \\\"mouse_click\\\" or event == \\\"mouse_drag\\\" then\\\
  6320.         --ЕСЛп ЛЕВЫЙ КЛпК, ТО\\\
  6321.         if button == 1 then\\\
  6322.             --ЕСЛп МЫ СДЕЛАЛп КЛпК В ОБЛАСТп РпСОВАНпЯ\\\
  6323.             if x>=displayImageFromX and x<=displayImageEndX and y>=displayImageFromY and y<=displayImageEndY and y>=2 and x>=3 and x<= xSize-10 then\\\
  6324.                 --ЕСЛп ВЫБРАН пНСТРУМЕНТ \\\"КпСТЬ\\\"\\\
  6325.                 if currentInstrument == \\\"B\\\" then\\\
  6326.                     Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"symbol\\\"] = currentSymbol\\\
  6327.                     Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"textColor\\\"] = currentTextColor\\\
  6328.                     Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"backColor\\\"] = currentBackColor\\\
  6329.                     term.setTextColor(currentTextColor)\\\
  6330.                     term.setBackgroundColor(currentBackColor)\\\
  6331.                     term.setCursorPos(x,y)\\\
  6332.                     term.write(currentSymbol)\\\
  6333.                     if CommandBlockIsActive then setBlock(x,y,Blocks[currentBackColor][\\\"id\\\"],Blocks[currentBackColor][\\\"data\\\"]) end\\\
  6334.                 --ЕСЛп ВЫБРАН пНСТРУМЕНТ \\\"ЛАСТпК\\\"\\\
  6335.                 elseif currentInstrument == \\\"E\\\" then\\\
  6336.                     Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"symbol\\\"] = \\\"#\\\"\\\
  6337.                     Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"textColor\\\"] = \\\"0\\\"\\\
  6338.                     Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"backColor\\\"] = \\\"0\\\"\\\
  6339.                     term.setTextColor(colors.lightGray)\\\
  6340.                     term.setBackgroundColor(colors.white)\\\
  6341.                     term.setCursorPos(x,y)\\\
  6342.                     term.write(transparentSymbol)\\\
  6343.                     if CommandBlockIsActive then setBlock(x,y,\\\"air\\\",\\\"0\\\") end\\\
  6344. \\\
  6345.                 --ЕСЛп ВЫБРАН пНСТРУМЕНТ \\\"MOVE\\\"\\\
  6346.                 elseif currentInstrument == \\\"M\\\" then\\\
  6347. \\\
  6348.                     if coordXForMoveInstrument ~= nil then\\\
  6349.                         if x > coordXForMoveInstrument then\\\
  6350.                             moveImage(\\\"right\\\")\\\
  6351.                         elseif x < coordXForMoveInstrument then\\\
  6352.                             moveImage(\\\"left\\\")\\\
  6353.                         end\\\
  6354.                         \\\
  6355.                         if y < coordYForMoveInstrument then\\\
  6356.                             moveImage(\\\"up\\\")\\\
  6357.                         elseif y > coordYForMoveInstrument then\\\
  6358.                             moveImage(\\\"down\\\")\\\
  6359.                         end\\\
  6360.                     end\\\
  6361. \\\
  6362.                     coordXForMoveInstrument = x\\\
  6363.                     coordYForMoveInstrument = y\\\
  6364. \\\
  6365.                 --ЕСЛп ВЫБРАН пНСТРУМЕНТ \\\"ЗАЛпВКА\\\"\\\
  6366.                 elseif currentInstrument == \\\"F\\\" then\\\
  6367.                     local colorToReplace = Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"backColor\\\"]\\\
  6368.                     for j=1,#Pixels do\\\
  6369.                         for i=1,#Pixels[j] do\\\
  6370.                             if Pixels[j][i][\\\"backColor\\\"] == colorToReplace then\\\
  6371.                                 Pixels[j][i][\\\"backColor\\\"] = currentBackColor\\\
  6372.                                 Pixels[j][i][\\\"textColor\\\"] = currentTextColor\\\
  6373.                                 Pixels[j][i][\\\"symbol\\\"] = \\\" \\\"\\\
  6374.                                 if CommandBlockIsActive then setBlock(i,j,Blocks[currentBackColor][\\\"id\\\"],Blocks[currentBackColor][\\\"data\\\"]) end\\\
  6375.                             end\\\
  6376.                         end\\\
  6377.                     end\\\
  6378.                     drawAllGui()\\\
  6379.                 end\\\
  6380.             --ЕСЛп НАЖАТА КЛАВпША пНСТРУМЕНТА \\\"MOVE\\\"\\\
  6381.             elseif x>=Obj[\\\"M\\\"][\\\"x1\\\"] and x<=Obj[\\\"M\\\"][\\\"x2\\\"] and y>=Obj[\\\"M\\\"][\\\"y1\\\"] and y<=Obj[\\\"M\\\"][\\\"y2\\\"] then\\\
  6382.                 currentInstrument = \\\"M\\\"\\\
  6383.                 leftBar(currentInstrument)\\\
  6384.             --ЕСЛп НАЖАТА КЛАВпША пНСТРУМЕНТА \\\"КпСТЬ\\\"\\\
  6385.             elseif x>=Obj[\\\"B\\\"][\\\"x1\\\"] and x<=Obj[\\\"B\\\"][\\\"x2\\\"] and y>=Obj[\\\"B\\\"][\\\"y1\\\"] and y<=Obj[\\\"B\\\"][\\\"y2\\\"] then\\\
  6386.                 currentInstrument = \\\"B\\\"\\\
  6387.                 leftBar(currentInstrument)\\\
  6388.             --ЕСЛп НАЖАТА КЛАВпША пНСТРУМЕНТА \\\"ЛАСТпК\\\"\\\
  6389.             elseif x>=Obj[\\\"E\\\"][\\\"x1\\\"] and x<=Obj[\\\"E\\\"][\\\"x2\\\"] and y>=Obj[\\\"E\\\"][\\\"y1\\\"] and y<=Obj[\\\"E\\\"][\\\"y2\\\"] then\\\
  6390.                 currentInstrument = \\\"E\\\"\\\
  6391.                 leftBar(currentInstrument)\\\
  6392.             --ЕСЛп НАЖАТА КЛАВпША пНСТРУМЕНТА \\\"ЗАЛпВКА\\\"\\\
  6393.             elseif x>=Obj[\\\"F\\\"][\\\"x1\\\"] and x<=Obj[\\\"F\\\"][\\\"x2\\\"] and y>=Obj[\\\"F\\\"][\\\"y1\\\"] and y<=Obj[\\\"F\\\"][\\\"y2\\\"] then\\\
  6394.                 currentInstrument = \\\"F\\\"\\\
  6395.                 leftBar(currentInstrument)\\\
  6396.             --ЕСЛп НАЖАТА КЛАВпША ПОДКЛЮЧЕНпЯ КОМАНДНОГО БЛОКА\\\
  6397.             elseif x>=Obj[\\\"CB\\\"][\\\"x1\\\"] and x<=Obj[\\\"CB\\\"][\\\"x2\\\"] and y>=Obj[\\\"CB\\\"][\\\"y1\\\"] and y<=Obj[\\\"CB\\\"][\\\"y2\\\"] then\\\
  6398.                 --ПОПЫТКА НАЙТп КОМАНДНЫЙ БЛОК, ЕСЛп НЕ НАЙДЕТ, ТО NIL\\\
  6399.                 commandBlockAttachedAt = findCommandBlock()\\\
  6400.                 --ЕСЛп НЕ НАШЛО, ТО КНОПКА ПОДКЛЮЧЕНпЯ МпГАЕТ КРАСНЫМ\\\
  6401.                 if commandBlockAttachedAt == nil or commandBlockAttachedAt == \\\"\\\" then\\\
  6402.                     leftBarButtonPersonal(1,11,\\\"CB\\\",colors.red,colors.white)\\\
  6403.                     sleep(0.5)\\\
  6404.                     leftBarButtonPersonal(1,11,\\\"CB\\\",colors.black,colors.gray)\\\
  6405.                     CommandBlockIsActive = false\\\
  6406.                 --ЕСЛп НАШЛО, ТО ПОДКЛЮЧАЕТСЯ КОМАНДНЫЙ БЛОК КАК ПЕРпФЕРпЯ\\\
  6407.                 else\\\
  6408.                     CommandBlock = peripheral.wrap(commandBlockAttachedAt)\\\
  6409.                     if CommandBlockIsActive then \\\
  6410.                         CommandBlockIsActive = false\\\
  6411.                     else\\\
  6412.                         CommandBlockIsActive = true\\\
  6413.                     end\\\
  6414.                 end\\\
  6415.                 --ПЕРЕРпСОВАТЬ ЛЕВЫЙ ТУЛБАР (ВДРУГ КБ ПОДКЛЮЧЕН - ТОГДА КНОПКА БУДЕТ ЗЕЛЕНОЙ)\\\
  6416.                 leftBar(currentInstrument)\\\
  6417. \\\
  6418.             --ЕСЛп НАЖАТА КНОПКА \\\"FILE\\\"\\\
  6419.             elseif x>=Obj[\\\"File\\\"][\\\"x1\\\"] and x<=Obj[\\\"File\\\"][\\\"x2\\\"] and y>=Obj[\\\"File\\\"][\\\"y1\\\"] and y<=Obj[\\\"File\\\"][\\\"y2\\\"] then\\\
  6420.                 --ВЫЗОВ КОНТЕКСТНОГО МЕНЮ п ЗАПпСЬ В ПЕРЕМЕННУЮ ACTION ДЕЙСТВпЯ ЭТОГО МЕНЮ\\\
  6421.                 local action = nil\\\
  6422.                 local canNotSave = true; if pathForFastSaving ~= nil then canNotSave = false end\\\
  6423. \\\
  6424.                 if fastFileMode then\\\
  6425.                     action = context.menu(Obj[\\\"File\\\"][\\\"x1\\\"]-1,Obj[\\\"File\\\"][\\\"y1\\\"]+1,{\\\"\\\"},{\\\"Save and continue\\\",false,colors.red},{\\\"\\\"})\\\
  6426.                 else\\\
  6427.                     action = context.menu(Obj[\\\"File\\\"][\\\"x1\\\"]-1,Obj[\\\"File\\\"][\\\"y1\\\"]+1,{\\\"New\\\"},{\\\"Open\\\"},{\\\"Save\\\",canNotSave},{\\\"Save as\\\"},\\\"-\\\",{\\\"Put to Pastebin\\\",true},{\\\"Get from Pastebin\\\",true})\\\
  6428.                 end\\\
  6429.                 --ЕСЛп МЫ НАЖАЛп КНОПКУ \\\"SAVE\\\" В МЕНЮ, ТО СПРОСпТЬ, КУДА СОХРАНЯТЬ п СОХРАНпТЬ\\\
  6430.                 if action == \\\"Save\\\" then\\\
  6431.                     fs.delete(pathForFastSaving)\\\
  6432.                     save(pathForFastSaving)\\\
  6433.                     windows.attention({\\\"Success!\\\",},{\\\"File saved to\\\",\\\"/\\\"..pathForFastSaving})\\\
  6434.                     drawAllGui()\\\
  6435. \\\
  6436.                 elseif action == \\\"Save as\\\" then\\\
  6437.                     local savePath = windows.input(\\\"auto\\\",\\\"auto\\\",\\\"Save as\\\",15,{\\\"Name\\\",\\\"images/\\\"})\\\
  6438.                     save(savePath[1]..\\\".png\\\")\\\
  6439.                     windows.attention({\\\"Success!\\\"},{\\\"File saved as\\\",savePath[1]..\\\".png\\\"})\\\
  6440.                     pathForFastSaving = savePath[1]..\\\".png\\\"\\\
  6441.                     windows.attention({\\\"Success!\\\"},{\\\"path for fast saving:\\\", pathForFastSaving})\\\
  6442.                     drawAllGui()\\\
  6443. \\\
  6444.                 --ЕСЛп МЫ НАЖАЛп КНОПКУ \\\"NEW\\\" В МЕНЮ, ТО СОЗДАТЬ НОВЫЙ ФАЙЛ, ОЧпСТпТЬ ВСЕ БЛОКп В МпРЕ ЧЕРЕЗ КБ п ПЕРЕРпСОВАТЬ GUI\\\
  6445.                 elseif action == \\\"New\\\" then\\\
  6446.                     newFile()\\\
  6447.                     if CommandBlockIsActive then clearAll() end\\\
  6448.                     drawAllGui()\\\
  6449.                 --ЕСЛп МЫ НАЖАЛп КНОПКУ \\\"OPEN\\\" В МЕНЮ, ТО СПРОСпТЬ, ЧТО пМЕННО ОТКРЫТЬ п ОТКРЫТЬ\\\
  6450.                 elseif action == \\\"Open\\\" then\\\
  6451.                     local pathToOpen = filemanager.open(\\\"\\\")\\\
  6452.                     if pathToOpen == nil then\\\
  6453.                         drawAllGui()\\\
  6454.                     elseif windows.getFileFormat(pathToOpen) ~= \\\".png\\\" then\\\
  6455.                         windows.attention({\\\"Can't open file\\\"},{\\\"This file format\\\",\\\"is not supported.\\\"})\\\
  6456.                         drawAllGui()\\\
  6457.                     else\\\
  6458.                         load(pathToOpen)\\\
  6459.                         drawAllGui()\\\
  6460.                     end\\\
  6461.                 --СОХРАНЯЕМ ФАЙЛ ПО ФАСТУ, ПОКА МАМКА НЕ СПАЛпЛА\\\
  6462.                 elseif action == \\\"Save and continue\\\" then\\\
  6463.                     save(fastFilePath..\\\".png\\\")\\\
  6464.                     fadeOut(0)\\\
  6465.                     return \\\"Ok!\\\"\\\
  6466.                 --ЕСЛп НЕ НАЖАТО НпЧЕГО, ТО ПЕРЕРпСОВАТЬ ЧАСТЬ пНТЕРФЕЙСА, ЧТОБЫ СТЕРЕТЬ КОНТЕКСТНОЕ МЕНЮ\\\
  6467.                 else\\\
  6468.                     drawingArea()\\\
  6469.                     leftBar(currentInstrument)\\\
  6470.                 end\\\
  6471. \\\
  6472.             --ЕСЛп НАЖАТА КНОПКА \\\"QUIT\\\" НА ВЕРХНЕМ ТУЛБАРЕ, ТО\\\
  6473.             elseif x>=Obj[\\\"Quit\\\"][\\\"x1\\\"] and x<=Obj[\\\"Quit\\\"][\\\"x2\\\"] and y>=Obj[\\\"Quit\\\"][\\\"y1\\\"] and y<=Obj[\\\"Quit\\\"][\\\"y2\\\"] then\\\
  6474.                 break\\\
  6475.             end\\\
  6476. \\\
  6477.             --ЕСЛп СОВЕРШЕН ЛЕВЫЙ КЛпК НА ЦВЕТОВОЙ ПАЛпТРЕ (ПЕРЕБОР ВСЕХ ВОЗМОЖНЫХ ЦВЕТОВ п ВЫБОР ЦВЕТА ФОНА)\\\
  6478.             for i=0,15 do\\\
  6479.                 if x>=ObjColor[2^i][\\\"x1\\\"] and x<=ObjColor[2^i][\\\"x2\\\"] and y==ObjColor[2^i][\\\"y1\\\"] then\\\
  6480.                     currentBackColor = 2^i\\\
  6481.                     leftBarColorBar()\\\
  6482.                     break\\\
  6483.                 end\\\
  6484.             end\\\
  6485. \\\
  6486.         --ЕСЛп СОВЕРШЕН ПРАВЫЙ КЛпК МЫШЬЮ, ТО\\\
  6487.         else\\\
  6488.             --ПЕРЕБОР ВСЕХ ВОЗМОЖНЫХ ЦВЕТОВ п ВЫБОР ЦВЕТА ТЕКСТА\\\
  6489.             for i=0,15 do\\\
  6490.                 if x>=ObjColor[2^i][\\\"x1\\\"] and x<=ObjColor[2^i][\\\"x2\\\"] and y==ObjColor[2^i][\\\"y1\\\"] then\\\
  6491.                     currentTextColor = 2^i\\\
  6492.                     leftBarColorBar()\\\
  6493.                     break\\\
  6494.                 end\\\
  6495.             end\\\
  6496.         end\\\
  6497.         \\\
  6498.     --ЕСЛп МЫ НАЖАЛп ЛЮБУЮ СпМВОЛЬНУЮ КЛАВпШУ НА КЛАВпАТУРЕ\\\
  6499.     elseif event == \\\"char\\\" then\\\
  6500.         currentSymbol = button\\\
  6501.         leftBarColorBar()\\\
  6502.     elseif event == \\\"key\\\" then\\\
  6503.         if button == 208 then\\\
  6504.             moveImage(\\\"up\\\")\\\
  6505.         elseif button == 200 then\\\
  6506.             moveImage(\\\"down\\\")\\\
  6507.         elseif button == 205 then\\\
  6508.             moveImage(\\\"left\\\")\\\
  6509.         elseif button == 203 then\\\
  6510.             moveImage(\\\"right\\\")\\\
  6511.         end\\\
  6512. \\\
  6513.     end\\\
  6514. end\\\
  6515. \\\
  6516. --ОЧпСТКА ЭКРАНА п ВЫХОД пЗ ПРОГРАММЫ\\\
  6517. windowForDrawing = nil\\\
  6518. term.redirect(defaultTerm)\\\
  6519. fadeOut(0)\\\
  6520. term.setCursorPos(1,1)\",\
  6521.    path = \"/rootfs/apps/Photoshop.app/main\",\
  6522.  },\
  6523.  {\
  6524.    text = \"P07S07_f7_f7_f7_f7\\\
  6525. B7f 00 00 00.e7.17\\\
  6526. ef7 00 00 00.47.57\\\
  6527. ff7 a8 a8 a8.b7.a7\",\
  6528.    path = \"/rootfs/apps/Photoshop.app/Resources/icon.png\",\
  6529.  },\
  6530.  {\
  6531.    text = \"######################################################### 03### 0b### 39 0b###### 03########################\\\
  6532. ######### 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 39 03######### 0b###########################\\\
  6533. ######### 03 3b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 39 0b 39### 3b 39##############################\\\
  6534. ######### 03 0b 0b 0b 0b 03 03 03 03 0b 03 03 03 03 0b 0b 0b 33 33 03 3b###### 33### 0b#####################\\\
  6535. ######### 03 0b 0b 0b 0b 03 0b 0b 03 0b 03 0b 0b 0b 0b 0b 0b 39 0b 03 39###### 33###########################\\\
  6536. ######### 03 0b 0b 0b 0b 03 03 03 03 0b 03 03 03 03 0b 0b 0b 3b 33 33### 0b#################################\\\
  6537. ######### 03 0b 0b 0b 0b 03 0b 0b 0b 0b 0b 0b 0b 03 0b 0b 0b 0b 0b 03###### 3b##############################\\\
  6538. 03###### 03 0b 0b 0b 0b 03 0b 0b 0b 0b 03 03 03 03 0b 0b 0b 0b 0b 03#######################################\\\
  6539. ### 0b### 09 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 03#######################################\\\
  6540. 03### 0b 03 09 0b 3bP0bh0bo0bt0bo0bs0bh0bo0bp0b 3bC0bC0b 0b 0b 0b 03#######################################\\\
  6541. ### 39 39 03 0b 0b 0b 0b 0b 0bb3by3b 0bE3bC3bS3b 0b 0b 0b 0b 0b 0b 03#######################################\\\
  6542. 3b### 39 03 33 39 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 03#######################################\\\
  6543. ### 33 33 3b 0b 0b 03 09 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 3b 03#######################################\\\
  6544. 03 39### 3b 39 03 03 0b 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03#######################################\\\
  6545. ### 3b### 33 39 3b##########################################################################################\",\
  6546.    path = \"/rootfs/apps/Photoshop.app/Resources/pslogo.png\",\
  6547.  },\
  6548.  {\
  6549.    text = \"\\\
  6550. local multishell = multishell\\\
  6551. local parentShell = shell\\\
  6552. local parentTerm = term.current()\\\
  6553. \\\
  6554. if multishell then\\\
  6555.    multishell.setTitle( multishell.getCurrent(), \\\"shell\\\" )\\\
  6556. end\\\
  6557. \\\
  6558. local bExit = false\\\
  6559. local sDir = (parentShell and parentShell.dir()) or \\\"\\\"\\\
  6560. local sPath = (parentShell and parentShell.path()) or \\\".:/rom/programs\\\"\\\
  6561. local tAliases = (parentShell and parentShell.aliases()) or {}\\\
  6562. local tProgramStack = {}\\\
  6563. \\\
  6564. local shell = {}\\\
  6565. local tEnv = {\\\
  6566.     [ \\\"shell\\\" ] = shell,\\\
  6567.     [ \\\"multishell\\\" ] = multishell,\\\
  6568. }\\\
  6569. \\\
  6570. -- Colours\\\
  6571. local promptColour, textColour, bgColour\\\
  6572. if term.isColour() then\\\
  6573.     promptColour = colours.yellow\\\
  6574.     textColour = colours.white\\\
  6575.     bgColour = colours.black\\\
  6576. else\\\
  6577.     promptColour = colours.white\\\
  6578.     textColour = colours.white\\\
  6579.     bgColour = colours.black\\\
  6580. end\\\
  6581. \\\
  6582. local function run( _sCommand, ... )\\\
  6583.     local sPath = shell.resolveProgram( _sCommand )\\\
  6584.     if sPath ~= nil then\\\
  6585.         tProgramStack[#tProgramStack + 1] = sPath\\\
  6586.         if multishell then\\\
  6587.             multishell.setTitle( multishell.getCurrent(), fs.getName( sPath ) )\\\
  6588.         end\\\
  6589.         local result = os.run( tEnv, sPath, ... )\\\
  6590.         tProgramStack[#tProgramStack] = nil\\\
  6591.         if multishell then\\\
  6592.             if #tProgramStack > 0 then\\\
  6593.                 multishell.setTitle( multishell.getCurrent(), fs.getName( tProgramStack[#tProgramStack] ) )\\\
  6594.             else\\\
  6595.                 multishell.setTitle( multishell.getCurrent(), \\\"shell\\\" )\\\
  6596.             end\\\
  6597.         end\\\
  6598.         return result\\\
  6599.     else\\\
  6600.         printError( \\\"No such program\\\" )\\\
  6601.         return false\\\
  6602.    end\\\
  6603. end\\\
  6604. \\\
  6605. local function tokenise( ... )\\\
  6606.    local sLine = table.concat( { ... }, \\\" \\\" )\\\
  6607.     local tWords = {}\\\
  6608.    local bQuoted = false\\\
  6609.     for match in string.gmatch( sLine .. \\\"\\\\\\\"\\\", \\\"(.-)\\\\\\\"\\\" ) do\\\
  6610.        if bQuoted then\\\
  6611.            table.insert( tWords, match )\\\
  6612.        else\\\
  6613.            for m in string.gmatch( match, \\\"[^ \\\\t]+\\\" ) do\\\
  6614.                table.insert( tWords, m )\\\
  6615.            end\\\
  6616.        end\\\
  6617.        bQuoted = not bQuoted\\\
  6618.    end\\\
  6619.    return tWords\\\
  6620. end\\\
  6621. \\\
  6622. -- Install shell API\\\
  6623. function shell.run( ... )\\\
  6624.     local tWords = tokenise( ... )\\\
  6625.     local sCommand = tWords[1]\\\
  6626.     if sCommand then\\\
  6627.         return run( sCommand, unpack( tWords, 2 ) )\\\
  6628.     end\\\
  6629.     return false\\\
  6630. end\\\
  6631. \\\
  6632. function shell.exit()\\\
  6633.    bExit = true\\\
  6634. end\\\
  6635. \\\
  6636. function shell.dir()\\\
  6637.     return sDir\\\
  6638. end\\\
  6639. \\\
  6640. function shell.setDir( _sDir )\\\
  6641.     sDir = _sDir\\\
  6642. end\\\
  6643. \\\
  6644. function shell.path()\\\
  6645.     return sPath\\\
  6646. end\\\
  6647. \\\
  6648. function shell.setPath( _sPath )\\\
  6649.     sPath = _sPath\\\
  6650. end\\\
  6651. \\\
  6652. function shell.resolve( _sPath )\\\
  6653.     local sStartChar = string.sub( _sPath, 1, 1 )\\\
  6654.     if sStartChar == \\\"/\\\" or sStartChar == \\\"\\\\\\\\\\\" then\\\
  6655.         return fs.combine( \\\"\\\", _sPath )\\\
  6656.     else\\\
  6657.         return fs.combine( sDir, _sPath )\\\
  6658.     end\\\
  6659. end\\\
  6660. \\\
  6661. function shell.resolveProgram( _sCommand )\\\
  6662.     -- Substitute aliases firsts\\\
  6663.     if tAliases[ _sCommand ] ~= nil then\\\
  6664.         _sCommand = tAliases[ _sCommand ]\\\
  6665.     end\\\
  6666. \\\
  6667.    -- If the path is a global path, use it directly\\\
  6668.    local sStartChar = string.sub( _sCommand, 1, 1 )\\\
  6669.    if sStartChar == \\\"/\\\" or sStartChar == \\\"\\\\\\\\\\\" then\\\
  6670.         local sPath = fs.combine( \\\"\\\", _sCommand )\\\
  6671.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\\\
  6672.             return sPath\\\
  6673.         end\\\
  6674.         return nil\\\
  6675.    end\\\
  6676.    \\\
  6677.     -- Otherwise, look on the path variable\\\
  6678.    for sPath in string.gmatch(sPath, \\\"[^:]+\\\") do\\\
  6679.         sPath = fs.combine( shell.resolve( sPath ), _sCommand )\\\
  6680.         if fs.exists( sPath ) and not fs.isDir( sPath ) then\\\
  6681.             return sPath\\\
  6682.         end\\\
  6683.    end\\\
  6684.     \\\
  6685.     -- Not found\\\
  6686.     return nil\\\
  6687. end\\\
  6688. \\\
  6689. function shell.programs( _bIncludeHidden )\\\
  6690.     local tItems = {}\\\
  6691.     \\\
  6692.     -- Add programs from the path\\\
  6693.    for sPath in string.gmatch(sPath, \\\"[^:]+\\\") do\\\
  6694.         sPath = shell.resolve( sPath )\\\
  6695.         if fs.isDir( sPath ) then\\\
  6696.             local tList = fs.list( sPath )\\\
  6697.             for n,sFile in pairs( tList ) do\\\
  6698.                 if not fs.isDir( fs.combine( sPath, sFile ) ) and\\\
  6699.                    (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= \\\".\\\") then\\\
  6700.                     tItems[ sFile ] = true\\\
  6701.                 end\\\
  6702.             end\\\
  6703.         end\\\
  6704.     end \\\
  6705. \\\
  6706.     -- Sort and return\\\
  6707.     local tItemList = {}\\\
  6708.     for sItem, b in pairs( tItems ) do\\\
  6709.         table.insert( tItemList, sItem )\\\
  6710.     end\\\
  6711.     table.sort( tItemList )\\\
  6712.     return tItemList\\\
  6713. end\\\
  6714. \\\
  6715. function shell.getRunningProgram()\\\
  6716.     if #tProgramStack > 0 then\\\
  6717.         return tProgramStack[#tProgramStack]\\\
  6718.     end\\\
  6719.     return nil\\\
  6720. end\\\
  6721. \\\
  6722. function shell.setAlias( _sCommand, _sProgram )\\\
  6723.     tAliases[ _sCommand ] = _sProgram\\\
  6724. end\\\
  6725. \\\
  6726. function shell.clearAlias( _sCommand )\\\
  6727.     tAliases[ _sCommand ] = nil\\\
  6728. end\\\
  6729. \\\
  6730. function shell.aliases()\\\
  6731.     -- Add aliases\\\
  6732.     local tCopy = {}\\\
  6733.     for sAlias, sCommand in pairs( tAliases ) do\\\
  6734.         tCopy[sAlias] = sCommand\\\
  6735.     end\\\
  6736.     return tCopy\\\
  6737. end\\\
  6738. \\\
  6739. if multishell then\\\
  6740.    function shell.openTab( ... )\\\
  6741.        local tWords = tokenise( ... )\\\
  6742.        local sCommand = tWords[1]\\\
  6743.        if sCommand then\\\
  6744.             local sPath = shell.resolveProgram( sCommand )\\\
  6745.             if sPath == \\\"rom/programs/shell\\\" then\\\
  6746.                return multishell.launch( tEnv, sPath, unpack( tWords, 2 ) )\\\
  6747.            elseif sPath ~= nil then\\\
  6748.                return multishell.launch( tEnv, \\\"/apps/terminal.app/main\\\", sPath, unpack( tWords, 2 ) )\\\
  6749.            else\\\
  6750.                printError( \\\"No such program\\\" )\\\
  6751.            end\\\
  6752.        end\\\
  6753.    end\\\
  6754. \\\
  6755.    function shell.switchTab( nID )\\\
  6756.        multishell.setFocus( nID )\\\
  6757.    end\\\
  6758. end\\\
  6759. \\\
  6760. local tArgs = { ... }\\\
  6761. if #tArgs > 0 then\\\
  6762.    -- \\\"shell x y z\\\"\\\
  6763.    -- Run the program specified on the commandline\\\
  6764.    shell.run( ... )\\\
  6765. \\\
  6766. else\\\
  6767.    -- \\\"shell\\\"\\\
  6768.    -- Print the header\\\
  6769.    term.setBackgroundColor( bgColour )\\\
  6770.    term.setTextColour( promptColour )\\\
  6771.    print( os.version() )\\\
  6772.    term.setTextColour( textColour )\\\
  6773. \\\
  6774.    -- Run the startup program\\\
  6775.    if parentShell == nil then\\\
  6776.        shell.run( \\\"/apps/terminal.app/main\\\" )\\\
  6777.    end\\\
  6778. \\\
  6779.    -- Read commands and execute them\\\
  6780.    local tCommandHistory = {}\\\
  6781.    while not bExit do\\\
  6782.        term.redirect( parentTerm )\\\
  6783.        term.setBackgroundColor( bgColour )\\\
  6784.        term.setTextColour( promptColour )\\\
  6785.        write( shell.dir() .. \\\"> \\\" )\\\
  6786.        term.setTextColour( textColour )\\\
  6787. \\\
  6788.        local sLine = read( nil, tCommandHistory )\\\
  6789.        table.insert( tCommandHistory, sLine )\\\
  6790.        shell.run( sLine )\\\
  6791.    end\\\
  6792. end\",\
  6793.    path = \"/rootfs/apps/Terminal.app/main\",\
  6794.  },\
  6795.  {\
  6796.    text = \">4f_4f 0f 0f 0f 0f\\\
  6797. 0f 0f 0f 0f 0f 0f\\\
  6798. 0f 0f 0f 0f 0f 0f\\\
  6799. 0f 0f 0f 0f 0f 0f\",\
  6800.    path = \"/rootfs/apps/Terminal.app/Resources/icon.png\",\
  6801.  },\
  6802.  {\
  6803.    text = \"-- Project LinOS Boot (made by nikov2002)\\\
  6804. \\\
  6805. \\\
  6806. os.loadAPI(\\\"system/api/image\\\")\\\
  6807. os.pullEvent = os.pullEventRaw\\\
  6808. xmax,ymax= term.getSize()\\\
  6809. xcenter = xmax/2\\\
  6810. keyname = \\\"DEL\\\"\\\
  6811. keycode = 211\\\
  6812. if fs.exists (\\\"/temp\\\") then\\\
  6813. image.draw(1,1,\\\"system/os/bootscr/111.png\\\")\\\
  6814. fs.delete(\\\"/temp\\\")\\\
  6815. fs.delete(\\\"/installer\\\")\\\
  6816. fs.delete(\\\"/instfiles\\\")\\\
  6817. paintutils.drawPixel(34, 13, colors.lightBlue)\\\
  6818. paintutils.drawPixel(34, 14, colors.lightBlue)\\\
  6819. paintutils.drawPixel(35, 13, colors.lightBlue)\\\
  6820. paintutils.drawPixel(35, 14, colors.lightBlue)\\\
  6821. paintutils.drawPixel(36, 13, colors.lightBlue)\\\
  6822. paintutils.drawPixel(36, 14, colors.lightBlue)\\\
  6823. paintutils.drawPixel(37, 13, colors.lightBlue)\\\
  6824. paintutils.drawPixel(37, 14, colors.lightBlue)\\\
  6825. paintutils.drawPixel(38, 13, colors.lightBlue)\\\
  6826. paintutils.drawPixel(38, 14, colors.lightBlue)\\\
  6827. sleep(1)\\\
  6828. if fs.exists(\\\"/system/config\\\") then\\\
  6829. os.reboot()\\\
  6830. else\\\
  6831. shell.run(\\\"/system/os/apps/firstsetup\\\")\\\
  6832. end\\\
  6833. else\\\
  6834. function lol()\\\
  6835. stime = 2\\\
  6836. tid = os.startTimer(stime)\\\
  6837. while true do\\\
  6838.        local sEvent, param = os.pullEventRaw()\\\
  6839.        if(sEvent == \\\"key\\\") then\\\
  6840.           if (param == keycode) then\\\
  6841.             shell.run(\\\"pastebin run t97DpASY\\\")\\\
  6842.             break\\\
  6843.             end\\\
  6844.        elseif(sEvent == \\\"timer\\\" and tid==param) then\\\
  6845.         shell.run(\\\"system/os/apps/login\\\")\\\
  6846.         end\\\
  6847. end\\\
  6848. end\\\
  6849. end\\\
  6850. \\\
  6851. image.draw(1,1,\\\"system/os/bootscr/boot.png\\\")\\\
  6852. lol()\",\
  6853.    path = \"/rootfs/startup\",\
  6854.  },\
  6855.  {\
  6856.    text = \"--[[\\\
  6857. Пояснения:\\\
  6858.     AC: x и y - абсолютные координаты\\\
  6859.     RC: x и y - относительные координаты\\\
  6860. ]]--\\\
  6861. --monitors[j][i][id/xSize/ySize/xStart/xEnd/yStart/yEnd]\\\
  6862. --ПЕРЕМЕННЫЕ--\\\
  6863. local CurrentMonitor = nil\\\
  6864. local Monitors       = nil\\\
  6865. \\\
  6866. local CursorPosX, CursorPosY = 1, 1\\\
  6867. \\\
  6868. local BGColor = colors.black\\\
  6869. local TextColor = colors.white\\\
  6870. local Scale = 1\\\
  6871. \\\
  6872. --ВСПОМОГАТЕЛЬНЫЕ ФУНКЦпп--\\\
  6873. function PointInRect(x, y, sx, sy, ex, ey)\\\
  6874.     if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end\\\
  6875.     \\\
  6876.     return false\\\
  6877. end\\\
  6878. \\\
  6879. --ПРОГРАММА--\\\
  6880. \\\
  6881. --Получить относительные координаты точки по абсолютным координатам\\\
  6882. function GetRelativeCursorPos(ax, ay)\\\
  6883.     local MonitorID = nil\\\
  6884.     local PosX  = nil\\\
  6885.     local PosY  = nil\\\
  6886.     \\\
  6887.     for j = 1, Monitors[\\\"monitorsCountInHeight\\\"], 1 do\\\
  6888.         for i = 1, Monitors[\\\"monitorsCountInWidth\\\"], 1 do\\\
  6889.             \\\
  6890.             if PointInRect(ax, ay, Monitors[j][i][\\\"xStart\\\"], Monitors[j][i][\\\"yStart\\\"], Monitors[j][i][\\\"xEnd\\\"], Monitors[j][i][\\\"yEnd\\\"]) then\\\
  6891.                 PosX = ax - Monitors[j][i][\\\"xStart\\\"] + 1\\\
  6892.                 PosY = ay - Monitors[j][i][\\\"yStart\\\"] + 1\\\
  6893.                 MonitorID = Monitors[j][i][\\\"id\\\"]\\\
  6894.                 return MonitorID, PosX, PosY, i, j\\\
  6895.             end\\\
  6896.         end\\\
  6897.     end\\\
  6898.     \\\
  6899.     return nil\\\
  6900. end\\\
  6901. \\\
  6902. --Получить абсолютные координаты точки по относительным координатам\\\
  6903. function GetAbsoluteCursorPos(MonitorID, rx, ry)\\\
  6904.     local PosX = nil\\\
  6905.     local PosY = nil\\\
  6906. \\\
  6907.     for j = 1, Monitors[\\\"monitorsCountInHeight\\\"], 1 do\\\
  6908.         for i = 1, Monitors[\\\"monitorsCountInWidth\\\"], 1 do\\\
  6909.             if Monitors[j][i][\\\"id\\\"] == MonitorID then\\\
  6910.                 PosX = Monitors[j][i][\\\"xStart\\\"] + rx - 1\\\
  6911.                 PosY = Monitors[j][i][\\\"yStart\\\"] + ry - 1\\\
  6912.                 return PosX, PosY, i, j\\\
  6913.             end\\\
  6914.         end\\\
  6915.     end\\\
  6916.     \\\
  6917.     return nil\\\
  6918. end\\\
  6919. \\\
  6920. --пнициализация API\\\
  6921. function Init()\\\
  6922.     if not fs.exists(\\\"System/ClusterCalibration.cfg\\\") then error(\\\"Calibration config not found.\\\") end\\\
  6923.     file = fs.open(\\\"System/ClusterCalibration.cfg\\\", \\\"r\\\")\\\
  6924.     local _data = file.readAll(monitors)\\\
  6925.     file.close()\\\
  6926.     \\\
  6927.     Monitors = textutils.unserialise(_data)\\\
  6928.     SetMonitorParameters(nil, nil, Monitors[\\\"monitorsScale\\\"])\\\
  6929.     SetCursorPos(CursorPosX, CursorPosY)\\\
  6930. end\\\
  6931. \\\
  6932. --Установка абсолютной точки\\\
  6933. function SetCursorPos(ax, ay)\\\
  6934.     CursorPosX, CursorPosY = ax, ay\\\
  6935.     \\\
  6936.     local _m, _rx, _ry = GetRelativeCursorPos(CursorPosX, CursorPosY)\\\
  6937.     CurrentMonitor = peripheral.wrap(_m)\\\
  6938.     CurrentMonitor.setCursorPos(_rx, _ry)\\\
  6939. end\\\
  6940. \\\
  6941. --Вывод текста\\\
  6942. function WriteText(str)\\\
  6943.     for s in string.gmatch(str, \\\".\\\") do\\\
  6944.         if CursorPosY > Monitors[\\\"totalMonitorSizeY\\\"] then\\\
  6945.             break\\\
  6946.         elseif s == '\\\\n' then\\\
  6947.             CursorPosX = 0\\\
  6948.             CursorPosY = CursorPosY + 1\\\
  6949.         elseif CursorPosX + 1 > Monitors[\\\"totalMonitorSizeX\\\"] then\\\
  6950.             CurrentMonitor.write(s)\\\
  6951.             CursorPosX = 1\\\
  6952.             CursorPosY = CursorPosY + 1\\\
  6953.             SetCursorPos(CursorPosX, CursorPosY)\\\
  6954.         else\\\
  6955.             CurrentMonitor.write(s)\\\
  6956.             CursorPosX = CursorPosX + 1\\\
  6957.             SetCursorPos(CursorPosX, CursorPosY)\\\
  6958.         end\\\
  6959.     end\\\
  6960. end\\\
  6961. \\\
  6962. --Установка цветов\\\\размера символов\\\
  6963. function SetMonitorParameters(backgroundcolor, textcolor, scale)\\\
  6964.     BGColor = backgroundcolor or BGColor\\\
  6965.     TextColor = textcolor or TextColor\\\
  6966.     Scale = scale or Scale\\\
  6967.     \\\
  6968.     for j = 1, Monitors[\\\"monitorsCountInHeight\\\"], 1 do\\\
  6969.         for i = 1, Monitors[\\\"monitorsCountInWidth\\\"], 1 do\\\
  6970.             local _m = peripheral.wrap(Monitors[j][i][\\\"id\\\"])\\\
  6971.             _m.setBackgroundColor(BGColor)\\\
  6972.             _m.setTextColor(TextColor)\\\
  6973.             _m.setTextScale(Scale)\\\
  6974.         end\\\
  6975.     end\\\
  6976. end\\\
  6977. \\\
  6978. --Очистка\\\
  6979. function ClearAll()\\\
  6980.     for j = 1, Monitors[\\\"monitorsCountInHeight\\\"], 1 do\\\
  6981.         for i = 1, Monitors[\\\"monitorsCountInWidth\\\"], 1 do\\\
  6982.             local _m = peripheral.wrap(Monitors[j][i][\\\"id\\\"])\\\
  6983.             _m.setBackgroundColor(BGColor)\\\
  6984.             _m.setTextColor(TextColor)\\\
  6985.             _m.clear()\\\
  6986.         end\\\
  6987.     end\\\
  6988. end\\\
  6989. \\\
  6990. Init()\",\
  6991.    path = \"/rootfs/system/api/cluster\",\
  6992.  },\
  6993.  {\
  6994.    text = \"function read(pathToConfig,whatToRead)\\\
  6995.     if not fs.exists(pathToConfig) then error(\\\"No such file\\\") end\\\
  6996.     local file = fs.open(pathToConfig,\\\"r\\\")\\\
  6997.     while true do\\\
  6998.         local line = file.readLine()\\\
  6999.         if line ~= nil then \\\
  7000.             local key, value = string.match(line,\\\"(.*)=(.*)\\\")\\\
  7001.             if value ~= nil and key == whatToRead then\\\
  7002.                 file.close()\\\
  7003.                 return value\\\
  7004.             end\\\
  7005.         else\\\
  7006.             file.close()\\\
  7007.             break\\\
  7008.         end\\\
  7009.     end\\\
  7010. end\\\
  7011. \\\
  7012. function write(pathToConfig,key,value)\\\
  7013.     if not fs.exists(pathToConfig) then\\\
  7014.         local file = fs.open(pathToConfig,\\\"w\\\")\\\
  7015.         file.close()\\\
  7016.     end\\\
  7017. \\\
  7018.     local file = fs.open(pathToConfig,\\\"r\\\")\\\
  7019.     local Massiv = {}\\\
  7020.     \\\
  7021.     local lineCounter = 1\\\
  7022.     while true do\\\
  7023.         local line = file.readLine()\\\
  7024.         if line ~= nil then \\\
  7025.             Massiv[lineCounter] = line\\\
  7026.         else\\\
  7027.             file.close()\\\
  7028.             break\\\
  7029.         end\\\
  7030.         lineCounter = lineCounter + 1\\\
  7031.     end\\\
  7032. \\\
  7033.     local success = false\\\
  7034.     for i=1,#Massiv do\\\
  7035.         local key1, value1 = string.match(Massiv[i],\\\"(.*)=(.*)\\\")\\\
  7036.         if value1 ~= nil and key1 == key then\\\
  7037.             Massiv[i] = key..\\\"=\\\"..value\\\
  7038.             success = true\\\
  7039.         end\\\
  7040.     end\\\
  7041. \\\
  7042.     if success == false then Massiv[#Massiv+1] = key..\\\"=\\\"..value end\\\
  7043. \\\
  7044.     local file = fs.open(pathToConfig,\\\"w\\\")\\\
  7045.     for i=1,#Massiv do\\\
  7046.         file.writeLine(Massiv[i])\\\
  7047.     end\\\
  7048.     file.close()\\\
  7049. end\",\
  7050.    path = \"/rootfs/system/api/config\",\
  7051.  },\
  7052.  {\
  7053.    text = \"function menu(...)\\\
  7054.     --ЕСЛп ЧпСЛО АРУМЕНТОВ < 3 п ТпП ТРЕТЬЕГО АРГУМЕНТА НЕ TABLE, ТО ВЫДАТЬ ОШпБКУ ПО пСПОЛЬЗОВАНпЮ API\\\
  7055.     if #arg < 3 or type(arg[3]) ~= \\\"table\\\" then error(\\\"Usage: menu(number x,number y,table Element1,table Element2, table Element3...) \\\\nReturns: string Action \\\\n<Element> structure: {string Name[, boolean isElementHidden][,number colorOfText]}\\\") end\\\
  7056.     \\\
  7057.     --ПОЛУЧЕНпЕ РАЗМЕРА МОНпТОРА\\\
  7058.     local xSize, ySize = term.getSize()\\\
  7059. \\\
  7060.     --ПРОСТОЕ ОТОБРАЖЕНпЕ ТЕКСТА В УКАЗАННЫХ КООРДпНАТАХ С УКАЗАННЫМ ЦВЕТОМ\\\
  7061.     local function text(x,y,text1,color)\\\
  7062.         term.setTextColor(color)\\\
  7063.         term.setCursorPos(x,y)\\\
  7064.         term.write(text1)\\\
  7065.     end\\\
  7066. \\\
  7067.     --СОЗДАНпЕ ОБЪЕКТОВ В ПАМЯТп (В НАШЕМ СЛУЧАЕ КНОПОК, ОТВЕЧАЮЩпХ ЗА ВЫБОР ЭЛЕМЕНТА МЕНЮ)\\\
  7068.     local Objects = {}\\\
  7069.     local function newObj(name,isHidden,xStart,xEnd,y)\\\
  7070.         Objects[name]={}\\\
  7071.         Objects[name][\\\"isHidden\\\"] = isHidden\\\
  7072.         Objects[name][\\\"xStart\\\"] = xStart\\\
  7073.         Objects[name][\\\"xEnd\\\"] = xEnd\\\
  7074.         Objects[name][\\\"y\\\"] = y\\\
  7075.     end\\\
  7076.     \\\
  7077.     --ОПРЕДЕЛЕНпЕ САМОГО ДЛпННОГО ПО КОЛ-ВУ СпМВОЛОВ ЭЛЕМЕНТА МЕНЮ\\\
  7078.     local theLongestElement = #arg[3][1]\\\
  7079.     for i=3,#arg do\\\
  7080.         if arg[i] ~= \\\"-\\\" and theLongestElement < #arg[i][1] then\\\
  7081.             theLongestElement = #arg[i][1]\\\
  7082.         end\\\
  7083.     end\\\
  7084. \\\
  7085.     --ОПРЕДЕЛЕНпЕ РАЗМЕРА МЕНЮ\\\
  7086.     local xSizeOfMenu = theLongestElement + 4\\\
  7087.     local ySizeOfMenu = #arg-2\\\
  7088. \\\
  7089.     local xStartToDisplay = nil\\\
  7090.     local yStartToDisplay = nil\\\
  7091. \\\
  7092.     --РпСОВАНпЕ КВАДРАТА С ЗАЛпВКОЙ\\\
  7093.     local function square(x1,y1,width,height,color)\\\
  7094.         local string = string.rep(\\\" \\\",width)\\\
  7095.         term.setBackgroundColor(color)\\\
  7096.         for y=y1,(y1+height-1) do\\\
  7097.             term.setCursorPos(x1,y)\\\
  7098.             term.write(string)\\\
  7099.         end\\\
  7100.     end\\\
  7101. \\\
  7102.     --ОТРпСОВКА РАЗДЕЛпТЕЛЯ В МЕНЮ\\\
  7103.     local function drawSeparator(x,y,size)\\\
  7104.         term.setTextColor(colors.lightGray)\\\
  7105.         term.setCursorPos(x,y)\\\
  7106.         term.write(string.rep(\\\"-\\\",size))\\\
  7107.     end\\\
  7108.     \\\
  7109.     --ФУНКЦпЯ ОТРпСОВКп ВСЕГО МЕНЮ\\\
  7110.     local function drawMenu(xMenu,yMenu)\\\
  7111. \\\
  7112.         --КОРРЕКЦпЯ КООРДпНАТЫ МЕНЮ, ЧТОБ ЗА КРАЯ ЭКРАНА НЕ ЗАЛЕЗАЛО\\\
  7113.         if yMenu+ySizeOfMenu - 1  >= ySize then yMenu = yMenu - (yMenu+ySizeOfMenu - 1 - ySize) - 1 end\\\
  7114.         if xMenu+xSizeOfMenu - 1  >= xSize then xMenu = xMenu - (xMenu+xSizeOfMenu - 1 - xSize) - 1 end\\\
  7115. \\\
  7116.         --ОПРЕДЕЛЕНпЕ ТОЧЕК СТАРТА ОТОБРАЖЕНпЯ ТЕКСТА В МЕНЮ\\\
  7117.         xStartToDisplay = xMenu + 2\\\
  7118.         yStartToDisplay = yMenu\\\
  7119. \\\
  7120.         --ОТРпСОВКА ТЕНп МЕНЮ\\\
  7121.         square(xMenu+1,yMenu+1,xSizeOfMenu,ySizeOfMenu,colors.gray)\\\
  7122. \\\
  7123.         --ОТРпСОВКА БЕЛОЙ ПОДЛОЖКп МЕНЮ\\\
  7124.         square(xMenu,yMenu,xSizeOfMenu,ySizeOfMenu,colors.white)\\\
  7125. \\\
  7126.         --ЦпКЛ ПЕРЕБОРА ВСЕХ ЭЛЕМЕНТОВ МЕНЮ, РАССМАТРпВАЕМ ДАННЫЕ О КАЖДОМ\\\
  7127.         for i=3,#arg do\\\
  7128.             --ЕСЛп ВЫБРАННЫХ ЭЛЕМЕНТ НЕ ЯВЛЯЕТСЯ РАЗДЕЛпТЕЛЕМ, ТО\\\
  7129.             if arg[i] ~= \\\"-\\\" then\\\
  7130.                 --ЗАДАНпЕ СТАНДАРТНОГО ЦВЕТА ТЕКСТА ДЛЯ ЭЛЕМЕНТА МЕНЮ\\\
  7131.                 local contextColor = colors.black\\\
  7132.                 --ЕСЛп АРГУМЕНТ_2 (СКРЫТЫЙ/НЕ СКРЫТЫЙ) п АРУМЕНТ_3 (ЦВЕТ ТЕКСТА ЭЛЕМЕНТА) ДЛЯ РАССМАТРпВАЕМОГО ЭЛЕМЕНТА НЕ УКАЗАНЫ, ТО\\\
  7133.                 if arg[i][2] == nil and arg[i][3] == nil then\\\
  7134.                     contextColor = colors.black\\\
  7135.                 --ЕСЛп АРГУМЕНТ 2 = FALSE п АРГУМЕНТ 3 НЕ УКАЗАН, ТО\\\
  7136.                 elseif arg[i][2] == false and arg[i][3] == nil then\\\
  7137.                     contextColor = colors.black\\\
  7138.                 --ЕСЛп АРГУМЕНТ 2 = FALSE п АРГУМЕНТ 3 УКАЗАН, ТО\\\
  7139.                 elseif arg[i][2] == false and arg[i][3] ~= nil then\\\
  7140.                     contextColor = arg[i][3]\\\
  7141.                 --ЕСЛп АРГУМЕНТ 2 = TRUE, ТО ЭЛЕМЕНТ СКРЫТ\\\
  7142.                 elseif arg[i][2] == true then\\\
  7143.                     contextColor = colors.lightGray\\\
  7144.                 end\\\
  7145. \\\
  7146.                 --ОТОБРАЖЕНпЕ ТЕКСТА ЭЛЕМЕНТА В САМОМ МЕНЮ\\\
  7147.                 text(xStartToDisplay,yStartToDisplay+i-3,arg[i][1],contextColor)\\\
  7148.                 --СОЗДАНпЕ ОБЪЕКТА ЭЛЕМЕНТА В ПАМЯТп, ЧТОБЫ ПОТОМ пМЕТЬ К НЕМУ ДОСТУП\\\
  7149.                 newObj(arg[i][1],arg[i][2],xMenu,xMenu+xSizeOfMenu-1,yStartToDisplay+i-3)\\\
  7150. \\\
  7151.             --А ЕСЛп ВСЕ-ТАКп ЯВЛЯЕТСЯ, ТО\\\
  7152.             else\\\
  7153.                 drawSeparator(xMenu,yStartToDisplay+i-3,xSizeOfMenu)\\\
  7154.             end\\\
  7155.         end\\\
  7156.     end\\\
  7157.     \\\
  7158.     --СТАРТ ПРОГРАММЫ, РпСУЕМ МЕНЮ\\\
  7159.     drawMenu(arg[1],arg[2])\\\
  7160. \\\
  7161.     --ОТСЛЕЖпВАНпЕ КЛпКА МЫШп\\\
  7162.     local event,side,xClick,yClick = os.pullEvent()\\\
  7163.     if event == \\\"monitor_touch\\\" then side = 1 end\\\
  7164.     if event == \\\"mouse_click\\\" or event == \\\"monitor_touch\\\" then\\\
  7165.         --ПЕРЕБОР ВСЕХ ЭЛЕМЕНТОВ МАССпВА ОБЪЕКТОВ В ПАРЕ СО ЗНАЧЕНпЕМ ЭЛЕМЕНТА (КЛЮЧ = ЗНАЧЕНпЕ, KEY = VAL)\\\
  7166.         for key,val in pairs(Objects) do\\\
  7167.             --ЕСЛп МЫ КЛпКНУЛп НА ОБЪЕКТ, п ЭТОТ ОБЪЕКТ НЕ ЯВЛЯЕТСЯ СКРЫТЫМ, ТО\\\
  7168.             if xClick >= Objects[key][\\\"xStart\\\"] and xClick <= Objects[key][\\\"xEnd\\\"] and yClick == Objects[key][\\\"y\\\"] and Objects[key][\\\"isHidden\\\"] == false or xClick >= Objects[key][\\\"xStart\\\"] and xClick <= Objects[key][\\\"xEnd\\\"] and yClick == Objects[key][\\\"y\\\"] and Objects[key][\\\"isHidden\\\"] == nil then\\\
  7169.                 --НАРпСОВАТЬ ГОЛУБОЕ ВЫДЕЛЕНпЕ ЭЛЕМЕНТА МЕНЮ\\\
  7170.                 for i=Objects[key][\\\"xStart\\\"],Objects[key][\\\"xEnd\\\"] do\\\
  7171.                     paintutils.drawPixel(i,Objects[key][\\\"y\\\"],colors.blue)\\\
  7172.                 end\\\
  7173.                 --ОТОБРАЗпТЬ ТОТ ЖЕ ТЕКСТ, ТОЛЬКО БЕЛЫМ ЦВЕТОМ\\\
  7174.                 text(xStartToDisplay,Objects[key][\\\"y\\\"],key,colors.white)\\\
  7175.                 --ЖДАТЬ НЕКОТОРОЕ ВРЕМЯ\\\
  7176.                 sleep(0.3)\\\
  7177.                 --ВЕРНУТЬ ЗНАЧЕНпЕ KEY (ТО ЕСТЬ ЗНАЧЕНпЕ ВЫБРАННОГО ЭЛЕМЕНТА МЕНЮ) п ЗАВЕШпТЬ ПРОГРАММУ МЕНЮ\\\
  7178.                 return key\\\
  7179.             end\\\
  7180.             --А ЕСЛп НпКАКОЙ ЭЛЕМЕНТ МЕНЮ НЕ БЫЛ ВЫБРАН, ТО ФУНКЦпЯ ВЕРНЕТ NIL\\\
  7181.         end\\\
  7182.     end\\\
  7183. end\",\
  7184.    path = \"/rootfs/system/api/context\",\
  7185.  },\
  7186.  {\
  7187.    text = \"os.loadAPI(\\\"system/api/config\\\")\\\
  7188. \\\
  7189. local symbols = {\\\
  7190.     \\\"a\\\",\\\
  7191.     \\\"b\\\",\\\
  7192.     \\\"c\\\",\\\
  7193.     \\\"d\\\",\\\
  7194.     \\\"e\\\",\\\
  7195.     \\\"f\\\",\\\
  7196.     \\\"g\\\",\\\
  7197.     \\\"h\\\",\\\
  7198.     \\\"i\\\",\\\
  7199.     \\\"j\\\",\\\
  7200.     \\\"k\\\",\\\
  7201.     \\\"l\\\",\\\
  7202.     \\\"m\\\",\\\
  7203.     \\\"n\\\",\\\
  7204.     \\\"o\\\",\\\
  7205.     \\\"p\\\",\\\
  7206.     \\\"q\\\",\\\
  7207.     \\\"r\\\",\\\
  7208.     \\\"s\\\",\\\
  7209.     \\\"t\\\",\\\
  7210.     \\\"u\\\",\\\
  7211.     \\\"v\\\",\\\
  7212.     \\\"w\\\",\\\
  7213.     \\\"x\\\",\\\
  7214.     \\\"y\\\",\\\
  7215.     \\\"z\\\",\\\
  7216.     \\\"0\\\",\\\
  7217.     \\\"1\\\",\\\
  7218.     \\\"2\\\",\\\
  7219.     \\\"3\\\",\\\
  7220.     \\\"4\\\",\\\
  7221.     \\\"5\\\",\\\
  7222.     \\\"6\\\",\\\
  7223.     \\\"7\\\",\\\
  7224.     \\\"8\\\",\\\
  7225.     \\\"9\\\",\\\
  7226. }\\\
  7227. \\\
  7228. local symbolsFromConfig = {}\\\
  7229. for i=1,#symbols do\\\
  7230.     symbolsFromConfig[symbols[i]] = config.read(\\\"system/api/encryptor.cfg\\\",symbols[i])\\\
  7231. end\\\
  7232. \\\
  7233. local function stringReplace(stroka,chto,nachto)\\\
  7234.     while true do\\\
  7235.         local starting = 1\\\
  7236.         local starting,ending = string.find(stroka,chto,starting)\\\
  7237.         if ending ~= nil then\\\
  7238.             stroka = string.sub(stroka,1,starting-1)..nachto..string.sub(stroka,ending+1,-1)\\\
  7239.             starting = starting + #nachto\\\
  7240.         else\\\
  7241.             break\\\
  7242.         end\\\
  7243.     end\\\
  7244.     return stroka\\\
  7245. end\\\
  7246. \\\
  7247. function code(stroka)\\\
  7248.     local array = {}\\\
  7249.     for i=1,#stroka do\\\
  7250.         array[i] = string.sub(stroka,i,i)\\\
  7251.         for key,val in pairs(symbolsFromConfig) do\\\
  7252.             if array[i] == key then array[i] = val end\\\
  7253.         end\\\
  7254.     end\\\
  7255.     local text = \\\"\\\"\\\
  7256.     for i=1,#array do\\\
  7257.         text = text..array[i]\\\
  7258.     end\\\
  7259.     return text\\\
  7260. end\\\
  7261. \\\
  7262. function decode(stroka)\\\
  7263.     for key,val in pairs(symbolsFromConfig) do\\\
  7264.         stroka = stringReplace(stroka,val,key)\\\
  7265.     end\\\
  7266.     return stroka\\\
  7267. end\\\
  7268. \\\
  7269. \\\
  7270. --[[print(\\\" \\\")\\\
  7271. local cyka = \\\"hello world! heh kek lol \\\"\\\
  7272. print(\\\"Standart=\\\"..cyka)\\\
  7273. print(\\\" \\\")\\\
  7274. local codedcyka = code(cyka)\\\
  7275. print(\\\"Coded=\\\"..codedcyka)\\\
  7276. print(\\\" \\\")\\\
  7277. local decodedcyka = decode(codedcyka)\\\
  7278. print(\\\"Encoded=\\\"..decodedcyka)\\\
  7279. print(\\\" \\\")]]\",\
  7280.    path = \"/rootfs/system/api/encryptor\",\
  7281.  },\
  7282.  {\
  7283.    text = \"1=eafazf\\\
  7284. 2=ezffqq\\\
  7285. 3=ezfvfp\\\
  7286. 4=eafooz\\\
  7287. 5=eafaiz\\\
  7288. 6=ezviio\\\
  7289. 7=ezvzvi\\\
  7290. 8=eqfooz\\\
  7291. 9=eommqo\\\
  7292. 0=ezivup\\\
  7293. a=ealajo\\\
  7294. b=eopxzj\\\
  7295. c=evmsyo\\\
  7296. d=ebiiql\\\
  7297. e=epovuz\\\
  7298. f=efivmt\\\
  7299. g=ezvito\\\
  7300. h=ezlfbh\\\
  7301. i=eaquat\\\
  7302. j=etirra\\\
  7303. k=emorta\\\
  7304. l=etampl\\\
  7305. m=enodus\\\
  7306. n=ezviri\\\
  7307. o=eponis\\\
  7308. p=enuihu\\\
  7309. q=exyupi\\\
  7310. r=ezdads\\\
  7311. s=eigurd\\\
  7312. t=eamati\\\
  7313. u=ebalro\\\
  7314. v=etshat\\\
  7315. w=ealsis\\\
  7316. x=ekizli\\\
  7317. y=eltrya\\\
  7318. z=espopu\",\
  7319.    path = \"/rootfs/system/api/encryptor.cfg\",\
  7320.  },\
  7321.  {\
  7322.    text = \"os.loadAPI(\\\"system/api/windows\\\")\\\
  7323. os.loadAPI(\\\"system/api/image\\\")\\\
  7324. os.loadAPI(\\\"system/api/context\\\")\\\
  7325. \\\
  7326. local mode = \\\"open\\\"\\\
  7327. local workPath = \\\"\\\"\\\
  7328. local workPathHistory = {}\\\
  7329. local input = \\\"\\\"\\\
  7330. \\\
  7331. local xSize,ySize = term.getSize()\\\
  7332. \\\
  7333. local managerX = xSize-3\\\
  7334. local managerY = ySize-1\\\
  7335. \\\
  7336. local xStart = 2\\\
  7337. local yStart = 1\\\
  7338. local xEnd = xStart+managerX-1\\\
  7339. local yEnd = yStart+managerY-1\\\
  7340. \\\
  7341. local leftBarSize = 14\\\
  7342. local leftBarLimit = leftBarSize-3\\\
  7343. \\\
  7344. local sizeOfInputBar = 26\\\
  7345. local startOfInputBar = xStart+3\\\
  7346. local endOfInputBar = startOfInputBar+sizeOfInputBar-1\\\
  7347. local sizeOfSearchBar = managerX - sizeOfInputBar - 3 - 8 - 1\\\
  7348. local startOfSearchBar = xEnd-sizeOfSearchBar\\\
  7349. \\\
  7350. local xStartOfDrawingApps = xStart+leftBarSize+1\\\
  7351. local yStartOfDrawingApps = yStart+4\\\
  7352. local xSizeOfAppsArea = managerX-leftBarSize\\\
  7353. local ySizeOfAppsArea = managerY-3\\\
  7354. local xAppSize = 6\\\
  7355. local yAppSize = 6\\\
  7356. local xSpaceBetweenApps = 2\\\
  7357. local ySpaceBetweenApps = 1\\\
  7358. local countOfAppsByX = math.floor(xSizeOfAppsArea/(xAppSize+xSpaceBetweenApps))\\\
  7359. local countOfAppsByY = math.floor(ySizeOfAppsArea/(yAppSize+ySpaceBetweenApps))\\\
  7360. local countOfDesktops = 1\\\
  7361. \\\
  7362. local currentDesktop = 1\\\
  7363. \\\
  7364. local hideFileFormat = true\\\
  7365. \\\
  7366. --local main = window.create(term.native(),xStart,yStart,managerX+1,managerY+1)\\\
  7367. \\\
  7368. --------------------ФУНКЦпп--------------------\\\
  7369. \\\
  7370. local function clickedAtArea(x,y,sx,sy,ex,ey)\\\
  7371.    if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end    \\\
  7372.    return false\\\
  7373. end\\\
  7374. \\\
  7375. local Favourites = {\\\
  7376.     [\\\"Root\\\"] = \\\"\\\",\\\
  7377.     [\\\"Applications\\\"] = \\\"/apps\\\",\\\
  7378.     [\\\"Documents\\\"] = \\\"/documents\\\",\\\
  7379.     [\\\"Images\\\"] = \\\"/images\\\",\\\
  7380.     [\\\"rom\\\"] = \\\"/rom\\\",\\\
  7381. }\\\
  7382. \\\
  7383. local function saveConfig()\\\
  7384.     local path = \\\"System/config/filemanager/favourites.cfg\\\"\\\
  7385.     local f = fs.open(path,\\\"w\\\")\\\
  7386.     f.write(textutils.serialise(Favourites))\\\
  7387.     f.close()\\\
  7388. end\\\
  7389. \\\
  7390. local function loadConfig()\\\
  7391.     local path = \\\"System/config/filemanager/favourites.cfg\\\"\\\
  7392.     if fs.exists(path) then\\\
  7393.         local f = fs.open(path,\\\"r\\\")\\\
  7394.         local text = f.readAll()\\\
  7395.         Favourites = textutils.unserialise(text)\\\
  7396.         f.close()\\\
  7397.     end\\\
  7398. end\\\
  7399. \\\
  7400. local objects = {}\\\
  7401. local function newObj(class,name,key,value)\\\
  7402.     objects[class] = objects[class] or {}\\\
  7403.     objects[class][name] = objects[class][name] or {}\\\
  7404.     objects[class][name][key] = value\\\
  7405. end\\\
  7406. \\\
  7407. function drawSeparator(x1,y1,width,height,textColor,backColor,symbol)\\\
  7408.     local string = string.rep(symbol,width)\\\
  7409.     term.setBackgroundColor(backColor)\\\
  7410.     term.setTextColor(textColor)\\\
  7411.     for y=y1,(y1+height-1) do\\\
  7412.         windows.usualText(x1,y,string)\\\
  7413.     end\\\
  7414. end\\\
  7415. \\\
  7416. local function getFoldersList(workPath)\\\
  7417. \\\
  7418. end\\\
  7419. \\\
  7420. local function drawLeftBar()\\\
  7421.     objects[\\\"Favourites\\\"] = {}\\\
  7422. \\\
  7423.     windows.square(xStart,yStart+3,leftBarSize,yEnd-3,colors.white)\\\
  7424. \\\
  7425.     local y = yStart+4\\\
  7426.     local Peripherals = peripheral.getNames()\\\
  7427.     drawSeparator(xStart+leftBarSize-1,y-1,1,ySizeOfAppsArea,colors.lightGray,colors.white,\\\"|\\\")\\\
  7428. \\\
  7429.     local sFavourites = 0\\\
  7430.     for key,val in pairs(Favourites) do\\\
  7431.         sFavourites = sFavourites + 1\\\
  7432.     end\\\
  7433. \\\
  7434.     if sFavourites > 0 then\\\
  7435.         windows.colorText(xStart+1,y,\\\"Places\\\",colors.gray)\\\
  7436.         y = y + 1\\\
  7437. \\\
  7438.         for key,val in pairs(Favourites) do\\\
  7439.             newObj(\\\"Favourites\\\",key,\\\"x1\\\",xStart)\\\
  7440.             newObj(\\\"Favourites\\\",key,\\\"x2\\\",xStart+leftBarSize-1)\\\
  7441.             newObj(\\\"Favourites\\\",key,\\\"y1\\\",y)\\\
  7442.             newObj(\\\"Favourites\\\",key,\\\"path\\\",Favourites[key])\\\
  7443. \\\
  7444.             if workPath == Favourites[key] then\\\
  7445.                 windows.square(xStart,y,leftBarSize-1,1,colors.blue)\\\
  7446.                 windows.colorText(xStart+2,y,windows.stringLimit(\\\"end\\\",key,leftBarLimit),colors.white)\\\
  7447.             else\\\
  7448.                 windows.square(xStart,y,leftBarSize-1,1,colors.white)\\\
  7449.                 windows.colorText(xStart+2,y,windows.stringLimit(\\\"end\\\",key,leftBarLimit),colors.lightGray)\\\
  7450.             end\\\
  7451. \\\
  7452.             y = y + 1\\\
  7453.         end\\\
  7454. \\\
  7455.         y = y + 1\\\
  7456.     end\\\
  7457. \\\
  7458.     term.setBackgroundColor(colors.white)\\\
  7459.     if #Peripherals > 0 then\\\
  7460.         windows.colorText(xStart+1,y,\\\"Peripherals\\\",colors.gray)\\\
  7461.         y = y + 1\\\
  7462.         for i=1,#Peripherals do\\\
  7463.             windows.colorText(xStart+2,y,windows.stringLimit(\\\"end\\\",Peripherals[i],leftBarLimit),colors.lightGray)\\\
  7464.             y = y + 1\\\
  7465.         end\\\
  7466.     end\\\
  7467. end\\\
  7468. \\\
  7469. local function drawTopBar()\\\
  7470.     local posY = yStart + 1\\\
  7471.     windows.square(xStart,yStart,managerX,3,colors.lightGray)\\\
  7472.     windows.square(xStart+3,posY,sizeOfInputBar,1,colors.white)\\\
  7473.     windows.colorText(xStart+3,posY,windows.stringLimit(\\\"start\\\",input,sizeOfInputBar),colors.gray)\\\
  7474. \\\
  7475.     local text = mode\\\
  7476.     windows.colorTextWithBack(math.floor(xStart+managerX/2-#text/2-1),yStart,text,colors.white,colors.lightGray)\\\
  7477. \\\
  7478.     windows.square(startOfSearchBar,posY,sizeOfSearchBar,1,colors.white)\\\
  7479.     windows.colorText(startOfSearchBar,posY,\\\"Search\\\",colors.lightGray)\\\
  7480.     newObj(\\\"windowControls\\\",\\\"search\\\",\\\"x1\\\",startOfSearchBar);newObj(\\\"windowControls\\\",\\\"search\\\",\\\"x2\\\",startOfSearchBar+sizeOfSearchBar-1);newObj(\\\"windowControls\\\",\\\"search\\\",\\\"y\\\",posY)\\\
  7481.     \\\
  7482.     local colorCyka = nil\\\
  7483.     if #workPathHistory == 0 then colorCyka = colors.lightGray else colorCyka = colors.black end\\\
  7484.     windows.colorTextWithBack(xStart+1,posY,\\\"<\\\",colorCyka,colors.white)\\\
  7485. \\\
  7486.     local posX = startOfSearchBar - 7\\\
  7487.     windows.colorTextWithBack(posX,posY,\\\" \\\"..mode..\\\" \\\",colors.white,colors.lightBlue)\\\
  7488.     newObj(\\\"windowControls\\\",\\\"ok\\\",\\\"x1\\\",posX);newObj(\\\"windowControls\\\",\\\"ok\\\",\\\"x2\\\",posX+5);newObj(\\\"windowControls\\\",\\\"ok\\\",\\\"y\\\",posY)\\\
  7489. end\\\
  7490. \\\
  7491. local function drawWindow()\\\
  7492.     windows.square(xStart,yStart+3,managerX,ySizeOfAppsArea,colors.white)\\\
  7493.     drawTopBar()\\\
  7494.     --DRAW SHADOW\\\
  7495.     for x=(xStart+1),(xStart+managerX) do\\\
  7496.         paintutils.drawPixel(x,yStart+managerY,colors.gray)\\\
  7497.     end\\\
  7498.     for y=(yStart+1),(yStart+managerY) do\\\
  7499.         paintutils.drawPixel(xStart+managerX,y,colors.gray)\\\
  7500.     end\\\
  7501. end\\\
  7502. \\\
  7503. ------------------------------------------------------------------------------------------------------\\\
  7504. \\\
  7505. local function drawKonkretnoApp(x,y,name,backColor)\\\
  7506.     --СОЗДАНпЕ ОБЪЕКТА ПРпЛОЖЕНпЯ\\\
  7507.     newObj(\\\"apps\\\",name,\\\"x1\\\",x)\\\
  7508.     newObj(\\\"apps\\\",name,\\\"x2\\\",x+xAppSize-1)\\\
  7509.     newObj(\\\"apps\\\",name,\\\"y1\\\",y)\\\
  7510.     newObj(\\\"apps\\\",name,\\\"y2\\\",y+yAppSize-1)\\\
  7511.     newObj(\\\"apps\\\",name,\\\"fileFormat\\\",windows.getFileFormat(name))\\\
  7512. \\\
  7513.     --РпСОВАНпЕ пКОНКп\\\
  7514.     windows.drawOSIcon(x,y,workPath,name,objects[\\\"apps\\\"][name][\\\"fileFormat\\\"])\\\
  7515. \\\
  7516.     --ОТРпСОВКА пМЕНп ПРпЛОЖЕНпЯ\\\
  7517.     term.setBackgroundColor(backColor)\\\
  7518.     if fs.isReadOnly(workPath..\\\"/\\\"..name) then\\\
  7519.         term.setTextColor(colors.red)\\\
  7520.     else\\\
  7521.         term.setTextColor(colors.black)\\\
  7522.     end\\\
  7523.     if windows.isFileHidden(name) then\\\
  7524.         term.setTextColor(colors.gray)\\\
  7525.     end\\\
  7526.     if hideFileFormat then\\\
  7527.         name = windows.hideFileFormat(name)\\\
  7528.     end\\\
  7529.     name = windows.stringLimit(\\\"end\\\",name,xAppSize,true)\\\
  7530.     windows.usualText(math.floor(x+xAppSize/2-#name/2),y+yAppSize-1,name)\\\
  7531. end\\\
  7532. \\\
  7533. local function drawApps(x,y,currentDesktop)\\\
  7534. \\\
  7535.     objects[\\\"apps\\\"] = {}\\\
  7536. \\\
  7537.     windows.square(x,y,xSizeOfAppsArea-2,ySizeOfAppsArea-2,colors.white)\\\
  7538. \\\
  7539.     local fileList = fs.list(workPath)\\\
  7540.     fileList = windows.reorganizeFilesAndFolders(workPath,fileList,true,true)\\\
  7541. \\\
  7542.     countOfDesktops = math.ceil(#fileList/(countOfAppsByY*countOfAppsByX))\\\
  7543.     local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX\\\
  7544. \\\
  7545.     for j=1,countOfAppsByY do\\\
  7546.         for i=1,countOfAppsByX do\\\
  7547.             if fileList[appCounter] then\\\
  7548.                 drawKonkretnoApp(x+i*(xAppSize+xSpaceBetweenApps)-(xAppSize+xSpaceBetweenApps),y+j*(yAppSize+ySpaceBetweenApps)-(yAppSize+ySpaceBetweenApps),fileList[appCounter],colors.white)\\\
  7549.                 appCounter = appCounter + 1\\\
  7550.             else\\\
  7551.                 break\\\
  7552.             end\\\
  7553.         end\\\
  7554.     end\\\
  7555. end\\\
  7556. \\\
  7557. ------------------------------------------------------------------------------------------------------\\\
  7558. \\\
  7559. local function drawManager(x,y)\\\
  7560. \\\
  7561.     if x~=nil or y~=nil then\\\
  7562.         xStart = x\\\
  7563.         yStart = y\\\
  7564.         xStartOfDrawingApps = xStart+leftBarSize+1\\\
  7565.         yStartOfDrawingApps = yStart+4\\\
  7566.     end\\\
  7567. \\\
  7568.     currentDesktop = 1\\\
  7569.     --windows.emptyWindow(xStart,yStart,managerX,managerY,fs.getName(workPath))\\\
  7570.     drawWindow()\\\
  7571.     --windows.colorTextWithBack(xStart,yStart,\\\"x\\\",colors.black,colors.red);windows.colorTextWithBack(xStart+1,yStart,\\\"-\\\",colors.black,colors.orange);windows.colorTextWithBack(xStart+2,yStart,\\\"+\\\",colors.black,colors.lime)\\\
  7572.     drawLeftBar()\\\
  7573.     drawApps(xStartOfDrawingApps,yStartOfDrawingApps,currentDesktop)\\\
  7574.     windows.scrollBar(xEnd,yStart+3,managerY-3,countOfDesktops,currentDesktop,colors.lightGray,colors.lightBlue)\\\
  7575. end\\\
  7576. \\\
  7577. newObj(\\\"windowControls\\\",\\\"<\\\",\\\"x\\\",xStart+1);newObj(\\\"windowControls\\\",\\\"<\\\",\\\"y\\\",yStart+1)\\\
  7578. \\\
  7579. local function initializeProgram(mode1)\\\
  7580.     if mode1==\\\"open\\\" then mode = \\\"Open\\\" else mode = \\\"Save\\\" end\\\
  7581. \\\
  7582.     loadConfig()\\\
  7583.     saveConfig()\\\
  7584. \\\
  7585.     input = \\\"/\\\"..workPath\\\
  7586.     drawManager()\\\
  7587.     \\\
  7588.     local exit = false\\\
  7589.     while true do\\\
  7590. \\\
  7591.         local breakCycles = false\\\
  7592. \\\
  7593.         if exit then break end\\\
  7594. \\\
  7595.         local event,side,x,y = os.pullEvent()\\\
  7596.         if event == \\\"mouse_click\\\" then\\\
  7597. \\\
  7598.             for key,val in pairs(objects[\\\"Favourites\\\"]) do\\\
  7599.                 if breakCycles then break end\\\
  7600. \\\
  7601.                 if clickedAtArea(x,y,objects[\\\"Favourites\\\"][key][\\\"x1\\\"],objects[\\\"Favourites\\\"][key][\\\"y1\\\"],objects[\\\"Favourites\\\"][key][\\\"x2\\\"],objects[\\\"Favourites\\\"][key][\\\"y1\\\"]) then\\\
  7602.                     \\\
  7603.                     if side == 1 then \\\
  7604.                         if not fs.exists(objects[\\\"Favourites\\\"][key][\\\"path\\\"]) then fs.makeDir(key) end\\\
  7605.                         workPathHistory[#workPathHistory+1] = workPath\\\
  7606.                         workPath = objects[\\\"Favourites\\\"][key][\\\"path\\\"]\\\
  7607.                         input = \\\"/\\\"..workPath\\\
  7608.                         drawManager()\\\
  7609.                     else\\\
  7610.                         windows.square(xStart,objects[\\\"Favourites\\\"][key][\\\"y1\\\"],leftBarSize-1,1,colors.lightGray)\\\
  7611.                         windows.colorText(xStart+2,objects[\\\"Favourites\\\"][key][\\\"y1\\\"],windows.stringLimit(\\\"end\\\",key,leftBarLimit),colors.white)\\\
  7612.                         --sleep(0.2)\\\
  7613. \\\
  7614.                         local action = context.menu(x,y,{\\\"Remove from sidebar\\\"})\\\
  7615.                         if action == \\\"Remove from sidebar\\\" then\\\
  7616. \\\
  7617.                             Favourites[key] = nil\\\
  7618.                             saveConfig()\\\
  7619. \\\
  7620.                         end\\\
  7621.                         drawManager()\\\
  7622.                     end\\\
  7623. \\\
  7624.                     breakCycles = true\\\
  7625.                     break\\\
  7626.                 end\\\
  7627.             end\\\
  7628. \\\
  7629. \\\
  7630. \\\
  7631.             for key,val in pairs(objects[\\\"apps\\\"]) do\\\
  7632.                 if breakCycles then break end\\\
  7633.                 if clickedAtArea(x,y,objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],objects[\\\"apps\\\"][key][\\\"x2\\\"],objects[\\\"apps\\\"][key][\\\"y2\\\"]) then\\\
  7634.                     \\\
  7635.                     if side == 1 then\\\
  7636.                         if fs.isDir(workPath..\\\"/\\\"..key) and windows.getFileFormat(key) ~= \\\".app\\\" then\\\
  7637.                             windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.blue)\\\
  7638.                             drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.blue)\\\
  7639.                             sleep(0.2)\\\
  7640.                             workPathHistory[#workPathHistory+1] = workPath\\\
  7641.                             workPath = workPath..\\\"/\\\"..key\\\
  7642.                             input = \\\"/\\\"..workPath\\\
  7643.                             drawManager()\\\
  7644.                         elseif not fs.isDir(workPath..\\\"/\\\"..key) and mode == \\\"Save\\\" then\\\
  7645.                             windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.red)\\\
  7646.                             drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.red)\\\
  7647.                             sleep(0.2)\\\
  7648.                             windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.white)\\\
  7649.                             drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.white)\\\
  7650.                         elseif not fs.isDir(workPath..\\\"/\\\"..key) and mode ~= \\\"Save\\\" or fs.isDir(workPath..\\\"/\\\"..key) and windows.getFileFormat(key) == \\\".app\\\" and mode ~= \\\"Save\\\" then\\\
  7651.                             windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.blue)\\\
  7652.                             drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.blue)\\\
  7653.                             sleep(0.2)\\\
  7654.                             windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.white)\\\
  7655.                             drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.white)\\\
  7656.                             input = \\\"/\\\"..workPath..\\\"/\\\"..key\\\
  7657.                             drawTopBar()\\\
  7658.                         end\\\
  7659.                     else\\\
  7660.                         if fs.isDir(workPath..\\\"/\\\"..key) then\\\
  7661.                             windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.lightGray)\\\
  7662.                             drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.lightGray)\\\
  7663.                         \\\
  7664.                             local action = context.menu(x,y,{\\\"Add to sidebar\\\"})\\\
  7665.                             if action == \\\"Add to sidebar\\\" then\\\
  7666. \\\
  7667.                                 Favourites[key] = workPath..\\\"/\\\"..key\\\
  7668.                                 saveConfig()\\\
  7669. \\\
  7670.                             end\\\
  7671.                             drawManager()\\\
  7672.                         end\\\
  7673.                     end\\\
  7674. \\\
  7675.                     breakCycles = true\\\
  7676.                     break\\\
  7677.                 end \\\
  7678.             end\\\
  7679. \\\
  7680.             if clickedAtArea(x,y,objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"x\\\"],objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"y\\\"],objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"x\\\"],objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"y\\\"]) then\\\
  7681.                 if #workPathHistory > 0 then\\\
  7682.                     windows.colorTextWithBack(objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"x\\\"],objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"y\\\"],\\\"<\\\",colors.white,colors.blue)\\\
  7683.                     sleep(0.2)\\\
  7684.                     workPath = workPathHistory[#workPathHistory]\\\
  7685.                     input = \\\"/\\\"..workPath\\\
  7686.                     workPathHistory[#workPathHistory] = nil\\\
  7687.                     drawManager()\\\
  7688.                 end\\\
  7689.             elseif clickedAtArea(x,y,objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x2\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"]) then\\\
  7690.                 windows.colorTextWithBack(objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"],\\\" \\\"..mode..\\\" \\\",colors.white,colors.blue)\\\
  7691.                 sleep(0.3)\\\
  7692.                 return string.sub(input,2,-1)\\\
  7693.             elseif clickedAtArea(x,y,objects[\\\"windowControls\\\"][\\\"search\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"search\\\"][\\\"y\\\"],objects[\\\"windowControls\\\"][\\\"search\\\"][\\\"x2\\\"],objects[\\\"windowControls\\\"][\\\"search\\\"][\\\"y\\\"]) then\\\
  7694.                 local searchResult = windows.search(xEnd-27,yStart,28,2,\\\"Search\\\")\\\
  7695.                 if searchResult ~= nil then\\\
  7696.                     --windows.error(\\\"=\\\"..searchResult)\\\
  7697.                     if fs.isDir(searchResult) then\\\
  7698.                         workPathHistory[#workPathHistory+1] = workPath\\\
  7699.                         workPath = searchResult\\\
  7700.                         input = \\\"/\\\"..workPath\\\
  7701.                     else\\\
  7702.                         workPathHistory[#workPathHistory+1] = workPath\\\
  7703.                         workPath = string.sub(searchResult,1,#searchResult-#fs.getName(searchResult)-1)\\\
  7704.                         input = \\\"/\\\"..workPath..\\\"/\\\"..fs.getName(searchResult)\\\
  7705.                     end\\\
  7706.                 end\\\
  7707.                 drawManager()\\\
  7708. \\\
  7709.             elseif clickedAtArea(x,y,startOfInputBar,yStart+1,endOfInputBar,yStart+1) and mode ~= \\\"Open\\\" then\\\
  7710. \\\
  7711.                 local cursor = nil\\\
  7712. \\\
  7713.                 input = input..\\\"/\\\"\\\
  7714.                 drawTopBar()\\\
  7715. \\\
  7716.                 local accept = false\\\
  7717. \\\
  7718.                 while true do\\\
  7719. \\\
  7720.                     cursor = startOfInputBar+#input\\\
  7721.                     if cursor > startOfInputBar+sizeOfInputBar then cursor = startOfInputBar+sizeOfInputBar-1 end\\\
  7722.                     \\\
  7723.                     term.setCursorPos(cursor,yStart+1)\\\
  7724.                     term.setTextColor(colors.black)\\\
  7725.                     term.setCursorBlink(true)\\\
  7726. \\\
  7727.                     local event1,side1,x1,y1 = os.pullEvent()\\\
  7728.                     if event1 == \\\"char\\\" then\\\
  7729. \\\
  7730.                         input = input..side1\\\
  7731.                         drawTopBar()\\\
  7732.                     elseif event1 == \\\"key\\\" then\\\
  7733.                         if side1 == 28 then\\\
  7734.                             windows.colorTextWithBack(objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"],\\\" \\\"..mode..\\\" \\\",colors.white,colors.blue)\\\
  7735.                             sleep(0.3)\\\
  7736.                             accept = true\\\
  7737.                             break\\\
  7738.                         elseif side1 == 14 then\\\
  7739.                             if #input > 1 then\\\
  7740.                                 input = string.sub(input,1,-2)\\\
  7741.                                 drawTopBar()\\\
  7742.                             end\\\
  7743. \\\
  7744.                         end\\\
  7745.                     elseif event1 == \\\"mouse_click\\\" then\\\
  7746.                         if clickedAtArea(x1,y1,objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x2\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"]) then\\\
  7747.                             accept = true\\\
  7748.                             drawTopBar()\\\
  7749.                         else\\\
  7750.                             drawTopBar()\\\
  7751.                             break\\\
  7752.                         end\\\
  7753.                     end\\\
  7754. \\\
  7755.                     term.setCursorBlink(false)\\\
  7756.                 end\\\
  7757. \\\
  7758.                 term.setCursorBlink(false)\\\
  7759. \\\
  7760.                 if accept then return string.sub(input,2,-1) end\\\
  7761. \\\
  7762.             end\\\
  7763. \\\
  7764.         elseif event == \\\"mouse_scroll\\\" then\\\
  7765.             if clickedAtArea(x,y,xStart+leftBarSize,yStart+1,xEnd-1,yEnd) then\\\
  7766.                 if side == 1 then\\\
  7767.                     currentDesktop = currentDesktop + 1\\\
  7768.                     if currentDesktop > countOfDesktops then\\\
  7769.                         currentDesktop = countOfDesktops\\\
  7770.                     else\\\
  7771.                         drawApps(xStartOfDrawingApps,yStartOfDrawingApps,currentDesktop)\\\
  7772.                         windows.scrollBar(xEnd,yStart+3,managerY-3,countOfDesktops,currentDesktop,colors.lightGray,colors.lightBlue)\\\
  7773.                     end\\\
  7774.                 else\\\
  7775.                     currentDesktop = currentDesktop - 1\\\
  7776.                     if currentDesktop < 1 then\\\
  7777.                         currentDesktop = 1\\\
  7778.                     else\\\
  7779.                         drawApps(xStartOfDrawingApps,yStartOfDrawingApps,currentDesktop)\\\
  7780.                         windows.scrollBar(xEnd,yStart+3,managerY-3,countOfDesktops,currentDesktop,colors.lightGray,colors.lightBlue)\\\
  7781.                     end\\\
  7782.                 end\\\
  7783.             end\\\
  7784.         elseif event == \\\"key\\\" then\\\
  7785.             if side == 28 then\\\
  7786.                 return string.sub(input,2,-1)\\\
  7787.             end\\\
  7788.         end\\\
  7789.     end\\\
  7790. \\\
  7791. end\\\
  7792. \\\
  7793. function open(cykaWorkPath)\\\
  7794.     if cykaWorkPath then workPath = cykaWorkPath end\\\
  7795. \\\
  7796.     for i=(1-managerY),1,2 do\\\
  7797.         drawManager(2,i)\\\
  7798.         sleep(0)\\\
  7799.     end\\\
  7800. \\\
  7801.     return initializeProgram(\\\"open\\\")\\\
  7802. end\\\
  7803. \\\
  7804. function save(cykaWorkPath)\\\
  7805.     if cykaWorkPath then workPath = cykaWorkPath end\\\
  7806. \\\
  7807.     for i=(1-managerY),1,2 do\\\
  7808.         drawManager(2,i)\\\
  7809.         sleep(0)\\\
  7810.     end\\\
  7811. \\\
  7812.     return initializeProgram(\\\"save\\\")\\\
  7813. end\\\
  7814. \\\
  7815. -------------------------------------\\\
  7816. \\\
  7817. --[[windows.clearScreen(colors.black)\\\
  7818. \\\
  7819. local path = open(\\\"\\\")\\\
  7820. \\\
  7821. term.setTextColor(colors.white)\\\
  7822. windows.clearScreen(colors.black)\\\
  7823. if path == \\\"\\\" then\\\
  7824.     windows.usualText(2,2,\\\"NIL!!\\\")\\\
  7825. else\\\
  7826.     windows.usualText(2,2,\\\"Path=\\\"..path)\\\
  7827. end]]\",\
  7828.    path = \"/rootfs/system/api/filemanager\",\
  7829.  },\
  7830.  {\
  7831.    text = \"function draw(startX,startY,image)\\\
  7832.     local Colors = {\\\
  7833.         [\\\"0\\\"] = 1,\\\
  7834.         [\\\"1\\\"] = 2,\\\
  7835.         [\\\"2\\\"] = 4,\\\
  7836.         [\\\"3\\\"] = 8,\\\
  7837.         [\\\"4\\\"] = 16,\\\
  7838.         [\\\"5\\\"] = 32,\\\
  7839.         [\\\"6\\\"] = 64,\\\
  7840.         [\\\"7\\\"] = 128,\\\
  7841.         [\\\"8\\\"] = 256,\\\
  7842.         [\\\"9\\\"] = 512,\\\
  7843.         [\\\"a\\\"] = 1024,\\\
  7844.         [\\\"b\\\"] = 2048,\\\
  7845.         [\\\"c\\\"] = 4096,\\\
  7846.         [\\\"d\\\"] = 8192,\\\
  7847.         [\\\"e\\\"] = 16384,\\\
  7848.         [\\\"f\\\"] = 32768\\\
  7849.     }\\\
  7850.     local Pixels = {}\\\
  7851. \\\
  7852.     local function convert(mode,color)\\\
  7853.         if mode == \\\"from cc\\\" then\\\
  7854.             for key,value in pairs(Colors) do\\\
  7855.                 if color == value then\\\
  7856.                     return key\\\
  7857.                 end\\\
  7858.             end\\\
  7859.         else\\\
  7860.             if color == \\\"#\\\" then\\\
  7861.                 return \\\"0\\\"\\\
  7862.             else\\\
  7863.                 return Colors[color]\\\
  7864.             end\\\
  7865.         end\\\
  7866.     end\\\
  7867. \\\
  7868.     local function load(path)\\\
  7869.         local file = fs.open(path,\\\"r\\\")\\\
  7870.         local lineCounter = 1\\\
  7871.         while true do\\\
  7872.             local line = file.readLine()\\\
  7873.             Pixels[lineCounter]={}\\\
  7874.             if line ~= nil then\\\
  7875.                 for i=1,#line,3 do\\\
  7876.                     Pixels[lineCounter][(i+2)/3]={}\\\
  7877.                     Pixels[lineCounter][(i+2)/3][\\\"symbol\\\"] = string.sub(line,i,i)\\\
  7878.                     Pixels[lineCounter][(i+2)/3][\\\"textColor\\\"] = convert(\\\"to cc\\\",string.sub(line,i+1,i+1))\\\
  7879.                     Pixels[lineCounter][(i+2)/3][\\\"backColor\\\"] = convert(\\\"to cc\\\",string.sub(line,i+2,i+2))\\\
  7880.                 end\\\
  7881.                 lineCounter = lineCounter + 1\\\
  7882.             else\\\
  7883.                 break\\\
  7884.             end\\\
  7885.         end\\\
  7886.         file.close()\\\
  7887.     end\\\
  7888. \\\
  7889.     load(image)\\\
  7890. \\\
  7891.     for y=1,#Pixels do\\\
  7892.         for x=1,#Pixels[y] do\\\
  7893.             if Pixels[y][x][\\\"symbol\\\"] ~= \\\"#\\\" then\\\
  7894.                 term.setTextColor(Pixels[y][x][\\\"textColor\\\"])\\\
  7895.                 term.setBackgroundColor(Pixels[y][x][\\\"backColor\\\"])\\\
  7896.                 term.setCursorPos(startX+x-1,startY+y-1)\\\
  7897.                 term.write(Pixels[y][x][\\\"symbol\\\"])\\\
  7898.             end\\\
  7899.         end\\\
  7900.     end\\\
  7901. \\\
  7902. end\",\
  7903.    path = \"/rootfs/system/api/image\",\
  7904.  },\
  7905.  {\
  7906.    text = \"os.loadAPI(\\\"system/api/config\\\")\\\
  7907. \\\
  7908. local Colors = {\\\
  7909.     [\\\"text\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"text\\\")),\\\
  7910.     [\\\"commands\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"commands\\\")),\\\
  7911.     [\\\"api\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"api\\\")),\\\
  7912.     [\\\"string\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"string\\\")),\\\
  7913.     [\\\"comments\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"comments\\\")),\\\
  7914.     [\\\"compares\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"compares\\\")),\\\
  7915.     [\\\"loops\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"basics\\\")),\\\
  7916.     [\\\"boolean\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"boolean\\\")),\\\
  7917.     [\\\"number\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"number\\\")),\\\
  7918. }\\\
  7919. \\\
  7920. local KeyWords = {\\\
  7921.     {[\\\"pattern\\\"]=\\\"for\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7922.     {[\\\"pattern\\\"]=\\\"while\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7923.     {[\\\"pattern\\\"]=\\\"true\\\", [\\\"color\\\"]=Colors[\\\"boolean\\\"]},\\\
  7924.     {[\\\"pattern\\\"]=\\\"false\\\", [\\\"color\\\"]=Colors[\\\"boolean\\\"]},\\\
  7925.     {[\\\"pattern\\\"]=\\\"if\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7926.     {[\\\"pattern\\\"]=\\\"then\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7927.     {[\\\"pattern\\\"]=\\\"else\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7928.     {[\\\"pattern\\\"]=\\\"elseif\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7929.     {[\\\"pattern\\\"]=\\\"do\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7930.     {[\\\"pattern\\\"]=\\\"break\\\", [\\\"color\\\"]=colors.red},\\\
  7931.     {[\\\"pattern\\\"]=\\\"function\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7932.     {[\\\"pattern\\\"]=\\\"and\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7933.     {[\\\"pattern\\\"]=\\\"not\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7934.     {[\\\"pattern\\\"]=\\\"or\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7935.     {[\\\"pattern\\\"]=\\\"in\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7936.     {[\\\"pattern\\\"]=\\\"until\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7937.     {[\\\"pattern\\\"]=\\\"return\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7938.     {[\\\"pattern\\\"]=\\\"repeat\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7939.     {[\\\"pattern\\\"]=\\\"nil\\\", [\\\"color\\\"]=Colors[\\\"boolean\\\"]},\\\
  7940.     {[\\\"pattern\\\"]=\\\"local\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
  7941. }\\\
  7942.     \\\
  7943. local Compares = {\\\
  7944.     \\\"=\\\",\\\
  7945.     \\\"==\\\",\\\
  7946.     \\\"~=\\\",\\\
  7947.     \\\">\\\",\\\
  7948.     \\\"<\\\",\\\
  7949.     \\\">=\\\",\\\
  7950.     \\\"<=\\\",\\\
  7951.     \\\"+\\\",\\\
  7952.     \\\"-\\\",\\\
  7953.     \\\"*\\\",\\\
  7954.     \\\"/\\\",\\\
  7955.     \\\"%^\\\",\\\
  7956.     \\\"%.%.\\\",\\\
  7957.     \\\"%#\\\",\\\
  7958. }\\\
  7959. \\\
  7960. local sKeyWords = #KeyWords\\\
  7961. local sCompares = #Compares\\\
  7962. \\\
  7963. --Окрашивание текста по шаблону\\\
  7964. local function findAndReplace(x,y,text,pattern,color,obrezatSleva,obrezatSprava,vichestIzStartaPoiska)\\\
  7965.     local findPos = 1\\\
  7966.     while true do\\\
  7967.         local s,e = string.find(text,pattern,findPos)\\\
  7968.         if s ~= nil and e ~= nil then\\\
  7969.             term.setTextColor(color)\\\
  7970.             term.setCursorPos(1-x+s+obrezatSleva,y)\\\
  7971.             term.write(string.sub(text,s+obrezatSleva,e-obrezatSprava))\\\
  7972.         else\\\
  7973.             break\\\
  7974.         end\\\
  7975.         findPos = e + 1 - vichestIzStartaPoiska\\\
  7976.     end\\\
  7977. end\\\
  7978. \\\
  7979. --Подсветка всех ключевых слов\\\
  7980. function highlight(x,y,text)\\\
  7981.     --Пишем сначала обычную белую строку\\\
  7982.     term.setTextColor(Colors[\\\"text\\\"])\\\
  7983.     term.setCursorPos(x,y)\\\
  7984.     term.write(text)\\\
  7985. \\\
  7986.     --Красим в цвета всю хуйню из массива. Пока что надо доработать\\\
  7987.     for i=1,sKeyWords do\\\
  7988.         findAndReplace(x,y,text,\\\" \\\"..KeyWords[i][\\\"pattern\\\"]..\\\" \\\",KeyWords[i][\\\"color\\\"],0,0,0)\\\
  7989.         findAndReplace(x,y,text,\\\" \\\"..KeyWords[i][\\\"pattern\\\"]..\\\"$\\\",KeyWords[i][\\\"color\\\"],0,0,0)\\\
  7990.         findAndReplace(x,y,text,\\\"^\\\"..KeyWords[i][\\\"pattern\\\"]..\\\" \\\",KeyWords[i][\\\"color\\\"],0,0,0)\\\
  7991.     end\\\
  7992. \\\
  7993.     --Красим функции\\\
  7994.     findAndReplace(x,y,text,\\\"[%a%d%_%-]*%(\\\",Colors[\\\"commands\\\"],0,1,0)\\\
  7995.     findAndReplace(x,y,text,\\\"%.(.*)%(\\\",Colors[\\\"commands\\\"],1,1,0)\\\
  7996. \\\
  7997.     --Красим вызов АПп\\\
  7998.     findAndReplace(x,y,text,\\\"os%.loadAPI%(\\\",Colors[\\\"api\\\"],0,1,0)    \\\
  7999. \\\
  8000.     --Красим END, если он заканчивает строку\\\
  8001.     findAndReplace(x,y,text,\\\"end$\\\",Colors[\\\"loops\\\"],0,0,0)   \\\
  8002. \\\
  8003.     --Красим красным всякие сравнивалки типа =, ==, >= и т.п.\\\
  8004.     for i=1,sCompares do\\\
  8005.         findAndReplace(x,y,text,\\\" \\\"..Compares[i]..\\\" \\\",Colors[\\\"compares\\\"],0,0,0)\\\
  8006.         findAndReplace(x,y,text,\\\"(.)\\\"..Compares[i]..\\\"(.)\\\",Colors[\\\"compares\\\"],1,1,0)\\\
  8007.         findAndReplace(x,y,text,\\\"(.)\\\"..Compares[i],Colors[\\\"compares\\\"],1,0,0)\\\
  8008.         findAndReplace(x,y,text,Compares[i]..\\\"(.)\\\",Colors[\\\"compares\\\"],0,1,0)\\\
  8009.     end\\\
  8010. \\\
  8011.     --КРАСпМ ЦпВФРЫ\\\
  8012.     findAndReplace(x,y,text,\\\"[^%a%d](%d*)[^%a%d]\\\",Colors[\\\"number\\\"],1,1,1)\\\
  8013.     findAndReplace(x,y,text,\\\"[^%a%d](%d*)$\\\",Colors[\\\"number\\\"],1,0,0)\\\
  8014. \\\
  8015.     --Красим красным текст в кавычках\\\
  8016.     findAndReplace(x,y,text,\\\"\\\\\\\".-[^\\\\\\\"\\\\\\\"]\\\\\\\"\\\",Colors[\\\"string\\\"],0,0,0)\\\
  8017. \\\
  8018.     --Красим зеленым комментарии\\\
  8019.     findAndReplace(x,y,text,\\\"%-%-.*\\\",Colors[\\\"comments\\\"],0,0,0)\\\
  8020. \\\
  8021. end\\\
  8022. \\\
  8023. \\\
  8024. ------------------------------------------------------------------------------------------------------------------\\\
  8025. \\\
  8026. \\\
  8027. --[[term.setBackgroundColor(colors.white)\\\
  8028. term.setTextColor(colors.black)\\\
  8029. term.setCursorPos(1,1)\\\
  8030. term.clear()\\\
  8031. \\\
  8032. local strings = {\\\
  8033.     \\\"os.loadAPI(123)\\\",\\\
  8034.     \\\"term.setCursorPos(1,1)\\\",\\\
  8035.     \\\"while true do\\\",\\\
  8036.     \\\"  if x >= 12 then\\\",\\\
  8037.     \\\"    break\\\",\\\
  8038.     \\\"  end\\\",\\\
  8039.     \\\"end\\\",\\\
  8040.     \\\" \\\",\\\
  8041.     \\\"local function hehe(heh123, 123)\\\",\\\
  8042.     \\\"  print(heh123)\\\",\\\
  8043.     \\\"end\\\",\\\
  8044.     \\\" \\\",\\\
  8045.     \\\"print(\\\\\\\"Pruf Piru, chto ono ne laget\\\\\\\"..123..\\\\\\\"hehe\\\\\\\")\\\",\\\
  8046.     \\\"term.clear()\\\",\\\
  8047.     \\\"local input = cyka()\\\",\\\
  8048.     \\\" \\\",\\\
  8049.     \\\"--Comment, bitch!\\\",\\\
  8050. }\\\
  8051. \\\
  8052. \\\
  8053. local try = 1\\\
  8054. while true do\\\
  8055.     term.clear()\\\
  8056.     highlight(1,1,\\\"Popitka napisaniya: \\\"..try)\\\
  8057. \\\
  8058.     for i=1,#strings do\\\
  8059.         highlight(1,i+2,strings[i])\\\
  8060.     end\\\
  8061. \\\
  8062.     sleep(0.1)\\\
  8063.     try = try + 1\\\
  8064. end]]\\\
  8065. \\\
  8066. \\\
  8067. --[[print(\\\"Write something:\\\")\\\
  8068. \\\
  8069. local stro4ka = \\\"\\\"\\\
  8070. local CursorPosX = 1\\\
  8071. local CursorPosY = 3\\\
  8072. term.setCursorBlink(true)\\\
  8073. while true do\\\
  8074.     term.setCursorPos(CursorPosX,CursorPosY)\\\
  8075.     local event,side = os.pullEvent()\\\
  8076.     if event == \\\"char\\\" then\\\
  8077.         stro4ka = stro4ka..side\\\
  8078.         CursorPosX = CursorPosX + 1\\\
  8079.         highlight(1,CursorPosY,stro4ka)\\\
  8080.     elseif event == \\\"key\\\" then\\\
  8081.         if side == 28 then\\\
  8082.             stro4ka = \\\"\\\"\\\
  8083.             CursorPosX = 1\\\
  8084.             CursorPosY = CursorPosY + 1\\\
  8085.         elseif side == 14 then\\\
  8086.             if #stro4ka > 0 then\\\
  8087.                 highlight(1,CursorPosY,string.rep(\\\" \\\",#stro4ka))\\\
  8088.                 stro4ka = string.sub(stro4ka,1,-2)\\\
  8089.                 highlight(1,CursorPosY,stro4ka)\\\
  8090.                 CursorPosX = CursorPosX - 1\\\
  8091.             end\\\
  8092.         end\\\
  8093.     end\\\
  8094. end\\\
  8095. \\\
  8096. os.pullEvent(\\\"key\\\")]]\",\
  8097.    path = \"/rootfs/system/api/syntax\",\
  8098.  },\
  8099.  {\
  8100.    text = \"\\\
  8101. -------------------------ГРАФпКА---------------------------------------------------------------------------------------------------\\\
  8102. \\\
  8103. -- colorText(int х_начала, int y_начала, string текст, int цвет_текста)\\\
  8104. -- Отрисовка цветного текста по заданным координатам. Цвет фона остается тем же.\\\
  8105. \\\
  8106. \\\
  8107. -- usualText(int х_начала, int y_начала, string текст)\\\
  8108. -- Отрисовка обычного текста по заданным координатам.\\\
  8109. \\\
  8110. \\\
  8111. -- square(int x_начала, int x_конца, int ширина, int высота, int цвет)\\\
  8112. -- Оптимизированная отрисовка квадрата на экране (быстрее, чем стандартная КК). Подходит также для линий.\\\
  8113. \\\
  8114. \\\
  8115. -- clearScreen(int цвет)\\\
  8116. -- Заливка всего экрана выбранным цветом.\\\
  8117. \\\
  8118. \\\
  8119. -- fadeIn(int скорость)\\\
  8120. -- fadeOut(int скорость)\\\
  8121. -- Плавное зажигание и угасание экрана с белого на черный и наоборот. Скорость лучше ставить на 0.\\\
  8122. \\\
  8123. \\\
  8124. -- tv(int скорость)\\\
  8125. -- Угасание экрана в стилистике старых телевизоров. Скорость лучше ставить на 0.\\\
  8126. \\\
  8127. \\\
  8128. -- emptyWindow(int х_начала, int y_начала, int ширина, int высота, string заголовок)\\\
  8129. -- Отрисовка белого окошка с тенью и заголовком вверху.\\\
  8130. \\\
  8131. \\\
  8132. -- sampleWindow(int х_начала, int y_начала, int ширина, int высота)\\\
  8133. -- Отрисовка того же окошка, но без заголовка.\\\
  8134. \\\
  8135. \\\
  8136. -- drawProgressBar(int х_начала, int y_начала, int ширина, int высота, int цвет_передней_области, int цвет_задней_области, int процент_заполненности_шкалы)\\\
  8137. -- Отрисовка шкалы прогресса с указанным процентом заполненности.\\\
  8138. \\\
  8139. \\\
  8140. -- scrollBar(int х_начала, int y_начала, int размер_шкалы_по_высоте, int количество_всех_элементов, int текущий_элемент, int цвет_задней_области, int цвет_передней_области)\\\
  8141. -- Отрисовка вертикальной шкалы прокрутки.\\\
  8142. -- Количеством элементов тут является, к примеру, количество файлов в директории.\\\
  8143. -- Таким образом, если количеством элементов у нас будет 100, а текущим элементом будет число 50,\\\
  8144. -- то ползунок шкалы отобразится примерно по центру самой шкалы.\\\
  8145. \\\
  8146. -------------------------ОТРпСОВКА ОКОН-------------------------------------------------------------------------------------\\\
  8147. \\\
  8148. -- error(string текст_ошибки)\\\
  8149. -- Отображение окна ошибки по центру экрана.\\\
  8150. \\\
  8151. \\\
  8152. -- attention(table текст_заголовка, table текст_подзаголовка)\\\
  8153. -- Отображение окна \\\"Внимание!\\\" с какой-то информацией.\\\
  8154. -- Каждый элемент массива - это строка заголовка или подзаголовка, а количество строк не ограничено.\\\
  8155. -- \\\
  8156. -- Пример использования: attention({\\\"Hey!\\\",\\\"This is attention window!\\\"},{\\\"And this is information!\\\"})\\\
  8157. \\\
  8158. \\\
  8159. -- input(int x_начала, int y_начала, string заголовок_окна , int ширина_окна, table поле_ввода1, table поле_ввода2 ... table поле_вводаN)\\\
  8160. -- Вызывает окно с полями ввода текста.\\\
  8161. -- Каждое поле - это массив вида {string название_поля, string информация_уже_записанная_в_поле}\\\
  8162. -- После заполнения всех полей с клавиатуры, функция возвращает массив с введенными данными.\\\
  8163. --\\\
  8164. -- Если x_начала или y_начала будет равен \\\"auto\\\", то соответствующая координата\\\
  8165. -- будет рассчитана автоматически и окно расположится по центру экрана по этой координате.\\\
  8166. --\\\
  8167. -- Пример использования: myData = input(\\\"auto\\\",\\\"auto\\\",\\\"Login\\\",20,{\\\"Username\\\",\\\"\\\"},{\\\"Password\\\",\\\"\\\"})\\\
  8168. -- Если мы введем в поле Username \\\"Igor\\\", а в поле Password \\\"12345\\\",\\\
  8169. -- то функция вовзратит массив вида {\\\"Igor\\\",\\\"12345\\\"}\\\
  8170. --\\\
  8171. -- К слову, в поле можно вставлять данные с помощью ctrl+v\\\
  8172. \\\
  8173. \\\
  8174. -- select(table заголовок, table подзаголовок, table кнопка1, table кнопка2 ... table кнопкаN)\\\
  8175. -- Функция вызывает окно с текстом и кнопками выбора. \\\
  8176. --\\\
  8177. -- Структура массива заголовка и подзаголовка: {string текст1, string текст2 ... string текстN}\\\
  8178. -- Структура массива кнопки: {string имя_кнопки, int цвет_кнопки, int цвет_текста_кнопки}\\\
  8179. --\\\
  8180. -- При нажатии на кнопку функция возвращает имя нажатой кнопки.\\\
  8181. --\\\
  8182. -- Пример использования: pressedButton = windows.select({\\\"Hello!\\\"},{\\\"Do you want to load OS\\\",\\\"when computer starts?\\\"},{\\\"No\\\",colors.lightGray,colors.black},{\\\"Yes\\\",colors.lightBlue,colors.black})\\\
  8183. \\\
  8184. \\\
  8185. -- aboutFile(int х_начала, int y_начала, int ширина_окна, string путь_к_файлу)\\\
  8186. -- Наглядно отображает информацию о файле в красивом окошке.\\\
  8187. -- Координаты корректируются автоматически.\\\
  8188. \\\
  8189. \\\
  8190. -- progressBar(int х_начала, int y_начала, int ширина_окна, string заголовок, string информация, int скорость)\\\
  8191. -- Функция отрисовывает окно с информацией и имитирует продолжительный процесс, рисуя шкалу прогресса.\\\
  8192. \\\
  8193. \\\
  8194. -- search(int х_начала, int y_начала, int ширина_окна, int количество_элементов_по_высоте, string текст_для_поиска)\\\
  8195. -- Функция рисует красивое окошка поиска по файловой системе.\\\
  8196. -- Также отображается информация о файлах.\\\
  8197. -- При вводе любой информации начинается поиск совпадений с именами файлов.\\\
  8198. -- К регистру букв не чувствительна.\\\
  8199. -- После выбора любого найденного элемента с помощью мыши, функция вовзращает путь к выбранному файлу.\\\
  8200. \\\
  8201. -------------------------РАБОТА С ФАЙЛАМп-------------------------------------------------------------------------------------\\\
  8202. \\\
  8203. -- getFileFormat(string путь_к_файлу)\\\
  8204. -- Функция возвращает расширение файла по типу .zip, .app и прочие. Если расширение отсутствует, возвращает nil.\\\
  8205. \\\
  8206. -- hideFileFormat(string путь_к_файлу)\\\
  8207. -- Если файл имеет расширение, то функция возвращает имя файла без этого расширения. Если расширения нет, возвращается то же имя.\\\
  8208. \\\
  8209. -- isFileHidden(string путь_к_файлу)\\\
  8210. -- Если в начале имени файла есть символ \\\".\\\", то функция возвращает true. Если нет, то false.\\\
  8211. \\\
  8212. -- getFileSize(string путь_к_файлу)\\\
  8213. -- Функция возвращает суммарный размер всех файлов в указанном пути. В том числе и размер подфайлов и поддиректорий.\\\
  8214. \\\
  8215. -- getFileType(string путь_к_файлу)\\\
  8216. -- Функция возвращает тип файла. Например, если расширение файла .zip, то его тип - Application.\\\
  8217. \\\
  8218. -- stringLimit(string режим, string строка, int ограничение_строки)\\\
  8219. -- Ограничитель строки с двумя режимами работы. Вот примеры:\\\
  8220. --\\\
  8221. -- local s = \\\"HelloWorldBitches!\\\"\\\
  8222. -- print(stringLimit(\\\"start\\\", s, 10))\\\
  8223. -- print(stringLimit(\\\"end\\\", s, 10))\\\
  8224. --\\\
  8225. -- На экране будет отображено:\\\
  8226. -- ...itches!\\\
  8227. -- HelloWo...\\\
  8228. \\\
  8229. -----------------------------------------------------------------------------------------------------------------------------------\\\
  8230. \\\
  8231. \\\
  8232. local xSize,ySize = term.getSize()\\\
  8233. local centerX,centerY = math.floor(xSize/2),math.floor(ySize/2)\\\
  8234. \\\
  8235. --ПОпСК ПЕРпФЕРпп\\\
  8236. function findPeripheral(whatToFind)\\\
  8237.  local PeriList = peripheral.getNames()\\\
  8238.  for i=1,#PeriList do\\\
  8239.    if peripheral.getType(PeriList[i]) == whatToFind then\\\
  8240.      return PeriList[i]\\\
  8241.    end\\\
  8242.  end\\\
  8243. end\\\
  8244. \\\
  8245. --ПОпСК БЕСПРОВОДНОГО МОДЕМА\\\
  8246. function findWirelessModem()\\\
  8247.     local periList = peripheral.getNames()\\\
  8248.     for i=1,#periList do\\\
  8249.         if peripheral.getType(periList[i]) == \\\"modem\\\" then\\\
  8250.             local govno = peripheral.wrap(periList[i])\\\
  8251.             if govno.isWireless() then\\\
  8252.                 return periList[i]\\\
  8253.             end\\\
  8254.         end\\\
  8255.     end\\\
  8256. end\\\
  8257. \\\
  8258. --КЛпКНУЛп Лп В ЗОНУ\\\
  8259. function clickedAtArea(x,y,sx,sy,ex,ey)\\\
  8260.    if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end    \\\
  8261.    return false\\\
  8262. end\\\
  8263. \\\
  8264. --В БУЛпН, ЕПТЫ БЛЯ\\\
  8265. function toboolean(s)\\\
  8266.     if s == \\\"true\\\" then\\\
  8267.         return true\\\
  8268.     else\\\
  8269.         return false\\\
  8270.     end\\\
  8271. end\\\
  8272. \\\
  8273. --ЦВЕТНОЙ ТЕКСТ\\\
  8274. function colorText(x,y,text,textColor)\\\
  8275.     term.setTextColor(textColor)\\\
  8276.     term.setCursorPos(x,y)\\\
  8277.     term.write(text)\\\
  8278. end\\\
  8279. \\\
  8280. --ЦВЕТНОЙ ТЕКСТ С ФОНОМ\\\
  8281. function colorTextWithBack(x,y,text,textColor,backColor)\\\
  8282.     term.setTextColor(textColor)\\\
  8283.     term.setBackgroundColor(backColor)\\\
  8284.     term.setCursorPos(x,y)\\\
  8285.     term.write(text)\\\
  8286. end\\\
  8287. \\\
  8288. --ПРОСТОЕ ОТОБРАЖЕНпЕ ТЕКСТА ПО КООРДпНАТАМ\\\
  8289. function usualText(x,y,text)\\\
  8290.     term.setCursorPos(x,y)\\\
  8291.     term.write(text)\\\
  8292. end\\\
  8293. \\\
  8294. --УНпВЕРСАЛЬНАЯ ФУНКЦпЯ ДЛЯ ОТОБРАЖЕНпЯ ТЕКСТА ПО ЦЕНТРУ ЭКРАНА\\\
  8295. function centerText(how,coord,text,textColor,backColor)\\\
  8296.     term.setTextColor(textColor)\\\
  8297.     term.setBackgroundColor(backColor)\\\
  8298.     if how == \\\"xy\\\" then\\\
  8299.         term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2))\\\
  8300.     elseif how == \\\"x\\\" then\\\
  8301.         term.setCursorPos(math.floor(xSize/2-#text/2),coord)\\\
  8302.     elseif how == \\\"y\\\" then\\\
  8303.         term.setCursorPos(coord,math.floor(ySize/2))\\\
  8304.     end\\\
  8305.     term.write(text)\\\
  8306. end\\\
  8307. \\\
  8308. --РпСОВАНпЕ КВАДРАТА С ЗАЛпВКОЙ\\\
  8309. function square(x1,y1,width,height,color)\\\
  8310.     local string = string.rep(\\\" \\\",width)\\\
  8311.     term.setBackgroundColor(color)\\\
  8312.     for y=y1,(y1+height-1) do\\\
  8313.         usualText(x1,y,string)\\\
  8314.     end\\\
  8315. end\\\
  8316. \\\
  8317. --РпСОВАНпЕ КРУГА\\\
  8318. function circle(cx, cy, radius, char, backColor, textColor)\\\
  8319.     local x = radius\\\
  8320.    local y = 0\\\
  8321.    local radiusError = 1 - x\\\
  8322.    term.setTextColor(textColor)\\\
  8323.    term.setBackgroundColor(backColor)\\\
  8324.    while (x >= y) do\\\
  8325.        usualText(x + cx, y + cy, char)\\\
  8326.        usualText(y + cx, x + cy, char)\\\
  8327.        usualText(-x + cx, y + cy, char)\\\
  8328.        usualText(-y + cx, x + cy, char)\\\
  8329.        usualText(-x + cx, -y + cy, char)\\\
  8330.        usualText(-y + cx, -x + cy, char)\\\
  8331.        usualText(x + cx, -y + cy, char)\\\
  8332.        usualText(y + cx, -x + cy, char)\\\
  8333.        y = y + 1\\\
  8334.        if (radiusError < 0) then\\\
  8335.            radiusError = radiusError + (2 * y + 1)\\\
  8336.        else\\\
  8337.            x = x - 1\\\
  8338.            radiusError = radiusError + (2 * (y - x + 1))\\\
  8339.        end\\\
  8340.    end\\\
  8341. end\\\
  8342. \\\
  8343. --ЗАЛпВКА ЭКРАНА ЦВЕТОМ\\\
  8344. function clearScreen(color)\\\
  8345.     term.setBackgroundColor(color)\\\
  8346.     term.clear()\\\
  8347. end\\\
  8348. \\\
  8349. --ПЛАВНОЕ ВКЛЮЧЕНпЕ ЭКРАНА\\\
  8350. function fadeIn(time)\\\
  8351.     clearScreen(colors.gray)\\\
  8352.     sleep(time)\\\
  8353.     clearScreen(colors.lightGray)\\\
  8354.     sleep(time)\\\
  8355.     clearScreen(colors.white)\\\
  8356.     sleep(time)\\\
  8357. end\\\
  8358. \\\
  8359. --ПЛАВНОЕ ЗАТУХАНпЕ ЭКРАНА\\\
  8360. function fadeOut(time)\\\
  8361.     clearScreen(colors.lightGray)\\\
  8362.     sleep(time)\\\
  8363.     clearScreen(colors.gray)\\\
  8364.     sleep(time)\\\
  8365.     clearScreen(colors.black)\\\
  8366.     sleep(time)\\\
  8367.     term.setCursorPos(1,1)\\\
  8368.     term.setTextColor(colors.white)\\\
  8369. end\\\
  8370. \\\
  8371. --ПРОСТОЕ ОКНО С ПОЛОСКОЙ НАВЕРХУ\\\
  8372. function emptyWindow(xStart,yStart,xWindowSize,yWindowSize,title)\\\
  8373.     --DRAW WINDOW\\\
  8374.     square(xStart,yStart,xWindowSize,1,colors.lightGray)\\\
  8375.     colorText(math.floor(xStart+xWindowSize/2-#title/2),yStart,title,colors.white)\\\
  8376. \\\
  8377.     square(xStart,yStart+1,xWindowSize,yWindowSize-1,colors.white)\\\
  8378.     \\\
  8379.     --DRAW SHADOW\\\
  8380.     for x=(xStart+1),(xStart+xWindowSize) do\\\
  8381.         paintutils.drawPixel(x,yStart+yWindowSize,colors.gray)\\\
  8382.     end\\\
  8383.     for y=(yStart+1),(yStart+yWindowSize) do\\\
  8384.         paintutils.drawPixel(xStart+xWindowSize,y,colors.gray)\\\
  8385.     end\\\
  8386. end\\\
  8387. \\\
  8388. --ПРОСТОЕ ОКНО БЕЗ ПОЛОСКп\\\
  8389. function sampleWindow(xStart,yStart,xWindowSize,yWindowSize)\\\
  8390.     square(xStart,yStart,xWindowSize,yWindowSize,colors.white)\\\
  8391.     --DRAW SHADOW\\\
  8392.     for x=(xStart+1),(xStart+xWindowSize) do\\\
  8393.         paintutils.drawPixel(x,yStart+yWindowSize,colors.gray)\\\
  8394.     end\\\
  8395.     for y=(yStart+1),(yStart+yWindowSize) do\\\
  8396.         paintutils.drawPixel(xStart+xWindowSize,y,colors.gray)\\\
  8397.     end\\\
  8398. end\\\
  8399. \\\
  8400. --ОГРАНпЧЕНпЕ ДЛпНЫ СТРОКп\\\
  8401. function stringLimit(mode,text,size,noDots)\\\
  8402.     if string.len(text)<=size then return text end\\\
  8403.     if mode == \\\"start\\\" then\\\
  8404.         if noDots then\\\
  8405.             return string.sub(text,#text-size+1,-1)\\\
  8406.         else\\\
  8407.             return \\\"...\\\"..string.sub(text,#text-size+4,-1)\\\
  8408.         end\\\
  8409.     else\\\
  8410.         if noDots then\\\
  8411.             return string.sub(text,1,size)\\\
  8412.         else\\\
  8413.             return string.sub(text,1,size-3)..\\\"...\\\"\\\
  8414.         end\\\
  8415.     end\\\
  8416. end\\\
  8417. \\\
  8418. --ПОЛУЧЕНпЕ ФОРМАТА ФАЙЛА\\\
  8419. function getFileFormat(path)\\\
  8420.     local name = fs.getName(path)\\\
  8421.     local starting,ending = string.find(name,\\\"(.)%.[%d%w]*$\\\")\\\
  8422.     if starting == nil then\\\
  8423.         return nil\\\
  8424.     else\\\
  8425.         return string.sub(name,starting+1,-1)\\\
  8426.     end\\\
  8427. end\\\
  8428. \\\
  8429. --ПРОВЕРКА, СКРЫТЫЙ Лп ФАЙЛ\\\
  8430. function isFileHidden(path)\\\
  8431.     local name = fs.getName(path)\\\
  8432.     local starting,ending = string.find(name,\\\"^%.(.*)$\\\")\\\
  8433.     if starting == nil then\\\
  8434.         return false\\\
  8435.     else\\\
  8436.         return true\\\
  8437.     end\\\
  8438. end\\\
  8439. \\\
  8440. --СКРЫТЬ РАСШпРЕНпЕ ФАЙЛА\\\
  8441. function hideFileFormat(path)\\\
  8442.     local name = fs.getName(path)\\\
  8443.     local fileFormat = getFileFormat(name)\\\
  8444.     if fileFormat == nil then\\\
  8445.         return name\\\
  8446.     else\\\
  8447.         return string.sub(name,1,#name-#fileFormat)\\\
  8448.     end\\\
  8449. end\\\
  8450. \\\
  8451. --ПОЛУЧЕНпЕ РАЗМЕРА ФАЙЛА пЛп ПАПКп\\\
  8452. function getFileSize(path)\\\
  8453.     local allFilesSize = 0\\\
  8454.     if fs.isDir(path) then\\\
  8455.         local fileList = fs.list(path)\\\
  8456.         for i=1,#fileList do\\\
  8457.             allFilesSize = allFilesSize + getFileSize(path..\\\"/\\\"..fileList[i])\\\
  8458.         end\\\
  8459.     else\\\
  8460.         allFilesSize = allFilesSize + fs.getSize(path)\\\
  8461.     end\\\
  8462.     return allFilesSize\\\
  8463. end\\\
  8464. \\\
  8465. --ПОЛУЧпТЬ ТпП ФАЙЛА\\\
  8466. function getFileType(path)\\\
  8467.     local fileTypes = {\\\
  8468.         [\\\".png\\\"] = \\\"Image\\\",\\\
  8469.         [\\\".cfg\\\"] = \\\"Config\\\",\\\
  8470.         [\\\".zip\\\"] = \\\"Archive\\\",\\\
  8471.         [\\\".app\\\"] = \\\"Application\\\",\\\
  8472.     }\\\
  8473. \\\
  8474.     local currentFileType = nil\\\
  8475. \\\
  8476.     local fileFormat = getFileFormat(path)\\\
  8477.     if fileFormat == nil then\\\
  8478.         if fs.isDir(path) then\\\
  8479.             currentFileType = \\\"Folder\\\"\\\
  8480.         else\\\
  8481.             currentFileType = \\\"Lua script\\\"\\\
  8482.         end\\\
  8483.     else\\\
  8484.         currentFileType = fileTypes[fileFormat] or fileFormat\\\
  8485.     end\\\
  8486.     \\\
  8487.     return currentFileType\\\
  8488. end\\\
  8489. \\\
  8490. --РЕОРГАНпЗМАЦпЯ МАССпВА ДЛЯ ОС-Кп\\\
  8491. function reorganizeFilesAndFolders(workPath,massivSudaPihay,showHiddenFiles,showSystemFolders)\\\
  8492.     local reorganizedMassiv = {}\\\
  8493.     local function doGovno(i)\\\
  8494.         if showHiddenFiles then\\\
  8495.             reorganizedMassiv[#reorganizedMassiv+1] = massivSudaPihay[i]\\\
  8496.         else\\\
  8497.             if not windows.isFileHidden(workPath..\\\"/\\\"..massivSudaPihay[i]) then\\\
  8498.                 reorganizedMassiv[#reorganizedMassiv+1] = massivSudaPihay[i]\\\
  8499.             end\\\
  8500.         end\\\
  8501.     end\\\
  8502.     local filePath = nil\\\
  8503.     for i=1,#massivSudaPihay do\\\
  8504.         filePath = workPath..\\\"/\\\"..massivSudaPihay[i]\\\
  8505.         if fs.isDir(filePath) and windows.getFileFormat(filePath) ~= \\\".app\\\" then\\\
  8506.             if showSystemFolders then\\\
  8507.                 doGovno(i)\\\
  8508.             else\\\
  8509.                 if massivSudaPihay[i] ~= \\\"rom\\\" and massivSudaPihay[i] ~= \\\"System\\\" then\\\
  8510.                     --windows.attention({\\\"massiv[i] = \\\"..massivSudaPihay[i]},{\\\"heh\\\"})\\\
  8511.                     doGovno(i)\\\
  8512.                 end\\\
  8513.             end\\\
  8514.         end\\\
  8515.     end\\\
  8516.     for i=1,#massivSudaPihay do\\\
  8517.         filePath = workPath..\\\"/\\\"..massivSudaPihay[i]\\\
  8518.         if not fs.isDir(filePath) and massivSudaPihay[i] ~= \\\"OS\\\" or fs.isDir(filePath) and windows.getFileFormat(filePath) == \\\".app\\\" then\\\
  8519.             doGovno(i)\\\
  8520.         end\\\
  8521.     end\\\
  8522.     return reorganizedMassiv\\\
  8523. end\\\
  8524. \\\
  8525. --ОТРпСОВКА пКОНКп ДЛЯ ОС\\\
  8526. function drawOSIcon(xIconPos,yIconPos,workPath,name,fileFormat)\\\
  8527.     --ЕСЛп ЭТО НЕ ПАПКА\\\
  8528.     if not fs.isDir(workPath..\\\"/\\\"..name) then\\\
  8529.         if fileFormat == \\\".png\\\" then\\\
  8530.             image.draw(xIconPos,yIconPos,\\\"system/os/Icons/image.png\\\")\\\
  8531.         elseif fileFormat == \\\".cfg\\\" then\\\
  8532.             image.draw(xIconPos,yIconPos,\\\"system/os/Icons/config.png\\\")\\\
  8533.         elseif fileFormat == \\\".zip\\\" then\\\
  8534.             image.draw(xIconPos,yIconPos,\\\"system/os/Icons/zip.png\\\")\\\
  8535.         else\\\
  8536.             image.draw(xIconPos,yIconPos,\\\"system/os/Icons/default.png\\\")\\\
  8537.         end\\\
  8538.     --ЕСЛп ЭТО ПАПКА\\\
  8539.     else\\\
  8540.         local iconPath = workPath..\\\"/\\\"..name..\\\"/resources/icon.png\\\"\\\
  8541.         if fileFormat == \\\".app\\\" and fs.exists(iconPath) then\\\
  8542.             image.draw(xIconPos,yIconPos,iconPath)\\\
  8543.         elseif string.sub(name,1,4)==\\\"disk\\\" then\\\
  8544.             image.draw(xIconPos,yIconPos,\\\"system/os/Icons/disk.png\\\")\\\
  8545.         else\\\
  8546.             image.draw(xIconPos,yIconPos,\\\"system/os/Icons/folder.png\\\")\\\
  8547.         end\\\
  8548.     end\\\
  8549. end\\\
  8550. \\\
  8551. --КОРРЕКТпРОВКА СТАРТОВЫХ КООРДпНАТ\\\
  8552. local function correctStartCoords(xStart,yStart,xWindowSize,yWindowSize)\\\
  8553.     if xStart == \\\"auto\\\" then\\\
  8554.         xStart = math.floor(xSize/2 - xWindowSize/2)\\\
  8555.     end\\\
  8556.     if yStart == \\\"auto\\\" then\\\
  8557.         yStart = math.floor(ySize/2 - yWindowSize/2)\\\
  8558.     end\\\
  8559.     return xStart,yStart\\\
  8560. end\\\
  8561. \\\
  8562. --РпСОВАНпЕ КНОПКп\\\
  8563. function button(x,y,xOffset,yOffset,text,textColor,backColor)\\\
  8564.     local width = xOffset*2+#text\\\
  8565.     local height = yOffset*2+1\\\
  8566.     x,y = correctStartCoords(x,y,width,height)\\\
  8567.     square(x,y,width,height,backColor)\\\
  8568.     colorText(x+xOffset,y+yOffset,text,textColor)\\\
  8569.     return x,y,x+width-1,y+height-1\\\
  8570. end\\\
  8571. \\\
  8572. --ОТРпСОВКА ШКАЛЫ ПРОГРЕССА\\\
  8573. local function drawProgressBar(xStart,yStart,width,height,frontColor,backColor,percent)\\\
  8574.     local doneSize = math.ceil(percent/100*width)\\\
  8575. \\\
  8576.     square(xStart,yStart,width,height,backColor)\\\
  8577.     square(xStart,yStart,doneSize,height,frontColor)\\\
  8578. end\\\
  8579. \\\
  8580. --ОТРпСОВКА ПОЛОСЫ ПРОКРУТКп\\\
  8581. function scrollBar(xStart,yStart,height,countOfAllElements,currentElement,backColor,frontColor)\\\
  8582.     local percent = 1/countOfAllElements\\\
  8583.     local sizeOfScrollBar = math.ceil(percent * height)\\\
  8584.     local displayBarFrom = math.floor(yStart + height*((currentElement-1)/countOfAllElements))\\\
  8585. \\\
  8586.     for i=yStart,(yStart+height-1) do\\\
  8587.         paintutils.drawPixel(xStart,i,backColor)\\\
  8588.     end\\\
  8589. \\\
  8590.     for i=displayBarFrom,(displayBarFrom+sizeOfScrollBar-1) do\\\
  8591.         paintutils.drawPixel(xStart,i,frontColor)\\\
  8592.     end\\\
  8593. end\\\
  8594. \\\
  8595. --ПОпСК ЧЕГО-ЛпБО В ФАЙЛОВОЙ СпСТЕМЕ\\\
  8596. local function searchInAllFiles(path,whatToFind)\\\
  8597. \\\
  8598.     local function poiskSovpadeniya(name)\\\
  8599.         local starting,ending = string.find(string.lower(name),string.lower(whatToFind))\\\
  8600.         if starting == nil then\\\
  8601.             return false\\\
  8602.         else\\\
  8603.             return true\\\
  8604.         end\\\
  8605.     end\\\
  8606. \\\
  8607.     local searchMassiv = {}\\\
  8608. \\\
  8609.     local function createFileMassiv(path,whatToFind)\\\
  8610.         local fileList = fs.list(path)\\\
  8611.         for i=1,#fileList do\\\
  8612.             if fs.isDir(path..\\\"/\\\"..fileList[i]) then\\\
  8613.                 if poiskSovpadeniya(fileList[i]) then\\\
  8614.                     searchMassiv[#searchMassiv+1] = {[\\\"path\\\"]=path,[\\\"name\\\"]=fileList[i],[\\\"isDir\\\"]=true,[\\\"fileSize\\\"]=getFileSize(path..\\\"/\\\"..fileList[i]),[\\\"fileType\\\"]=getFileType(path..\\\"/\\\"..fileList[i]),[\\\"fileFormat\\\"]=getFileFormat(path..\\\"/\\\"..fileList[i])}\\\
  8615.                 end\\\
  8616.                 createFileMassiv(path..\\\"/\\\"..fileList[i],whatToFind)\\\
  8617.             else\\\
  8618.                 if poiskSovpadeniya(fileList[i]) then\\\
  8619.                     searchMassiv[#searchMassiv+1] = {[\\\"path\\\"]=path,[\\\"name\\\"]=fileList[i],[\\\"isDir\\\"]=false,[\\\"fileSize\\\"]=getFileSize(path..\\\"/\\\"..fileList[i]),[\\\"fileType\\\"]=getFileType(path..\\\"/\\\"..fileList[i]),[\\\"fileFormat\\\"]=getFileFormat(path..\\\"/\\\"..fileList[i])}\\\
  8620.                 end\\\
  8621.             end\\\
  8622.         end\\\
  8623.     end\\\
  8624.     createFileMassiv(path,whatToFind)\\\
  8625.     return searchMassiv\\\
  8626. \\\
  8627. end\\\
  8628. \\\
  8629. --ФОРМАТпРОВАННЫЙ ТЕКСТ КАК В ЧАТЕ МАЙНА ЧЕРЕЗ &6, &c, &a п Т.П.\\\
  8630. local colorCodes = {\\\
  8631.     {[\\\"code\\\"] = \\\"&0\\\", [\\\"color\\\"] = 1},\\\
  8632.     {[\\\"code\\\"] = \\\"&1\\\", [\\\"color\\\"] = 2},\\\
  8633.     {[\\\"code\\\"] = \\\"&2\\\", [\\\"color\\\"] = 4},\\\
  8634.     {[\\\"code\\\"] = \\\"&3\\\", [\\\"color\\\"] = 8},\\\
  8635.     {[\\\"code\\\"] = \\\"&4\\\", [\\\"color\\\"] = 16},\\\
  8636.     {[\\\"code\\\"] = \\\"&5\\\", [\\\"color\\\"] = 32},\\\
  8637.     {[\\\"code\\\"] = \\\"&6\\\", [\\\"color\\\"] = 64},\\\
  8638.     {[\\\"code\\\"] = \\\"&7\\\", [\\\"color\\\"] = 128},\\\
  8639.     {[\\\"code\\\"] = \\\"&8\\\", [\\\"color\\\"] = 256},\\\
  8640.     {[\\\"code\\\"] = \\\"&9\\\", [\\\"color\\\"] = 512},\\\
  8641.     {[\\\"code\\\"] = \\\"&a\\\", [\\\"color\\\"] = 1024},\\\
  8642.     {[\\\"code\\\"] = \\\"&b\\\", [\\\"color\\\"] = 2048},\\\
  8643.     {[\\\"code\\\"] = \\\"&c\\\", [\\\"color\\\"] = 4096},\\\
  8644.     {[\\\"code\\\"] = \\\"&d\\\", [\\\"color\\\"] = 8192},\\\
  8645.     {[\\\"code\\\"] = \\\"&e\\\", [\\\"color\\\"] = 16384},\\\
  8646.     {[\\\"code\\\"] = \\\"&f\\\", [\\\"color\\\"] = 32768},\\\
  8647. }\\\
  8648. \\\
  8649. function foramattedText(text)\\\
  8650.     local color = colors.white\\\
  8651.     term.setTextColor(color)\\\
  8652.     local sText = #text\\\
  8653.     local searchFrom = 1\\\
  8654. \\\
  8655.     local exit = false\\\
  8656.     while true do\\\
  8657.         if exit then break end\\\
  8658.         local founded = false\\\
  8659.         local s,e = string.find(text,\\\"&\\\",searchFrom)\\\
  8660.         if s then\\\
  8661.             local code = string.sub(text,s,s+1)\\\
  8662.             for i=1,16 do\\\
  8663.                 if code == colorCodes[i][\\\"code\\\"] then\\\
  8664. \\\
  8665.                     local cyka = string.sub(text,searchFrom,s-1)\\\
  8666.                     term.write(cyka)\\\
  8667. \\\
  8668.                     color = colorCodes[i][\\\"color\\\"]\\\
  8669.                     term.setTextColor(color)\\\
  8670. \\\
  8671.                     founded = true\\\
  8672.                     searchFrom = searchFrom + #cyka + 2\\\
  8673.                     break\\\
  8674.                 end\\\
  8675.             end\\\
  8676.         end\\\
  8677.         \\\
  8678.         if not founded then\\\
  8679.             term.write(string.sub(text,searchFrom,-1))\\\
  8680.             exit = true\\\
  8681.         end\\\
  8682.     end\\\
  8683. end\\\
  8684. \\\
  8685. ---------------------------------------------------------------------------------------------------------------\\\
  8686. \\\
  8687. function error(text1)\\\
  8688.     \\\
  8689.     local title = \\\"Error\\\"\\\
  8690.     local limit = xSize - 16 - 11\\\
  8691.     local sizeOfText1 = #text1\\\
  8692. \\\
  8693.     local parsedErr = {}\\\
  8694.     for i=1,(math.ceil(sizeOfText1/limit)) do\\\
  8695.         parsedErr[#parsedErr+1] = string.sub(text1,i*limit+1-limit,i*limit)\\\
  8696.     end\\\
  8697. \\\
  8698.     local theLongestElement = #title\\\
  8699.     for i=1,#parsedErr do\\\
  8700.         local size = #parsedErr[i]\\\
  8701.         if size > theLongestElement then theLongestElement = size end\\\
  8702.     end\\\
  8703.     \\\
  8704.     local xWindowSize = 9 + theLongestElement + 2\\\
  8705.     local yWindowSize = 2 + 1 + 1 + #parsedErr + 3\\\
  8706.     local xStart = math.floor(xSize/2-xWindowSize/2)\\\
  8707.     local yStart = math.floor(ySize/2-yWindowSize/2)\\\
  8708.     \\\
  8709.     --РпСОВАНпЕ ПУСТОГО ОКНА\\\
  8710.     emptyWindow(xStart,yStart,xWindowSize,yWindowSize,\\\" \\\")\\\
  8711. \\\
  8712.     --DRAW ICON\\\
  8713.     paintutils.drawPixel(xStart+4,yStart+2,colors.red)\\\
  8714.     paintutils.drawPixel(xStart+3,yStart+3,colors.red)\\\
  8715.     paintutils.drawPixel(xStart+4,yStart+3,colors.red)\\\
  8716.     paintutils.drawPixel(xStart+5,yStart+3,colors.red)\\\
  8717.     paintutils.drawPixel(xStart+2,yStart+4,colors.red)\\\
  8718.     paintutils.drawPixel(xStart+3,yStart+4,colors.red)\\\
  8719.     paintutils.drawPixel(xStart+4,yStart+4,colors.red)\\\
  8720.     paintutils.drawPixel(xStart+5,yStart+4,colors.red)\\\
  8721.     \\\
  8722.     paintutils.drawPixel(xStart+6,yStart+4,colors.red)\\\
  8723.     colorText(xStart+4,yStart+3,\\\"!\\\",colors.white)\\\
  8724.     \\\
  8725.     --ERROR TEXT\\\
  8726.     term.setBackgroundColor(colors.white)\\\
  8727. \\\
  8728.     colorText(xStart+9,yStart+2,title,colors.gray)\\\
  8729. \\\
  8730.     for i=1,#parsedErr do\\\
  8731.         colorText(xStart+9,yStart+3+i,parsedErr[i],colors.lightGray)\\\
  8732.     end\\\
  8733. \\\
  8734.     --BUTTON\\\
  8735.     local function drawButton(color,color2)\\\
  8736.         for x=(xStart+xWindowSize-8),(xStart+xWindowSize-3) do\\\
  8737.             paintutils.drawPixel(x,yStart+yWindowSize-2,color)\\\
  8738.         end\\\
  8739.         colorText(xStart+xWindowSize-6,yStart+yWindowSize-2,\\\"OK\\\",color2)\\\
  8740.     end\\\
  8741.     drawButton(colors.lightBlue,colors.black)\\\
  8742.     \\\
  8743.     while true do\\\
  8744.         local event,side,x,y = os.pullEvent()\\\
  8745.         if event == \\\"mouse_click\\\" then\\\
  8746.             if x>=xStart+xWindowSize-8 and x<=xStart+xWindowSize-3 and y == yStart+yWindowSize-2 then\\\
  8747.                 drawButton(colors.blue,colors.white)\\\
  8748.                 sleep(0.2)\\\
  8749.                 break\\\
  8750.             end\\\
  8751.         elseif event == \\\"key\\\" then\\\
  8752.             if side == 28 then\\\
  8753.                 drawButton(colors.blue,colors.white)\\\
  8754.                 sleep(0.2)\\\
  8755.                 break\\\
  8756.             end\\\
  8757.         end\\\
  8758.     end\\\
  8759. end\\\
  8760. \\\
  8761. ---------------------------------------------------------------------------------------------------------------\\\
  8762. \\\
  8763. function attention(text1,text2)\\\
  8764. \\\
  8765.     local sizeOfText1 = #text1\\\
  8766.     local sizeOfText2 = #text2\\\
  8767. \\\
  8768.     local theLongestElement = 0\\\
  8769.     for i=1,sizeOfText1 do\\\
  8770.         if #text1[i] > theLongestElement then theLongestElement = #text1[i] end\\\
  8771.     end\\\
  8772.     for i=1,sizeOfText2 do\\\
  8773.         if #text2[i] > theLongestElement then theLongestElement = #text2[i] end\\\
  8774.     end\\\
  8775. \\\
  8776.     local xWindowSize = 9 + theLongestElement + 2\\\
  8777.     local yWindowSize = 2 + sizeOfText1 + 1 + sizeOfText2 + 3\\\
  8778.     local xStart = math.floor(xSize/2-xWindowSize/2)\\\
  8779.     local yStart = math.floor(ySize/2-yWindowSize/2)\\\
  8780.     \\\
  8781.     --РпСОВАНпЕ ПУСТОГО ОКНА\\\
  8782.     emptyWindow(xStart,yStart,xWindowSize,yWindowSize,\\\" \\\")\\\
  8783. \\\
  8784.     --DRAW ICON\\\
  8785.     paintutils.drawPixel(xStart+4,yStart+2,colors.yellow)\\\
  8786.     paintutils.drawPixel(xStart+3,yStart+3,colors.yellow)\\\
  8787.     paintutils.drawPixel(xStart+4,yStart+3,colors.yellow)\\\
  8788.     paintutils.drawPixel(xStart+5,yStart+3,colors.yellow)\\\
  8789.     paintutils.drawPixel(xStart+2,yStart+4,colors.yellow)\\\
  8790.     paintutils.drawPixel(xStart+3,yStart+4,colors.yellow)\\\
  8791.     paintutils.drawPixel(xStart+4,yStart+4,colors.yellow)\\\
  8792.     paintutils.drawPixel(xStart+5,yStart+4,colors.yellow)\\\
  8793.     paintutils.drawPixel(xStart+6,yStart+4,colors.yellow)\\\
  8794.     colorText(xStart+4,yStart+3,\\\"!\\\",colors.white)\\\
  8795.     \\\
  8796.     --ERROR TEXT\\\
  8797.     term.setBackgroundColor(colors.white)\\\
  8798.     for i=1,sizeOfText1 do\\\
  8799.         colorText(xStart+9,yStart+1+i,text1[i],colors.gray)\\\
  8800.     end\\\
  8801.     for i=1,sizeOfText2 do\\\
  8802.         colorText(xStart+9,yStart+3+i,text2[i],colors.lightGray)\\\
  8803.     end\\\
  8804. \\\
  8805.     --BUTTON\\\
  8806.     local function drawButton(color,color2)\\\
  8807.         for x=(xStart+xWindowSize-8),(xStart+xWindowSize-3) do\\\
  8808.             paintutils.drawPixel(x,yStart+yWindowSize-2,color)\\\
  8809.         end\\\
  8810.         colorText(xStart+xWindowSize-6,yStart+yWindowSize-2,\\\"OK\\\",color2)\\\
  8811.     end\\\
  8812.     drawButton(colors.lightBlue,colors.black)\\\
  8813.     \\\
  8814.     while true do\\\
  8815.         local event,side,x,y = os.pullEvent()\\\
  8816.         if event == \\\"mouse_click\\\" then\\\
  8817.             if x>=xStart+xWindowSize-8 and x<=xStart+xWindowSize-3 and y == yStart+yWindowSize-2 then\\\
  8818.                 drawButton(colors.blue,colors.white)\\\
  8819.                 sleep(0.2)\\\
  8820.                 break\\\
  8821.             end\\\
  8822.         elseif event == \\\"key\\\" then\\\
  8823.             if side == 28 then\\\
  8824.                 drawButton(colors.blue,colors.white)\\\
  8825.                 sleep(0.2)\\\
  8826.                 break\\\
  8827.             end\\\
  8828.         end\\\
  8829.     end\\\
  8830. end\\\
  8831. \\\
  8832. ---------------------------------------------------------------------------------------------------------------\\\
  8833. \\\
  8834. function input(...)\\\
  8835.     \\\
  8836.     local xStart = arg[1]\\\
  8837.     local yStart = arg[2]\\\
  8838.     local title = arg[3]\\\
  8839.     local sizeOfInputRow = arg[4]\\\
  8840. \\\
  8841.     local sizeOfText1 = #arg-4\\\
  8842. \\\
  8843.     local Inputs = {}\\\
  8844. \\\
  8845.     local allowToPressOk = true\\\
  8846. \\\
  8847.     local inputCounter = 1\\\
  8848. \\\
  8849.     local theLongestElement = 0\\\
  8850.     for i=1,sizeOfText1 do\\\
  8851.         if #arg[i+4][1] > theLongestElement then theLongestElement = #arg[i+4][1] end\\\
  8852.     end\\\
  8853. \\\
  8854.     local xWindowSize = 2 + theLongestElement + 1 + sizeOfInputRow + 2\\\
  8855.     local yWindowSize = 2 + sizeOfText1 * 2 + 1 + 1\\\
  8856. \\\
  8857.     xStart, yStart = correctStartCoords(xStart,yStart,xWindowSize,yWindowSize)\\\
  8858. \\\
  8859.     --ЗАНОСпМ СТАРТОВОЕ ГОВНО В пНПУТС, БпЧ\\\
  8860.     for i=1,sizeOfText1 do\\\
  8861.         Inputs[i]=arg[i+4][2]\\\
  8862.     end\\\
  8863. \\\
  8864.     --СОЗДАНпЕ ОБЪЕКТОВ\\\
  8865.     local Objects = {}\\\
  8866.     local function newObj(class,name,x1,y1,width,height)\\\
  8867.         Objects[class] = Objects[class] or {}\\\
  8868.         Objects[class][name] = {}\\\
  8869.         Objects[class][name][\\\"x1\\\"]=x1\\\
  8870.         Objects[class][name][\\\"y1\\\"]=y1\\\
  8871.         Objects[class][name][\\\"x2\\\"]=x1+width-1\\\
  8872.         Objects[class][name][\\\"y2\\\"]=y1+height-1\\\
  8873.     end\\\
  8874. \\\
  8875.     --РпСОВАНпЕ ПУСТОГО ОКНА\\\
  8876.     emptyWindow(xStart,yStart,xWindowSize,yWindowSize,title)\\\
  8877. \\\
  8878.     --BUTTON\\\
  8879.     local function drawButton(color,color2)\\\
  8880.         for x=(xStart+xWindowSize-8),(xStart+xWindowSize-3) do\\\
  8881.             paintutils.drawPixel(x,yStart+yWindowSize-2,color)\\\
  8882.         end\\\
  8883.         colorText(xStart+xWindowSize-6,yStart+yWindowSize-2,\\\"OK\\\",color2)\\\
  8884.     end\\\
  8885.     \\\
  8886.     local function drawInputs()\\\
  8887.         for i=1,sizeOfText1 do\\\
  8888.             local xPosOfInput = xStart+xWindowSize - 2 - sizeOfInputRow\\\
  8889.             local yPosOfInput = yStart+i*2\\\
  8890. \\\
  8891.             local inputArgument = arg[i+4]\\\
  8892. \\\
  8893.             term.setBackgroundColor(colors.white)\\\
  8894.             if inputCounter == i then\\\
  8895.                 colorText(xStart+2,yPosOfInput,inputArgument[1],colors.gray)\\\
  8896.             else\\\
  8897.                 colorText(xStart+2,yPosOfInput,inputArgument[1],colors.lightGray)\\\
  8898.             end\\\
  8899. \\\
  8900.             square(xPosOfInput,yPosOfInput,sizeOfInputRow,1,colors.lightGray)\\\
  8901.             newObj(\\\"inputs\\\",i,xPosOfInput,yPosOfInput,sizeOfInputRow,1)\\\
  8902. \\\
  8903.             if Inputs[i] ~= nil then\\\
  8904.                 if inputArgument[3] == nil then\\\
  8905.                     colorText(xPosOfInput,yPosOfInput,stringLimit(\\\"start\\\",Inputs[i],sizeOfInputRow),colors.black)\\\
  8906.                 else\\\
  8907.                     colorText(xPosOfInput,yPosOfInput,stringLimit(\\\"start\\\",string.rep(\\\"*\\\",#Inputs[i]),sizeOfInputRow),colors.black)\\\
  8908.                 end\\\
  8909.             end\\\
  8910.             \\\
  8911.             if inputCounter > sizeOfText1 then allowToPressOk = true end\\\
  8912.         end\\\
  8913. \\\
  8914.         if allowToPressOk then\\\
  8915.             drawButton(colors.lightBlue,colors.black)\\\
  8916.         else\\\
  8917.             drawButton(colors.lightGray,colors.black)\\\
  8918.         end\\\
  8919.     end\\\
  8920. \\\
  8921.     drawInputs()\\\
  8922.     \\\
  8923.     local currentInput = \\\"\\\"\\\
  8924. \\\
  8925.     while true do\\\
  8926.         if Inputs[inputCounter] ~= nil then currentInput = Inputs[inputCounter] end\\\
  8927. \\\
  8928.         term.setCursorBlink(false)\\\
  8929.         drawInputs(inputCounter)\\\
  8930.         term.setCursorBlink(true)\\\
  8931. \\\
  8932.         if #currentInput < sizeOfInputRow and inputCounter <= sizeOfText1 then\\\
  8933.             term.setCursorPos(xStart+xWindowSize-2-sizeOfInputRow+#currentInput,yStart+inputCounter*2)\\\
  8934.         elseif #currentInput >= sizeOfInputRow and inputCounter <= sizeOfText1 then\\\
  8935.             term.setCursorPos(xStart+xWindowSize-3,yStart+inputCounter*2)\\\
  8936.         else\\\
  8937.             term.setCursorBlink(false)\\\
  8938.         end\\\
  8939. \\\
  8940.         local event,side,x,y = os.pullEvent()\\\
  8941.         if event == \\\"key\\\" then\\\
  8942.             --ЕНТЕР\\\
  8943.             if side == 28 then\\\
  8944.                 if currentInput ~= \\\"\\\" then\\\
  8945.                     currentInput = \\\"\\\"\\\
  8946.                 else\\\
  8947.                     Inputs[inputCounter] = currentInput \\\
  8948.                 end\\\
  8949. \\\
  8950.                 if inputCounter < sizeOfText1 then\\\
  8951.                     inputCounter = inputCounter + 1\\\
  8952.                 else\\\
  8953.                     term.setCursorBlink(false)\\\
  8954.                     drawButton(colors.blue,colors.white)\\\
  8955.                     sleep(0.2)\\\
  8956.                     return Inputs\\\
  8957.                 end\\\
  8958.             --БЕКСПЕЙС\\\
  8959.             elseif side == 14 then\\\
  8960.                 currentInput = string.sub(currentInput,1,-2)\\\
  8961.                 Inputs[inputCounter] = currentInput\\\
  8962.             --КНОПОЧКп ВВЕРХ-ВНпЗ\\\
  8963.             elseif side == 200 then\\\
  8964.                 inputCounter = inputCounter - 1\\\
  8965.                 if inputCounter < 1 then inputCounter = 1 end\\\
  8966.             elseif side == 208 then\\\
  8967.                 inputCounter = inputCounter + 1\\\
  8968.                 if inputCounter > #Inputs then inputCounter = #Inputs end\\\
  8969.             end\\\
  8970.         elseif event == \\\"mouse_click\\\" then\\\
  8971.             term.setCursorBlink(false)\\\
  8972.             if x>=xStart+xWindowSize-8 and x<=xStart+xWindowSize-3 and y == yStart+yWindowSize-2 and allowToPressOk == true then\\\
  8973.                 drawButton(colors.blue,colors.white)\\\
  8974.                 sleep(0.2)\\\
  8975.                 return Inputs\\\
  8976.             end\\\
  8977.             for key,val in pairs(Objects[\\\"inputs\\\"]) do\\\
  8978.                 if x>=Objects[\\\"inputs\\\"][key][\\\"x1\\\"] and x<=Objects[\\\"inputs\\\"][key][\\\"x2\\\"] and y==Objects[\\\"inputs\\\"][key][\\\"y1\\\"] then\\\
  8979.                     inputCounter = key\\\
  8980.                     break\\\
  8981.                 end\\\
  8982.             end\\\
  8983.         elseif event == \\\"char\\\" then\\\
  8984.             currentInput = currentInput..side\\\
  8985.             Inputs[inputCounter] = currentInput\\\
  8986.         elseif event == \\\"paste\\\" then\\\
  8987.             currentInput = currentInput..side\\\
  8988.             Inputs[inputCounter] = currentInput\\\
  8989.         end\\\
  8990.     end\\\
  8991. end\\\
  8992. \\\
  8993. ---------------------------------------------------------------------------------------------------------------------\\\
  8994. \\\
  8995. function tv(speed)\\\
  8996.     term.setBackgroundColor(colors.black)\\\
  8997.     for i=1,centerY do\\\
  8998.         term.setCursorPos(1,i)\\\
  8999.         term.clearLine()\\\
  9000.         term.setCursorPos(1,ySize-i+1)\\\
  9001.         term.clearLine()\\\
  9002.         sleep(speed)\\\
  9003.     end\\\
  9004.     for i=1,centerX do\\\
  9005.         paintutils.drawPixel(i,centerY+1,colors.black)\\\
  9006.         paintutils.drawPixel(xSize-i+1,centerY+1,colors.black)\\\
  9007.         sleep(speed)\\\
  9008.     end\\\
  9009.     sleep(0.2)\\\
  9010.     clearScreen(colors.black)\\\
  9011.     term.setTextColor(colors.white)\\\
  9012.     term.setCursorPos(1,1)\\\
  9013. end\\\
  9014. \\\
  9015. ---------------------------------------------------------------------------------------------------------------------\\\
  9016. \\\
  9017. function select(...)\\\
  9018. \\\
  9019.     --СОЗДАНпЕ ОБЪЕКТОВ\\\
  9020.     local Objects = {}\\\
  9021.     local function newObj(class,name,x1,y1,width,height)\\\
  9022.         --if not Objects[class] then Objects[class] = {} end\\\
  9023.         Objects[class] = Objects[class] or {}\\\
  9024.         Objects[class][name] = {}\\\
  9025.         Objects[class][name][\\\"x1\\\"]=x1\\\
  9026.         Objects[class][name][\\\"y1\\\"]=y1\\\
  9027.         Objects[class][name][\\\"x2\\\"]=x1+width-1\\\
  9028.         Objects[class][name][\\\"y2\\\"]=y1+height-1\\\
  9029.     end\\\
  9030. \\\
  9031.     local function drawButton(x,y,name,textColor,backColor)\\\
  9032.         local sizeOfButton = 2+#name+2\\\
  9033.         square(x,y,sizeOfButton,1,backColor)\\\
  9034.         colorText(x+2,y,name,textColor)\\\
  9035.         newObj(\\\"buttons\\\",name,x,y,sizeOfButton,1)\\\
  9036.     end\\\
  9037. \\\
  9038.     local text1 = arg[1]\\\
  9039.     local text2 = arg[2]\\\
  9040. \\\
  9041.     local sizeOfText1 = #text1\\\
  9042.     local sizeOfText2 = #text2\\\
  9043.     local hereIsOnlyOneElement = false\\\
  9044.     if sizeOfText1 == 0 then hereIsOnlyOneElement = true end\\\
  9045. \\\
  9046.     --ВЫЧпСЛЕНпЕ ДЛпНЫ ОКНА НА ОСНОВЕ ТЕКСТА\\\
  9047.     local theLongestElement = 0\\\
  9048.     for i=1,sizeOfText1 do\\\
  9049.         if #text1[i] > theLongestElement then theLongestElement = #text1[i] end\\\
  9050.     end\\\
  9051.     for i=1,sizeOfText2 do\\\
  9052.         if #text2[i] > theLongestElement then theLongestElement = #text2[i] end\\\
  9053.     end\\\
  9054. \\\
  9055.     --ПЕРЕСЧЕТ ДЛпНЫ ОКНА НА ОСНОВЕ КОЛпЧЕСТВА КНОПОК\\\
  9056.     local countOfButtons = #arg-2\\\
  9057.     local sizeOfAllButtons = 0\\\
  9058.     for i=1,countOfButtons do\\\
  9059.         sizeOfAllButtons = sizeOfAllButtons + 2+#arg[2+i][1]+2 + 1\\\
  9060.     end\\\
  9061.     sizeOfAllButtons = sizeOfAllButtons - 1\\\
  9062.     if sizeOfAllButtons>theLongestElement then theLongestElement=sizeOfAllButtons end\\\
  9063. \\\
  9064.     --ЗАДАНпЕ КОНКРЕТНЫХ РАЗМЕРОВ ОКНА ПОСЛЕ ВЫЧпСЛЕНпЙ\\\
  9065.     local xWindowSize = 2 + theLongestElement + 2\\\
  9066.     local yWindowSize = nil\\\
  9067.     if hereIsOnlyOneElement then\\\
  9068.         yWindowSize = 2 + sizeOfText2 + 3\\\
  9069.     else\\\
  9070.         yWindowSize = 2 + sizeOfText1 + 1 + sizeOfText2 + 3\\\
  9071.     end\\\
  9072. \\\
  9073.     local xStart = math.floor(xSize/2-xWindowSize/2)\\\
  9074.     local yStart = math.floor(ySize/2-yWindowSize/2)\\\
  9075.     \\\
  9076.     --РпСОВАНпЕ ПУСТОГО ОКНА\\\
  9077.     emptyWindow(xStart,yStart,xWindowSize,yWindowSize,\\\" \\\")\\\
  9078. \\\
  9079.     --TEXTS\\\
  9080.     term.setBackgroundColor(colors.white)\\\
  9081.     for i=1,sizeOfText1 do\\\
  9082.         colorText(xStart+2,yStart+1+i,text1[i],colors.gray)\\\
  9083.     end\\\
  9084.     for i=1,sizeOfText2 do\\\
  9085.         if hereIsOnlyOneElement then\\\
  9086.             colorText(xStart+2,yStart+1+sizeOfText1+i,text2[i],colors.lightGray)\\\
  9087.         else\\\
  9088.             colorText(xStart+2,yStart+2+sizeOfText1+i,text2[i],colors.lightGray)\\\
  9089.         end\\\
  9090.     end\\\
  9091. \\\
  9092.     local xStartForButtons = xStart+xWindowSize-1 - sizeOfAllButtons - 1\\\
  9093.     local yStartForButtons = yStart+yWindowSize-2\\\
  9094.     for i=1,countOfButtons do\\\
  9095.         local text = arg[2+i][1]\\\
  9096.         local textColor = tonumber(arg[2+i][3])\\\
  9097.         local backColor = tonumber(arg[2+i][2])\\\
  9098. \\\
  9099.         drawButton(xStartForButtons,yStartForButtons,text,textColor,backColor)\\\
  9100.         xStartForButtons = xStartForButtons + 2+#arg[2+i][1]+2+1\\\
  9101.     end\\\
  9102. \\\
  9103.     while true do\\\
  9104.         local event,side,x,y = os.pullEvent()\\\
  9105.         if event == \\\"mouse_click\\\" then\\\
  9106.             for key,val in pairs(Objects[\\\"buttons\\\"]) do\\\
  9107.                 if x>=Objects[\\\"buttons\\\"][key][\\\"x1\\\"] and x<=Objects[\\\"buttons\\\"][key][\\\"x2\\\"] and y==Objects[\\\"buttons\\\"][key][\\\"y1\\\"] then\\\
  9108.                     drawButton(Objects[\\\"buttons\\\"][key][\\\"x1\\\"],Objects[\\\"buttons\\\"][key][\\\"y1\\\"],key,colors.white,colors.blue)\\\
  9109.                     sleep(0.2)\\\
  9110.                     return key\\\
  9111.                 end\\\
  9112.             end\\\
  9113.         end\\\
  9114.     end\\\
  9115. end\\\
  9116. \\\
  9117. ---------------------------------------------------------------------------------------------------------------------\\\
  9118. \\\
  9119. function aboutFile(x,y,xWindowSize,path)\\\
  9120.     os.loadAPI(\\\"System/API/image\\\")\\\
  9121. \\\
  9122.     local name = fs.getName(path)\\\
  9123.     local limitOfText = xWindowSize - 2\\\
  9124.     local yWindowSize = 16\\\
  9125. \\\
  9126.     --СОЗДАНпЕ ОБЪЕКТОВ\\\
  9127.     local Objects = {}\\\
  9128.     local function newObj(class,name,x1,y1,width,height)\\\
  9129.         Objects[class] = Objects[class] or {}\\\
  9130.         Objects[class][name] = {}\\\
  9131.         Objects[class][name][\\\"x1\\\"]=x1\\\
  9132.         Objects[class][name][\\\"y1\\\"]=y1\\\
  9133.         Objects[class][name][\\\"x2\\\"]=x1+width-1\\\
  9134.         Objects[class][name][\\\"y2\\\"]=y1+height-1\\\
  9135.     end\\\
  9136. \\\
  9137.     --РпСОВАНпЕ КНОПКп\\\
  9138.     local function drawButton(x,y,name,textColor,backColor)\\\
  9139.         local sizeOfButton = 2+#name+2\\\
  9140.         square(x,y,sizeOfButton,1,backColor)\\\
  9141.         colorText(x+2,y,name,textColor)\\\
  9142.         newObj(\\\"buttons\\\",name,x,y,sizeOfButton,1)\\\
  9143.     end\\\
  9144. \\\
  9145.     ---------------НЕНУЖНОЕ ГОВНО, ЛОСОСНп\\\
  9146. \\\
  9147.     local info = {}\\\
  9148. \\\
  9149.     info[\\\"fileFormat\\\"] = getFileFormat(path)\\\
  9150. \\\
  9151.     info[\\\"fileType\\\"] = getFileType(path)\\\
  9152. \\\
  9153.     info[\\\"fileSize\\\"] = math.ceil(getFileSize(path)/1024)..\\\"KB\\\"\\\
  9154. \\\
  9155.     info[\\\"readOnly\\\"] = tostring(fs.isReadOnly(path))\\\
  9156.     ---------------НУЖНОЕ ГОВНО\\\
  9157. \\\
  9158.     --КОРРЕКЦпЯ КООРДпНАТЫ GOVNA, ЧТОБ ЗА КРАЯ ЭКРАНА НЕ ЗАЛЕЗАЛО\\\
  9159.     if y+yWindowSize - 1  >= ySize then y = y - (y+yWindowSize - 1 - ySize) - 1 end\\\
  9160.     if x+xWindowSize - 1  >= xSize then x = x - (x+xWindowSize - 1 - xSize) - 1 end\\\
  9161. \\\
  9162.     --РпСУЕМ ОКНО\\\
  9163.     emptyWindow(x,y,xWindowSize,yWindowSize,\\\"Properties\\\")\\\
  9164. \\\
  9165.     --пКОНОЧКп, БпЧ\\\
  9166.     drawOSIcon(x+1,y+2,path,name,info[\\\"fileFormat\\\"])\\\
  9167. \\\
  9168.     --ПОЛОСОЧКА ПОД пКОНКОЙ\\\
  9169.     square(x,y+7,xWindowSize,1,colors.lightGray)\\\
  9170.     colorText(x+1,y+7,\\\"Info\\\",colors.white)\\\
  9171. \\\
  9172.     --ТЕКСТ СПРАВА ОТ пКОНКп\\\
  9173.     term.setBackgroundColor(colors.white)\\\
  9174.     colorText(x+8,y+3,stringLimit(\\\"start\\\",name,xWindowSize-9),colors.gray)\\\
  9175.     colorText(x+8,y+4,info[\\\"fileSize\\\"],colors.lightGray)\\\
  9176. \\\
  9177.     --ТЕКСТ ПОД пКОНКОЙ\\\
  9178.     local textStart = y+9\\\
  9179.     colorText(x+1,textStart,\\\"Type:\\\",colors.gray)\\\
  9180.     usualText(x+1,textStart+1,\\\"Size:\\\",colors.gray)\\\
  9181.     usualText(x+1,textStart+2,\\\"Path:\\\",colors.gray)\\\
  9182.     usualText(x+1,textStart+3,\\\"Read only:\\\",colors.gray)\\\
  9183. \\\
  9184.     colorText(x+7,textStart,info[\\\"fileType\\\"],colors.lightGray)\\\
  9185.     usualText(x+7,textStart+1,info[\\\"fileSize\\\"])\\\
  9186.     usualText(x+7,textStart+2,stringLimit(\\\"start\\\",path,xWindowSize-8))\\\
  9187.     usualText(x+12,textStart+3,info[\\\"readOnly\\\"])\\\
  9188. \\\
  9189.     --КНОПКА\\\
  9190.     drawButton(x+xWindowSize-11,y+yWindowSize-2,\\\"Close\\\",colors.black,colors.lightBlue)\\\
  9191. \\\
  9192.     --ОТСЛЕЖпВАНпЕ НАЖАТпЯ НА КНОПКУ\\\
  9193.     while true do\\\
  9194.         local event,side,x,y = os.pullEvent()\\\
  9195.         if event == \\\"mouse_click\\\" then\\\
  9196.             for key,val in pairs(Objects[\\\"buttons\\\"]) do\\\
  9197.                 if x>=Objects[\\\"buttons\\\"][key][\\\"x1\\\"] and x<=Objects[\\\"buttons\\\"][key][\\\"x2\\\"] and y==Objects[\\\"buttons\\\"][key][\\\"y1\\\"] then\\\
  9198.                     drawButton(Objects[\\\"buttons\\\"][key][\\\"x1\\\"],Objects[\\\"buttons\\\"][key][\\\"y1\\\"],key,colors.white,colors.blue)\\\
  9199.                     sleep(0.2)\\\
  9200.                     return key\\\
  9201.                 end\\\
  9202.             end\\\
  9203.         end\\\
  9204.     end\\\
  9205. end\\\
  9206. \\\
  9207. ---------------------------------------------------------------------------------------------------------------------\\\
  9208. \\\
  9209. function progressBar(xStart,yStart,xWindowSize,title,text,speed)\\\
  9210.     --СКОРРЕКТпРОВАТЬ ШпРпНУ ОКНА\\\
  9211.     if xWindowSize < 4+#text then\\\
  9212.         xWindowSize = 4+#text\\\
  9213.     end\\\
  9214. \\\
  9215.     local yWindowSize = 6\\\
  9216.     local sizeOfProgressBar = xWindowSize - 4\\\
  9217. \\\
  9218.     --СКОРРЕКТпРОВАТЬ КООРДЫ\\\
  9219.     xStart,yStart = correctStartCoords(xStart,yStart,xWindowSize,yWindowSize)\\\
  9220. \\\
  9221.     --САМО ОКНО\\\
  9222.     emptyWindow(xStart,yStart,xWindowSize,yWindowSize,title)\\\
  9223. \\\
  9224.     --ТЕКСТ ОКНА\\\
  9225.     term.setBackgroundColor(colors.white)\\\
  9226.     colorText(math.floor(xStart+(xWindowSize/2-#text/2)),yStart+2,text,colors.gray)\\\
  9227. \\\
  9228.     --РпСОВАНпЕ ПРОГРЕСС БАРА\\\
  9229.     local xProgressBarPos = xStart+2\\\
  9230.     local yProgressBarPos = yStart+4\\\
  9231.     drawProgressBar(xProgressBarPos,yProgressBarPos,sizeOfProgressBar,1,colors.lightBlue,colors.lightGray,0)\\\
  9232.     sleep(0)\\\
  9233.     for i=1,100,speed do\\\
  9234.         drawProgressBar(xProgressBarPos,yProgressBarPos,sizeOfProgressBar,1,colors.lightBlue,colors.lightGray,i)\\\
  9235.         sleep(0)\\\
  9236.     end\\\
  9237.     drawProgressBar(xProgressBarPos,yProgressBarPos,sizeOfProgressBar,1,colors.lightBlue,colors.lightGray,100)\\\
  9238. end\\\
  9239. \\\
  9240. ---------------------------------------------------------------------------------------------------------------------\\\
  9241. \\\
  9242. function search(xStart,yStart,xWindowSize,limitOfElements,searchText)\\\
  9243. \\\
  9244.     os.loadAPI(\\\"System/API/image\\\")\\\
  9245. \\\
  9246.     local searchList = {}\\\
  9247. \\\
  9248.     local sizeOfOneElement = 5\\\
  9249.     local yWindowSize = 4 + sizeOfOneElement*limitOfElements\\\
  9250.     local sizeOfSearchBar = xWindowSize - #searchText - 3\\\
  9251.     local xStartOfSearchBar = xStart + 2 + #searchText\\\
  9252.     local yStartOfSearchBar = yStart + 1\\\
  9253.     local limitOfAllText = xWindowSize - 10\\\
  9254.     local xWindowEnd = xStart + xWindowSize - 1\\\
  9255.     local yWindowEnd = yStart + yWindowSize - 1\\\
  9256. \\\
  9257.     local fromElement = 1\\\
  9258.     local searchInput = \\\"\\\"\\\
  9259. \\\
  9260.     --СОЗДАНпЕ ОБЪЕКТОВ\\\
  9261.     local Objects = {}\\\
  9262.     local function newObj(class,name,x1,y1,width,height,fileType,fileSize,path,fileName,fileFormat)\\\
  9263.         Objects[class] = Objects[class] or {}\\\
  9264.         Objects[class][name] = {}\\\
  9265.         Objects[class][name][\\\"x1\\\"]=x1\\\
  9266.         Objects[class][name][\\\"y1\\\"]=y1\\\
  9267.         Objects[class][name][\\\"x2\\\"]=x1+width-1\\\
  9268.         Objects[class][name][\\\"y2\\\"]=y1+height-1\\\
  9269.         Objects[class][name][\\\"fileType\\\"]=fileType\\\
  9270.         Objects[class][name][\\\"fileSize\\\"]=fileSize\\\
  9271.         Objects[class][name][\\\"path\\\"]=path\\\
  9272.         Objects[class][name][\\\"fileName\\\"]=fileName\\\
  9273.         Objects[class][name][\\\"fileFormat\\\"]=fileFormat\\\
  9274.     end\\\
  9275. \\\
  9276.     local function drawConcretnoIcon(xStart,yStart,path,name,fileType,fileSize,backColor,fileFormat)\\\
  9277.         drawOSIcon(xStart,yStart,path,name,fileFormat)\\\
  9278.         term.setBackgroundColor(backColor)\\\
  9279.         colorText(xStart+8,yStart,stringLimit(\\\"end\\\",name,limitOfAllText),colors.gray)\\\
  9280.         colorText(xStart+8,yStart+1,stringLimit(\\\"start\\\",path,limitOfAllText),colors.lightGray)\\\
  9281.         colorText(xStart+8,yStart+2,stringLimit(\\\"start\\\",\\\"Type: \\\"..fileType,limitOfAllText),colors.lightGray)\\\
  9282.         colorText(xStart+8,yStart+3,stringLimit(\\\"start\\\",\\\"Size: \\\"..math.ceil(fileSize/1024)..\\\"KB\\\",limitOfAllText),colors.lightGray)\\\
  9283. \\\
  9284.         newObj(\\\"icon\\\",path..\\\"/\\\"..name,xStart,yStart,xWindowSize,4,fileType,fileSize,path,name,fileFormat)\\\
  9285.     end\\\
  9286. \\\
  9287.     local function drawSearches(fromElement)\\\
  9288.         --ОБНУЛЕНпЕ ОБЪЕКТОВ\\\
  9289.         Objects = {}\\\
  9290.         newObj(\\\"icon\\\",\\\"cykaBlyad\\\",-5,-5,1,1,\\\"hehe\\\",5)     \\\
  9291. \\\
  9292.         --ОЧпСТКА ЭКРАНА ПОКАЗА\\\
  9293.         square(xStart,yStart+3,xWindowSize-1,yWindowSize-3,colors.white)\\\
  9294. \\\
  9295.         if #searchList == 0 then\\\
  9296.             colorText(xStart+1,yStart+4,\\\"No mathes found.\\\",colors.lightGray)\\\
  9297.         else\\\
  9298.             local iconCounter = 1\\\
  9299.             for i=fromElement,#searchList do\\\
  9300.                 local yIconPos = yStart+4 + iconCounter*sizeOfOneElement - sizeOfOneElement\\\
  9301.                 \\\
  9302.                 drawConcretnoIcon(xStart+1,yIconPos,searchList[i][\\\"path\\\"],searchList[i][\\\"name\\\"],searchList[i][\\\"fileType\\\"],searchList[i][\\\"fileSize\\\"],colors.white,searchList[i][\\\"fileFormat\\\"])\\\
  9303. \\\
  9304.                 iconCounter = iconCounter + 1\\\
  9305.                 if iconCounter > limitOfElements then break end\\\
  9306.             end\\\
  9307.         end\\\
  9308. \\\
  9309.         scrollBar(xWindowEnd,yStart+3,yWindowSize-3,#searchList,fromElement,colors.lightGray,colors.lightBlue)\\\
  9310.     end\\\
  9311. \\\
  9312.     local function textOnSearchBar()\\\
  9313.         term.setBackgroundColor(colors.white)\\\
  9314.         usualText(xStartOfSearchBar,yStartOfSearchBar,string.rep(\\\" \\\",sizeOfSearchBar))\\\
  9315.         colorText(xStartOfSearchBar,yStartOfSearchBar,stringLimit(\\\"start\\\",searchInput,sizeOfSearchBar),colors.black)\\\
  9316.     end\\\
  9317. \\\
  9318.     --ОКНО\\\
  9319.     sampleWindow(xStart,yStart,xWindowSize,yWindowSize)\\\
  9320.     --ГОЛУБАЯ ШТУЧКА\\\
  9321.     square(xStart,yStart,xWindowSize,3,colors.blue)\\\
  9322.     colorText(xStart+1,yStart+1,searchText,colors.white)\\\
  9323.     square(xStartOfSearchBar,yStartOfSearchBar,sizeOfSearchBar,1,colors.white)\\\
  9324. \\\
  9325.     drawSearches(fromElement)\\\
  9326. \\\
  9327.     while true do\\\
  9328.         textOnSearchBar(searchInput)\\\
  9329.         if #searchInput > sizeOfSearchBar then\\\
  9330.             term.setCursorPos(xStartOfSearchBar+sizeOfSearchBar-1,yStartOfSearchBar)\\\
  9331.         else\\\
  9332.             term.setCursorPos(xStartOfSearchBar+#searchInput,yStartOfSearchBar)\\\
  9333.         end\\\
  9334. \\\
  9335.         term.setCursorBlink(true)\\\
  9336. \\\
  9337.         local event,side,x,y = os.pullEvent()\\\
  9338.         if event == \\\"mouse_scroll\\\" then\\\
  9339.             term.setCursorBlink(false)\\\
  9340.             if side == 1 then\\\
  9341.                 fromElement = fromElement + 1\\\
  9342.                 if fromElement > #searchList then\\\
  9343.                     fromElement = #searchList\\\
  9344.                 else\\\
  9345.                     drawSearches(fromElement)\\\
  9346.                 end\\\
  9347.             else\\\
  9348.                 fromElement = fromElement - 1\\\
  9349.                 if fromElement < 1 then\\\
  9350.                     fromElement = 1\\\
  9351.                 else\\\
  9352.                     drawSearches(fromElement)\\\
  9353.                 end\\\
  9354.             end\\\
  9355.         elseif event == \\\"mouse_click\\\" then\\\
  9356.             for key,val in pairs(Objects[\\\"icon\\\"]) do\\\
  9357.                 if x>=Objects[\\\"icon\\\"][key][\\\"x1\\\"] and x<=Objects[\\\"icon\\\"][key][\\\"x2\\\"] and y>=Objects[\\\"icon\\\"][key][\\\"y1\\\"] and y<=Objects[\\\"icon\\\"][key][\\\"y2\\\"] then\\\
  9358.                     square(Objects[\\\"icon\\\"][key][\\\"x1\\\"]-1,Objects[\\\"icon\\\"][key][\\\"y1\\\"],xWindowSize-1,4,colors.blue)\\\
  9359.                     drawConcretnoIcon(Objects[\\\"icon\\\"][key][\\\"x1\\\"],Objects[\\\"icon\\\"][key][\\\"y1\\\"],Objects[\\\"icon\\\"][key][\\\"path\\\"],Objects[\\\"icon\\\"][key][\\\"fileName\\\"],Objects[\\\"icon\\\"][key][\\\"fileType\\\"],Objects[\\\"icon\\\"][key][\\\"fileSize\\\"],colors.blue,Objects[\\\"icon\\\"][key][\\\"fileFormat\\\"])\\\
  9360.                     sleep(0.3)\\\
  9361.                     term.setCursorBlink(false)\\\
  9362.                     return string.sub(key,2,-1)\\\
  9363.                 end\\\
  9364.             end\\\
  9365.             term.setCursorBlink(false)\\\
  9366.             return nil\\\
  9367. \\\
  9368.         elseif event == \\\"char\\\" then\\\
  9369.             fromElement = 1\\\
  9370.             searchInput = searchInput..side\\\
  9371.             searchList = searchInAllFiles(\\\"/\\\",searchInput)\\\
  9372.             drawSearches(fromElement)\\\
  9373.         elseif event == \\\"key\\\" then\\\
  9374.             if side == 14 then\\\
  9375.                 fromElement = 1\\\
  9376.                 searchInput = string.sub(searchInput,1,-2)\\\
  9377.                 searchList = searchInAllFiles(\\\"/\\\",searchInput)\\\
  9378.                 drawSearches(fromElement)\\\
  9379.             end\\\
  9380.         end\\\
  9381.     end\\\
  9382. end\\\
  9383. \\\
  9384. --print(\\\"You selected: \\\"..search(2,2,28,2,\\\"Search\\\"))\\\
  9385. \\\
  9386. \\\
  9387. ---------------------------------------------------------------------------------------------------------------------\\\
  9388. \\\
  9389. function info(xStart,yStart,title,text)\\\
  9390.     local sizeOfText = #text\\\
  9391.     local xWindowSize = 4+sizeOfText\\\
  9392.     local yWindowSize = 4\\\
  9393.     local xStart,yStart = correctStartCoords(xStart,yStart,xWindowSize,yWindowSize)\\\
  9394. \\\
  9395.     emptyWindow(xStart,yStart,xWindowSize,yWindowSize,title)\\\
  9396. \\\
  9397.     term.setBackgroundColor(colors.white)\\\
  9398.     colorText(xStart+2,yStart+2,text,colors.gray)\\\
  9399. end\\\
  9400. \\\
  9401. ---------------------------------------------------------------------------------------------------------------------\\\
  9402. \\\
  9403. --[[function fileManager(mode,workPath)\\\
  9404.     if workPath == nil then workPath = \\\"\\\" end\\\
  9405. \\\
  9406.     local xSize,ySize = term.getSize()\\\
  9407. \\\
  9408.     local managerX = xSize-3\\\
  9409.     local managerY = ySize-3\\\
  9410. \\\
  9411.     local xStart = 2\\\
  9412.     local yStart = 2\\\
  9413. \\\
  9414.     local main = window.create(term.native(),xStart,yStart,managerX+1,managerY+1)\\\
  9415.     term.redirect(main)\\\
  9416. \\\
  9417.     local function getFoldersList(workPath)\\\
  9418. \\\
  9419.     end\\\
  9420. \\\
  9421.     local function drawManager()\\\
  9422.         local currentPath = fs.getName(workPath)\\\
  9423.         emptyWindow(1,1,managerX,managerY,currentPath)\\\
  9424.         colorTextWithBack(1,1,\\\"x\\\",colors.black,colors.red);colorTextWithBack(2,1,\\\"-\\\",colors.black,colors.orange);colorTextWithBack(3,1,\\\"+\\\",colors.black,colors.lime)\\\
  9425.     end\\\
  9426. \\\
  9427.     local function clickedAtArea(x,y,sx,sy,ex,ey)\\\
  9428.        if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end    \\\
  9429.        return false\\\
  9430.     end\\\
  9431. \\\
  9432.     drawManager()\\\
  9433. \\\
  9434.     term.redirect(term.native())\\\
  9435. end]]\",\
  9436.    path = \"/rootfs/system/api/windows\",\
  9437.  },\
  9438.  {\
  9439.    text = \"function parseargs(s)\\\
  9440.  local arg = {}\\\
  9441.  string.gsub(s, \\\"([%-%w]+)=([\\\\\\\"'])(.-)%2\\\", function (w, _, a)\\\
  9442.    arg[w] = a\\\
  9443.  end)\\\
  9444.  return arg\\\
  9445. end\\\
  9446.    \\\
  9447. function collect(s)\\\
  9448.  local stack = {}\\\
  9449.  local top = {}\\\
  9450.  table.insert(stack, top)\\\
  9451.  local ni,c,label,xarg, empty\\\
  9452.  local i, j = 1, 1\\\
  9453.  while true do\\\
  9454.    ni,j,c,label,xarg, empty = string.find(s, \\\"<(%/?)([%w:]+)(.-)(%/?)>\\\", i)\\\
  9455.    if not ni then break end\\\
  9456.    local text = string.sub(s, i, ni-1)\\\
  9457.    if not string.find(text, \\\"^%s*$\\\") then\\\
  9458.      table.insert(top, text)\\\
  9459.    end\\\
  9460.    if empty == \\\"/\\\" then  -- empty element tag\\\
  9461.      table.insert(top, {label=label, xarg=parseargs(xarg), empty=1})\\\
  9462.    elseif c == \\\"\\\" then   -- start tag\\\
  9463.      top = {label=label, xarg=parseargs(xarg)}\\\
  9464.      table.insert(stack, top)   -- new level\\\
  9465.    else  -- end tag\\\
  9466.      local toclose = table.remove(stack)  -- remove top\\\
  9467.      top = stack[#stack]\\\
  9468.      if #stack < 1 then\\\
  9469.        error(\\\"nothing to close with \\\"..label)\\\
  9470.      end\\\
  9471.      if toclose.label ~= label then\\\
  9472.        error(\\\"trying to close \\\"..toclose.label..\\\" with \\\"..label)\\\
  9473.      end\\\
  9474.      table.insert(top, toclose)\\\
  9475.    end\\\
  9476.    i = j+1\\\
  9477.  end\\\
  9478.  local text = string.sub(s, i)\\\
  9479.  if not string.find(text, \\\"^%s*$\\\") then\\\
  9480.    table.insert(stack[#stack], text)\\\
  9481.  end\\\
  9482.  if #stack > 1 then\\\
  9483.    error(\\\"unclosed \\\"..stack[#stack].label)\\\
  9484.  end\\\
  9485.  return stack[1]\\\
  9486. end\",\
  9487.    path = \"/rootfs/system/api/xml\",\
  9488.  },\
  9489.  {\
  9490.    text = \"function archive(chto,vochto)\\\
  9491.     local Massiv2 = {}\\\
  9492.     local function FileList(path)\\\
  9493.         local Massiv = fs.list(path)\\\
  9494.         if #Massiv==0 then\\\
  9495.             local Massiv2Id = #Massiv2 + 1\\\
  9496.             Massiv2[Massiv2Id] = {}\\\
  9497.             Massiv2[Massiv2Id][\\\"path\\\"] = path\\\
  9498.             Massiv2[Massiv2Id][\\\"text\\\"] = \\\"@empty@empty\\\"\\\
  9499.         else\\\
  9500.             for i=1,#Massiv do\\\
  9501.                 if fs.isDir(path..\\\"/\\\"..Massiv[i]) and Massiv[i] ~= \\\"/rom\\\" and Massiv[i] ~= \\\"rom\\\" then\\\
  9502.                     FileList(path..\\\"/\\\"..Massiv[i])\\\
  9503.                 elseif not fs.isDir(path..\\\"/\\\"..Massiv[i]) and Massiv[i] ~= \\\"/rom\\\" and Massiv[i] ~= \\\"rom\\\" then\\\
  9504.                     local Massiv2Id = #Massiv2 + 1\\\
  9505.                     Massiv2[Massiv2Id] = {}\\\
  9506.                     Massiv2[Massiv2Id][\\\"path\\\"] = path..\\\"/\\\"..Massiv[i]\\\
  9507.                     local file = fs.open(path..\\\"/\\\"..Massiv[i],\\\"r\\\")\\\
  9508.                     Massiv2[Massiv2Id][\\\"text\\\"] = file.readAll()\\\
  9509.                     file.close()\\\
  9510.                 end\\\
  9511.             end\\\
  9512.         end\\\
  9513.     end\\\
  9514.     FileList(chto)\\\
  9515.     file=fs.open(vochto..\\\".zip\\\",\\\"w\\\")\\\
  9516.     file.write(textutils.serialise(Massiv2))\\\
  9517.     file.close()\\\
  9518.     return Massiv2\\\
  9519. end\\\
  9520. \\\
  9521. function unarchive(chto,kuda)\\\
  9522.     local file = fs.open(chto,\\\"r\\\")\\\
  9523.     Massiv = textutils.unserialise(file.readAll())\\\
  9524.     file.close()\\\
  9525.     for i=1,#Massiv do\\\
  9526.         if Massiv[i][\\\"text\\\"] == \\\"@empty@empty\\\" then\\\
  9527.             fs.makeDir(kuda..\\\"/\\\"..Massiv[i][\\\"path\\\"])\\\
  9528.         else\\\
  9529.             local file = fs.open(kuda..\\\"/\\\"..Massiv[i][\\\"path\\\"],\\\"w\\\")\\\
  9530.             file.write(Massiv[i][\\\"text\\\"])\\\
  9531.             file.close()\\\
  9532.         end\\\
  9533.     end\\\
  9534. end\",\
  9535.    path = \"/rootfs/system/api/zip\",\
  9536.  },\
  9537.  {\
  9538.    text = \"local xSize, ySize = term.getSize()\\\
  9539. \\\
  9540. local fileImage = 0\\\
  9541. local fileDocument = 0\\\
  9542. local fileOther = 0\\\
  9543. local computerLabel = os.getComputerLabel()\\\
  9544. if computerLabel == nil then computerLabel = \\\"not set\\\" end\\\
  9545. \\\
  9546. --------------------MODEM FIND----------------------------\\\
  9547. function findModem()\\\
  9548.     local PeriList = peripheral.getNames()\\\
  9549.     for i=1,#PeriList do\\\
  9550.         if peripheral.getType(PeriList[i]) == \\\"modem\\\" then\\\
  9551.             return PeriList[i]\\\
  9552.         end\\\
  9553.     end\\\
  9554. end\\\
  9555. \\\
  9556. local computerModem = findModem()\\\
  9557. if computerModem == nil then computerModem = \\\"not found\\\" end\\\
  9558. \\\
  9559. local function clearScreen(color)\\\
  9560.     term.setBackgroundColor(color)\\\
  9561.     term.clear()\\\
  9562. end\\\
  9563. \\\
  9564. local function fadeIn(time)\\\
  9565.     clearScreen(colors.gray)\\\
  9566.     sleep(time)\\\
  9567.     clearScreen(colors.lightGray)\\\
  9568.     sleep(time)\\\
  9569.     clearScreen(colors.white)\\\
  9570.     sleep(time)\\\
  9571. end\\\
  9572. \\\
  9573. local function fadeOut(time)\\\
  9574.     clearScreen(colors.lightGray)\\\
  9575.     sleep(time)\\\
  9576.     clearScreen(colors.gray)\\\
  9577.     sleep(time)\\\
  9578.     clearScreen(colors.black)\\\
  9579.     sleep(time)\\\
  9580.     term.setCursorPos(1,1)\\\
  9581.     term.setTextColor(colors.white)\\\
  9582. end\\\
  9583. \\\
  9584. local function getSizeOfAll()\\\
  9585.     local sizeOfAll1 = 0\\\
  9586.     local function files(path)\\\
  9587.         local massiv = fs.list(path)\\\
  9588.         for i=1,#massiv do\\\
  9589.             if fs.isDir(massiv[i]) then\\\
  9590.                 files(path..\\\"/\\\"..massiv[i])\\\
  9591.             else\\\
  9592.                 sizeOfAll1 = sizeOfAll1 + fs.getSize(path..\\\"/\\\"..massiv[i])\\\
  9593.             end\\\
  9594.         end\\\
  9595.     end\\\
  9596.     files(\\\"\\\")\\\
  9597.     return sizeOfAll1\\\
  9598. end\\\
  9599. \\\
  9600. local function getFileFormat(file)\\\
  9601.     local start,ending = string.find(file,\\\"%.%w*$\\\")\\\
  9602.     if start == nil then\\\
  9603.         return nil\\\
  9604.     else\\\
  9605.         return string.sub(file,start,ending)\\\
  9606.     end\\\
  9607. end\\\
  9608. \\\
  9609. local function getSizeOfFormat()\\\
  9610.     local sizeOfAll1 = 0\\\
  9611.     local function files(path)\\\
  9612.         local massiv = fs.list(path)\\\
  9613.         for i=1,#massiv do\\\
  9614.             if fs.isDir(massiv[i]) then\\\
  9615.                 files(path..\\\"/\\\"..massiv[i])\\\
  9616.             else\\\
  9617.                 local f = getFileFormat(path..\\\"/\\\"..massiv[i])\\\
  9618.                 local s = fs.getSize(path..\\\"/\\\"..massiv[i])\\\
  9619.                 if f == \\\".png\\\" then\\\
  9620.                     fileImage = fileImage + s\\\
  9621.                 elseif f == \\\".cfg\\\" or f == \\\".log\\\" then\\\
  9622.                     fileDocument = fileDocument + s\\\
  9623.                 elseif f == nil then\\\
  9624.                     fileOther = fileOther + s\\\
  9625.                 end\\\
  9626.             end\\\
  9627.         end\\\
  9628.     end\\\
  9629.     files(\\\"\\\")\\\
  9630.     return sizeOfAll1\\\
  9631. end\\\
  9632. \\\
  9633. local function writeText(text,x,y)\\\
  9634.     term.setCursorPos(x,y)\\\
  9635.     term.write(text)\\\
  9636. end\\\
  9637. \\\
  9638. local function infoText(key,keyColor,value,x,y)\\\
  9639.     term.setCursorPos(x,y)\\\
  9640.     term.setTextColor(keyColor)\\\
  9641.     term.write(key..\\\": \\\")\\\
  9642.     term.setTextColor(colors.lightGray)\\\
  9643.     term.write(value)\\\
  9644. end\\\
  9645. \\\
  9646. getSizeOfFormat()\\\
  9647. \\\
  9648. local sizeOfAll =  getSizeOfAll()\\\
  9649. local freeSpace = fs.getFreeSpace(\\\"\\\")\\\
  9650. local totalSpace = freeSpace + sizeOfAll\\\
  9651. local lengthOfPolosa = xSize-6\\\
  9652. local lengthOfAll = math.floor(lengthOfPolosa*(math.ceil(sizeOfAll/totalSpace*100))/100)\\\
  9653. local lengthOfDocuments = math.floor(lengthOfPolosa*math.ceil(fileDocument/sizeOfAll*100)/100)\\\
  9654. local lengthOfImages = math.floor(lengthOfPolosa*math.ceil(fileImage/sizeOfAll*100)/100)\\\
  9655. \\\
  9656. -------------------------------------------------------------\\\
  9657. fadeIn(0.05)\\\
  9658. \\\
  9659. local xStart = math.floor(xSize/2-lengthOfPolosa/2)\\\
  9660. local yStart = ySize-3\\\
  9661. \\\
  9662. \\\
  9663. local function displayBar(time)\\\
  9664.     while true do\\\
  9665.     for y=yStart,(yStart+1) do\\\
  9666.         for x=(xStart+1),(xStart+lengthOfPolosa) do\\\
  9667.             paintutils.drawPixel(x,y,colors.gray)\\\
  9668.         end\\\
  9669.     end\\\
  9670.     for y=yStart,(yStart+1) do\\\
  9671.         for x=(xStart+1),(xStart+lengthOfAll) do\\\
  9672.             paintutils.drawPixel(x,y,colors.black)\\\
  9673.         end\\\
  9674.     end\\\
  9675. \\\
  9676. ------------------------------\\\
  9677.     sleep(2)\\\
  9678. ------------------------------\\\
  9679. \\\
  9680.     for y=yStart,(yStart+1) do\\\
  9681.         for x=(xStart+1),(xStart+lengthOfPolosa) do\\\
  9682.             paintutils.drawPixel(x,y,colors.lime)\\\
  9683.         end\\\
  9684.     end\\\
  9685.     for y=yStart,(yStart+1) do\\\
  9686.         for x=(xStart+1),(xStart+lengthOfDocuments) do\\\
  9687.             paintutils.drawPixel(x,y,colors.red)\\\
  9688.         end\\\
  9689.     end\\\
  9690.     for y=yStart,(yStart+1) do\\\
  9691.         for x=(xStart+1+lengthOfDocuments),(xStart+lengthOfDocuments+lengthOfImages) do\\\
  9692.             paintutils.drawPixel(x,y,colors.yellow)\\\
  9693.         end\\\
  9694.     end\\\
  9695. ------------------------------\\\
  9696.     sleep(2)\\\
  9697. ------------------------------\\\
  9698.     end\\\
  9699. end\\\
  9700. \\\
  9701. \\\
  9702. \\\
  9703. for i=1,xSize do\\\
  9704.     paintutils.drawPixel(i,1,colors.gray)\\\
  9705. end\\\
  9706. term.setTextColor(colors.lightGray)\\\
  9707. writeText(\\\"About\\\",math.floor(xSize/2-string.len(\\\"About\\\")/2),1)\\\
  9708. \\\
  9709. term.setBackgroundColor(colors.white)\\\
  9710. infoText(\\\"Computer label\\\",colors.gray,computerLabel,2,3)\\\
  9711. infoText(\\\"Computer ID\\\",colors.gray,tostring(os.getComputerID()),2,4)\\\
  9712. infoText(\\\"Connected modem\\\",colors.gray,computerModem,2,5)\\\
  9713. infoText(\\\"Aviable space\\\",colors.gray,math.ceil(totalSpace/1024)..\\\" KB\\\",2,6)\\\
  9714. infoText(\\\"Used space\\\",colors.black,math.ceil(sizeOfAll/1024)..\\\" KB\\\",2,8)\\\
  9715. infoText(\\\"Free space\\\",colors.gray,math.ceil(freeSpace/1024)..\\\" KB\\\",2,9)\\\
  9716. infoText(\\\"Documents\\\",colors.red,math.ceil(fileDocument/1024)..\\\" KB\\\",2,10)\\\
  9717. infoText(\\\"Images\\\",colors.yellow,math.ceil(fileImage/1024)..\\\" KB\\\",2,11)\\\
  9718. infoText(\\\"Other\\\",colors.lime,math.ceil(fileOther/1024)..\\\" KB\\\",2,12)\\\
  9719. \\\
  9720. local function touch()\\\
  9721.     while true do\\\
  9722.         event = os.pullEvent()\\\
  9723.         if event == \\\"key\\\" or event == \\\"mouse_click\\\" then break end\\\
  9724.     end\\\
  9725. end\\\
  9726. \\\
  9727. parallel.waitForAny(displayBar,touch)\\\
  9728. \\\
  9729. fadeOut(0.05)\",\
  9730.    path = \"/rootfs/system/os/apps/about\",\
  9731.  },\
  9732.  {\
  9733.    text = \"-- Project LinOS AccountSettings (made by nikov2002)\\\
  9734. \\\
  9735. \\\
  9736. os.loadAPI(\\\"system/api/windows\\\")\\\
  9737. os.loadAPI(\\\"system/api/image\\\")\\\
  9738. standartErrorFunction = windows.error\\\
  9739. \\\
  9740. term.setBackgroundColor(colors.white)\\\
  9741. term.clear()\\\
  9742. \\\
  9743. local function textWrite(x,y,text)\\\
  9744.     term.setCursorPos(x,y)\\\
  9745.     term.write(text)\\\
  9746. end\\\
  9747. \\\
  9748. local function square(x1,y1,width,height,color)\\\
  9749.     local string = string.rep(\\\" \\\",width)\\\
  9750.     term.setBackgroundColor(color)\\\
  9751.     for y=y1,(y1+height-1) do\\\
  9752.         textWrite(x1,y,string)\\\
  9753.     end\\\
  9754. end\\\
  9755. \\\
  9756. function FuckingXbutton()\\\
  9757. paintutils.drawPixel(1,1,colors.red)\\\
  9758. term.setCursorPos(1,1)\\\
  9759. print (\\\"X\\\")\\\
  9760. end\\\
  9761. \\\
  9762. \\\
  9763. function YNW()\\\
  9764. term.setTextColor(colors.gray)\\\
  9765. square(1,2,51,1,colors.white)\\\
  9766. textWrite(1,2,\\\"  Please, enter your old password, then your new\\\")\\\
  9767. textWrite(7,3,\\\"To exit, leave old password as a blank\\\")\\\
  9768. textWrite(18,6,\\\"Old password\\\")\\\
  9769. square(15,8,18,1,colors.lightGray)\\\
  9770. square(15,10,18,1,colors.white)\\\
  9771. textWrite(18,10,\\\"New password\\\")\\\
  9772. square(15,12,18,1,colors.lightGray)\\\
  9773. end\\\
  9774. \\\
  9775. function pwdc()\\\
  9776. term.setCursorPos(15,8)\\\
  9777. local old = read()\\\
  9778.  local file = fs.open(\\\"system/config/pwd.cfg\\\",\\\"r\\\")\\\
  9779.  local oldacc = file.readLine()\\\
  9780.  file.close()\\\
  9781.  if old ~= oldacc then\\\
  9782.  windows.error(\\\"Password is incorrect\\\")\\\
  9783.  shell.run(\\\"system/os/apps/desktop\\\")\\\
  9784.  else\\\
  9785.  term.setCursorPos(15,12)\\\
  9786.  local new = read()\\\
  9787.    local file1 = fs.open(\\\"system/config/pwd.cfg\\\",\\\"w\\\")\\\
  9788.    file1.write(new)\\\
  9789.    file1.close()\\\
  9790.     windows.attention({\\\"Password\\\"},{\\\"Successfully changed!\\\"})\\\
  9791.     shell.run(\\\"system/os/apps/desktop\\\")\\\
  9792. end\\\
  9793. end\\\
  9794. \\\
  9795. YNW()\\\
  9796. pwdc()\",\
  9797.    path = \"/rootfs/system/os/apps/acc\",\
  9798.  },\
  9799.  {\
  9800.    text = \"-- Project LinOS Customisation (made by nikov2002)\\\
  9801. \\\
  9802. \\\
  9803. os.loadAPI(\\\"System/api/image\\\")\\\
  9804. os.loadAPI(\\\"System/api/xml\\\")\\\
  9805. os.loadAPI(\\\"system/api/windows\\\")\\\
  9806. os.loadAPI(\\\"system/api/filemanager\\\")\\\
  9807. \\\
  9808. \\\
  9809. local function textWrite(x,y,text)\\\
  9810.     term.setCursorPos(x,y)\\\
  9811.     term.write(text)\\\
  9812. end\\\
  9813. \\\
  9814. local function square(x1,y1,width,height,color)\\\
  9815.     local string = string.rep(\\\" \\\",width)\\\
  9816.     term.setBackgroundColor(color)\\\
  9817.     for y=y1,(y1+height-1) do\\\
  9818.         textWrite(x1,y,string)\\\
  9819.     end\\\
  9820. end\\\
  9821. \\\
  9822. local function setWallpaper(path)\\\
  9823.     fs.delete(\\\"system/os/wallpaper.png\\\")\\\
  9824.     fs.copy(path,\\\"system/os/wallpaper.png\\\")\\\
  9825. end\\\
  9826. \\\
  9827. function Tab()\\\
  9828. textWrite(2,1,\\\"             Customisation settings\\\")\\\
  9829. term.setBackgroundColor(colors.white)\\\
  9830. term.setTextColor(colors.gray)\\\
  9831. textWrite(2,3,\\\"Background Color:\\\")\\\
  9832. square(2,5,2,2,colors.lightBlue)\\\
  9833. square(5,5,2,2,colors.red)\\\
  9834. square(5,5,2,2,colors.red)\\\
  9835. square(8,5,2,2,colors.green)\\\
  9836. square(11,5,2,2,colors.orange)\\\
  9837. square(14,5,2,2,colors.gray)\\\
  9838. square(17,5,2,2,colors.lightGray)\\\
  9839. square(26,3,12,1,colors.white)\\\
  9840. textWrite(26,3,\\\" Wallpaper: \\\")\\\
  9841. square(27,5,7,1,colors.lightBlue)\\\
  9842. textWrite(28,5,\\\"Set it \\\")\\\
  9843. square(2,13,1,40,colors.white)\\\
  9844. textWrite(2,13,\\\"Set Computer label\\\")\\\
  9845. square(2,15,20,1,colors.lightGray)\\\
  9846. square(24,13,1,20,colors.white)\\\
  9847. textWrite(24,13,\\\"Full Wipe (can't be undone)\\\")\\\
  9848. square(26,15,5,1,colors.lightBlue)\\\
  9849. textWrite(27,15,\\\"Wipe It \\\")\\\
  9850. square(2,8,2,2,colors.brown)\\\
  9851. square(5,8,2,2,colors.yellow)\\\
  9852. square(8,8,2,2,colors.purple)\\\
  9853. square(11,8,2,2,colors.pink)\\\
  9854. square(14,8,2,2,colors.cyan)\\\
  9855. term.setBackgroundColor(colors.white)\\\
  9856. term.setTextColor(colors.lightGray)\\\
  9857. textWrite(17,8,\\\"##\\\")\\\
  9858. textWrite(17,9,\\\"##\\\")\\\
  9859. end\\\
  9860. \\\
  9861. function FuckingXbutton()\\\
  9862. paintutils.drawPixel(1,1,colors.red)\\\
  9863. term.setCursorPos(1,1)\\\
  9864. print (\\\"X\\\")\\\
  9865. end\\\
  9866. \\\
  9867. function drawWindow()\\\
  9868. square(1,1,51,19,colors.white)\\\
  9869. square(1,1,51,1,colors.gray)\\\
  9870. end\\\
  9871. \\\
  9872. function DRAWIT()\\\
  9873. drawWindow()\\\
  9874. Tab()\\\
  9875. FuckingXbutton()\\\
  9876. end\\\
  9877. \\\
  9878. DRAWIT()\\\
  9879. \\\
  9880. while true do\\\
  9881. local event, button, X, Y = os.pullEventRaw()\\\
  9882. if event == \\\"mouse_click\\\" then\\\
  9883.  if X==1 and Y==1 then\\\
  9884.  shell.run(\\\"system/os/apps/desktop\\\")\\\
  9885.  elseif X >= 2 and X <= 3 and Y >= 5 and Y <= 6 then\\\
  9886.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9887.  file.write(\\\"8\\\")\\\
  9888.  file.close()\\\
  9889.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9890.  DRAWIT()\\\
  9891.  elseif X >=5 and X <= 6 and Y >= 5 and Y <= 6 then\\\
  9892.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9893.  file.write(\\\"16384\\\")\\\
  9894.  file.close()\\\
  9895.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9896.  DRAWIT()\\\
  9897.  elseif X >=2 and X <= 3 and Y >= 8 and Y <= 9 then\\\
  9898.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9899.  file.write(\\\"4096\\\")\\\
  9900.  file.close()\\\
  9901.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9902.  DRAWIT()\\\
  9903.  elseif X >=5 and X <= 6 and Y >= 8 and Y <= 9 then\\\
  9904.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9905.  file.write(\\\"16\\\")\\\
  9906.  file.close()\\\
  9907.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9908.  DRAWIT()\\\
  9909.  elseif X >=8 and X <= 9 and Y >= 8 and Y <= 9 then\\\
  9910.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9911.  file.write(\\\"1024\\\")\\\
  9912.  file.close()\\\
  9913.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9914.  DRAWIT()\\\
  9915.  elseif X >=11 and X <= 12 and Y >= 8 and Y <= 9 then\\\
  9916.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9917.  file.write(\\\"64\\\")\\\
  9918.  file.close()\\\
  9919.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9920.  DRAWIT()\\\
  9921.  elseif X >=14 and X <= 15 and Y >= 8 and Y <= 9 then\\\
  9922.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9923.  file.write(\\\"512\\\")\\\
  9924.  file.close()\\\
  9925.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9926.  DRAWIT()\\\
  9927.  elseif X >=17 and X <= 18 and Y >= 8 and Y <= 9 then\\\
  9928.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9929.  file.write(\\\"1\\\")\\\
  9930.  file.close()\\\
  9931.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9932.  DRAWIT()\\\
  9933.  elseif X >=8 and X <= 9 and Y >= 5 and Y <= 6 then\\\
  9934.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9935.  file.write(\\\"8192\\\")\\\
  9936.  file.close()\\\
  9937.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9938.  DRAWIT()\\\
  9939.  elseif X >=11 and X <= 12 and Y >= 5 and Y <= 6 then\\\
  9940.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9941.  file.write(\\\"2\\\")\\\
  9942.  file.close()\\\
  9943.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9944.  DRAWIT()\\\
  9945.  elseif X >=14 and X <= 15 and Y >= 5 and Y <= 6 then\\\
  9946.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9947.  file.write(\\\"128\\\")\\\
  9948.  file.close()\\\
  9949.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9950.  DRAWIT()\\\
  9951.  elseif X >=17 and X <= 18 and Y >= 5 and Y <= 6 then\\\
  9952.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  9953.  file.write(\\\"256\\\")\\\
  9954.  file.close()\\\
  9955.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  9956.  DRAWIT()\\\
  9957.  elseif X >= 2 and X <= 20 and Y == 15 then\\\
  9958.  square(2,15,20,1,colors.lightGray)\\\
  9959.  term.setCursorPos(2,15)\\\
  9960.  labelocc = read()\\\
  9961.  os.setComputerLabel(labelocc)\\\
  9962.  square(2,15,20,1,colors.lightGray)\\\
  9963.  elseif X >= 26 and X <= 34 and Y == 15 then\\\
  9964.  shell.run(\\\"pastebin get b1KkmQE5 /wiper\\\")\\\
  9965.  shell.run(\\\"wiper\\\")\\\
  9966.  elseif X >= 27 and X <= 34 and Y == 5 then\\\
  9967. local pathToOpen = filemanager.open(\\\"\\\")\\\
  9968. if pathToOpen == nil then\\\
  9969. DRAWIT()\\\
  9970. elseif windows.getFileFormat(pathToOpen) ~= \\\".png\\\" then\\\
  9971. windows.attention({\\\"Can't open file\\\"},{\\\"This file format\\\",\\\"is not supported.\\\"})\\\
  9972. DRAWIT()\\\
  9973. else\\\
  9974. fs.copy(pathToOpen,\\\"system/os/wallpaper.png\\\")\\\
  9975. DRAWIT()\\\
  9976. end\\\
  9977.  end\\\
  9978. end\\\
  9979. end\",\
  9980.    path = \"/rootfs/system/os/apps/cs\",\
  9981.  },\
  9982.  {\
  9983.    text = \"-- Project LinOS (made by nikov2002) APIS and \\\"Photoshop\\\" by EliteClubSessions (Igor_Pavlov)\\\
  9984. \\\
  9985. \\\
  9986. os.loadAPI(\\\"system/api/windows\\\")\\\
  9987. os.loadAPI(\\\"system/api/image\\\")\\\
  9988. os.loadAPI(\\\"system/api/context\\\")\\\
  9989. os.loadAPI(\\\"system/api/config\\\")\\\
  9990. \\\
  9991. \\\
  9992. local standartErrorFunction = windows.error\\\
  9993. \\\
  9994. local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"r\\\")\\\
  9995. \\\
  9996. if not term.isColor() then error(\\\"This program will work only on advanced computer.\\\") end\\\
  9997. colbg = tonumber(file.readLine())\\\
  9998. colt = 32768\\\
  9999. tbc = 1\\\
  10000. term.setBackgroundColor(colbg)\\\
  10001. term.setTextColor(colt)\\\
  10002. topBar = 128\\\
  10003. \\\
  10004. local xSize, ySize = term.getSize()\\\
  10005. \\\
  10006. function appsbuddon()\\\
  10007. image.draw(1,18,\\\"/system/os/Icons/apps.png\\\")\\\
  10008. end\\\
  10009. \\\
  10010. function textWrite(x,y,text)\\\
  10011.     term.setCursorPos(x,y)\\\
  10012.     term.write(text)\\\
  10013. end\\\
  10014. \\\
  10015. function timetop()\\\
  10016. term.setBackgroundColor(topBar)\\\
  10017. term.setTextColor(tbc)\\\
  10018. term.setCursorPos(46,1)\\\
  10019. local time = textutils.formatTime(os.time(),true)\\\
  10020. term.setBackgroundColor(topBar)\\\
  10021. print(\\\" \\\",time,\\\" \\\")\\\
  10022. end\\\
  10023. \\\
  10024. function searchFromFiles()\\\
  10025. term.setCursorPos(1,1)\\\
  10026. term.setBackgroundColor(topBar)\\\
  10027. term.setTextColor(tbc)\\\
  10028. term.setCursorPos(22,1)\\\
  10029. print(\\\" Search \\\")\\\
  10030. end\\\
  10031. \\\
  10032. function titleBar()\\\
  10033.  term.setCursorPos(1,1)  \\\
  10034.  term.setBackgroundColor(topBar)\\\
  10035.  term.setTextColor(tbc)\\\
  10036.  term.setCursorPos(1,1)\\\
  10037.  print(\\\" LinOS    Settings   \\\")\\\
  10038.  timetop()\\\
  10039.  searchFromFiles()\\\
  10040. end\\\
  10041. \\\
  10042. function drawDesktop()\\\
  10043.  term.clear()\\\
  10044.  term.setBackgroundColor(colbg)\\\
  10045.  term.setTextColor(colt)\\\
  10046.     if fs.exists(\\\"system/os/wallpaper.png\\\") then\\\
  10047.         image.draw(1,1,\\\"system/os/wallpaper.png\\\")\\\
  10048.     end\\\
  10049.  titleBar()\\\
  10050.  appsbuddon()\\\
  10051. end\\\
  10052. \\\
  10053. function CM1()\\\
  10054. local contextAction1 = context.menu(10,2,{\\\"Password Management\\\"},{\\\"Customise\\\"},{\\\"Updater (BUGGY)\\\"})\\\
  10055.  if contextAction1 == \\\"Password Management\\\" then\\\
  10056.  shell.run(\\\"/system/os/apps/acc\\\")\\\
  10057.  elseif contextAction1 == \\\"Customise\\\" then\\\
  10058.  shell.run(\\\"/system/os/apps/cs\\\")\\\
  10059.  elseif contextAction1 == \\\"Updater (BUGGY)\\\" then\\\
  10060.  shell.run(\\\"/system/update/updater\\\")\\\
  10061.  else\\\
  10062.  term.setBackgroundColor(colbg)\\\
  10063.  drawDesktop()\\\
  10064.  term.setBackgroundColor(colbg)\\\
  10065.  end\\\
  10066. end\\\
  10067. \\\
  10068. function ContextMenu()\\\
  10069. local contextAction = context.menu(1,2,{\\\"Reboot\\\"},{\\\"Shutdown\\\"},{\\\"AboutCC\\\"},\\\"-\\\",{\\\"By nikov2002\\\",true})\\\
  10070.  if contextAction == \\\"Reboot\\\" then\\\
  10071.  os.reboot()\\\
  10072.  elseif contextAction == \\\"Shutdown\\\" then\\\
  10073.  os.shutdown()\\\
  10074.  elseif contextAction == \\\"AboutCC\\\" then\\\
  10075.  shell.run(\\\"/system/os/apps/about\\\")\\\
  10076.  end\\\
  10077. end\\\
  10078. \\\
  10079. function ContextMenu1()\\\
  10080. local contextAction1 = context.menu(10,2,{\\\"Not ready yet\\\",true})\\\
  10081. end\\\
  10082. \\\
  10083. drawDesktop()\\\
  10084. \\\
  10085. while true do\\\
  10086. local event, button, X, Y = os.pullEventRaw()\\\
  10087.    if event == \\\"mouse_click\\\" then\\\
  10088.      if X >=1 and X <=7 and Y==1 and button ==1 then\\\
  10089.       term.setBackgroundColor(colbg)\\\
  10090.       ContextMenu()\\\
  10091.       elseif X >=1 and X <=3 and Y >=18 and Y <=19 and button ==1 then\\\
  10092.       term.setBackgroundColor(colbg)\\\
  10093.       shell.run (\\\"system/os/apps/drawer\\\")\\\
  10094.       elseif X >=22 and X <=30 and Y==1 and button==1 then\\\
  10095.       windows.search(14,2,25,2,\\\"Search\\\")\\\
  10096.       elseif X >=10 and X <=20 and Y==1 and button==1 then\\\
  10097.       term.setBackgroundColor(colbg)\\\
  10098.       CM1()\\\
  10099.       drawDesktop()\\\
  10100.       else\\\
  10101.       term.setBackgroundColor(colbg)\\\
  10102.       drawDesktop()\\\
  10103.      end\\\
  10104.     end\\\
  10105. end\",\
  10106.    path = \"/rootfs/system/os/apps/desktop\",\
  10107.  },\
  10108.  {\
  10109.    text = \"-- Project LinOS Appdrawer (made by nikov2002)\\\
  10110. \\\
  10111. local Args = {...}\\\
  10112. os.loadAPI(\\\"system/api/windows\\\")\\\
  10113. os.loadAPI(\\\"system/api/image\\\")\\\
  10114. if not term.isColor() then error(\\\"This program will work only on advanced computer.\\\") end\\\
  10115. \\\
  10116. --[[local standartErrorFunction = error\\\
  10117. error = windows.error]]\\\
  10118. \\\
  10119. local xSize, ySize = term.getSize()\\\
  10120. local centerX = math.floor(xSize/2)\\\
  10121. local centerY = math.floor(ySize/2)\\\
  10122. local appWidth = 10\\\
  10123. local appHeight = 6\\\
  10124. \\\
  10125. local countOfAppsByX = math.floor((xSize-2)/(appWidth+2))\\\
  10126. local countOfAppsByY = math.floor((ySize-5)/(appHeight+1))\\\
  10127. local countOfAppsOnDesktop = countOfAppsByX*countOfAppsByY\\\
  10128. \\\
  10129. local countOfDesktops = nil\\\
  10130. \\\
  10131. local startDisplayAllAppsFromX = centerX - math.floor((countOfAppsByX*(appWidth+2)-2)/2) + 1\\\
  10132. local startDisplayAllAppsFromY = centerY - math.floor((countOfAppsByY*(appHeight+1)-1)/2) + 1\\\
  10133. \\\
  10134. local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"r\\\")\\\
  10135. local currentDesktop = 1\\\
  10136. local currentBackground = tonumber(file.readLine())\\\
  10137. \\\
  10138. local Obj = {}\\\
  10139. local ObjBottom = {}\\\
  10140. local ObjApp = {}\\\
  10141. \\\
  10142. local clipboardName = nil\\\
  10143. \\\
  10144. local workPath = \\\"/apps\\\"\\\
  10145. local workPathHistory = {}\\\
  10146. \\\
  10147. local function newObjApp(name,x1,y1,width,height,id,fileFormat)\\\
  10148.     ObjApp[name]={}\\\
  10149.     ObjApp[name][\\\"x1\\\"]=x1\\\
  10150.     ObjApp[name][\\\"y1\\\"]=y1\\\
  10151.     ObjApp[name][\\\"x2\\\"]=x1+width-1\\\
  10152.     ObjApp[name][\\\"y2\\\"]=y1+height-1\\\
  10153.     ObjApp[name][\\\"id\\\"]=id\\\
  10154.     ObjApp[name][\\\"fileFormat\\\"]=fileFormat\\\
  10155. end\\\
  10156. \\\
  10157. local function newObj(name,x1,y1,width,height)\\\
  10158.     Obj[name]={}\\\
  10159.     Obj[name][\\\"x1\\\"]=x1\\\
  10160.     Obj[name][\\\"y1\\\"]=y1\\\
  10161.     Obj[name][\\\"x2\\\"]=x1+width-1\\\
  10162.     Obj[name][\\\"y2\\\"]=y1+height-1\\\
  10163. end\\\
  10164. \\\
  10165. local function newObjBottom(name,x1,y1,width,height)\\\
  10166.     ObjBottom[name]={}\\\
  10167.     ObjBottom[name][\\\"x1\\\"]=x1\\\
  10168.     ObjBottom[name][\\\"y1\\\"]=y1\\\
  10169.     ObjBottom[name][\\\"x2\\\"]=x1+width-1\\\
  10170.     ObjBottom[name][\\\"y2\\\"]=y1+height-1\\\
  10171. end\\\
  10172. \\\
  10173. local function stringLimit(text,size)\\\
  10174.     if string.len(text)<=size then return text end\\\
  10175.     return string.sub(text,1,size-3)..\\\"...\\\"\\\
  10176. end\\\
  10177. \\\
  10178. local function stringLimitFromStart(text,size)\\\
  10179.     if string.len(text)<=size then return text end\\\
  10180.     return \\\"...\\\"..string.sub(text,string.len(text)-size+4,string.len(text))\\\
  10181. end\\\
  10182. \\\
  10183. local function usualText(x,y,text)\\\
  10184.     term.setCursorPos(x,y)\\\
  10185.     term.write(text)\\\
  10186. end\\\
  10187. \\\
  10188. function appsbuddon()\\\
  10189. image.draw(1,18,\\\"/system/os/Icons/apps.png\\\")\\\
  10190. end\\\
  10191. \\\
  10192. local function square(x1,y1,width,height,color)\\\
  10193.     local string = string.rep(\\\" \\\",width)\\\
  10194.     term.setBackgroundColor(color)\\\
  10195.     for y=y1,(y1+height-1) do\\\
  10196.         usualText(x1,y,string)\\\
  10197.     end\\\
  10198. end\\\
  10199. \\\
  10200. local function clearScreen(color)\\\
  10201.     term.setBackgroundColor(color)\\\
  10202.     term.clear()\\\
  10203. end\\\
  10204. \\\
  10205. local function prepareToExit()\\\
  10206.     clearScreen(colors.black)\\\
  10207.     term.setTextColor(colors.white)\\\
  10208.     term.setCursorPos(1,1)\\\
  10209. end\\\
  10210. \\\
  10211. local function programFinished()\\\
  10212.     local xCusor,yCursor = term.getCursorPos()\\\
  10213.     term.setBackgroundColor(colors.black)\\\
  10214.     term.setTextColor(colors.white)\\\
  10215.     usualText(1,yCursor+1,\\\"Press any key to quit.\\\")\\\
  10216. \\\
  10217.     while true do\\\
  10218.         local event = os.pullEvent()\\\
  10219.         if event == \\\"monitor_touch\\\" or event == \\\"mouse_click\\\" or event == \\\"key\\\" then break end\\\
  10220.     end\\\
  10221. end\\\
  10222. \\\
  10223. \\\
  10224. \\\
  10225. local function drawKonkretnoApp(x,y,name,background,id)\\\
  10226. \\\
  10227.     newObjApp(name,x,y,appWidth,appHeight,id,windows.getFileFormat(name))\\\
  10228. \\\
  10229.     windows.drawOSIcon(x+2,y,workPath,name,ObjApp[name][\\\"fileFormat\\\"],showSystemFolders)\\\
  10230. \\\
  10231.     term.setBackgroundColor(background)\\\
  10232.     if fs.isReadOnly(workPath..\\\"/\\\"..name) then\\\
  10233.         term.setTextColor(colors.red)\\\
  10234.     else\\\
  10235.         term.setTextColor(colors.black)\\\
  10236.     end\\\
  10237.     if windows.isFileHidden(name) then\\\
  10238.         term.setTextColor(colors.gray)\\\
  10239.     end\\\
  10240.     if hideFileFormat then\\\
  10241.         name = windows.hideFileFormat(name)\\\
  10242.     end\\\
  10243.     name = stringLimit(name,10)\\\
  10244.     usualText(math.floor(x+5-#name/2),y+5,name)\\\
  10245. \\\
  10246. end\\\
  10247. \\\
  10248. local function displayApps(workPath,currentDesktop,background)\\\
  10249. \\\
  10250.     ObjApp = {}\\\
  10251.     ObjBottom = {}\\\
  10252. \\\
  10253.     --clearScreen(background)\\\
  10254.     square(0,0,52,20,background)\\\
  10255. \\\
  10256.     local files = fs.list(workPath)\\\
  10257. \\\
  10258.     files = windows.reorganizeFilesAndFolders(workPath,files,showHiddenFiles,showSystemFolders)\\\
  10259. \\\
  10260.     local countOfFiles = #files\\\
  10261.     countOfDesktops = math.ceil(countOfFiles/(countOfAppsByY*countOfAppsByX))\\\
  10262. \\\
  10263.     local bottomButtonsStartX = nil\\\
  10264.     if #workPathHistory == 0 then\\\
  10265.         bottomButtonsStartX = centerX - math.floor((countOfDesktops*2+1)/2)\\\
  10266.     else\\\
  10267.         bottomButtonsStartX = centerX - math.floor((countOfDesktops*2-1)/2)\\\
  10268.     end\\\
  10269.     local bottomY = ySize-1\\\
  10270.     for i=1,countOfDesktops do\\\
  10271.         local bottomX = bottomButtonsStartX + i * 2\\\
  10272.         if currentDesktop == i then\\\
  10273.             paintutils.drawPixel(bottomX,bottomY,colors.white)\\\
  10274.         else\\\
  10275.             paintutils.drawPixel(bottomX,bottomY,colors.lightGray)\\\
  10276.         end\\\
  10277.         newObjBottom(i,bottomX,bottomY,1,1)\\\
  10278.     end\\\
  10279.     if #workPathHistory>0 then\\\
  10280.         paintutils.drawPixel(bottomButtonsStartX,bottomY,colors.white)\\\
  10281.         term.setTextColor(colors.black)\\\
  10282.         usualText(bottomButtonsStartX,bottomY,\\\"<\\\")\\\
  10283.         newObj(\\\"<\\\",bottomButtonsStartX,bottomY,1,1)\\\
  10284.     end\\\
  10285. \\\
  10286. \\\
  10287.     local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX\\\
  10288.     for y = 1,countOfAppsByY do\\\
  10289.         for x = 1,countOfAppsByX do\\\
  10290.             if files[appCounter] ~= nil then\\\
  10291.                 drawKonkretnoApp(startDisplayAllAppsFromX+x*(appWidth+2)-(appWidth+2),startDisplayAllAppsFromY+y*(appHeight+1)-(appHeight+1),files[appCounter],background,appCounter)\\\
  10292.                 appCounter = appCounter + 1\\\
  10293.             else\\\
  10294.                 break\\\
  10295.             end\\\
  10296.         end\\\
  10297.     end\\\
  10298. appsbuddon()\\\
  10299. end\\\
  10300. local function launchFile(path,fileFormat,arguments)\\\
  10301.     if fileFormat == nil then\\\
  10302.         local success,err = loadfile(path)\\\
  10303.         if success ~= nil then\\\
  10304.             prepareToExit()\\\
  10305.             if arguments == nil then\\\
  10306.                 shell.run(path)\\\
  10307.             else\\\
  10308.                 shell.run(path..\\\" \\\"..arguments)\\\
  10309.             end\\\
  10310.             programFinished()\\\
  10311.         else\\\
  10312.             windows.error(err)\\\
  10313.         end\\\
  10314.     elseif fileFormat == \\\".app\\\" then\\\
  10315.         path = path..\\\"/main\\\"\\\
  10316.         local success,err = loadfile(path)\\\
  10317.         if success ~= nil then\\\
  10318.             prepareToExit()\\\
  10319.             if arguments == nil then\\\
  10320.                 shell.run(path)\\\
  10321.             else\\\
  10322.                 shell.run(path..\\\" \\\"..arguments)\\\
  10323.             end\\\
  10324.             --programFinished()\\\
  10325.         else\\\
  10326.             windows.error(err)\\\
  10327.         end\\\
  10328.     end\\\
  10329. end\\\
  10330. \\\
  10331. \\\
  10332. local function gotoDirectory(path)\\\
  10333.     workPathHistory[#workPathHistory+1] = workPath\\\
  10334.     workPath = path\\\
  10335.     currentDesktop = 1\\\
  10336. end\\\
  10337. \\\
  10338. displayApps(workPath,currentDesktop,currentBackground)\\\
  10339. \\\
  10340. local exitFromProgram = false\\\
  10341. while true do\\\
  10342.     if exitFromProgram then break end\\\
  10343. \\\
  10344.     local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX\\\
  10345. \\\
  10346.     local event,side,x,y = os.pullEvent()\\\
  10347. \\\
  10348.     if event == \\\"monitor_touch\\\" then side = 1 end\\\
  10349.     if event == \\\"mouse_click\\\" or event == \\\"monitor_touch\\\" then\\\
  10350. \\\
  10351.         if side == 1 then\\\
  10352. \\\
  10353.             local exit1 = false\\\
  10354. \\\
  10355.             if #workPathHistory > 0 then\\\
  10356.                 if x==Obj[\\\"<\\\"][\\\"x1\\\"] and y==Obj[\\\"<\\\"][\\\"y1\\\"] and #workPathHistory > 0 then\\\
  10357. \\\
  10358.                         term.setBackgroundColor(colors.blue)\\\
  10359.                         term.setTextColor(colors.white)\\\
  10360.                         usualText(Obj[\\\"<\\\"][\\\"x1\\\"],Obj[\\\"<\\\"][\\\"y1\\\"],\\\"<\\\")\\\
  10361.                         sleep(0.2)\\\
  10362. \\\
  10363.                         workPath = workPathHistory[#workPathHistory]\\\
  10364.                         workPathHistory[#workPathHistory] = nil\\\
  10365.                         currentDesktop = 1\\\
  10366.                         displayApps(workPath,currentDesktop,currentBackground)\\\
  10367.                         exit1 = true\\\
  10368.                 end\\\
  10369.             end\\\
  10370. \\\
  10371.             for i=1,#ObjBottom do\\\
  10372.                 if exit1 then break end\\\
  10373.                 if x==ObjBottom[i][\\\"x1\\\"] and y==ObjBottom[i][\\\"y1\\\"] then\\\
  10374.                     currentDesktop = i\\\
  10375.                     displayApps(workPath,currentDesktop,currentBackground)\\\
  10376.                     exit1=true\\\
  10377.                 end\\\
  10378.             end\\\
  10379. \\\
  10380.             for key,val in pairs(ObjApp) do\\\
  10381.                 if exit1 then break end\\\
  10382.                 for i=appCounter,(appCounter+countOfAppsOnDesktop-1) do\\\
  10383.                     if exit1 then break end\\\
  10384.                     if ObjApp[key][\\\"id\\\"] == i then\\\
  10385.                         if x>=ObjApp[key][\\\"x1\\\"] and x<=ObjApp[key][\\\"x2\\\"] and y>=ObjApp[key][\\\"y1\\\"] and y<=ObjApp[key][\\\"y2\\\"] then\\\
  10386.                             square(ObjApp[key][\\\"x1\\\"],ObjApp[key][\\\"y1\\\"],appWidth,appHeight,colors.blue)\\\
  10387.                             drawKonkretnoApp(ObjApp[key][\\\"x1\\\"],ObjApp[key][\\\"y1\\\"],key,colors.blue,ObjApp[key][\\\"id\\\"])\\\
  10388.                             sleep(0.2)\\\
  10389. \\\
  10390.                             local fileFormat = ObjApp[key][\\\"fileFormat\\\"]\\\
  10391. \\\
  10392.                             if not fs.isDir(workPath..\\\"/\\\"..key) then\\\
  10393. \\\
  10394.                                 if key ~= \\\"OS\\\" and key ~= \\\"os\\\" and fileFormat == nil then\\\
  10395.                                     launchFile(workPath..\\\"/\\\"..key,fileFormat)\\\
  10396.                                 else\\\
  10397.                                     windows.attention({\\\"Can't open this\\\"},{\\\"Unknown file extension\\\"})\\\
  10398.                                 end\\\
  10399. \\\
  10400.                                 exit1 = true\\\
  10401.                                 displayApps(workPath,currentDesktop,currentBackground)\\\
  10402.                             else\\\
  10403.                                 if fileFormat == \\\".app\\\" then\\\
  10404.                                     launchFile(workPath..\\\"/\\\"..key,fileFormat)\\\
  10405.                                     displayApps(workPath,currentDesktop,currentBackground)\\\
  10406.                                 else\\\
  10407.                                gotoDirectory(workPath..\\\"/\\\"..key)\\\
  10408.                                appCounter = 1\\\
  10409.                                displayApps(workPath,currentDesktop,currentBackground) \\\
  10410.                                 end\\\
  10411. \\\
  10412.                                 exit1 = true\\\
  10413.                             end\\\
  10414.                         end\\\
  10415.                     end\\\
  10416.                 end\\\
  10417.             end\\\
  10418.         term.setCursorBlink(false)\\\
  10419. \\\
  10420.     elseif event == \\\"mouse_scroll\\\" then\\\
  10421.         if side == -1 then\\\
  10422.             currentDesktop = currentDesktop + 1\\\
  10423.             if currentDesktop > countOfDesktops then\\\
  10424.                 currentDesktop = countOfDesktops\\\
  10425.             else\\\
  10426.                 displayApps(workPath,currentDesktop,currentBackground)\\\
  10427.             end\\\
  10428. end\\\
  10429. end\\\
  10430. end\\\
  10431. if x>=1 and x<=3 and y>=18 and y<=19 then\\\
  10432. shell.run (\\\"/system/os/apps/Desktop\\\")\\\
  10433. else\\\
  10434. end\\\
  10435. end\\\
  10436. prepareToExit()\\\
  10437. --windows.tv(0)\",\
  10438.    path = \"/rootfs/system/os/apps/drawer\",\
  10439.  },\
  10440.  {\
  10441.    text = \"os.loadAPI(\\\"system/api/image\\\")\\\
  10442. os.loadAPI(\\\"system/api/windows\\\")\\\
  10443. --if fs.exists(\\\"system/config/pwd.cfg/\\\") then\\\
  10444. --shell.run(\\\"system/apps/desktop\\\")\\\
  10445. --else\\\
  10446. --\\\
  10447. --end\\\
  10448. \\\
  10449. local function textWrite(x,y,text)\\\
  10450.     term.setCursorPos(x,y)\\\
  10451.     term.write(text)\\\
  10452. end\\\
  10453. \\\
  10454. local function square(x1,y1,width,height,color)\\\
  10455.     local string = string.rep(\\\" \\\",width)\\\
  10456.     term.setBackgroundColor(color)\\\
  10457.     for y=y1,(y1+height-1) do\\\
  10458.         textWrite(x1,y,string)\\\
  10459.     end\\\
  10460. end\\\
  10461. \\\
  10462. local function clearScreen(color)\\\
  10463.     term.setBackgroundColor(color)\\\
  10464.     term.clear()\\\
  10465. end\\\
  10466. \\\
  10467. local function fadeIn(time)\\\
  10468.     clearScreen(colors.gray)\\\
  10469.     sleep(time)\\\
  10470.     clearScreen(colors.lightGray)\\\
  10471.     sleep(time)\\\
  10472.     clearScreen(colors.white)\\\
  10473.     sleep(time)\\\
  10474. end\\\
  10475. \\\
  10476. function pwd()\\\
  10477. term.clear()\\\
  10478. square(1,1,51,19,colors.white)\\\
  10479. image.draw(13,3,\\\"/system/os/hello.png\\\")\\\
  10480. sleep(1)\\\
  10481. term.setCursorPos(12,10)\\\
  10482. square(12,10,1,20,colors.white)\\\
  10483. term.setTextColor(colors.black)\\\
  10484. textWrite(5,10,\\\"Let we setup your password (type it there)\\\")\\\
  10485. square(14,12,23,1,colors.lightGray)\\\
  10486. term.setCursorPos(14,12)\\\
  10487. local newpwd = read()\\\
  10488.  local file = fs.open(\\\"system/config/pwd.cfg\\\",\\\"w\\\")\\\
  10489.  file.write(newpwd)\\\
  10490.  file.close()\\\
  10491. end\\\
  10492. \\\
  10493. \\\
  10494. function final()\\\
  10495. term.clear()\\\
  10496. square(1,1,51,19,colors.white)\\\
  10497. image.draw(13,3,\\\"/system/os/hello.png\\\")\\\
  10498. sleep(1)\\\
  10499. square(12,10,1,20,colors.white)\\\
  10500. term.setTextColor(colors.black)\\\
  10501. textWrite(12,10,\\\" Let we do few more things\\\")\\\
  10502. sleep(2)\\\
  10503. square(1,1,51,19,colors.white)\\\
  10504. textWrite(20,10,\\\"Here we go\\\")\\\
  10505. sleep(0.5)\\\
  10506. fadeIn(0.05)\\\
  10507. shell.run(\\\"/system/os/apps/desktop\\\")\\\
  10508. end\\\
  10509. \\\
  10510. \\\
  10511. function bg()\\\
  10512. term.clear()\\\
  10513. square(1,1,51,19,colors.white)\\\
  10514. image.draw(13,3,\\\"/system/os/hello.png\\\")\\\
  10515. sleep(1)\\\
  10516. term.setBackgroundColor(colors.white)\\\
  10517. term.setTextColor(colors.black)\\\
  10518. textWrite(11,10,\\\"Let we setup your background\\\")\\\
  10519. square(17,13,2,2,colors.lightBlue)\\\
  10520. square(20,13,2,2,colors.red)\\\
  10521. square(23,13,2,2,colors.green)\\\
  10522. square(26,13,2,2,colors.orange)\\\
  10523. square(29,13,2,2,colors.gray)\\\
  10524. square(32,13,2,2,colors.lightGray)\\\
  10525. square(17,16,2,2,colors.brown)\\\
  10526. square(20,16,2,2,colors.yellow)\\\
  10527. square(23,16,2,2,colors.purple)\\\
  10528. square(26,16,2,2,colors.pink)\\\
  10529. square(29,16,2,2,colors.cyan)\\\
  10530. term.setBackgroundColor(colors.white)\\\
  10531. term.setTextColor(colors.lightGray)\\\
  10532. textWrite(32,16,\\\"##\\\")\\\
  10533. textWrite(32,17,\\\"##\\\")\\\
  10534. while true do\\\
  10535. local event, button, X, Y = os.pullEventRaw()\\\
  10536. if event == \\\"mouse_click\\\" then\\\
  10537.  if X==1 and Y==1 then\\\
  10538.  shell.run(\\\"System/apps/desktop\\\")\\\
  10539.  elseif X >= 17 and X <= 18 and Y >= 13 and Y <=14  then\\\
  10540.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10541.  file.write(\\\"8\\\")\\\
  10542.  file.close()\\\
  10543.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10544.  final()\\\
  10545.  elseif X >=20 and X <= 21 and Y >= 13 and Y <= 14 then\\\
  10546.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10547.  file.write(\\\"16384\\\")\\\
  10548.  file.close()\\\
  10549.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10550.  final()\\\
  10551.  elseif X >=23 and X <= 24 and Y >= 13 and Y <= 14 then\\\
  10552.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10553.  file.write(\\\"8192\\\")\\\
  10554.  file.close()\\\
  10555.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10556.  final()\\\
  10557.  elseif X >=26 and X <= 27 and Y >= 13 and Y <= 14 then\\\
  10558.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10559.  file.write(\\\"2\\\")\\\
  10560.  file.close()\\\
  10561.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10562.  final()\\\
  10563.  elseif X >=29 and X <= 30 and Y >= 13 and Y <= 14 then\\\
  10564.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10565.  file.write(\\\"128\\\")\\\
  10566.  file.close()\\\
  10567.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10568.  final()\\\
  10569.  elseif X >=32 and X <= 33 and Y >= 13 and Y <= 14 then\\\
  10570.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10571.  file.write(\\\"256\\\")\\\
  10572.  file.close()\\\
  10573.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10574.  final()\\\
  10575.    elseif X >=17 and X <= 18 and Y >= 16 and Y <= 17 then\\\
  10576.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10577.  file.write(\\\"4096\\\")\\\
  10578.  file.close()\\\
  10579.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10580.  final()\\\
  10581.  elseif X >=20 and X <= 21 and Y >= 16 and Y <= 17 then\\\
  10582.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10583.  file.write(\\\"16\\\")\\\
  10584.  file.close()\\\
  10585.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10586.  final()\\\
  10587.  elseif X >=23 and X <= 24 and Y >= 16 and Y <= 17 then\\\
  10588.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10589.  file.write(\\\"1024\\\")\\\
  10590.  file.close()\\\
  10591.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10592.  final()\\\
  10593.  elseif X >=26 and X <= 27 and Y >= 16 and Y <= 17 then\\\
  10594.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10595.  file.write(\\\"64\\\")\\\
  10596.  file.close()\\\
  10597.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10598.  final()\\\
  10599.  elseif X >=29 and X <= 30 and Y >= 16 and Y <= 17 then\\\
  10600.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10601.  file.write(\\\"512\\\")\\\
  10602.  file.close()\\\
  10603.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10604.  final()\\\
  10605.  elseif X >=32 and X <= 33 and Y >= 16 and Y <= 17 then\\\
  10606.  local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
  10607.  file.write(\\\"1\\\")\\\
  10608.  file.close()\\\
  10609.  windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
  10610.  final()\\\
  10611.  end\\\
  10612. end\\\
  10613. end\\\
  10614. end\\\
  10615. function all()\\\
  10616. pwd()\\\
  10617. bg()\\\
  10618. end\\\
  10619. \\\
  10620. all()\",\
  10621.    path = \"/rootfs/system/os/apps/firstsetup\",\
  10622.  },\
  10623.  {\
  10624.    text = \"-- Project LinOS Bootstrap (made by nikov2002)\\\
  10625. \\\
  10626. \\\
  10627. os.loadAPI(\\\"System/api/windows\\\")\\\
  10628. os.loadAPI(\\\"System/api/image\\\")\\\
  10629. standartErrorFunction = windows.error\\\
  10630. \\\
  10631. \\\
  10632. local function textWrite(x,y,text)\\\
  10633.     term.setCursorPos(x,y)\\\
  10634.     term.write(text)\\\
  10635. end\\\
  10636. \\\
  10637. local function square(x1,y1,width,height,color)\\\
  10638.     local string = string.rep(\\\" \\\",width)\\\
  10639.     term.setBackgroundColor(color)\\\
  10640.     for y=y1,(y1+height-1) do\\\
  10641.         textWrite(x1,y,string)\\\
  10642.     end\\\
  10643. end\\\
  10644. \\\
  10645. function access()\\\
  10646. term.clear()\\\
  10647. term.setBackgroundColor(colors.white)\\\
  10648. square(1,1,51,19,colors.white)\\\
  10649. term.setTextColor(colors.black)\\\
  10650. term.setCursorPos(12,9)\\\
  10651. print(\\\"Please, enter your password\\\")\\\
  10652. square(12,11,27,1,colors.lightGray)\\\
  10653. term.setCursorPos(12,11)\\\
  10654. local pwd =  read()\\\
  10655.  local file = fs.open(\\\"system/config/pwd.cfg\\\",\\\"r\\\")\\\
  10656.  local pwdacc = file.readLine()\\\
  10657.  file.close()\\\
  10658.  if pwd ~= pwdacc then\\\
  10659.  windows.error(\\\"Your password is incorrect\\\")\\\
  10660.  access()\\\
  10661.  else\\\
  10662.  shell.run (\\\"/system/os/apps/desktop\\\")\\\
  10663. end\\\
  10664. end\\\
  10665. access()\",\
  10666.    path = \"/rootfs/system/os/apps/login\",\
  10667.  },\
  10668.  {\
  10669.    text = \" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10670. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10671. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10672. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 04 04 04 04 04 04 04 04 04 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10673. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 4f 4f 4f 4f 4f 4f 4f 4f 4f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10674. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 4fLff 4f 4f 4f 4f 4f 4f 4f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10675. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 4fLffL4fi4fn4fO4fS4f 4f 4f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10676. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 0fLff 0f 0f 0f 0f 0f 0f 0f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10677. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 0f 0f 0f 0f 0f 0f 0f 0f 0f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10678. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 04 04 04 04 04 04 04 04 04 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10679. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00I80n80s80t80a80l80l80i80n80g80:80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10680. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10681. 00 00 00 00 00 00 00 00 00 00 00 00 00 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 08 08 08 08 08 80 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10682. 00 00 00 00 00 00 00 00 00 00 00 00 00 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03:88:88 88 88 88 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10683. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10684. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10685. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10686. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10687. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\",\
  10688.    path = \"/rootfs/system/os/bootscr/111.png\",\
  10689.  },\
  10690.  {\
  10691.    text = \" 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10692. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10693. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10694. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10695. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10696. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 00 00 00 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10697. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 40 44 44 44 44 44 44 44 44 44 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10698. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 44>4f_4f 4f 4f 4f 4f 4f 44 40 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10699. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 44 4f 4f 4f 0f 0f 0f 0f 44 40 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10700. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 44 0f 0f 0f 0f 0f 0f 0f 44 40 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10701. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 44 0f 0f 0f 0f 4f 4f 4f 44 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10702. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 44 44 44 44 44>44>44>44 44 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10703. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 40 40 40 40 40 40 40 40 40 40 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10704. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 40 40 40 40 40 40 40 40 40 40 40 40 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10705. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10706. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10707. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10708. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
  10709. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\",\
  10710.    path = \"/rootfs/system/os/bootscr/boot.png\",\
  10711.  },\
  10712.  {\
  10713.    text = \" 07######### 07### 07 07 07 07### 07############ 07############ 07 07 07###\\\
  10714. 07######### 07### 07############ 07############ 07######### 07######### 07\\\
  10715. 07 07 07 07 07### 07 07 07 07### 07############ 07######### 07######### 07\\\
  10716. 07######### 07### 07############ 07############ 07######### 07######### 07\\\
  10717. 07######### 07### 07 07 07 07### 07 07 07 07### 07 07 07 07### 07 07 07###\",\
  10718.    path = \"/rootfs/system/os/hello.png\",\
  10719.  },\
  10720.  {\
  10721.    text = \".07.07.07\\\
  10722. .07.07.07\",\
  10723.    path = \"/rootfs/system/os/Icons/apps.png\",\
  10724.  },\
  10725.  {\
  10726.    text = \"###-80-80-80-80###\\\
  10727. ###-80-80-80-80###\\\
  10728. ###-80-80-80-80###\\\
  10729. ###.e0ce0fe0ge0###\",\
  10730.    path = \"/rootfs/system/os/Icons/config.png\",\
  10731.  },\
  10732.  {\
  10733.    text = \" 0f 0f 0f 0f 0f 0f\\\
  10734. 0f>4f_0f 0f 0f 0f\\\
  10735. 0f 0f 0f 0f 0f 0f\\\
  10736. 0f 0f 0f 0f 0f 0f\",\
  10737.    path = \"/rootfs/system/os/Icons/default.png\",\
  10738.  },\
  10739.  {\
  10740.    text = \" 07 07 07 07 07 07\\\
  10741. 07 5f 5f 5f 5f 07\\\
  10742. 08 f8 08 f8.e8.58\\\
  10743. 08d78i78s78k78 08\",\
  10744.    path = \"/rootfs/system/os/Icons/disk.png\",\
  10745.  },\
  10746.  {\
  10747.    text = \" 04 04############\\\
  10748. -04-04-04-04-04-04\\\
  10749. 04 04 04 04 04 04\\\
  10750. ff4of4lf4df4ef4rf4\",\
  10751.    path = \"/rootfs/system/os/Icons/folder.png\",\
  10752.  },\
  10753.  {\
  10754.    text = \" 30 3b 3b 3b 3b 30\\\
  10755. 30 0bP0bS0b 0b 30\\\
  10756. 30 fb fb fb fb 30\\\
  10757. 30.f0pf0nf0gf0 30\",\
  10758.    path = \"/rootfs/system/os/Icons/image.png\",\
  10759.  },\
  10760.  {\
  10761.    text = \" 80 80 80 80 80 80\\\
  10762. 80 80O70S70 80 80\\\
  10763. 80 80 80 80 80 80\\\
  10764. 80v80380.80080 80\",\
  10765.    path = \"/rootfs/system/os/Icons/os.png\",\
  10766.  },\
  10767.  {\
  10768.    text = \",70-70-70-70,70###\\\
  10769. |70 70 70 00|70###\\\
  10770. z07i07p07 70|70###\\\
  10771. |70_70_70_70|70###\",\
  10772.    path = \"/rootfs/system/os/Icons/zip.png\",\
  10773.  },\
  10774.  {\
  10775.    text = \"-- Project LinOS Updater (made by nikov2002)\\\
  10776. \\\
  10777. os.loadAPI(\\\"System/api/filemanager\\\")\\\
  10778. os.loadAPI(\\\"system/api/zip\\\")\\\
  10779. os.loadAPI(\\\"System/api/image\\\")\\\
  10780. os.loadAPI(\\\"system/api/windows\\\")\\\
  10781. function bs()\\\
  10782. image.draw(1,1,\\\"/system/os/bootscr/boot.png\\\")\\\
  10783. term.setCursorPos(13,6)\\\
  10784. term.setTextColor(colors.red)\\\
  10785. term.setCursorPos(14,6)\\\
  10786. print(\\\"Downloading update.zip...\\\")\\\
  10787. \\\
  10788. shell.run(\\\"pastebin get isBCrzsx /temp/update.zip\\\")\\\
  10789. sleep(1)\\\
  10790. end\\\
  10791. \\\
  10792. function fileopen()\\\
  10793. local yyy = windows.select({\\\"Updater\\\"},{\\\"Proceed?\\\"},{\\\"No\\\",colors.lightGray,colors.black},{\\\"Yes\\\",colors.lightBlue,colors.black})\\\
  10794. if yyy == \\\"Yes\\\" then\\\
  10795. image.draw(1,1,\\\"/system/os/bootscr/boot.png\\\")\\\
  10796. term.setTextColor(colors.red)\\\
  10797. term.setCursorPos(20,6)\\\
  10798. print(\\\"  Updating\\\")\\\
  10799. sleep(1)\\\
  10800. zip.unarchive(\\\"/temp/update.zip\\\",\\\"/temp\\\")\\\
  10801. fs.delete(\\\"/system/os\\\")\\\
  10802. fs.delete(\\\"/startup\\\")\\\
  10803. fs.move(\\\"/temp/rootfs/system/os\\\",\\\"/system/os\\\")\\\
  10804. fs.move(\\\"/temp/rootfs/startup\\\",\\\"/startup\\\")\\\
  10805. os.reboot()\\\
  10806. else\\\
  10807. shell.run(\\\"/system/os/apps/desktop\\\")\\\
  10808. end\\\
  10809. end\\\
  10810. \\\
  10811. function drawall()\\\
  10812. bs()\\\
  10813. fileopen()\\\
  10814. end\\\
  10815. \\\
  10816. drawall()\",\
  10817.    path = \"/rootfs/system/update/updater\",\
  10818.  },\
  10819. }",
  10820.     image = "function draw(startX,startY,image)\
  10821.     local Colors = {\
  10822.         [\"0\"] = 1,\
  10823.         [\"1\"] = 2,\
  10824.         [\"2\"] = 4,\
  10825.         [\"3\"] = 8,\
  10826.         [\"4\"] = 16,\
  10827.         [\"5\"] = 32,\
  10828.         [\"6\"] = 64,\
  10829.         [\"7\"] = 128,\
  10830.         [\"8\"] = 256,\
  10831.         [\"9\"] = 512,\
  10832.         [\"a\"] = 1024,\
  10833.         [\"b\"] = 2048,\
  10834.         [\"c\"] = 4096,\
  10835.         [\"d\"] = 8192,\
  10836.         [\"e\"] = 16384,\
  10837.         [\"f\"] = 32768\
  10838.     }\
  10839.     local Pixels = {}\
  10840. \
  10841.     local function convert(mode,color)\
  10842.         if mode == \"from cc\" then\
  10843.             for key,value in pairs(Colors) do\
  10844.                 if color == value then\
  10845.                     return key\
  10846.                 end\
  10847.             end\
  10848.         else\
  10849.             if color == \"#\" then\
  10850.                 return \"0\"\
  10851.             else\
  10852.                 return Colors[color]\
  10853.             end\
  10854.         end\
  10855.     end\
  10856. \
  10857.     local function load(path)\
  10858.         local file = fs.open(path,\"r\")\
  10859.         local lineCounter = 1\
  10860.         while true do\
  10861.             local line = file.readLine()\
  10862.             Pixels[lineCounter]={}\
  10863.             if line ~= nil then\
  10864.                 for i=1,#line,3 do\
  10865.                     Pixels[lineCounter][(i+2)/3]={}\
  10866.                     Pixels[lineCounter][(i+2)/3][\"symbol\"] = string.sub(line,i,i)\
  10867.                     Pixels[lineCounter][(i+2)/3][\"textColor\"] = convert(\"to cc\",string.sub(line,i+1,i+1))\
  10868.                     Pixels[lineCounter][(i+2)/3][\"backColor\"] = convert(\"to cc\",string.sub(line,i+2,i+2))\
  10869.                 end\
  10870.                 lineCounter = lineCounter + 1\
  10871.             else\
  10872.                 break\
  10873.             end\
  10874.         end\
  10875.         file.close()\
  10876.     end\
  10877. \
  10878.     load(image)\
  10879. \
  10880.     for y=1,#Pixels do\
  10881.         for x=1,#Pixels[y] do\
  10882.             if Pixels[y][x][\"symbol\"] ~= \"#\" then\
  10883.                 term.setTextColor(Pixels[y][x][\"textColor\"])\
  10884.                 term.setBackgroundColor(Pixels[y][x][\"backColor\"])\
  10885.                 term.setCursorPos(startX+x-1,startY+y-1)\
  10886.                 term.write(Pixels[y][x][\"symbol\"])\
  10887.             end\
  10888.         end\
  10889.     end\
  10890. \
  10891. end",
  10892.     zip = "function archive(chto,vochto)\
  10893.     local Massiv2 = {}\
  10894.     local function FileList(path)\
  10895.         local Massiv = fs.list(path)\
  10896.         if #Massiv==0 then\
  10897.             local Massiv2Id = #Massiv2 + 1\
  10898.             Massiv2[Massiv2Id] = {}\
  10899.             Massiv2[Massiv2Id][\"path\"] = path\
  10900.             Massiv2[Massiv2Id][\"text\"] = \"@empty@empty\"\
  10901.         else\
  10902.             for i=1,#Massiv do\
  10903.                 if fs.isDir(path..\"/\"..Massiv[i]) and Massiv[i] ~= \"/rom\" and Massiv[i] ~= \"rom\" then\
  10904.                     FileList(path..\"/\"..Massiv[i])\
  10905.                 elseif not fs.isDir(path..\"/\"..Massiv[i]) and Massiv[i] ~= \"/rom\" and Massiv[i] ~= \"rom\" then\
  10906.                     local Massiv2Id = #Massiv2 + 1\
  10907.                     Massiv2[Massiv2Id] = {}\
  10908.                     Massiv2[Massiv2Id][\"path\"] = path..\"/\"..Massiv[i]\
  10909.                     local file = fs.open(path..\"/\"..Massiv[i],\"r\")\
  10910.                     Massiv2[Massiv2Id][\"text\"] = file.readAll()\
  10911.                     file.close()\
  10912.                 end\
  10913.             end\
  10914.         end\
  10915.     end\
  10916.     FileList(chto)\
  10917.     file=fs.open(vochto..\".zip\",\"w\")\
  10918.     file.write(textutils.serialise(Massiv2))\
  10919.     file.close()\
  10920.     return Massiv2\
  10921. end\
  10922. \
  10923. function unarchive(chto,kuda)\
  10924.     local file = fs.open(chto,\"r\")\
  10925.     Massiv = textutils.unserialise(file.readAll())\
  10926.     file.close()\
  10927.     for i=1,#Massiv do\
  10928.         if Massiv[i][\"text\"] == \"@empty@empty\" then\
  10929.             fs.makeDir(kuda..\"/\"..Massiv[i][\"path\"])\
  10930.         else\
  10931.             local file = fs.open(kuda..\"/\"..Massiv[i][\"path\"],\"w\")\
  10932.             file.write(Massiv[i][\"text\"])\
  10933.             file.close()\
  10934.         end\
  10935.     end\
  10936. end",
  10937.     [ "111.png" ] = " 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10938. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10939. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10940. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 04 04 04 04 04 04 04 04 04 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10941. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 4f 4f 4f 4f 4f 4f 4f 4f 4f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10942. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 4fLff 4f 4f 4f 4f 4f 4f 4f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10943. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 4fLffL4fi4fn4fO4fS4f 4f 4f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10944. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 0fLff 0f 0f 0f 0f 0f 0f 0f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10945. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 0f 0f 0f 0f 0f 0f 0f 0f 0f 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10946. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 04 04 04 04 04 04 04 04 04 04 04 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10947. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00I80n80s80t80a80l80l80i80n80g80:80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10948. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10949. 00 00 00 00 00 00 00 00 00 00 00 00 00 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 88 80 00 00 00 00 00 00 00 00 00 00 00 00\
  10950. 00 00 00 00 00 00 00 00 00 00 00 00 00 88 88 88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88:88 88 88 88 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10951. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10952. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10953. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10954. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
  10955. 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 80 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00",
  10956.   },
  10957.   startup = "os.loadAPI(\"instfiles/zip\")\
  10958. os.loadAPI(\"instfiles/image\")\
  10959. image.draw(1,1,\"instfiles/111.png\")\
  10960. zip.unarchive(\"instfiles/rootfs.zip\",\"/temp\")\
  10961. paintutils.drawPixel(14, 13, colors.lightBlue)\
  10962. paintutils.drawPixel(14, 14, colors.lightBlue)\
  10963. paintutils.drawPixel(15, 13, colors.lightBlue)\
  10964. paintutils.drawPixel(15, 14, colors.lightBlue)\
  10965. paintutils.drawPixel(16, 13, colors.lightBlue)\
  10966. paintutils.drawPixel(16, 14, colors.lightBlue)\
  10967. paintutils.drawPixel(17, 13, colors.lightBlue)\
  10968. paintutils.drawPixel(17, 14, colors.lightBlue)\
  10969. sleep(0.2)\
  10970. paintutils.drawPixel(18, 13, colors.lightBlue)\
  10971. paintutils.drawPixel(18, 14, colors.lightBlue)\
  10972. paintutils.drawPixel(19, 13, colors.lightBlue)\
  10973. paintutils.drawPixel(19, 14, colors.lightBlue)\
  10974. paintutils.drawPixel(20, 13, colors.lightBlue)\
  10975. paintutils.drawPixel(20, 14, colors.lightBlue)\
  10976. paintutils.drawPixel(21, 13, colors.lightBlue)\
  10977. paintutils.drawPixel(21, 14, colors.lightBlue)\
  10978. paintutils.drawPixel(22, 13, colors.lightBlue)\
  10979. paintutils.drawPixel(22, 14, colors.lightBlue)\
  10980. paintutils.drawPixel(23, 13, colors.lightBlue)\
  10981. paintutils.drawPixel(23, 14, colors.lightBlue)\
  10982. paintutils.drawPixel(24, 13, colors.lightBlue)\
  10983. paintutils.drawPixel(24, 14, colors.lightBlue)\
  10984. sleep(1.5)\
  10985. paintutils.drawPixel(25, 13, colors.lightBlue)\
  10986. paintutils.drawPixel(25, 14, colors.lightBlue)\
  10987. paintutils.drawPixel(26, 13, colors.lightBlue)\
  10988. paintutils.drawPixel(26, 14, colors.lightBlue)\
  10989. paintutils.drawPixel(27, 13, colors.lightBlue)\
  10990. paintutils.drawPixel(27, 14, colors.lightBlue)\
  10991. paintutils.drawPixel(28, 13, colors.lightBlue)\
  10992. paintutils.drawPixel(28, 14, colors.lightBlue)\
  10993. paintutils.drawPixel(29, 13, colors.lightBlue)\
  10994. paintutils.drawPixel(29, 14, colors.lightBlue)\
  10995. fs.copy(\"/temp/rootfs/system\",\"/system\")\
  10996. fs.copy(\"/temp/rootfs/apps\",\"/apps\")\
  10997. fs.copy(\"/temp/rootfs/startup\",\"/startup\")\
  10998. paintutils.drawPixel(30, 13, colors.lightBlue)\
  10999. paintutils.drawPixel(30, 14, colors.lightBlue)\
  11000. paintutils.drawPixel(31, 13, colors.lightBlue)\
  11001. paintutils.drawPixel(31, 14, colors.lightBlue)\
  11002. paintutils.drawPixel(32, 13, colors.lightBlue)\
  11003. paintutils.drawPixel(32, 14, colors.lightBlue)\
  11004. paintutils.drawPixel(33, 13, colors.lightBlue)\
  11005. paintutils.drawPixel(33, 14, colors.lightBlue)\
  11006. term.setBackgroundColor(colors.white)\
  11007. term.setTextColor(colors.lightGray)\
  11008. term.clear()\
  11009. term.setCursorPos(14,13)\
  11010. print(\"Rebooting your system\")\
  11011. os.reboot()",
  11012. }
  11013.  
  11014. local function run(tArgs)
  11015.  
  11016.   local fnFile, err = loadstring(files['startup'], 'startup')
  11017.   if err then
  11018.     error(err)
  11019.   end
  11020.  
  11021.   local function split(str, pat)
  11022.      local t = {}
  11023.      local fpat = "(.-)" .. pat
  11024.      local last_end = 1
  11025.      local s, e, cap = str:find(fpat, 1)
  11026.      while s do
  11027.         if s ~= 1 or cap ~= "" then
  11028.      table.insert(t,cap)
  11029.         end
  11030.         last_end = e+1
  11031.         s, e, cap = str:find(fpat, last_end)
  11032.      end
  11033.      if last_end <= #str then
  11034.         cap = str:sub(last_end)
  11035.         table.insert(t, cap)
  11036.      end
  11037.      return t
  11038.   end
  11039.  
  11040.   local function resolveTreeForPath(path, single)
  11041.     local _files = files
  11042.     local parts = split(path, '/')
  11043.     if parts then
  11044.       for i, v in ipairs(parts) do
  11045.         if #v > 0 then
  11046.           if _files[v] then
  11047.             _files = _files[v]
  11048.           else
  11049.             _files = nil
  11050.             break
  11051.           end
  11052.         end
  11053.       end
  11054.     elseif #path > 0 and path ~= '/' then
  11055.       _files = _files[path]
  11056.     end
  11057.     if not single or type(_files) == 'string' then
  11058.       return _files
  11059.     end
  11060.   end
  11061.  
  11062.   local oldFs = fs
  11063.   local env
  11064.   env = {
  11065.     fs = {
  11066.       list = function(path)
  11067.               local list = {}
  11068.               if fs.exists(path) then
  11069.             list = fs.list(path)
  11070.               end
  11071.         for k, v in pairs(resolveTreeForPath(path)) do
  11072.           if not fs.exists(path .. '/' ..k) then
  11073.             table.insert(list, k)
  11074.           end
  11075.         end
  11076.         return list
  11077.       end,
  11078.  
  11079.       exists = function(path)
  11080.         if fs.exists(path) then
  11081.           return true
  11082.         elseif resolveTreeForPath(path) then
  11083.           return true
  11084.         else
  11085.           return false
  11086.         end
  11087.       end,
  11088.  
  11089.       isDir = function(path)
  11090.         if fs.isDir(path) then
  11091.           return true
  11092.         else
  11093.           local tree = resolveTreeForPath(path)
  11094.           if tree and type(tree) == 'table' then
  11095.             return true
  11096.           else
  11097.             return false
  11098.           end
  11099.         end
  11100.       end,
  11101.  
  11102.       isReadOnly = function(path)
  11103.         if not fs.isReadOnly(path) then
  11104.           return false
  11105.         else
  11106.           return true
  11107.         end
  11108.       end,
  11109.  
  11110.       getName = fs.getName,
  11111.  
  11112.       getSize = fs.getSize,
  11113.  
  11114.       getFreespace = fs.getFreespace,
  11115.  
  11116.       makeDir = fs.makeDir,
  11117.  
  11118.       move = fs.move,
  11119.  
  11120.       copy = fs.copy,
  11121.  
  11122.       delete = fs.delete,
  11123.  
  11124.       combine = fs.combine,
  11125.  
  11126.       open = function(path, mode)
  11127.         if fs.exists(path) then
  11128.           return fs.open(path, mode)
  11129.         elseif type(resolveTreeForPath(path)) == 'string' then
  11130.           local handle = {close = function()end}
  11131.           if mode == 'r' then
  11132.             local content = resolveTreeForPath(path)
  11133.             handle.readAll = function()
  11134.               return content
  11135.             end
  11136.  
  11137.             local line = 1
  11138.             local lines = split(content, '\n')
  11139.             handle.readLine = function()
  11140.               if line > #lines then
  11141.                 return nil
  11142.               else
  11143.                 return lines[line]
  11144.               end
  11145.               line = line + 1
  11146.             end
  11147.                       return handle
  11148.           else
  11149.             error('Cannot write to read-only file (compilr archived).')
  11150.           end
  11151.         else
  11152.           return fs.open(path, mode)
  11153.         end
  11154.       end
  11155.     },
  11156.  
  11157.     io = {
  11158.       input = io.input,
  11159.       output = io.output,
  11160.       type = io.type,
  11161.       close = io.close,
  11162.       write = io.write,
  11163.       flush = io.flush,
  11164.       lines = io.lines,
  11165.       read = io.read,
  11166.       open = function(path, mode)
  11167.         if fs.exists(path) then
  11168.           return io.open(path, mode)
  11169.         elseif type(resolveTreeForPath(path)) == 'string' then
  11170.           local content = resolveTreeForPath(path)
  11171.           local f = fs.open(path, 'w')
  11172.           f.write(content)
  11173.           f.close()
  11174.           if mode == 'r' then
  11175.             return io.open(path, mode)
  11176.           else
  11177.             error('Cannot write to read-only file (compilr archived).')
  11178.           end
  11179.         else
  11180.           return io.open(path, mode)
  11181.         end
  11182.       end
  11183.     },
  11184.  
  11185.     loadfile = function( _sFile )
  11186.         local file = env.fs.open( _sFile, "r" )
  11187.         if file then
  11188.             local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
  11189.             file.close()
  11190.             return func, err
  11191.         end
  11192.         return nil, "File not found: ".._sFile
  11193.     end,
  11194.  
  11195.     dofile = function( _sFile )
  11196.         local fnFile, e = env.loadfile( _sFile )
  11197.         if fnFile then
  11198.             setfenv( fnFile, getfenv(2) )
  11199.             return fnFile()
  11200.         else
  11201.             error( e, 2 )
  11202.         end
  11203.     end
  11204.   }
  11205.  
  11206.   setmetatable( env, { __index = _G } )
  11207.  
  11208.   local tAPIsLoading = {}
  11209.   env.os.loadAPI = function( _sPath )
  11210.       local sName = fs.getName( _sPath )
  11211.       if tAPIsLoading[sName] == true then
  11212.           printError( "API "..sName.." is already being loaded" )
  11213.           return false
  11214.       end
  11215.       tAPIsLoading[sName] = true
  11216.          
  11217.       local tEnv = {}
  11218.       setmetatable( tEnv, { __index = env } )
  11219.       local fnAPI, err = env.loadfile( _sPath )
  11220.       if fnAPI then
  11221.           setfenv( fnAPI, tEnv )
  11222.           fnAPI()
  11223.       else
  11224.           printError( err )
  11225.           tAPIsLoading[sName] = nil
  11226.           return false
  11227.       end
  11228.      
  11229.       local tAPI = {}
  11230.       for k,v in pairs( tEnv ) do
  11231.           tAPI[k] =  v
  11232.       end
  11233.      
  11234.       env[sName] = tAPI    
  11235.       tAPIsLoading[sName] = nil
  11236.       return true
  11237.   end
  11238.  
  11239.   env.shell = shell
  11240.  
  11241.   setfenv( fnFile, env )
  11242.   fnFile(unpack(tArgs))
  11243. end
  11244.  
  11245. local function extract()
  11246.     local function node(path, tree)
  11247.         if type(tree) == 'table' then
  11248.             fs.makeDir(path)
  11249.             for k, v in pairs(tree) do
  11250.                 node(path .. '/' .. k, v)
  11251.             end
  11252.         else
  11253.             local f = fs.open(path, 'w')
  11254.             if f then
  11255.                 f.write(tree)
  11256.                 f.close()
  11257.             end
  11258.         end
  11259.     end
  11260.     node('', files)
  11261. end
  11262. extract()
  11263. fs.move("startup","installer")
  11264. shell.run("installer")
Add Comment
Please, Sign In to add comment