Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Hideously Smashed Together by Compilr, a Hideous Smash-Stuff-Togetherer, (c) 2014 oeed --
- -- This file REALLLLLLLY isn't suitable to be used for anything other than being executed --
- -- To extract all the files, run: "<filename> --extract" in the Shell --
- local files = {
- instfiles = {
- [ "rootfs.zip" ] = "{\
- {\
- text = \"os.loadAPI(\\\"system/api/windows\\\")\\\
- \\\
- --ПАРОЛЬ\\\
- local password = \\\"12345\\\"\\\
- \\\
- --СКОЛЬКО БУДЕТ ОТКРЫТА ДВЕРЬ\\\
- local doorOpenTime = 5\\\
- \\\
- --СКОЛЬКО БУДЕТ НАЖАТА КНОПКА\\\
- local buttonPressTime = 0.2\\\
- \\\
- --ПЕРЕМЕННАЯ ТАЙМЕРА\\\
- local changePasswordTimer = nil\\\
- \\\
- --РЕЖпМ РАБОТЫ ДпСПЛЕЯ\\\
- local mode = \\\"default\\\"\\\
- \\\
- --СКРЫВАТЬ Лп ВВОДпМЫЙ ПАРОЛЬ\\\
- local hidePassword = \\\"false\\\"\\\
- \\\
- --ОТСЮДА пЗЛУЧАТЬ СпГНАЛ РЕДА, ЕСЛп ПАРОЛЬ ВЕРЕН\\\
- local redstoneSide = \\\"left\\\"\\\
- --А ОТСЮДА, ЕСЛп НЕ ВЕРЕН\\\
- local redstoneSideOnWrongPassword = \\\"right\\\"\\\
- \\\
- --КНОПОЧКп\\\
- local buttons = {\\\
- {\\\"1\\\",\\\"2\\\",\\\"3\\\"},\\\
- {\\\"4\\\",\\\"5\\\",\\\"6\\\"},\\\
- {\\\"7\\\",\\\"8\\\",\\\"9\\\"},\\\
- {\\\"C\\\",\\\"0\\\",\\\"#\\\"},\\\
- }\\\
- \\\
- --МАССпВ ОБЪЕКТОВ\\\
- local Obj = {}\\\
- \\\
- --МАССпВ СпМВОЛОВ, ВВЕДЕННЫХ С ПОМОЩЬЮ КНОПОК\\\
- local inputCode = {}\\\
- \\\
- --ПОЛУЧЕНпЕ РАЗМЕРА МОНпТОРА\\\
- local xSize, ySize = term.getSize()\\\
- \\\
- --ПОпСК ПЕРпФЕРпп\\\
- local function findPeripheral(whatToFind)\\\
- local PeriList = peripheral.getNames()\\\
- for i=1,#PeriList do\\\
- if peripheral.getType(PeriList[i]) == whatToFind then\\\
- return PeriList[i]\\\
- end\\\
- end\\\
- end\\\
- \\\
- --УНпВЕРСАЛЬНАЯ ФУНКЦпЯ ДЛЯ ОТОБРАЖЕНпЯ ТЕКСТА ПО ЦЕНТРУ ЭКРАНА\\\
- local function centerText(how,coord,text,textColor,backColor)\\\
- term.setTextColor(textColor)\\\
- term.setBackgroundColor(backColor)\\\
- if how == \\\"xy\\\" then\\\
- term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2))\\\
- elseif how == \\\"x\\\" then\\\
- term.setCursorPos(math.floor(xSize/2-#text/2),coord)\\\
- elseif how == \\\"y\\\" then\\\
- term.setCursorPos(coord,math.floor(ySize/2))\\\
- end\\\
- term.write(text)\\\
- end\\\
- \\\
- --ЧТЕНпЕ КОНФпГА\\\
- function configRead(pathToConfig,whatToRead)\\\
- if not fs.exists(pathToConfig) then error(\\\"No such file\\\") end\\\
- local file = fs.open(pathToConfig,\\\"r\\\")\\\
- while true do\\\
- local line = file.readLine()\\\
- if line ~= nil then \\\
- local key, value = string.match(line,\\\"(.*)=(.*)\\\")\\\
- if value ~= nil and key == whatToRead then\\\
- file.close()\\\
- return value\\\
- end\\\
- else\\\
- file.close()\\\
- break\\\
- end\\\
- end\\\
- end\\\
- \\\
- --ЗАПпСЬ В КОНФпГ\\\
- local function configWrite(pathToConfig,key,value)\\\
- if not fs.exists(pathToConfig) then\\\
- local file = fs.open(pathToConfig,\\\"w\\\")\\\
- file.close()\\\
- end\\\
- \\\
- local file = fs.open(pathToConfig,\\\"r\\\")\\\
- local Massiv = {}\\\
- \\\
- local lineCounter = 1\\\
- while true do\\\
- local line = file.readLine()\\\
- if line ~= nil then \\\
- Massiv[lineCounter] = line\\\
- else\\\
- file.close()\\\
- break\\\
- end\\\
- lineCounter = lineCounter + 1\\\
- end\\\
- \\\
- local success = false\\\
- for i=1,#Massiv do\\\
- local key1, value1 = string.match(Massiv[i],\\\"(.*)=(.*)\\\")\\\
- if value1 ~= nil and key1 == key then\\\
- Massiv[i] = key..\\\"=\\\"..value\\\
- success = true\\\
- end\\\
- end\\\
- \\\
- if success == false then Massiv[#Massiv+1] = key..\\\"=\\\"..value end\\\
- \\\
- local file = fs.open(pathToConfig,\\\"w\\\")\\\
- for i=1,#Massiv do\\\
- file.writeLine(Massiv[i])\\\
- end\\\
- file.close()\\\
- end\\\
- \\\
- --ОБЪЕКТЫ\\\
- local function newObj(name,x,y)\\\
- Obj[name]={}\\\
- Obj[name][\\\"x\\\"]=x\\\
- Obj[name][\\\"y\\\"]=y\\\
- end\\\
- \\\
- --ПРОСТАЯ ЗАЛпВКА ЭКРАНА ЦВЕТОМ\\\
- local function clearScreen(color)\\\
- term.setBackgroundColor(color)\\\
- term.clear()\\\
- end\\\
- \\\
- --ПРОСТОЙ ТЕКСТ\\\
- local function usualText(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- --ОТРпСОВКА ВЕРХНЕЙ ШТУЧКп\\\
- local function drawTab(textColor,backColor)\\\
- term.setBackgroundColor(backColor)\\\
- term.setTextColor(textColor)\\\
- term.setCursorPos(2,1)\\\
- term.clearLine()\\\
- term.write(\\\"-----\\\")\\\
- \\\
- for i=1,#inputCode do\\\
- if hidePassword == \\\"true\\\" then\\\
- usualText(i+1,1,\\\"*\\\")\\\
- else\\\
- usualText(i+1,1,inputCode[i])\\\
- end\\\
- end\\\
- end\\\
- \\\
- --ОТРпСОВКА КОНКРЕТНОЙ КНОПКп\\\
- local function drawButton(name,textColor,backColor)\\\
- term.setBackgroundColor(backColor)\\\
- term.setTextColor(textColor)\\\
- usualText(Obj[name][\\\"x\\\"],Obj[name][\\\"y\\\"],name)\\\
- end\\\
- \\\
- \\\
- --ОТРпСОВКА ВСЕГО пНТЕРФЕЙСА\\\
- local function gui()\\\
- --ОЧпСТКА ЭКРАНА\\\
- term.setCursorBlink(false)\\\
- clearScreen(colors.white)\\\
- term.setTextColor(colors.black)\\\
- \\\
- --ОТРпСОВКА КНОПОЧЕК\\\
- for j=1,#buttons do\\\
- for i=1,#buttons[j] do\\\
- local xPos = i*2\\\
- local yPos = 1+j\\\
- usualText(xPos,yPos,buttons[j][i])\\\
- newObj(buttons[j][i],xPos,yPos)\\\
- end\\\
- end\\\
- \\\
- --ОТРпСОВКА ВЕРХНЕЙ ШНЯГп\\\
- drawTab(colors.white,colors.black)\\\
- end\\\
- \\\
- ------------------------------CТАРТ ПРОГРАММЫ------------------------------------\\\
- \\\
- if not term.isColor() then\\\
- error(\\\"This program requires an advanced computer.\\\")\\\
- end\\\
- \\\
- --РпСУЕМ В КОМПЕ ХУЙНЮ\\\
- clearScreen(colors.white)\\\
- centerText(\\\"xy\\\",0,\\\"Program started.\\\",colors.lightGray,colors.white)\\\
- \\\
- --ПОДКЛЮЧЕНпЕ МОНпТОРА\\\
- local m = findPeripheral(\\\"monitor\\\")\\\
- if m ~= nil then\\\
- m = peripheral.wrap(m)\\\
- if not m.isColor() then\\\
- windows.error(\\\"This program works only with advanced monitor.\\\")\\\
- do return end\\\
- end\\\
- m.setTextScale(1)\\\
- term.redirect(m)\\\
- else\\\
- windows.error(\\\"This program requires advanced external monitor.\\\")\\\
- do return end\\\
- end\\\
- \\\
- --ЧТЕНпЕ КОНФпГА\\\
- if fs.exists(\\\"system/config/codedoor.cfg\\\") then\\\
- password = configRead(\\\"system/config/codedoor.cfg\\\",\\\"password\\\")\\\
- redstoneSide = configRead(\\\"system/config/codedoor.cfg\\\",\\\"redstone side\\\")\\\
- redstoneSideOnWrongPassword = configRead(\\\"system/config/codedoor.cfg\\\",\\\"redstone side on wrong password\\\")\\\
- doorOpenTime = configRead(\\\"system/config/codedoor.cfg\\\",\\\"door open time\\\")\\\
- hidePassword = configRead(\\\"system/config/codedoor.cfg\\\",\\\"hide password\\\")\\\
- else\\\
- configWrite(\\\"system/config/codedoor.cfg\\\",\\\"password\\\",password)\\\
- configWrite(\\\"system/config/codedoor.cfg\\\",\\\"redstone side\\\",redstoneSide)\\\
- configWrite(\\\"system/config/codedoor.cfg\\\",\\\"redstone side on wrong password\\\",redstoneSideOnWrongPassword)\\\
- configWrite(\\\"system/config/codedoor.cfg\\\",\\\"door open time\\\",doorOpenTime)\\\
- configWrite(\\\"system/config/codedoor.cfg\\\",\\\"hide password\\\",hidePassword)\\\
- end\\\
- \\\
- --РпСУЕМ ВСЕ\\\
- gui()\\\
- \\\
- --АНАЛпЗ КАСАНпЙ ЭКРАНА\\\
- while true do\\\
- --ЗАКРЫВАЕМ ДВЕРЬ НА ВСЯКпЙ ПОЖАРНЫЙ\\\
- rs.setOutput(redstoneSide,false)\\\
- rs.setOutput(redstoneSideOnWrongPassword,false)\\\
- \\\
- local event,side,x,y = os.pullEvent()\\\
- if event == \\\"monitor_touch\\\" then\\\
- --ПЕРЕБОР ВСЕХ ЭЛЕМЕНТОВ МАССпВА ОБЪЕКТОВ\\\
- for key,val in pairs(Obj) do\\\
- --ПРОВЕРКА СОВПАДЕНпЯ КООРДпНАТ КАСАНпЯ п КООРДпНАТ ОБЪЕКТОВ\\\
- if x==Obj[key][\\\"x\\\"] and y==Obj[key][\\\"y\\\"] then\\\
- --РпСУЕМ НАЖАТУЮ КНОПОЧКУ\\\
- drawButton(key,colors.white,colors.green)\\\
- sleep(buttonPressTime)\\\
- drawButton(key,colors.black,colors.white)\\\
- \\\
- --ПРОВЕРКА, ЧТО ЗА КЛАВпША НАЖАТА - ЦпФРА пЛп СпСТЕМНАЯ КЛАВпША\\\
- if key == \\\"C\\\" then\\\
- inputCode = {}\\\
- if mode == \\\"edit\\\" then\\\
- drawTab(colors.white,colors.orange)\\\
- else\\\
- drawTab(colors.white,colors.black)\\\
- end\\\
- \\\
- elseif key == \\\"#\\\" then\\\
- --СОВМЕЩЕНпЕ ВСЕХ ЭЛЕМЕНТОВ МАССпВА ВВОДА В ОДНУ СТРОКУ\\\
- local inputPass = \\\"\\\"\\\
- for i=1,#inputCode do\\\
- inputPass = inputPass..inputCode[i]\\\
- end\\\
- \\\
- --ПРОВЕРКА РЕЖпМА\\\
- if mode == \\\"edit\\\" then\\\
- --СМЕНА ПАРОЛЯ\\\
- password = inputPass\\\
- configWrite(\\\"system/config/codedoor.cfg\\\",\\\"password\\\",password)\\\
- inputCode = {}\\\
- term.setCursorPos(3,1)\\\
- term.setBackgroundColor(colors.orange)\\\
- term.clearLine()\\\
- term.setTextColor(colors.white)\\\
- term.write(\\\"Ok!\\\")\\\
- \\\
- sleep(2)\\\
- \\\
- drawTab(colors.white,colors.black)\\\
- mode = \\\"default\\\"\\\
- else\\\
- --СРАВНЕНпЕ ВВЕДЕННОГО ГОВНА С ПЕРЕМЕННОЙ ПАРОЛЯ\\\
- if inputPass == password then\\\
- drawTab(colors.white,colors.green)\\\
- rs.setOutput(redstoneSide,true)\\\
- rs.setOutput(redstoneSideOnWrongPassword,false)\\\
- \\\
- --СТАРТУЕМ ТАЙМЕР НА УКАЗАННОЕ ВРЕМЯ\\\
- changePasswordTimer = os.startTimer(tonumber(doorOpenTime))\\\
- while true do\\\
- local event2,side2,x2,y2 = os.pullEvent()\\\
- --ЕСЛп НпЧЕГО НЕ НАЖАТО, ТО ВЫХОД пЗ ЦпКЛА\\\
- if event2 == \\\"timer\\\" then\\\
- if side2 == changePasswordTimer then\\\
- break\\\
- end\\\
- --ЕСЛп НАЖАТА КЛАВпША \\\"С\\\", ТО ЗАПУСТпТЬ РЕЖпМ СМЕНЫ ПАРОЛЯ\\\
- elseif event2 == \\\"monitor_touch\\\" then\\\
- if x2==Obj[\\\"C\\\"][\\\"x\\\"] and y2==Obj[\\\"C\\\"][\\\"y\\\"] then\\\
- drawButton(\\\"C\\\",colors.white,colors.green)\\\
- sleep(buttonPressTime)\\\
- drawButton(\\\"C\\\",colors.black,colors.white)\\\
- mode = \\\"edit\\\"\\\
- os.queueEvent(\\\"timer\\\",changePasswordTimer)\\\
- end\\\
- end \\\
- end\\\
- \\\
- --ОЧпЩАЕМ ВВЕДЕННЫЙ ТЕКСТ п ЗАКРЫВАЕМ ДВЕРЬ\\\
- inputCode = {}\\\
- rs.setOutput(redstoneSide,false)\\\
- \\\
- --РпСУЕМ ВЕРХНЮЮ ШНЯГУ РАЗНОГО ЦВЕТА В ЗАВпСпМОСТп ОТ РЕЖпМА\\\
- if mode == \\\"edit\\\" then\\\
- drawTab(colors.white,colors.orange)\\\
- else\\\
- drawTab(colors.white,colors.black)\\\
- end\\\
- --ЕСЛп ВВЕДЕН НЕВЕРНЫЙ ПАРОЛЬ\\\
- else\\\
- drawTab(colors.white,colors.red)\\\
- rs.setOutput(redstoneSide,false)\\\
- rs.setOutput(redstoneSideOnWrongPassword,true)\\\
- sleep(3)\\\
- rs.setOutput(redstoneSideOnWrongPassword,false)\\\
- inputCode = {}\\\
- drawTab(colors.white,colors.black)\\\
- end\\\
- end\\\
- --ЕСЛп НАЖАТА ЛЮБАЯ ЦпФРА\\\
- else\\\
- if #inputCode < 5 then\\\
- inputCode[#inputCode+1] = key\\\
- if mode == \\\"edit\\\" then\\\
- drawTab(colors.white,colors.orange)\\\
- else\\\
- drawTab(colors.white,colors.black)\\\
- end\\\
- end\\\
- end\\\
- --ВЫХОД пЗ ЦпКЛА ПЕРЕБОРА ОБЪЕКТОВ\\\
- break\\\
- end\\\
- end\\\
- \\\
- --ЕСЛп НАЖАТА КЛАВпША ENTER\\\
- elseif event == \\\"key\\\" and side == 28 then\\\
- break\\\
- end\\\
- end\\\
- \\\
- clearScreen(colors.black)\\\
- term.setTextColor(colors.white)\\\
- \\\
- term.redirect(term.native())\\\
- \\\
- clearScreen(colors.black)\\\
- term.setTextColor(colors.white)\\\
- term.setCursorPos(1,1)\",\
- path = \"/rootfs/apps/CodeDoor.app/main\",\
- },\
- {\
- text = \" ff-0f-0f-0f ff###\\\
- f01f02f03f0 f0###\\\
- f04f05f06f0 f0###\\\
- f07f08f09f0 f0###\",\
- path = \"/rootfs/apps/CodeDoor.app/Resources/icon.png\",\
- },\
- {\
- text = \"os.loadAPI(\\\"system/api/image\\\")\\\
- os.loadAPI(\\\"system/api/filemanager\\\")\\\
- os.loadAPI(\\\"system/api/windows\\\")\\\
- \\\
- local filem = filemanager.open(\\\"\\\")\\\
- if windows.getFileFormat(filem) == nil then\\\
- shell.run(filem) \\\
- elseif windows.getFileFormat(filem) == \\\".app\\\" then\\\
- path = filem..\\\"/main\\\"\\\
- shell.run(path)\\\
- elseif windows.getFileFormat(filem) == \\\".png\\\" then\\\
- shell.run(\\\"/apps/photoshop.app/main o \\\"..filem)\\\
- elseif windows.getFileFormat(filem) == \\\".txt\\\" then\\\
- shell.run(\\\"/apps/ink.app/main \\\"..filem)\\\
- elseif windows.getFileFormat(filem) == \\\".cfg\\\" then\\\
- shell.run(\\\"/apps/ink.app/main \\\"..filem)\\\
- elseif windows.getFileFormat(filem) == \\\".lua\\\" then\\\
- shell.run(\\\"/apps/luaide.app/main \\\"..filem)\\\
- else\\\
- windows.attention({\\\"Can't open file\\\"},{\\\"This file format\\\",\\\"is not supported.\\\"})\\\
- return 0\\\
- end\",\
- path = \"/rootfs/apps/FileManager.app/main\",\
- },\
- {\
- text = \" 84 84############\\\
- -84-84-84-84-84-84\\\
- -84-84-84-84-84-84\\\
- -84-84-84-84-84-84\",\
- path = \"/rootfs/apps/FileManager.app/Resources/icon.png\",\
- },\
- {\
- text = \"tArgs = {...}\\\
- term.clear()\\\
- \\\
- \\\
- if OneOS then\\\
- --running under OneOS\\\
- OneOS.ToolBarColour = colours.grey\\\
- OneOS.ToolBarTextColour = colours.white\\\
- end\\\
- \\\
- local _w, _h = term.getSize()\\\
- \\\
- local round = function(num, idp)\\\
- local mult = 10^(idp or 0)\\\
- return math.floor(num * mult + 0.5) / mult\\\
- end\\\
- \\\
- UIColours = {\\\
- Toolbar = colours.grey,\\\
- ToolbarText = colours.lightGrey,\\\
- ToolbarSelected = colours.lightBlue,\\\
- ControlText = colours.white,\\\
- ToolbarItemTitle = colours.black,\\\
- Background = colours.lightGrey,\\\
- MenuBackground = colours.white,\\\
- MenuText = colours.black,\\\
- MenuSeparatorText = colours.grey,\\\
- MenuDisabledText = colours.lightGrey,\\\
- Shadow = colours.grey,\\\
- TransparentBackgroundOne = colours.white,\\\
- TransparentBackgroundTwo = colours.lightGrey,\\\
- MenuBarActive = colours.white\\\
- }\\\
- \\\
- local getNames = peripheral.getNames or function()\\\
- local tResults = {}\\\
- for n,sSide in ipairs( rs.getSides() ) do\\\
- if peripheral.isPresent( sSide ) then\\\
- table.insert( tResults, sSide )\\\
- local isWireless = false\\\
- if not pcall(function()isWireless = peripheral.call(sSide, 'isWireless') end) then\\\
- isWireless = true\\\
- end \\\
- if peripheral.getType( sSide ) == \\\"modem\\\" and not isWireless then\\\
- local tRemote = peripheral.call( sSide, \\\"getNamesRemote\\\" )\\\
- for n,sName in ipairs( tRemote ) do\\\
- table.insert( tResults, sName )\\\
- end\\\
- end\\\
- end\\\
- end\\\
- return tResults\\\
- end\\\
- \\\
- Peripheral = {\\\
- GetPeripheral = function(_type)\\\
- for i, p in ipairs(Peripheral.GetPeripherals()) do\\\
- if p.Type == _type then\\\
- return p\\\
- end\\\
- end\\\
- end,\\\
- \\\
- Call = function(type, ...)\\\
- local tArgs = {...}\\\
- local p = Peripheral.GetPeripheral(type)\\\
- peripheral.call(p.Side, unpack(tArgs))\\\
- end,\\\
- \\\
- GetPeripherals = function(filterType)\\\
- local peripherals = {}\\\
- for i, side in ipairs(getNames()) do\\\
- local name = peripheral.getType(side):gsub(\\\"^%l\\\", string.upper)\\\
- local code = string.upper(side:sub(1,1))\\\
- if side:find('_') then\\\
- code = side:sub(side:find('_')+1)\\\
- end\\\
- \\\
- local dupe = false\\\
- for i, v in ipairs(peripherals) do\\\
- if v[1] == name .. ' ' .. code then\\\
- dupe = true\\\
- end\\\
- end\\\
- \\\
- if not dupe then\\\
- local _type = peripheral.getType(side)\\\
- local isWireless = false\\\
- if _type == 'modem' then\\\
- if not pcall(function()isWireless = peripheral.call(sSide, 'isWireless') end) then\\\
- isWireless = true\\\
- end \\\
- if isWireless then\\\
- _type = 'wireless_modem'\\\
- name = 'W '..name\\\
- end\\\
- end\\\
- if not filterType or _type == filterType then\\\
- 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})\\\
- end\\\
- end\\\
- end\\\
- return peripherals\\\
- end,\\\
- \\\
- PresentNamed = function(name)\\\
- return peripheral.isPresent(name)\\\
- end,\\\
- \\\
- CallType = function(type, ...)\\\
- local tArgs = {...}\\\
- local p = GetPeripheral(type)\\\
- return peripheral.call(p.Side, unpack(tArgs))\\\
- end,\\\
- \\\
- CallNamed = function(name, ...)\\\
- local tArgs = {...}\\\
- return peripheral.call(name, unpack(tArgs))\\\
- end\\\
- }\\\
- \\\
- TextLine = {\\\
- Text = \\\"\\\",\\\
- Alignment = AlignmentLeft,\\\
- \\\
- Initialise = function(self, text, alignment)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Text = text\\\
- new.Alignment = alignment or AlignmentLeft\\\
- return new\\\
- end\\\
- }\\\
- \\\
- local StripColours = function(str)\\\
- return str:gsub('['..string.char(14)..'-'..string.char(29)..']','')\\\
- end\\\
- \\\
- Printer = {\\\
- Name = nil,\\\
- PeripheralType = 'printer',\\\
- \\\
- paperLevel = function(self)\\\
- return Peripheral.CallNamed(self.Name, 'getPaperLevel')\\\
- end,\\\
- \\\
- newPage = function(self)\\\
- return Peripheral.CallNamed(self.Name, 'newPage')\\\
- end,\\\
- \\\
- endPage = function(self)\\\
- return Peripheral.CallNamed(self.Name, 'endPage')\\\
- end,\\\
- \\\
- pageWrite = function(self, text)\\\
- return Peripheral.CallNamed(self.Name, 'write', text)\\\
- end,\\\
- \\\
- setPageTitle = function(self, title)\\\
- return Peripheral.CallNamed(self.Name, 'setPageTitle', title)\\\
- end,\\\
- \\\
- inkLevel = function(self)\\\
- return Peripheral.CallNamed(self.Name, 'getInkLevel')\\\
- end,\\\
- \\\
- getCursorPos = function(self)\\\
- return Peripheral.CallNamed(self.Name, 'getCursorPos')\\\
- end,\\\
- \\\
- setCursorPos = function(self, x, y)\\\
- return Peripheral.CallNamed(self.Name, 'setCursorPos', x, y)\\\
- end,\\\
- \\\
- pageSize = function(self)\\\
- return Peripheral.CallNamed(self.Name, 'getPageSize')\\\
- end,\\\
- \\\
- Present = function()\\\
- if Peripheral.GetPeripheral(Printer.PeripheralType) == nil then\\\
- return false\\\
- else\\\
- return true\\\
- end\\\
- end,\\\
- \\\
- PrintLines = function(self, lines, title, copies)\\\
- local pages = {}\\\
- local pageLines = {}\\\
- for i, line in ipairs(lines) do\\\
- table.insert(pageLines, TextLine:Initialise(StripColours(line)))\\\
- if i % 25 == 0 then\\\
- table.insert(pages, pageLines)\\\
- pageLines = {}\\\
- end\\\
- end\\\
- if #pageLines ~= 0 then\\\
- table.insert(pages, pageLines)\\\
- end\\\
- return self:PrintPages(pages, title, copies)\\\
- end,\\\
- \\\
- PrintPages = function(self, pages, title, copies)\\\
- copies = copies or 1\\\
- for c = 1, copies do\\\
- for p, page in ipairs(pages) do\\\
- if self:paperLevel() < #pages * copies then\\\
- return 'Add more paper to the printer'\\\
- end\\\
- if self:inkLevel() < #pages * copies then\\\
- return 'Add more ink to the printer'\\\
- end\\\
- self:newPage()\\\
- for i, line in ipairs(page) do\\\
- self:setCursorPos(1, i)\\\
- self:pageWrite(StripColours(line.Text))\\\
- end\\\
- if title then\\\
- self:setPageTitle(title)\\\
- end\\\
- self:endPage()\\\
- end\\\
- end\\\
- end,\\\
- \\\
- Initialise = function(self, name)\\\
- if Printer.Present() then --fix\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- if name and Peripheral.PresentNamed(name) then\\\
- new.Name = name\\\
- else\\\
- new.Name = Peripheral.GetPeripheral(Printer.PeripheralType).Side\\\
- end\\\
- return new\\\
- end\\\
- end\\\
- }\\\
- \\\
- Clipboard = {\\\
- Content = nil,\\\
- Type = nil,\\\
- IsCut = false,\\\
- \\\
- Empty = function()\\\
- Clipboard.Content = nil\\\
- Clipboard.Type = nil\\\
- Clipboard.IsCut = false\\\
- end,\\\
- \\\
- isEmpty = function()\\\
- return Clipboard.Content == nil\\\
- end,\\\
- \\\
- Copy = function(content, _type)\\\
- Clipboard.Content = content\\\
- Clipboard.Type = _type or 'generic'\\\
- Clipboard.IsCut = false\\\
- end,\\\
- \\\
- Cut = function(content, _type)\\\
- Clipboard.Content = content\\\
- Clipboard.Type = _type or 'generic'\\\
- Clipboard.IsCut = true\\\
- end,\\\
- \\\
- Paste = function()\\\
- local c, t = Clipboard.Content, Clipboard.Type\\\
- if Clipboard.IsCut then\\\
- Clipboard.Empty()\\\
- end\\\
- return c, t\\\
- end\\\
- }\\\
- \\\
- if OneOS and OneOS.Clipboard then\\\
- Clipboard = OneOS.Clipboard\\\
- end\\\
- \\\
- Drawing = {\\\
- \\\
- Screen = {\\\
- Width = _w,\\\
- Height = _h\\\
- },\\\
- \\\
- DrawCharacters = function (x, y, characters, textColour,bgColour)\\\
- Drawing.WriteStringToBuffer(x, y, characters, textColour, bgColour)\\\
- end,\\\
- \\\
- DrawBlankArea = function (x, y, w, h, colour)\\\
- Drawing.DrawArea (x, y, w, h, \\\" \\\", 1, colour)\\\
- end,\\\
- \\\
- DrawArea = function (x, y, w, h, character, textColour, bgColour)\\\
- --width must be greater than 1, other wise we get a stack overflow\\\
- if w < 0 then\\\
- w = w * -1\\\
- elseif w == 0 then\\\
- w = 1\\\
- end\\\
- \\\
- for ix = 1, w do\\\
- local currX = x + ix - 1\\\
- for iy = 1, h do\\\
- local currY = y + iy - 1\\\
- Drawing.WriteToBuffer(currX, currY, character, textColour, bgColour)\\\
- end\\\
- end\\\
- end,\\\
- \\\
- DrawImage = function(_x,_y,tImage, w, h)\\\
- if tImage then\\\
- for y = 1, h do\\\
- if not tImage[y] then\\\
- break\\\
- end\\\
- for x = 1, w do\\\
- if not tImage[y][x] then\\\
- break\\\
- end\\\
- local bgColour = tImage[y][x]\\\
- local textColour = tImage.textcol[y][x] or colours.white\\\
- local char = tImage.text[y][x]\\\
- Drawing.WriteToBuffer(x+_x-1, y+_y-1, char, textColour, bgColour)\\\
- end\\\
- end\\\
- elseif w and h then\\\
- Drawing.DrawBlankArea(x, y, w, h, colours.green)\\\
- end\\\
- end,\\\
- --using .nft\\\
- LoadImage = function(path)\\\
- local image = {\\\
- text = {},\\\
- textcol = {}\\\
- }\\\
- local fs = fs\\\
- if OneOS then\\\
- fs = OneOS.FS\\\
- end\\\
- if fs.exists(path) then\\\
- local _open = io.open\\\
- if OneOS then\\\
- _open = OneOS.IO.open\\\
- end\\\
- local file = _open(path, \\\"r\\\")\\\
- local sLine = file:read()\\\
- local num = 1\\\
- while sLine do \\\
- table.insert(image, num, {})\\\
- table.insert(image.text, num, {})\\\
- table.insert(image.textcol, num, {})\\\
- \\\
- --As we're no longer 1-1, we keep track of what index to write to\\\
- local writeIndex = 1\\\
- --Tells us if we've hit a 30 or 31 (BG and FG respectively)- next char specifies the curr colour\\\
- local bgNext, fgNext = false, false\\\
- --The current background and foreground colours\\\
- local currBG, currFG = nil,nil\\\
- for i=1,#sLine do\\\
- local nextChar = string.sub(sLine, i, i)\\\
- if nextChar:byte() == 30 then\\\
- bgNext = true\\\
- elseif nextChar:byte() == 31 then\\\
- fgNext = true\\\
- elseif bgNext then\\\
- currBG = Drawing.GetColour(nextChar)\\\
- bgNext = false\\\
- elseif fgNext then\\\
- currFG = Drawing.GetColour(nextChar)\\\
- fgNext = false\\\
- else\\\
- if nextChar ~= \\\" \\\" and currFG == nil then\\\
- currFG = colours.white\\\
- end\\\
- image[num][writeIndex] = currBG\\\
- image.textcol[num][writeIndex] = currFG\\\
- image.text[num][writeIndex] = nextChar\\\
- writeIndex = writeIndex + 1\\\
- end\\\
- end\\\
- num = num+1\\\
- sLine = file:read()\\\
- end\\\
- file:close()\\\
- end\\\
- return image\\\
- end,\\\
- \\\
- DrawCharactersCenter = function(x, y, w, h, characters, textColour,bgColour)\\\
- w = w or Drawing.Screen.Width\\\
- h = h or Drawing.Screen.Height\\\
- x = x or 0\\\
- y = y or 0\\\
- x = math.ceil((w - #characters) / 2) + x\\\
- y = math.floor(h / 2) + y\\\
- \\\
- Drawing.DrawCharacters(x, y, characters, textColour, bgColour)\\\
- end,\\\
- \\\
- GetColour = function(hex)\\\
- if hex == ' ' then\\\
- return colours.transparent\\\
- end\\\
- local value = tonumber(hex, 16)\\\
- if not value then return nil end\\\
- value = math.pow(2,value)\\\
- return value\\\
- end,\\\
- \\\
- Clear = function (_colour)\\\
- _colour = _colour or colours.black\\\
- Drawing.ClearBuffer()\\\
- Drawing.DrawBlankArea(1, 1, Drawing.Screen.Width, Drawing.Screen.Height, _colour)\\\
- end,\\\
- \\\
- Buffer = {},\\\
- BackBuffer = {},\\\
- \\\
- DrawBuffer = function()\\\
- for y,row in pairs(Drawing.Buffer) do\\\
- for x,pixel in pairs(row) do\\\
- local shouldDraw = true\\\
- local hasBackBuffer = true\\\
- if Drawing.BackBuffer[y] == nil or Drawing.BackBuffer[y][x] == nil or #Drawing.BackBuffer[y][x] ~= 3 then\\\
- hasBackBuffer = false\\\
- end\\\
- 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\\\
- shouldDraw = false\\\
- end\\\
- if shouldDraw then\\\
- term.setBackgroundColour(pixel[3])\\\
- term.setTextColour(pixel[2])\\\
- term.setCursorPos(x, y)\\\
- term.write(pixel[1])\\\
- end\\\
- end\\\
- end\\\
- Drawing.BackBuffer = Drawing.Buffer\\\
- Drawing.Buffer = {}\\\
- term.setCursorPos(1,1)\\\
- end,\\\
- \\\
- ClearBuffer = function()\\\
- Drawing.Buffer = {}\\\
- end,\\\
- \\\
- WriteStringToBuffer = function (x, y, characters, textColour,bgColour)\\\
- for i = 1, #characters do\\\
- local character = characters:sub(i,i)\\\
- Drawing.WriteToBuffer(x + i - 1, y, character, textColour, bgColour)\\\
- end\\\
- end,\\\
- \\\
- WriteToBuffer = function(x, y, character, textColour,bgColour)\\\
- x = round(x)\\\
- y = round(y)\\\
- if bgColour == colours.transparent then\\\
- Drawing.Buffer[y] = Drawing.Buffer[y] or {}\\\
- Drawing.Buffer[y][x] = Drawing.Buffer[y][x] or {\\\"\\\", colours.white, colours.black}\\\
- Drawing.Buffer[y][x][1] = character\\\
- Drawing.Buffer[y][x][2] = textColour\\\
- else\\\
- Drawing.Buffer[y] = Drawing.Buffer[y] or {}\\\
- Drawing.Buffer[y][x] = {character, textColour, bgColour}\\\
- end\\\
- end,\\\
- }\\\
- \\\
- Current = {\\\
- Document = nil,\\\
- TextInput = nil,\\\
- CursorPos = {1,1},\\\
- CursorColour = colours.black,\\\
- Selection = {8, 36},\\\
- Window = nil,\\\
- Modified = false,\\\
- }\\\
- \\\
- local isQuitting = false\\\
- \\\
- function OrderSelection()\\\
- if Current.Selection then\\\
- if Current.Selection[1] <= Current.Selection[2] then\\\
- return Current.Selection\\\
- else\\\
- return {Current.Selection[2], Current.Selection[1]}\\\
- end\\\
- end\\\
- end\\\
- \\\
- function StripColours(str)\\\
- return str:gsub('['..string.char(14)..'-'..string.char(29)..']','')\\\
- end\\\
- \\\
- function FindColours(str)\\\
- local _, count = str:gsub('['..string.char(14)..'-'..string.char(29)..']','')\\\
- return count\\\
- end\\\
- \\\
- ColourFromCharacter = function(character)\\\
- local n = character:byte() - 14\\\
- if n > 16 then\\\
- return nil\\\
- else\\\
- return 2^n\\\
- end\\\
- end\\\
- \\\
- CharacterFromColour = function(colour)\\\
- return string.char(math.floor(math.log(colour)/math.log(2))+14)\\\
- end\\\
- \\\
- Events = {}\\\
- \\\
- Button = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 0,\\\
- Height = 0,\\\
- BackgroundColour = colours.lightGrey,\\\
- TextColour = colours.white,\\\
- ActiveBackgroundColour = colours.lightGrey,\\\
- Text = \\\"\\\",\\\
- Parent = nil,\\\
- _Click = nil,\\\
- Toggle = nil,\\\
- \\\
- AbsolutePosition = function(self)\\\
- return self.Parent:AbsolutePosition()\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- local bg = self.BackgroundColour\\\
- local tc = self.TextColour\\\
- if type(bg) == 'function' then\\\
- bg = bg()\\\
- end\\\
- \\\
- if self.Toggle then\\\
- tc = UIColours.MenuBarActive\\\
- bg = self.ActiveBackgroundColour\\\
- end\\\
- \\\
- local pos = GetAbsolutePosition(self)\\\
- Drawing.DrawBlankArea(pos.X, pos.Y, self.Width, self.Height, bg)\\\
- Drawing.DrawCharactersCenter(pos.X, pos.Y, self.Width, self.Height, self.Text, tc, bg)\\\
- end,\\\
- \\\
- Initialise = function(self, x, y, width, height, backgroundColour, parent, click, text, textColour, toggle, activeBackgroundColour)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- height = height or 1\\\
- new.Width = width or #text + 2\\\
- new.Height = height\\\
- new.Y = y\\\
- new.X = x\\\
- new.Text = text or \\\"\\\"\\\
- new.BackgroundColour = backgroundColour or colours.lightGrey\\\
- new.TextColour = textColour or colours.white\\\
- new.ActiveBackgroundColour = activeBackgroundColour or colours.lightGrey\\\
- new.Parent = parent\\\
- new._Click = click\\\
- new.Toggle = toggle\\\
- return new\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- if self._Click then\\\
- if self:_Click(side, x, y, not self.Toggle) ~= false and self.Toggle ~= nil then\\\
- self.Toggle = not self.Toggle\\\
- Draw()\\\
- end\\\
- return true\\\
- else\\\
- return false\\\
- end\\\
- end\\\
- }\\\
- \\\
- TextBox = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 0,\\\
- Height = 0,\\\
- BackgroundColour = colours.lightGrey,\\\
- TextColour = colours.black,\\\
- Parent = nil,\\\
- TextInput = nil,\\\
- Placeholder = '',\\\
- \\\
- AbsolutePosition = function(self)\\\
- return self.Parent:AbsolutePosition()\\\
- end,\\\
- \\\
- Draw = function(self) \\\
- local pos = GetAbsolutePosition(self)\\\
- Drawing.DrawBlankArea(pos.X, pos.Y, self.Width, self.Height, self.BackgroundColour)\\\
- local text = self.TextInput.Value\\\
- if #tostring(text) > (self.Width - 2) then\\\
- text = text:sub(#text-(self.Width - 3))\\\
- if Current.TextInput == self.TextInput then\\\
- Current.CursorPos = {pos.X + 1 + self.Width-2, pos.Y}\\\
- end\\\
- else\\\
- if Current.TextInput == self.TextInput then\\\
- Current.CursorPos = {pos.X + 1 + self.TextInput.CursorPos, pos.Y}\\\
- end\\\
- end\\\
- \\\
- if #tostring(text) == 0 then\\\
- Drawing.DrawCharacters(pos.X + 1, pos.Y, self.Placeholder, colours.lightGrey, self.BackgroundColour)\\\
- else\\\
- Drawing.DrawCharacters(pos.X + 1, pos.Y, text, self.TextColour, self.BackgroundColour)\\\
- end\\\
- \\\
- term.setCursorBlink(true)\\\
- \\\
- Current.CursorColour = self.TextColour\\\
- end,\\\
- \\\
- Initialise = function(self, x, y, width, height, parent, text, backgroundColour, textColour, done, numerical)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- height = height or 1\\\
- new.Width = width or #text + 2\\\
- new.Height = height\\\
- new.Y = y\\\
- new.X = x\\\
- new.TextInput = TextInput:Initialise(text or '', function(key)\\\
- if done then\\\
- done(key)\\\
- end\\\
- Draw()\\\
- end, numerical)\\\
- new.BackgroundColour = backgroundColour or colours.lightGrey\\\
- new.TextColour = textColour or colours.black\\\
- new.Parent = parent\\\
- return new\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- Current.Input = self.TextInput\\\
- self:Draw()\\\
- end\\\
- }\\\
- \\\
- TextInput = {\\\
- Value = \\\"\\\",\\\
- Change = nil,\\\
- CursorPos = nil,\\\
- Numerical = false,\\\
- IsDocument = nil,\\\
- \\\
- Initialise = function(self, value, change, numerical, isDocument)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Value = tostring(value)\\\
- new.Change = change\\\
- new.CursorPos = #tostring(value)\\\
- new.Numerical = numerical\\\
- new.IsDocument = isDocument or false\\\
- return new\\\
- end,\\\
- \\\
- Insert = function(self, str)\\\
- if self.Numerical then\\\
- str = tostring(tonumber(str))\\\
- end\\\
- \\\
- local selection = OrderSelection()\\\
- \\\
- if self.IsDocument and selection then\\\
- self.Value = string.sub(self.Value, 1, selection[1]-1) .. str .. string.sub( self.Value, selection[2]+2)\\\
- self.CursorPos = selection[1]\\\
- Current.Selection = nil\\\
- else\\\
- local _, newLineAdjust = string.gsub(self.Value:sub(1, self.CursorPos), '\\\\n','')\\\
- \\\
- self.Value = string.sub(self.Value, 1, self.CursorPos + newLineAdjust) .. str .. string.sub( self.Value, self.CursorPos + 1 + newLineAdjust)\\\
- self.CursorPos = self.CursorPos + 1\\\
- end\\\
- \\\
- self.Change(key)\\\
- end,\\\
- \\\
- Extract = function(self, remove)\\\
- local selection = OrderSelection()\\\
- if self.IsDocument and selection then\\\
- local _, newLineAdjust = string.gsub(self.Value:sub(selection[1], selection[2]), '\\\\n','')\\\
- local str = string.sub(self.Value, selection[1], selection[2]+1+newLineAdjust)\\\
- if remove then\\\
- self.Value = string.sub(self.Value, 1, selection[1]-1) .. string.sub( self.Value, selection[2]+2+newLineAdjust)\\\
- self.CursorPos = selection[1] - 1\\\
- Current.Selection = nil\\\
- end\\\
- return str\\\
- end\\\
- end,\\\
- \\\
- Char = function(self, char)\\\
- if char == 'nil' then\\\
- return\\\
- end\\\
- self:Insert(char)\\\
- end,\\\
- \\\
- Key = function(self, key)\\\
- if key == keys.enter then\\\
- if self.IsDocument then\\\
- self.Value = string.sub(self.Value, 1, self.CursorPos ) .. '\\\\n' .. string.sub( self.Value, self.CursorPos + 1 )\\\
- self.CursorPos = self.CursorPos + 1\\\
- end\\\
- self.Change(key) \\\
- elseif key == keys.left then\\\
- -- Left\\\
- if self.CursorPos > 0 then\\\
- local colShift = FindColours(string.sub( self.Value, self.CursorPos, self.CursorPos))\\\
- self.CursorPos = self.CursorPos - 1 - colShift\\\
- self.Change(key)\\\
- end\\\
- \\\
- elseif key == keys.right then\\\
- -- Right \\\
- if self.CursorPos < string.len(self.Value) then\\\
- local colShift = FindColours(string.sub( self.Value, self.CursorPos+1, self.CursorPos+1))\\\
- self.CursorPos = self.CursorPos + 1 + colShift\\\
- self.Change(key)\\\
- end\\\
- \\\
- elseif key == keys.backspace then\\\
- -- Backspace\\\
- if self.IsDocument and Current.Selection then\\\
- self:Extract(true)\\\
- self.Change(key)\\\
- elseif self.CursorPos > 0 then\\\
- local colShift = FindColours(string.sub( self.Value, self.CursorPos, self.CursorPos))\\\
- local _, newLineAdjust = string.gsub(self.Value:sub(1, self.CursorPos), '\\\\n','')\\\
- \\\
- self.Value = string.sub( self.Value, 1, self.CursorPos - 1 - colShift + newLineAdjust) .. string.sub( self.Value, self.CursorPos + 1 - colShift + newLineAdjust)\\\
- self.CursorPos = self.CursorPos - 1 - colShift\\\
- self.Change(key)\\\
- end\\\
- elseif key == keys.home then\\\
- -- Home\\\
- self.CursorPos = 0\\\
- self.Change(key)\\\
- elseif key == keys.delete then\\\
- if self.IsDocument and Current.Selection then\\\
- self:Extract(true)\\\
- self.Change(key)\\\
- elseif self.CursorPos < string.len(self.Value) then\\\
- self.Value = string.sub( self.Value, 1, self.CursorPos ) .. string.sub( self.Value, self.CursorPos + 2 ) \\\
- self.Change(key)\\\
- end\\\
- elseif key == keys[\\\"end\\\"] then\\\
- -- End\\\
- self.CursorPos = string.len(self.Value)\\\
- self.Change(key)\\\
- elseif key == keys.up and self.IsDocument then\\\
- -- Up\\\
- if Current.Document.CursorPos then\\\
- local page = Current.Document.Pages[Current.Document.CursorPos.Page]\\\
- self.CursorPos = page:GetCursorPosFromPoint(Current.Document.CursorPos.Collum + page.MarginX, Current.Document.CursorPos.Line - page.MarginY - 1 + Current.Document.ScrollBar.Scroll, true)\\\
- self.Change(key)\\\
- end\\\
- elseif key == keys.down and self.IsDocument then\\\
- -- Down\\\
- if Current.Document.CursorPos then\\\
- local page = Current.Document.Pages[Current.Document.CursorPos.Page]\\\
- self.CursorPos = page:GetCursorPosFromPoint(Current.Document.CursorPos.Collum + page.MarginX, Current.Document.CursorPos.Line - page.MarginY + 1 + Current.Document.ScrollBar.Scroll, true)\\\
- self.Change(key)\\\
- end\\\
- end\\\
- end\\\
- }\\\
- \\\
- Menu = {\\\
- X = 0,\\\
- Y = 0,\\\
- Width = 0,\\\
- Height = 0,\\\
- Owner = nil,\\\
- Items = {},\\\
- RemoveTop = false,\\\
- \\\
- Draw = function(self)\\\
- Drawing.DrawBlankArea(self.X + 1, self.Y + 1, self.Width, self.Height, UIColours.Shadow)\\\
- if not self.RemoveTop then\\\
- Drawing.DrawBlankArea(self.X, self.Y, self.Width, self.Height, UIColours.MenuBackground)\\\
- for i, item in ipairs(self.Items) do\\\
- if item.Separator then\\\
- Drawing.DrawArea(self.X, self.Y + i, self.Width, 1, '-', colours.grey, UIColours.MenuBackground)\\\
- else\\\
- local textColour = item.Colour or UIColours.MenuText\\\
- if (item.Enabled and type(item.Enabled) == 'function' and item.Enabled() == false) or item.Enabled == false then\\\
- textColour = UIColours.MenuDisabledText\\\
- end\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + i, item.Title, textColour, UIColours.MenuBackground)\\\
- end\\\
- end\\\
- else\\\
- Drawing.DrawBlankArea(self.X, self.Y, self.Width, self.Height, UIColours.MenuBackground)\\\
- for i, item in ipairs(self.Items) do\\\
- if item.Separator then\\\
- Drawing.DrawArea(self.X, self.Y + i - 1, self.Width, 1, '-', colours.grey, UIColours.MenuBackground)\\\
- else\\\
- local textColour = item.Colour or UIColours.MenuText\\\
- if (item.Enabled and type(item.Enabled) == 'function' and item.Enabled() == false) or item.Enabled == false then\\\
- textColour = UIColours.MenuDisabledText\\\
- end\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + i - 1, item.Title, textColour, UIColours.MenuBackground)\\\
- \\\
- Drawing.DrawCharacters(self.X - 1 + self.Width-#item.KeyName, self.Y + i - 1, item.KeyName, textColour, UIColours.MenuBackground)\\\
- end\\\
- end\\\
- end\\\
- end,\\\
- \\\
- NameForKey = function(self, key)\\\
- if key == keys.leftCtrl then\\\
- return '^'\\\
- elseif key == keys.tab then\\\
- return 'Tab'\\\
- elseif key == keys.delete then\\\
- return 'Delete'\\\
- elseif key == keys.n then\\\
- return 'N'\\\
- elseif key == keys.a then\\\
- return 'A'\\\
- elseif key == keys.s then\\\
- return 'S'\\\
- elseif key == keys.o then\\\
- return 'O'\\\
- elseif key == keys.z then\\\
- return 'Z'\\\
- elseif key == keys.y then\\\
- return 'Y'\\\
- elseif key == keys.c then\\\
- return 'C'\\\
- elseif key == keys.x then\\\
- return 'X'\\\
- elseif key == keys.v then\\\
- return 'V'\\\
- elseif key == keys.r then\\\
- return 'R'\\\
- elseif key == keys.l then\\\
- return 'L'\\\
- elseif key == keys.t then\\\
- return 'T'\\\
- elseif key == keys.h then\\\
- return 'H'\\\
- elseif key == keys.e then\\\
- return 'E'\\\
- elseif key == keys.p then\\\
- return 'P'\\\
- elseif key == keys.f then\\\
- return 'F'\\\
- elseif key == keys.m then\\\
- return 'M'\\\
- elseif key == keys.q then\\\
- return 'Q'\\\
- else\\\
- return '?' \\\
- end\\\
- end,\\\
- \\\
- Initialise = function(self, x, y, items, owner, removeTop)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- if not owner then\\\
- return\\\
- end\\\
- \\\
- local keyNames = {}\\\
- \\\
- for i, v in ipairs(items) do\\\
- items[i].KeyName = ''\\\
- if v.Keys then\\\
- for _i, key in ipairs(v.Keys) do\\\
- items[i].KeyName = items[i].KeyName .. self:NameForKey(key)\\\
- end\\\
- end\\\
- if items[i].KeyName ~= '' then\\\
- table.insert(keyNames, items[i].KeyName)\\\
- end\\\
- end\\\
- local keysLength = LongestString(keyNames)\\\
- if keysLength > 0 then\\\
- keysLength = keysLength + 2\\\
- end\\\
- \\\
- new.Width = LongestString(items, 'Title') + 2 + keysLength\\\
- if new.Width < 10 then\\\
- new.Width = 10\\\
- end\\\
- new.Height = #items + 2\\\
- new.RemoveTop = removeTop or false\\\
- if removeTop then\\\
- new.Height = new.Height - 1\\\
- end\\\
- \\\
- if y < 1 then\\\
- y = 1\\\
- end\\\
- if x < 1 then\\\
- x = 1\\\
- end\\\
- \\\
- if y + new.Height > Drawing.Screen.Height + 1 then\\\
- y = Drawing.Screen.Height - new.Height\\\
- end\\\
- if x + new.Width > Drawing.Screen.Width + 1 then\\\
- x = Drawing.Screen.Width - new.Width\\\
- end\\\
- \\\
- \\\
- new.Y = y\\\
- new.X = x\\\
- new.Items = items\\\
- new.Owner = owner\\\
- return new\\\
- end,\\\
- \\\
- New = function(self, x, y, items, owner, removeTop)\\\
- if Current.Menu and Current.Menu.Owner == owner then\\\
- Current.Menu = nil\\\
- return\\\
- end\\\
- \\\
- local new = self:Initialise(x, y, items, owner, removeTop)\\\
- Current.Menu = new\\\
- return new\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- local i = y-1\\\
- if self.RemoveTop then\\\
- i = y\\\
- end\\\
- if i >= 1 and y < self.Height then\\\
- 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\\\
- self.Items[i]:Click()\\\
- if Current.Menu.Owner and Current.Menu.Owner.Toggle then\\\
- Current.Menu.Owner.Toggle = false\\\
- end\\\
- Current.Menu = nil\\\
- self = nil\\\
- end\\\
- return true\\\
- end\\\
- end\\\
- }\\\
- \\\
- MenuBar = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = Drawing.Screen.Width,\\\
- Height = 1,\\\
- MenuBarItems = {},\\\
- \\\
- AbsolutePosition = function(self)\\\
- return {X = self.X, Y = self.Y}\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- --Drawing.DrawArea(self.X - 1, self.Y, 1, self.Height, \\\"|\\\", UIColours.ToolbarText, UIColours.Background)\\\
- \\\
- Drawing.DrawBlankArea(self.X, self.Y, self.Width, self.Height, colours.grey)\\\
- for i, button in ipairs(self.MenuBarItems) do\\\
- button:Draw()\\\
- end\\\
- end,\\\
- \\\
- Initialise = function(self, items)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.X = 1\\\
- new.Y = 1\\\
- new.MenuBarItems = items\\\
- return new\\\
- end,\\\
- \\\
- AddToolbarItem = function(self, item)\\\
- table.insert(self.ToolbarItems, item)\\\
- self:CalculateToolbarItemPositions()\\\
- end,\\\
- \\\
- CalculateToolbarItemPositions = function(self)\\\
- local currY = 1\\\
- for i, toolbarItem in ipairs(self.ToolbarItems) do\\\
- toolbarItem.Y = currY\\\
- currY = currY + toolbarItem.Height\\\
- end\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- for i, item in ipairs(self.MenuBarItems) do\\\
- if item.X <= x and item.X + item.Width > x then\\\
- if item:Click(item, side, x - item.X + 1, 1) then\\\
- return true\\\
- end\\\
- end\\\
- end\\\
- return false\\\
- end\\\
- }\\\
- \\\
- TextFormatPlainText = 1\\\
- TextFormatInkText = 2\\\
- \\\
- Document = {\\\
- X = 1,\\\
- Y = 1,\\\
- PageSize = {Width = 25, Height = 21},\\\
- TextInput = nil,\\\
- Pages = {},\\\
- Format = TextFormatPlainText,\\\
- Title = '',\\\
- Path = nil,\\\
- ScrollBar = nil,\\\
- Lines = {},\\\
- CursorPos = nil,\\\
- \\\
- CalculateLineWrapping = function(self)\\\
- local limit = self.PageSize.Width\\\
- local text = self.TextInput.Value\\\
- local lines = {''}\\\
- local words = {}\\\
- \\\
- for word, space in text:gmatch('(%S+)(%s*)') do\\\
- for i = 1, math.ceil(#word/limit) do\\\
- local _space = ''\\\
- if i == math.ceil(#word/limit) then\\\
- _space = space\\\
- end\\\
- table.insert(words, {word:sub(1+limit*(i-1), limit*i), _space})\\\
- end\\\
- end\\\
- \\\
- for i, ws in ipairs(words) do\\\
- local word = ws[1]\\\
- local space = ws[2]\\\
- local temp = lines[#lines] .. word .. space:gsub('\\\\n','')\\\
- if #temp > limit then\\\
- table.insert(lines, '')\\\
- end\\\
- if space:find('\\\\n') then\\\
- lines[#lines] = lines[#lines] .. word\\\
- \\\
- space = space:gsub('\\\\n', function()\\\
- table.insert(lines, '')\\\
- return ''\\\
- end)\\\
- else\\\
- lines[#lines] = lines[#lines] .. word .. space\\\
- end\\\
- end\\\
- return lines\\\
- end,\\\
- \\\
- CalculateCursorPos = function(self)\\\
- local passedCharacters = 0\\\
- Current.CursorPos = nil\\\
- for p, page in ipairs(self.Pages) do\\\
- page:Draw()\\\
- if not Current.CursorPos then\\\
- for i, line in ipairs(page.Lines) do\\\
- local relCursor = self.TextInput.CursorPos - FindColours(self.TextInput.Value:sub(1,self.TextInput.CursorPos))\\\
- if passedCharacters + #StripColours(line.Text:gsub('\\\\n','')) >= relCursor then\\\
- Current.CursorPos = {self.X + page.MarginX + (relCursor - passedCharacters), page.Y + 1 + i}\\\
- self.CursorPos = {Page = p, Line = i, Collum = relCursor - passedCharacters - FindColours(self.TextInput.Value:sub(1,self.TextInput.CursorPos-1))}\\\
- break\\\
- end\\\
- passedCharacters = passedCharacters + #StripColours(line.Text:gsub('\\\\n',''))\\\
- end\\\
- end\\\
- end\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- self:CalculatePages()\\\
- self:CalculateCursorPos()\\\
- self.ScrollBar:Draw()\\\
- end,\\\
- \\\
- CalculatePages = function(self)\\\
- self.Pages = {}\\\
- local lines = self:CalculateLineWrapping()\\\
- self.Lines = lines\\\
- local pageLines = {}\\\
- local totalPageHeight = (3 + self.PageSize.Height + 2 * Page.MarginY)\\\
- for i, line in ipairs(lines) do\\\
- table.insert(pageLines, TextLine:Initialise(line))\\\
- if i % self.PageSize.Height == 0 then\\\
- table.insert(self.Pages, Page:Initialise(self, pageLines, 3 - self.ScrollBar.Scroll + totalPageHeight*(#self.Pages)))\\\
- pageLines = {}\\\
- end\\\
- end\\\
- if #pageLines ~= 0 then\\\
- table.insert(self.Pages, Page:Initialise(self, pageLines, 3 - self.ScrollBar.Scroll + totalPageHeight*(#self.Pages)))\\\
- end\\\
- \\\
- self.ScrollBar.MaxScroll = totalPageHeight*(#self.Pages) - Drawing.Screen.Height + 1\\\
- end,\\\
- \\\
- ScrollToCursor = function(self)\\\
- self:CalculateCursorPos()\\\
- if Current.CursorPos and \\\
- (Current.CursorPos[2] > Drawing.Screen.Height \\\
- or Current.CursorPos[2] < 2) then\\\
- self.ScrollBar:DoScroll(Current.CursorPos[2] - Drawing.Screen.Height)\\\
- end\\\
- end,\\\
- \\\
- SetSelectionColour = function(self, colour)\\\
- local selection = OrderSelection()\\\
- local text = self.TextInput:Extract(true)\\\
- local colChar = CharacterFromColour(colour)\\\
- local precedingColour = ''\\\
- if FindColours(self.TextInput.Value:sub(self.TextInput.CursorPos+1, self.TextInput.CursorPos+1)) == 0 then\\\
- for i = 1, self.TextInput.CursorPos do\\\
- local c = self.TextInput.Value:sub(self.TextInput.CursorPos - i,self.TextInput.CursorPos - i)\\\
- if FindColours(c) == 1 then\\\
- precedingColour = c\\\
- break\\\
- end\\\
- end\\\
- if precedingColour == '' then\\\
- precedingColour = CharacterFromColour(colours.black)\\\
- end\\\
- end\\\
- \\\
- self.TextInput:Insert(colChar..StripColours(text)..precedingColour)\\\
- --text = text:gsub('['..string.char(14)..'-'..string.char(29)..']','')\\\
- end,\\\
- \\\
- Initialise = function(self, text, title, path)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Title = title or 'New Document'\\\
- new.Path = path\\\
- new.X = (Drawing.Screen.Width - (new.PageSize.Width + 2*(Page.MarginX)))/2\\\
- new.Y = 2\\\
- new.TextInput = TextInput:Initialise(text, function()\\\
- new:ScrollToCursor() \\\
- Current.Modified = true\\\
- Draw()\\\
- end, false, true)\\\
- new.ScrollBar = ScrollBar:Initialise(Drawing.Screen.Width, new.Y, Drawing.Screen.Height-1, 0, nil, nil, nil, function()end)\\\
- Current.TextInput = new.TextInput\\\
- Current.ScrollBar = new.ScrollBar\\\
- return new\\\
- end\\\
- }\\\
- \\\
- ScrollBar = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 1,\\\
- Height = 1,\\\
- BackgroundColour = colours.grey,\\\
- BarColour = colours.lightBlue,\\\
- Parent = nil,\\\
- Change = nil,\\\
- Scroll = 0,\\\
- MaxScroll = 0,\\\
- ClickPoint = nil,\\\
- \\\
- AbsolutePosition = function(self)\\\
- return self.Parent:AbsolutePosition()\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- local pos = GetAbsolutePosition(self)\\\
- local barHeight = self.Height - self.MaxScroll\\\
- if barHeight < 3 then\\\
- barHeight = 3\\\
- end\\\
- local percentage = (self.Scroll/self.MaxScroll)\\\
- \\\
- Drawing.DrawBlankArea(pos.X, pos.Y, self.Width, self.Height, self.BackgroundColour)\\\
- Drawing.DrawBlankArea(pos.X, pos.Y + round(self.Height*percentage - barHeight*percentage), self.Width, barHeight, self.BarColour)\\\
- end,\\\
- \\\
- Initialise = function(self, x, y, height, maxScroll, backgroundColour, barColour, parent, change)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Width = 1\\\
- new.Height = height\\\
- new.Y = y\\\
- new.X = x\\\
- new.BackgroundColour = backgroundColour or colours.grey\\\
- new.BarColour = barColour or colours.lightBlue\\\
- new.Parent = parent\\\
- new.Change = change or function()end\\\
- new.MaxScroll = maxScroll\\\
- new.Scroll = 0\\\
- return new\\\
- end,\\\
- \\\
- DoScroll = function(self, amount)\\\
- amount = round(amount)\\\
- if self.Scroll < 0 or self.Scroll > self.MaxScroll then\\\
- return false\\\
- end\\\
- self.Scroll = self.Scroll + amount\\\
- if self.Scroll < 0 then\\\
- self.Scroll = 0\\\
- elseif self.Scroll > self.MaxScroll then\\\
- self.Scroll = self.MaxScroll\\\
- end\\\
- self.Change()\\\
- return true\\\
- end,\\\
- \\\
- Click = function(self, side, x, y, drag)\\\
- local percentage = (self.Scroll/self.MaxScroll)\\\
- local barHeight = (self.Height - self.MaxScroll)\\\
- if barHeight < 3 then\\\
- barHeight = 3\\\
- end\\\
- local relScroll = (self.MaxScroll*(y + barHeight*percentage)/self.Height)\\\
- if not drag then\\\
- self.ClickPoint = self.Scroll - relScroll + 1\\\
- end\\\
- \\\
- if self.Scroll-1 ~= relScroll then\\\
- self:DoScroll(relScroll-self.Scroll-1 + self.ClickPoint)\\\
- end\\\
- return true\\\
- end\\\
- }\\\
- \\\
- AlignmentLeft = 1\\\
- AlignmentCentre = 2\\\
- AlignmentRight = 3\\\
- \\\
- TextLine = {\\\
- Text = \\\"\\\",\\\
- Alignment = AlignmentLeft,\\\
- \\\
- Initialise = function(self, text, alignment)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Text = text\\\
- new.Alignment = alignment or AlignmentLeft\\\
- return new\\\
- end\\\
- }\\\
- \\\
- local clickPos = 1\\\
- Page = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 1,\\\
- Height = 1,\\\
- MarginX = 3,\\\
- MarginY = 2,\\\
- BackgroundColour = colours.white,\\\
- TextColour = colours.white,\\\
- ActiveBackgroundColour = colours.lightGrey,\\\
- Lines = {},\\\
- Parent = nil,\\\
- \\\
- AbsolutePosition = function(self)\\\
- return self.Parent:AbsolutePosition()\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- local pos = GetAbsolutePosition(self)\\\
- \\\
- if pos.Y > Drawing.Screen.Height or pos.Y + self.Height < 1 then\\\
- return\\\
- end\\\
- \\\
- Drawing.DrawBlankArea(pos.X+self.Width,pos.Y -1 + 1, 1, self.Height, UIColours.Shadow)\\\
- Drawing.DrawBlankArea(pos.X+1, pos.Y -1 + self.Height, self.Width, 1, UIColours.Shadow)\\\
- Drawing.DrawBlankArea(pos.X, pos.Y -1, self.Width, self.Height, self.BackgroundColour)\\\
- \\\
- local textColour = self.TextColour\\\
- if not Current.Selection then\\\
- for i, line in ipairs(self.Lines) do\\\
- local _c = 1\\\
- for c = 1, #line.Text do\\\
- local col = ColourFromCharacter(line.Text:sub(c,c))\\\
- if col then\\\
- textColour = col\\\
- else\\\
- Drawing.WriteToBuffer(pos.X + self.MarginX - 1 + _c, pos.Y -2 + i + self.MarginY, line.Text:sub(c,c), textColour, self.BackgroundColour)\\\
- _c = _c + 1\\\
- end\\\
- end\\\
- end\\\
- else\\\
- local selection = OrderSelection()\\\
- local char = 1\\\
- local textColour = self.TextColour\\\
- for i, line in ipairs(self.Lines) do\\\
- local _c = 1\\\
- for c = 1, #line.Text do\\\
- local col = ColourFromCharacter(line.Text:sub(c,c))\\\
- if col then\\\
- textColour = col\\\
- else\\\
- local tc = textColour\\\
- local colour = colours.white\\\
- if char >= selection[1] and char <= selection[2] then\\\
- colour = colours.lightBlue\\\
- tc = colours.white\\\
- end\\\
- \\\
- Drawing.WriteToBuffer(pos.X + self.MarginX - 1 + _c, pos.Y -2 + i + self.MarginY, line.Text:sub(c,c), tc, colour)\\\
- _c = _c + 1\\\
- end\\\
- char = char + 1\\\
- end\\\
- end\\\
- end\\\
- end,\\\
- \\\
- Initialise = function(self, parent, lines, y)\\\
- local new = {} -- the new instanc\\\
- setmetatable( new, {__index = self} )\\\
- new.Height = parent.PageSize.Height + 2 * self.MarginY\\\
- new.Width = parent.PageSize.Width + 2 * self.MarginX\\\
- new.X = 1\\\
- new.Y = y or 1\\\
- new.Lines = lines or {}\\\
- new.BackgroundColour = colours.white\\\
- new.TextColour = colours.black\\\
- new.Parent = parent\\\
- new.ClickPos = 1\\\
- return new\\\
- end,\\\
- \\\
- GetCursorPosFromPoint = function(self, x, y, rel)\\\
- local pos = GetAbsolutePosition(self)\\\
- if rel then\\\
- pos = {Y = 0, X = 0}\\\
- end\\\
- local row = y - pos.Y + self.MarginY - self.Parent.ScrollBar.Scroll\\\
- local col = x - self.MarginX - pos.X + 1\\\
- local cursorPos = 0\\\
- if row <= 0 or col <= 0 then\\\
- return 0\\\
- end\\\
- \\\
- if row > #self.Lines then\\\
- for i, v in ipairs(self.Lines) do\\\
- cursorPos = cursorPos + #v.Text-- - FindColours(v.Text)\\\
- end\\\
- return cursorPos\\\
- end\\\
- \\\
- --term.setCursorPos(1,3)\\\
- local prevLineCount = 0\\\
- for i, v in ipairs(self.Lines) do\\\
- if i == row then\\\
- if col > #v.Text then\\\
- col = #v.Text-- + FindColours(v.Text)\\\
- else\\\
- col = col + FindColours(v.Text:sub(1, col))\\\
- end\\\
- --term.setCursorPos(1,2)\\\
- --print(prevLineCount)\\\
- cursorPos = cursorPos + col + 2 - i - prevLineCount\\\
- break\\\
- else\\\
- prevLineCount = FindColours(v.Text)\\\
- if prevLineCount ~= 0 then\\\
- prevLineCount = prevLineCount\\\
- end\\\
- cursorPos = cursorPos + #v.Text + 2 - i + FindColours(v.Text)\\\
- end\\\
- end\\\
- \\\
- return cursorPos - 2\\\
- end,\\\
- \\\
- Click = function(self, side, x, y, drag)\\\
- local cursorPos = self:GetCursorPosFromPoint(x, y)\\\
- self.Parent.TextInput.CursorPos = cursorPos\\\
- if drag == nil then\\\
- Current.Selection = nil\\\
- clickPos = x\\\
- else\\\
- local relCursor = cursorPos-- - FindColours(self.Parent.TextInput.Value:sub(1,cursorPos)) + 1\\\
- if not Current.Selection then\\\
- local adder = 1\\\
- if clickPos and clickPos < x then\\\
- adder = 0\\\
- end\\\
- Current.Selection = {relCursor + adder, relCursor + 1 + adder}\\\
- else\\\
- Current.Selection[2] = relCursor + 1\\\
- end\\\
- end\\\
- Draw()\\\
- return true\\\
- end\\\
- }\\\
- \\\
- function GetAbsolutePosition(object)\\\
- local obj = object\\\
- local i = 0\\\
- local x = 1\\\
- local y = 1\\\
- while true do\\\
- x = x + obj.X - 1\\\
- y = y + obj.Y - 1\\\
- \\\
- if not obj.Parent then\\\
- return {X = x, Y = y}\\\
- end\\\
- \\\
- obj = obj.Parent\\\
- \\\
- if i > 32 then\\\
- return {X = 1, Y = 1}\\\
- end\\\
- \\\
- i = i + 1\\\
- end\\\
- \\\
- end\\\
- \\\
- function Draw()\\\
- if not Current.Window then\\\
- Drawing.Clear(colours.lightGrey)\\\
- else\\\
- Drawing.DrawArea(1, 2, Drawing.Screen.Width, Drawing.Screen.Height, '|', colours.black, colours.lightGrey)\\\
- end\\\
- \\\
- if Current.Document then\\\
- Current.Document:Draw()\\\
- end\\\
- \\\
- Current.MenuBar:Draw()\\\
- \\\
- if Current.Window then\\\
- Current.Window:Draw()\\\
- end\\\
- \\\
- if Current.Menu then\\\
- Current.Menu:Draw()\\\
- end\\\
- \\\
- Drawing.DrawBuffer()\\\
- \\\
- 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\\\
- term.setCursorPos(Current.CursorPos[1], Current.CursorPos[2])\\\
- term.setCursorBlink(true)\\\
- term.setTextColour(Current.CursorColour)\\\
- else\\\
- term.setCursorBlink(false)\\\
- end\\\
- end\\\
- MainDraw = Draw\\\
- \\\
- LongestString = function(input, key)\\\
- local length = 0\\\
- for i = 1, #input do\\\
- local value = input[i]\\\
- if key then\\\
- if value[key] then\\\
- value = value[key]\\\
- else\\\
- value = ''\\\
- end\\\
- end\\\
- local titleLength = string.len(value)\\\
- if titleLength > length then\\\
- length = titleLength\\\
- end\\\
- end\\\
- return length\\\
- end\\\
- \\\
- function LoadMenuBar()\\\
- Current.MenuBar = MenuBar:Initialise({\\\
- Button:Initialise(1, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
- if toggle then\\\
- Menu:New(1, 2, {\\\
- {\\\
- Title = \\\"New...\\\",\\\
- Click = function()\\\
- Current.Document = Document:Initialise('') \\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.n\\\
- }\\\
- },\\\
- {\\\
- Title = 'Open...',\\\
- Click = function()\\\
- DisplayOpenDocumentWindow()\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.o\\\
- }\\\
- },\\\
- {\\\
- Separator = true\\\
- },\\\
- {\\\
- Title = 'Save...',\\\
- Click = function()\\\
- SaveDocument()\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.s\\\
- },\\\
- Enabled = function()\\\
- return true\\\
- end\\\
- },\\\
- {\\\
- Separator = true\\\
- },\\\
- {\\\
- Title = 'Print...',\\\
- Click = function()\\\
- PrintDocument()\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.p\\\
- },\\\
- Enabled = function()\\\
- return true\\\
- end\\\
- },\\\
- {\\\
- Separator = true\\\
- },\\\
- {\\\
- Title = 'Quit',\\\
- Click = function()\\\
- Close()\\\
- end\\\
- },\\\
- --[[\\\
- {\\\
- Title = 'Save As...',\\\
- Click = function()\\\
- \\\
- end\\\
- } \\\
- ]]--\\\
- }, self, true)\\\
- else\\\
- Current.Menu = nil\\\
- end\\\
- return true \\\
- end, 'File', colours.lightGrey, false),\\\
- Button:Initialise(7, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
- if not self.Toggle then\\\
- Menu:New(7, 2, {\\\
- --[[\\\
- {\\\
- Title = \\\"Undo\\\",\\\
- Click = function()\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.z\\\
- },\\\
- Enabled = function()\\\
- return false\\\
- end\\\
- },\\\
- {\\\
- Title = 'Redo',\\\
- Click = function()\\\
- \\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.y\\\
- },\\\
- Enabled = function()\\\
- return false\\\
- end\\\
- },\\\
- {\\\
- Separator = true\\\
- },\\\
- ]]--\\\
- {\\\
- Title = 'Cut',\\\
- Click = function()\\\
- Clipboard.Cut(Current.Document.TextInput:Extract(true), 'text')\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.x\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil and Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil\\\
- end\\\
- },\\\
- {\\\
- Title = 'Copy',\\\
- Click = function()\\\
- Clipboard.Copy(Current.Document.TextInput:Extract(), 'text')\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.c\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil and Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil\\\
- end\\\
- },\\\
- {\\\
- Title = 'Paste',\\\
- Click = function()\\\
- local paste = Clipboard.Paste()\\\
- Current.Document.TextInput:Insert(paste)\\\
- Current.Document.TextInput.CursorPos = Current.Document.TextInput.CursorPos + #paste - 1\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.v\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil and (not Clipboard.isEmpty()) and Clipboard.Type == 'text'\\\
- end\\\
- },\\\
- {\\\
- Separator = true, \\\
- },\\\
- {\\\
- Title = 'Select All',\\\
- Click = function()\\\
- Current.Selection = {1, #Current.Document.TextInput.Value:gsub('\\\\n','')}\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.a\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil\\\
- end\\\
- }\\\
- }, self, true)\\\
- else\\\
- Current.Menu = nil\\\
- end\\\
- return true \\\
- end, 'Edit', colours.lightGrey, false)\\\
- })\\\
- end\\\
- \\\
- function LoadMenuBar()\\\
- Current.MenuBar = MenuBar:Initialise({\\\
- Button:Initialise(1, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
- if toggle then\\\
- Menu:New(1, 2, {\\\
- {\\\
- Title = \\\"New...\\\",\\\
- Click = function()\\\
- Current.Document = Document:Initialise('') \\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.n\\\
- }\\\
- },\\\
- {\\\
- Title = 'Open...',\\\
- Click = function()\\\
- DisplayOpenDocumentWindow()\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.o\\\
- }\\\
- },\\\
- {\\\
- Separator = true\\\
- },\\\
- {\\\
- Title = 'Save...',\\\
- Click = function()\\\
- SaveDocument()\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.s\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil\\\
- end\\\
- },\\\
- {\\\
- Separator = true\\\
- },\\\
- {\\\
- Title = 'Print...',\\\
- Click = function()\\\
- PrintDocument()\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.p\\\
- },\\\
- Enabled = function()\\\
- return true\\\
- end\\\
- },\\\
- {\\\
- Separator = true\\\
- },\\\
- {\\\
- Title = 'Quit',\\\
- Click = function()\\\
- if Close() and OneOS then\\\
- OneOS.Close()\\\
- end\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.q\\\
- }\\\
- },\\\
- --[[\\\
- {\\\
- Title = 'Save As...',\\\
- Click = function()\\\
- \\\
- end\\\
- } \\\
- ]]--\\\
- }, self, true)\\\
- else\\\
- Current.Menu = nil\\\
- end\\\
- return true \\\
- end, 'File', colours.lightGrey, false),\\\
- Button:Initialise(7, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
- if not self.Toggle then\\\
- Menu:New(7, 2, {\\\
- --[[\\\
- {\\\
- Title = \\\"Undo\\\",\\\
- Click = function()\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.z\\\
- },\\\
- Enabled = function()\\\
- return false\\\
- end\\\
- },\\\
- {\\\
- Title = 'Redo',\\\
- Click = function()\\\
- \\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.y\\\
- },\\\
- Enabled = function()\\\
- return false\\\
- end\\\
- },\\\
- {\\\
- Separator = true\\\
- },\\\
- ]]--\\\
- {\\\
- Title = 'Cut',\\\
- Click = function()\\\
- Clipboard.Cut(Current.Document.TextInput:Extract(true), 'text')\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.x\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil and Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil\\\
- end\\\
- },\\\
- {\\\
- Title = 'Copy',\\\
- Click = function()\\\
- Clipboard.Copy(Current.Document.TextInput:Extract(), 'text')\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.c\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil and Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil\\\
- end\\\
- },\\\
- {\\\
- Title = 'Paste',\\\
- Click = function()\\\
- local paste = Clipboard.Paste()\\\
- Current.Document.TextInput:Insert(paste)\\\
- Current.Document.TextInput.CursorPos = Current.Document.TextInput.CursorPos + #paste - 1\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.v\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil and (not Clipboard.isEmpty()) and Clipboard.Type == 'text'\\\
- end\\\
- },\\\
- {\\\
- Separator = true, \\\
- },\\\
- {\\\
- Title = 'Select All',\\\
- Click = function()\\\
- Current.Selection = {1, #Current.Document.TextInput.Value:gsub('\\\\n','')}\\\
- end,\\\
- Keys = {\\\
- keys.leftCtrl,\\\
- keys.a\\\
- },\\\
- Enabled = function()\\\
- return Current.Document ~= nil\\\
- end\\\
- }\\\
- }, self, true)\\\
- else\\\
- Current.Menu = nil\\\
- end\\\
- return true \\\
- end, 'Edit', colours.lightGrey, false),\\\
- Button:Initialise(13, 1, nil, nil, colours.grey, Current.MenuBar, function(self, side, x, y, toggle)\\\
- if not self.Toggle then\\\
- Menu:New(13, 2, {\\\
- {\\\
- Title = 'Red',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.red,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Orange',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.orange,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Yellow',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.yellow,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Pink',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.pink,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Magenta',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.magenta,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Purple',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.purple,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Light Blue',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.lightBlue,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Cyan',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.cyan,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Blue',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.blue,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Green',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.green,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Light Grey',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.lightGrey,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Grey',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.grey,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Black',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.black,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- },\\\
- {\\\
- Title = 'Brown',\\\
- Click = function(item)\\\
- Current.Document:SetSelectionColour(item.Colour)\\\
- end,\\\
- Colour = colours.brown,\\\
- Enabled = function()\\\
- return (Current.Document ~= nil and Current.Selection ~= nil and Current.Selection[1] ~= nil and Current.Selection[2] ~= nil)\\\
- end\\\
- }\\\
- }, self, true)\\\
- else\\\
- Current.Menu = nil\\\
- end\\\
- return true \\\
- end, 'Colour', colours.lightGrey, false)\\\
- })\\\
- end\\\
- \\\
- function SplashScreen()\\\
- local w = colours.white\\\
- local b = colours.black\\\
- local u = colours.blue\\\
- local lb = colours.lightBlue\\\
- 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,},\\\
- [\\\"text\\\"]={{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\"I\\\",\\\"n\\\",\\\"k\\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},{\\\" \\\",\\\" \\\",\\\"b\\\",\\\"y\\\",\\\" \\\",\\\"o\\\",\\\"e\\\",\\\"e\\\",\\\"d\\\",\\\" \\\",\\\" \\\"},{\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",\\\" \\\",},},\\\
- [\\\"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,},},}\\\
- Drawing.Clear(colours.white)\\\
- Drawing.DrawImage((Drawing.Screen.Width - 11)/2, (Drawing.Screen.Height - 9)/2, splashIcon, 11, 9)\\\
- Drawing.DrawBuffer()\\\
- Drawing.Clear(colours.black)\\\
- parallel.waitForAny(function()sleep(1)end, function()os.pullEvent('mouse_click')end)\\\
- end\\\
- \\\
- function Initialise(arg)\\\
- if OneOS then\\\
- fs = OneOS.FS\\\
- end\\\
- \\\
- if not OneOS then\\\
- SplashScreen()\\\
- end\\\
- EventRegister('mouse_click', TryClick)\\\
- EventRegister('mouse_drag', function(event, side, x, y)TryClick(event, side, x, y, true)end)\\\
- EventRegister('mouse_scroll', Scroll)\\\
- EventRegister('key', HandleKey)\\\
- EventRegister('char', HandleKey)\\\
- EventRegister('timer', Timer)\\\
- EventRegister('terminate', function(event) if Close() then error( \\\"Terminated\\\", 0 ) end end)\\\
- \\\
- LoadMenuBar()\\\
- \\\
- --Current.Document = Document:Initialise('abcdefghijklmnopqrtuvwxy')--'Hello everybody!')\\\
- if tArgs[1] then\\\
- if fs.exists(tArgs[1]) then\\\
- OpenDocument(tArgs[1])\\\
- else\\\
- --new\\\
- end\\\
- else\\\
- Current.Document = Document:Initialise('')--'Hello everybody!')\\\
- end\\\
- \\\
- --[[\\\
- if arg and fs.exists(arg) then\\\
- OpenDocument(arg)\\\
- else\\\
- DisplayNewDocumentWindow()\\\
- end\\\
- ]]--\\\
- Draw()\\\
- \\\
- EventHandler()\\\
- end\\\
- \\\
- local isControlPushed = false\\\
- controlPushedTimer = nil\\\
- closeWindowTimer = nil\\\
- function Timer(event, timer)\\\
- if timer == closeWindowTimer then\\\
- if Current.Window then\\\
- Current.Window:Close()\\\
- end\\\
- Draw()\\\
- elseif timer == controlPushedTimer then\\\
- isControlPushed = false\\\
- end\\\
- end\\\
- \\\
- local ignoreNextChar = false\\\
- function HandleKey(...)\\\
- local args = {...}\\\
- local event = args[1]\\\
- local keychar = args[2]\\\
- --Mac left command character\\\
- if event == 'key' and keychar == keys.leftCtrl or keychar == keys.rightCtrl or keychar == 219 then\\\
- isControlPushed = true\\\
- controlPushedTimer = os.startTimer(0.5)\\\
- elseif isControlPushed then\\\
- if event == 'key' then\\\
- if CheckKeyboardShortcut(keychar) then\\\
- isControlPushed = false\\\
- ignoreNextChar = true\\\
- end\\\
- end\\\
- elseif ignoreNextChar then\\\
- ignoreNextChar = false\\\
- elseif Current.TextInput then\\\
- if event == 'char' then\\\
- Current.TextInput:Char(keychar)\\\
- elseif event == 'key' then\\\
- Current.TextInput:Key(keychar)\\\
- end\\\
- end\\\
- end\\\
- \\\
- function CheckKeyboardShortcut(key)\\\
- local shortcuts = {}\\\
- shortcuts[keys.n] = function() Current.Document = Document:Initialise('') end\\\
- shortcuts[keys.o] = function() DisplayOpenDocumentWindow() end\\\
- shortcuts[keys.s] = function() if Current.Document ~= nil then SaveDocument() end end\\\
- shortcuts[keys.left] = function() if Current.TextInput then Current.TextInput:Key(keys.home) end end\\\
- shortcuts[keys.right] = function() if Current.TextInput then Current.TextInput:Key(keys[\\\"end\\\"]) end end\\\
- -- shortcuts[keys.q] = function() DisplayOpenDocumentWindow() end\\\
- if Current.Document ~= nil then\\\
- shortcuts[keys.s] = function() SaveDocument() end\\\
- shortcuts[keys.p] = function() PrintDocument() end\\\
- if Current.Selection and Current.Selection[1] and Current.Selection[2] ~= nil then\\\
- shortcuts[keys.x] = function() Clipboard.Cut(Current.Document.TextInput:Extract(true), 'text') end\\\
- shortcuts[keys.c] = function() Clipboard.Copy(Current.Document.TextInput:Extract(), 'text') end\\\
- end\\\
- if (not Clipboard.isEmpty()) and Clipboard.Type == 'text' then\\\
- shortcuts[keys.v] = function() local paste = Clipboard.Paste()\\\
- Current.Document.TextInput:Insert(paste)\\\
- Current.Document.TextInput.CursorPos = Current.Document.TextInput.CursorPos + #paste - 1\\\
- end\\\
- end\\\
- shortcuts[keys.a] = function() Current.Selection = {1, #Current.Document.TextInput.Value:gsub('\\\\n','')} end\\\
- end\\\
- \\\
- if shortcuts[key] then\\\
- shortcuts[key]()\\\
- Draw()\\\
- return true\\\
- else\\\
- return false\\\
- end\\\
- end\\\
- \\\
- --[[\\\
- Check if the given object falls under the click coordinates\\\
- ]]--\\\
- function CheckClick(object, x, y)\\\
- if object.X <= x and object.Y <= y and object.X + object.Width > x and object.Y + object.Height > y then\\\
- return true\\\
- end\\\
- end\\\
- \\\
- --[[\\\
- Attempt to clicka given object\\\
- ]]--\\\
- function DoClick(object, side, x, y, drag)\\\
- local obj = GetAbsolutePosition(object)\\\
- obj.Width = object.Width\\\
- obj.Height = object.Height\\\
- if object and CheckClick(obj, x, y) then\\\
- return object:Click(side, x - object.X + 1, y - object.Y + 1, drag)\\\
- end \\\
- end\\\
- \\\
- --[[\\\
- Try to click at the given coordinates\\\
- ]]--\\\
- function TryClick(event, side, x, y, drag)\\\
- if Current.Menu then\\\
- if DoClick(Current.Menu, side, x, y, drag) then\\\
- Draw()\\\
- return\\\
- else\\\
- if Current.Menu.Owner and Current.Menu.Owner.Toggle then\\\
- Current.Menu.Owner.Toggle = false\\\
- end\\\
- Current.Menu = nil\\\
- Draw()\\\
- return\\\
- end\\\
- elseif Current.Window then\\\
- if DoClick(Current.Window, side, x, y, drag) then\\\
- Draw()\\\
- return\\\
- else\\\
- Current.Window:Flash()\\\
- return\\\
- end\\\
- end\\\
- local interfaceElements = {}\\\
- \\\
- table.insert(interfaceElements, Current.MenuBar)\\\
- table.insert(interfaceElements, Current.ScrollBar)\\\
- for i, page in ipairs(Current.Document.Pages) do\\\
- table.insert(interfaceElements, page)\\\
- end\\\
- \\\
- for i, object in ipairs(interfaceElements) do\\\
- if DoClick(object, side, x, y, drag) then\\\
- Draw()\\\
- return\\\
- end \\\
- end\\\
- Draw()\\\
- end\\\
- \\\
- function Scroll(event, direction, x, y)\\\
- if Current.Window and Current.Window.OpenButton then\\\
- Current.Document.Scroll = Current.Document.Scroll + direction\\\
- if Current.Window.Scroll < 0 then\\\
- Current.Window.Scroll = 0\\\
- elseif Current.Window.Scroll > Current.Window.MaxScroll then\\\
- Current.Window.Scroll = Current.Window.MaxScroll\\\
- end\\\
- Draw()\\\
- elseif Current.ScrollBar then\\\
- if Current.ScrollBar:DoScroll(direction*2) then\\\
- Draw()\\\
- end\\\
- end\\\
- end\\\
- \\\
- \\\
- --[[\\\
- Registers functions to run on certain events\\\
- ]]--\\\
- function EventRegister(event, func)\\\
- if not Events[event] then\\\
- Events[event] = {}\\\
- end\\\
- \\\
- table.insert(Events[event], func)\\\
- end\\\
- \\\
- --[[\\\
- The main loop event handler, runs registered event functinos\\\
- ]]--\\\
- function EventHandler()\\\
- while true do\\\
- local event, arg1, arg2, arg3, arg4 = os.pullEventRaw()\\\
- if Events[event] then\\\
- for i, e in ipairs(Events[event]) do\\\
- e(event, arg1, arg2, arg3, arg4)\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- \\\
- local function Extension(path, addDot)\\\
- if not path then\\\
- return nil\\\
- elseif not string.find(fs.getName(path), '%.') then\\\
- if not addDot then\\\
- return fs.getName(path)\\\
- else\\\
- return ''\\\
- end\\\
- else\\\
- local _path = path\\\
- if path:sub(#path) == '/' then\\\
- _path = path:sub(1,#path-1)\\\
- end\\\
- local extension = _path:gmatch('%.[0-9a-z]+$')()\\\
- if extension then\\\
- extension = extension:sub(2)\\\
- else\\\
- --extension = nil\\\
- return ''\\\
- end\\\
- if addDot then\\\
- extension = '.'..extension\\\
- end\\\
- return extension:lower()\\\
- end\\\
- end\\\
- \\\
- local RemoveExtension = function(path)\\\
- if path:sub(1,1) == '.' then\\\
- return path\\\
- end\\\
- local extension = Extension(path)\\\
- if extension == path then\\\
- return fs.getName(path)\\\
- end\\\
- return string.gsub(path, extension, ''):sub(1, -2)\\\
- end\\\
- \\\
- local acknowledgedColour = false\\\
- function PrintDocument()\\\
- if OneOS then\\\
- OneOS.LoadAPI('/System/API/Helpers.lua')\\\
- OneOS.LoadAPI('/System/API/Peripheral.lua')\\\
- OneOS.LoadAPI('/System/API/Printer.lua')\\\
- end\\\
- \\\
- local doPrint = function()\\\
- local window = PrintDocumentWindow:Initialise():Show()\\\
- end\\\
- \\\
- if Peripheral.GetPeripheral('printer') == nil then\\\
- 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)\\\
- window:Close()\\\
- end):Show()\\\
- elseif not acknowledgedColour and FindColours(Current.Document.TextInput.Value) ~= 0 then\\\
- 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)\\\
- acknowledgedColour = true\\\
- window:Close()\\\
- doPrint()\\\
- end):Show()\\\
- else\\\
- doPrint()\\\
- end\\\
- end\\\
- \\\
- function SaveDocument()\\\
- local function save()\\\
- local h = fs.open(Current.Document.Path, 'w')\\\
- if h then\\\
- if Current.Document.Format == TextFormatPlainText then\\\
- h.write(Current.Document.TextInput.Value)\\\
- else\\\
- local lines = {}\\\
- for p, page in ipairs(Current.Document.Pages) do\\\
- for i, line in ipairs(page.Lines) do\\\
- table.insert(lines, line)\\\
- end\\\
- end\\\
- h.write(textutils.serialize(lines))\\\
- end\\\
- Current.Modified = false\\\
- else\\\
- ButtonDialougeWindow:Initialise('Error', 'An error occured while saving the file, try again.', 'Ok', nil, function(window, ok)\\\
- window:Close()\\\
- end):Show()\\\
- end\\\
- h.close()\\\
- end\\\
- \\\
- if not Current.Document.Path then\\\
- SaveDocumentWindow:Initialise(function(self, success, path)\\\
- self:Close()\\\
- if success then\\\
- local extension = ''\\\
- if Current.Document.Format == TextFormatPlainText then\\\
- extension = '.txt'\\\
- elseif Current.Document.Format == TextFormatInkText then\\\
- extension = '.ink'\\\
- end\\\
- \\\
- if path:sub(-4) ~= extension then\\\
- path = path .. extension\\\
- end\\\
- \\\
- Current.Document.Path = path\\\
- Current.Document.Title = fs.getName(path)\\\
- save()\\\
- end\\\
- if Current.Document then\\\
- Current.TextInput = Current.Document.TextInput\\\
- end\\\
- end):Show()\\\
- else\\\
- save()\\\
- end\\\
- end\\\
- \\\
- function DisplayOpenDocumentWindow()\\\
- OpenDocumentWindow:Initialise(function(self, success, path)\\\
- self:Close()\\\
- if success then\\\
- OpenDocument(path)\\\
- end\\\
- end):Show()\\\
- end\\\
- \\\
- function OpenDocument(path)\\\
- Current.Selection = nil\\\
- local h = fs.open(path, 'r')\\\
- if h then\\\
- Current.Document = Document:Initialise(h.readAll(), RemoveExtension(fs.getName(path)), path)\\\
- else\\\
- ButtonDialougeWindow:Initialise('Error', 'An error occured while opening the file, try again.', 'Ok', nil, function(window, ok)\\\
- window:Close()\\\
- if Current.Document then\\\
- Current.TextInput = Current.Document.TextInput\\\
- end\\\
- end):Show()\\\
- end\\\
- h.close()\\\
- end\\\
- \\\
- local TidyPath = function(path)\\\
- path = '/'..path\\\
- local fs = fs\\\
- if OneOS then\\\
- fs = OneOS.FS\\\
- end\\\
- if fs.isDir(path) then\\\
- path = path .. '/'\\\
- end\\\
- \\\
- path, n = path:gsub(\\\"//\\\", \\\"/\\\")\\\
- while n > 0 do\\\
- path, n = path:gsub(\\\"//\\\", \\\"/\\\")\\\
- end\\\
- return path\\\
- end\\\
- \\\
- OpenDocumentWindow = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 0,\\\
- Height = 0,\\\
- CursorPos = 1,\\\
- Visible = true,\\\
- Return = nil,\\\
- OpenButton = nil,\\\
- PathTextBox = nil,\\\
- CurrentDirectory = '/',\\\
- Scroll = 0,\\\
- MaxScroll = 0,\\\
- GoUpButton = nil,\\\
- SelectedFile = '',\\\
- Files = {},\\\
- Typed = false,\\\
- \\\
- AbsolutePosition = function(self)\\\
- return {X = self.X, Y = self.Y}\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- if not self.Visible then\\\
- return\\\
- end\\\
- Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
- Drawing.DrawBlankArea(self.X, self.Y, self.Width, 3, colours.lightGrey)\\\
- Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-6, colours.white)\\\
- Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
- Drawing.DrawBlankArea(self.X, self.Y + self.Height - 5, self.Width, 5, colours.lightGrey)\\\
- self:DrawFiles()\\\
- \\\
- if (fs.exists(self.PathTextBox.TextInput.Value)) or (self.SelectedFile and #self.SelectedFile > 0 and fs.exists(self.CurrentDirectory .. self.SelectedFile)) then\\\
- self.OpenButton.TextColour = colours.black\\\
- else\\\
- self.OpenButton.TextColour = colours.lightGrey\\\
- end\\\
- \\\
- self.PathTextBox:Draw()\\\
- self.OpenButton:Draw()\\\
- self.CancelButton:Draw()\\\
- self.GoUpButton:Draw()\\\
- end,\\\
- \\\
- DrawFiles = function(self)\\\
- for i, file in ipairs(self.Files) do\\\
- if i > self.Scroll and i - self.Scroll <= 11 then\\\
- if file == self.SelectedFile then\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.white, colours.lightBlue)\\\
- elseif string.find(file, '%.txt') or string.find(file, '%.text') or string.find(file, '%.ink') or fs.isDir(self.CurrentDirectory .. file) then\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.black, colours.white)\\\
- else\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.grey, colours.white)\\\
- end\\\
- end\\\
- end\\\
- self.MaxScroll = #self.Files - 11\\\
- if self.MaxScroll < 0 then\\\
- self.MaxScroll = 0\\\
- end\\\
- end,\\\
- \\\
- Initialise = function(self, returnFunc)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Width = 32\\\
- new.Height = 17\\\
- new.Return = returnFunc\\\
- new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
- new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
- new.Title = 'Open Document'\\\
- new.Visible = true\\\
- new.CurrentDirectory = '/'\\\
- new.SelectedFile = nil\\\
- if OneOS and fs.exists('/Desktop/Documents/') then\\\
- new.CurrentDirectory = '/Desktop/Documents/'\\\
- end\\\
- new.OpenButton = Button:Initialise(new.Width - 6, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
- if fs.exists(new.PathTextBox.TextInput.Value) and self.TextColour == colours.black and not fs.isDir(new.PathTextBox.TextInput.Value) then\\\
- returnFunc(new, true, TidyPath(new.PathTextBox.TextInput.Value))\\\
- elseif new.SelectedFile and self.TextColour == colours.black and fs.isDir(new.CurrentDirectory .. new.SelectedFile) then\\\
- new:GoToDirectory(new.CurrentDirectory .. new.SelectedFile)\\\
- elseif new.SelectedFile and self.TextColour == colours.black then\\\
- returnFunc(new, true, TidyPath(new.CurrentDirectory .. '/' .. new.SelectedFile))\\\
- end\\\
- end, 'Open', colours.black)\\\
- new.CancelButton = Button:Initialise(new.Width - 15, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
- returnFunc(new, false)\\\
- end, 'Cancel', colours.black)\\\
- new.GoUpButton = Button:Initialise(2, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
- local folderName = fs.getName(new.CurrentDirectory)\\\
- local parentDirectory = new.CurrentDirectory:sub(1, #new.CurrentDirectory-#folderName-1)\\\
- new:GoToDirectory(parentDirectory)\\\
- end, 'Go Up', colours.black)\\\
- new.PathTextBox = TextBox:Initialise(2, new.Height - 3, new.Width - 2, 1, new, new.CurrentDirectory, colours.white, colours.black)\\\
- new:GoToDirectory(new.CurrentDirectory)\\\
- return new\\\
- end,\\\
- \\\
- Show = function(self)\\\
- Current.Window = self\\\
- return self\\\
- end,\\\
- \\\
- Close = function(self)\\\
- Current.Input = nil\\\
- Current.Window = nil\\\
- self = nil\\\
- end,\\\
- \\\
- GoToDirectory = function(self, path)\\\
- path = TidyPath(path)\\\
- self.CurrentDirectory = path\\\
- self.Scroll = 0\\\
- self.SelectedFile = nil\\\
- self.Typed = false\\\
- self.PathTextBox.TextInput.Value = path\\\
- local fs = fs\\\
- if OneOS then\\\
- fs = OneOS.FS\\\
- end\\\
- self.Files = fs.list(self.CurrentDirectory)\\\
- Draw()\\\
- end,\\\
- \\\
- Flash = function(self)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- local items = {self.OpenButton, self.CancelButton, self.PathTextBox, self.GoUpButton}\\\
- local found = false\\\
- for i, v in ipairs(items) do\\\
- if CheckClick(v, x, y) then\\\
- v:Click(side, x, y)\\\
- found = true\\\
- end\\\
- end\\\
- \\\
- if not found then\\\
- if y <= 12 then\\\
- local fs = fs\\\
- if OneOS then\\\
- fs = OneOS.FS\\\
- end\\\
- self.SelectedFile = fs.list(self.CurrentDirectory)[y-1]\\\
- self.PathTextBox.TextInput.Value = TidyPath(self.CurrentDirectory .. '/' .. self.SelectedFile)\\\
- Draw()\\\
- end\\\
- end\\\
- return true\\\
- end\\\
- }\\\
- \\\
- PrintDocumentWindow = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 0,\\\
- Height = 0,\\\
- CursorPos = 1,\\\
- Visible = true,\\\
- Return = nil,\\\
- PrintButton = nil,\\\
- CopiesTextBox = nil,\\\
- Scroll = 0,\\\
- MaxScroll = 0,\\\
- PrinterSelectButton = nil,\\\
- Title = '',\\\
- Status = 0, --0 = neutral, 1 = good, -1 = error\\\
- StatusText = '',\\\
- SelectedPrinter = nil,\\\
- \\\
- AbsolutePosition = function(self)\\\
- return {X = self.X, Y = self.Y}\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- if not self.Visible then\\\
- return\\\
- end\\\
- Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
- Drawing.DrawBlankArea(self.X, self.Y, self.Width, 1, colours.lightGrey)\\\
- Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-1, colours.white)\\\
- Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
- \\\
- self.PrinterSelectButton:Draw()\\\
- Drawing.DrawCharactersCenter(self.X, self.Y + self.PrinterSelectButton.Y - 2, self.Width, 1, 'Printer', colours.black, colours.white)\\\
- Drawing.DrawCharacters(self.X + self.Width - 3, self.Y + self.PrinterSelectButton.Y - 1, '\\\\\\\\/', colours.black, colours.lightGrey)\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + self.CopiesTextBox.Y - 1, 'Copies', colours.black, colours.white)\\\
- local statusColour = colours.grey\\\
- if self.Status == -1 then\\\
- statusColour = colours.red\\\
- elseif self.Status == 1 then\\\
- statusColour = colours.green\\\
- end\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + self.CopiesTextBox.Y + 1, self.StatusText, statusColour, colours.white)\\\
- \\\
- self.CopiesTextBox:Draw()\\\
- self.PrintButton:Draw()\\\
- self.CancelButton:Draw()\\\
- end,\\\
- \\\
- Initialise = function(self)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Width = 32\\\
- new.Height = 11\\\
- new.Return = returnFunc\\\
- new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
- new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
- new.Title = 'Print Document'\\\
- new.Visible = true\\\
- new.PrintButton = Button:Initialise(new.Width - 7, new.Height - 1, nil, nil, colours.lightGrey, new, function(self, side, x, y, toggle)\\\
- local doPrint = true\\\
- if new.SelectedPrinter == nil then\\\
- local p = Peripheral.GetPeripheral('printer')\\\
- if p then\\\
- new.SelectedPrinter = p.Side\\\
- new.PrinterSelectButton.Text = p.Fullname\\\
- else\\\
- new.StatusText = 'No Connected Printer'\\\
- new.Status = -1\\\
- doPrint = false\\\
- end\\\
- end\\\
- if doPrint then\\\
- local printer = Printer:Initialise(new.SelectedPrinter)\\\
- local err = printer:PrintLines(Current.Document.Lines, Current.Document.Title, tonumber(new.CopiesTextBox.TextInput.Value))\\\
- if not err then\\\
- new.StatusText = 'Document Printed!'\\\
- new.Status = 1\\\
- closeWindowTimer = os.startTimer(1)\\\
- else\\\
- new.StatusText = err\\\
- new.Status = -1\\\
- end\\\
- end\\\
- end, 'Print', colours.black)\\\
- new.CancelButton = Button:Initialise(new.Width - 15, new.Height - 1, nil, nil, colours.lightGrey, new, function(self, side, x, y, toggle)\\\
- new:Close()\\\
- Draw()\\\
- end, 'Close', colours.black)\\\
- new.PrinterSelectButton = Button:Initialise(2, 4, new.Width - 2, nil, colours.lightGrey, new, function(self, side, x, y, toggle)\\\
- local printers = {\\\
- {\\\
- Title = \\\"Automatic\\\",\\\
- Click = function()\\\
- new.SelectedPrinter = nil\\\
- new.PrinterSelectButton.Text = 'Automatic'\\\
- end\\\
- },\\\
- {\\\
- Separator = true\\\
- }\\\
- }\\\
- for i, p in ipairs(Peripheral.GetPeripherals('printer')) do\\\
- table.insert(printers, {\\\
- Title = p.Fullname,\\\
- Click = function(self)\\\
- new.SelectedPrinter = p.Side\\\
- new.PrinterSelectButton.Text = p.Fullname\\\
- end\\\
- })\\\
- end\\\
- Current.Menu = Menu:New(x, y+4, printers, self, true)\\\
- end, 'Automatic', colours.black)\\\
- new.CopiesTextBox = TextBox:Initialise(9, 6, 4, 1, new, 1, colours.lightGrey, colours.black, nil, true)\\\
- Current.TextInput = new.CopiesTextBox.TextInput\\\
- new.StatusText = 'Waiting...'\\\
- new.Status = 0\\\
- return new\\\
- end,\\\
- \\\
- Show = function(self)\\\
- Current.Window = self\\\
- return self\\\
- end,\\\
- \\\
- Close = function(self)\\\
- Current.Input = nil\\\
- Current.Window = nil\\\
- self = nil\\\
- end,\\\
- \\\
- Flash = function(self)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- local items = {self.PrintButton, self.CancelButton, self.CopiesTextBox, self.PrinterSelectButton}\\\
- for i, v in ipairs(items) do\\\
- if CheckClick(v, x, y) then\\\
- v:Click(side, x, y)\\\
- end\\\
- end\\\
- return true\\\
- end\\\
- }\\\
- \\\
- SaveDocumentWindow = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 0,\\\
- Height = 0,\\\
- CursorPos = 1,\\\
- Visible = true,\\\
- Return = nil,\\\
- SaveButton = nil,\\\
- PathTextBox = nil,\\\
- CurrentDirectory = '/',\\\
- Scroll = 0,\\\
- MaxScroll = 0,\\\
- ScrollBar = nil,\\\
- GoUpButton = nil,\\\
- Files = {},\\\
- Typed = false,\\\
- \\\
- AbsolutePosition = function(self)\\\
- return {X = self.X, Y = self.Y}\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- if not self.Visible then\\\
- return\\\
- end\\\
- Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
- Drawing.DrawBlankArea(self.X, self.Y, self.Width, 3, colours.lightGrey)\\\
- Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-6, colours.white)\\\
- Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
- Drawing.DrawBlankArea(self.X, self.Y + self.Height - 5, self.Width, 5, colours.lightGrey)\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + self.Height - 5, self.CurrentDirectory, colours.grey, colours.lightGrey)\\\
- self:DrawFiles()\\\
- \\\
- if (self.PathTextBox.TextInput.Value) then\\\
- self.SaveButton.TextColour = colours.black\\\
- else\\\
- self.SaveButton.TextColour = colours.lightGrey\\\
- end\\\
- \\\
- self.PathTextBox:Draw()\\\
- self.SaveButton:Draw()\\\
- self.CancelButton:Draw()\\\
- self.GoUpButton:Draw()\\\
- end,\\\
- \\\
- DrawFiles = function(self)\\\
- for i, file in ipairs(self.Files) do\\\
- if i > self.Scroll and i - self.Scroll <= 10 then\\\
- if file == self.SelectedFile then\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.white, colours.lightBlue)\\\
- elseif fs.isDir(self.CurrentDirectory .. file) then\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.black, colours.white)\\\
- else\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + i - self.Scroll, file, colours.lightGrey, colours.white)\\\
- end\\\
- end\\\
- end\\\
- self.MaxScroll = #self.Files - 11\\\
- if self.MaxScroll < 0 then\\\
- self.MaxScroll = 0\\\
- end\\\
- end,\\\
- \\\
- Initialise = function(self, returnFunc)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Width = 32\\\
- new.Height = 16\\\
- new.Return = returnFunc\\\
- new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
- new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
- new.Title = 'Save Document'\\\
- new.Visible = true\\\
- new.CurrentDirectory = '/'\\\
- if OneOS and fs.exists('/Desktop/Documents/') then\\\
- new.CurrentDirectory = '/Desktop/Documents/'\\\
- end\\\
- new.SaveButton = Button:Initialise(new.Width - 6, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
- if self.TextColour == colours.black and not fs.isDir(new.CurrentDirectory ..'/' .. new.PathTextBox.TextInput.Value) then\\\
- returnFunc(new, true, TidyPath(new.CurrentDirectory ..'/' .. new.PathTextBox.TextInput.Value))\\\
- elseif new.SelectedFile and self.TextColour == colours.black and fs.isDir(new.CurrentDirectory .. new.SelectedFile) then\\\
- new:GoToDirectory(new.CurrentDirectory .. new.SelectedFile)\\\
- end\\\
- end, 'Save', colours.black)\\\
- new.CancelButton = Button:Initialise(new.Width - 15, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
- returnFunc(new, false)\\\
- end, 'Cancel', colours.black)\\\
- new.GoUpButton = Button:Initialise(2, new.Height - 1, nil, nil, colours.white, new, function(self, side, x, y, toggle)\\\
- local folderName = fs.getName(new.CurrentDirectory)\\\
- local parentDirectory = new.CurrentDirectory:sub(1, #new.CurrentDirectory-#folderName-1)\\\
- new:GoToDirectory(parentDirectory)\\\
- end, 'Go Up', colours.black)\\\
- new.PathTextBox = TextBox:Initialise(2, new.Height - 3, new.Width - 2, 1, new, '', colours.white, colours.black, function(key)\\\
- if key == keys.enter then\\\
- new.SaveButton:Click()\\\
- end\\\
- end)\\\
- new.PathTextBox.Placeholder = 'Document Name'\\\
- Current.TextInput = new.PathTextBox.TextInput\\\
- new:GoToDirectory(new.CurrentDirectory)\\\
- return new\\\
- end,\\\
- \\\
- Show = function(self)\\\
- Current.Window = self\\\
- return self\\\
- end,\\\
- \\\
- Close = function(self)\\\
- Current.Input = nil\\\
- Current.Window = nil\\\
- self = nil\\\
- end,\\\
- \\\
- GoToDirectory = function(self, path)\\\
- path = TidyPath(path)\\\
- self.CurrentDirectory = path\\\
- self.Scroll = 0\\\
- self.Typed = false\\\
- local fs = fs\\\
- if OneOS then\\\
- fs = OneOS.FS\\\
- end\\\
- self.Files = fs.list(self.CurrentDirectory)\\\
- Draw()\\\
- end,\\\
- \\\
- Flash = function(self)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- local items = {self.SaveButton, self.CancelButton, self.PathTextBox, self.GoUpButton}\\\
- local found = false\\\
- for i, v in ipairs(items) do\\\
- if CheckClick(v, x, y) then\\\
- v:Click(side, x, y)\\\
- found = true\\\
- end\\\
- end\\\
- \\\
- if not found then\\\
- if y <= 11 then\\\
- local files = fs.list(self.CurrentDirectory)\\\
- if files[y-1] then\\\
- self:GoToDirectory(self.CurrentDirectory..files[y-1])\\\
- Draw()\\\
- end\\\
- end\\\
- end\\\
- return true\\\
- end\\\
- }\\\
- \\\
- local WrapText = function(text, maxWidth)\\\
- local lines = {''}\\\
- for word, space in text:gmatch('(%S+)(%s*)') do\\\
- local temp = lines[#lines] .. word .. space:gsub('\\\\n','')\\\
- if #temp > maxWidth then\\\
- table.insert(lines, '')\\\
- end\\\
- if space:find('\\\\n') then\\\
- lines[#lines] = lines[#lines] .. word\\\
- \\\
- space = space:gsub('\\\\n', function()\\\
- table.insert(lines, '')\\\
- return ''\\\
- end)\\\
- else\\\
- lines[#lines] = lines[#lines] .. word .. space\\\
- end\\\
- end\\\
- return lines\\\
- end\\\
- \\\
- ButtonDialougeWindow = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 0,\\\
- Height = 0,\\\
- CursorPos = 1,\\\
- Visible = true,\\\
- CancelButton = nil,\\\
- OkButton = nil,\\\
- Lines = {},\\\
- \\\
- AbsolutePosition = function(self)\\\
- return {X = self.X, Y = self.Y}\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- if not self.Visible then\\\
- return\\\
- end\\\
- Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
- Drawing.DrawBlankArea(self.X, self.Y, self.Width, 1, colours.lightGrey)\\\
- Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-1, colours.white)\\\
- Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
- \\\
- for i, text in ipairs(self.Lines) do\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + 1 + i, text, colours.black, colours.white)\\\
- end\\\
- \\\
- self.OkButton:Draw()\\\
- if self.CancelButton then\\\
- self.CancelButton:Draw()\\\
- end\\\
- end,\\\
- \\\
- Initialise = function(self, title, message, okText, cancelText, returnFunc)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Width = 28\\\
- new.Lines = WrapText(message, new.Width - 2)\\\
- new.Height = 5 + #new.Lines\\\
- new.Return = returnFunc\\\
- new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
- new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
- new.Title = title\\\
- new.Visible = true\\\
- new.Visible = true\\\
- new.OkButton = Button:Initialise(new.Width - #okText - 2, new.Height - 1, nil, 1, nil, new, function()\\\
- returnFunc(new, true)\\\
- end, okText)\\\
- if cancelText then\\\
- new.CancelButton = Button:Initialise(new.Width - #okText - 2 - 1 - #cancelText - 2, new.Height - 1, nil, 1, nil, new, function()\\\
- returnFunc(new, false)\\\
- end, cancelText)\\\
- end\\\
- \\\
- return new\\\
- end,\\\
- \\\
- Show = function(self)\\\
- Current.Window = self\\\
- return self\\\
- end,\\\
- \\\
- Close = function(self)\\\
- Current.Window = nil\\\
- self = nil\\\
- end,\\\
- \\\
- Flash = function(self)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- local items = {self.OkButton, self.CancelButton}\\\
- local found = false\\\
- for i, v in ipairs(items) do\\\
- if CheckClick(v, x, y) then\\\
- v:Click(side, x, y)\\\
- found = true\\\
- end\\\
- end\\\
- return true\\\
- end\\\
- }\\\
- \\\
- TextDialougeWindow = {\\\
- X = 1,\\\
- Y = 1,\\\
- Width = 0,\\\
- Height = 0,\\\
- CursorPos = 1,\\\
- Visible = true,\\\
- CancelButton = nil,\\\
- OkButton = nil,\\\
- Lines = {},\\\
- TextInput = nil,\\\
- \\\
- AbsolutePosition = function(self)\\\
- return {X = self.X, Y = self.Y}\\\
- end,\\\
- \\\
- Draw = function(self)\\\
- if not self.Visible then\\\
- return\\\
- end\\\
- Drawing.DrawBlankArea(self.X + 1, self.Y+1, self.Width, self.Height, colours.grey)\\\
- Drawing.DrawBlankArea(self.X, self.Y, self.Width, 1, colours.lightGrey)\\\
- Drawing.DrawBlankArea(self.X, self.Y+1, self.Width, self.Height-1, colours.white)\\\
- Drawing.DrawCharactersCenter(self.X, self.Y, self.Width, 1, self.Title, colours.black, colours.lightGrey)\\\
- \\\
- for i, text in ipairs(self.Lines) do\\\
- Drawing.DrawCharacters(self.X + 1, self.Y + 1 + i, text, colours.black, colours.white)\\\
- end\\\
- \\\
- \\\
- Drawing.DrawBlankArea(self.X + 1, self.Y + self.Height - 4, self.Width - 2, 1, colours.lightGrey)\\\
- Drawing.DrawCharacters(self.X + 2, self.Y + self.Height - 4, self.TextInput.Value, colours.black, colours.lightGrey)\\\
- Current.CursorPos = {self.X + 2 + self.TextInput.CursorPos, self.Y + self.Height - 4}\\\
- Current.CursorColour = colours.black\\\
- \\\
- self.OkButton:Draw()\\\
- if self.CancelButton then\\\
- self.CancelButton:Draw()\\\
- end\\\
- end,\\\
- \\\
- Initialise = function(self, title, message, okText, cancelText, returnFunc, numerical)\\\
- local new = {} -- the new instance\\\
- setmetatable( new, {__index = self} )\\\
- new.Width = 28\\\
- new.Lines = WrapText(message, new.Width - 2)\\\
- new.Height = 7 + #new.Lines\\\
- new.Return = returnFunc\\\
- new.X = math.ceil((Drawing.Screen.Width - new.Width) / 2)\\\
- new.Y = math.ceil((Drawing.Screen.Height - new.Height) / 2)\\\
- new.Title = title\\\
- new.Visible = true\\\
- new.Visible = true\\\
- new.OkButton = Button:Initialise(new.Width - #okText - 2, new.Height - 1, nil, 1, nil, new, function()\\\
- if #new.TextInput.Value > 0 then\\\
- returnFunc(new, true, new.TextInput.Value)\\\
- end\\\
- end, okText)\\\
- if cancelText then\\\
- new.CancelButton = Button:Initialise(new.Width - #okText - 2 - 1 - #cancelText - 2, new.Height - 1, nil, 1, nil, new, function()\\\
- returnFunc(new, false)\\\
- end, cancelText)\\\
- end\\\
- new.TextInput = TextInput:Initialise('', function(enter)\\\
- if enter then\\\
- new.OkButton:Click()\\\
- end\\\
- Draw()\\\
- end, numerical)\\\
- \\\
- Current.Input = new.TextInput\\\
- \\\
- return new\\\
- end,\\\
- \\\
- Show = function(self)\\\
- Current.Window = self\\\
- return self\\\
- end,\\\
- \\\
- Close = function(self)\\\
- Current.Window = nil\\\
- Current.Input = nil\\\
- self = nil\\\
- end,\\\
- \\\
- Flash = function(self)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = false\\\
- Draw()\\\
- sleep(0.15)\\\
- self.Visible = true\\\
- Draw()\\\
- end,\\\
- \\\
- Click = function(self, side, x, y)\\\
- local items = {self.OkButton, self.CancelButton}\\\
- local found = false\\\
- for i, v in ipairs(items) do\\\
- if CheckClick(v, x, y) then\\\
- v:Click(side, x, y)\\\
- found = true\\\
- end\\\
- end\\\
- return true\\\
- end\\\
- }\\\
- \\\
- function PrintCentered(text, y)\\\
- local w, h = term.getSize()\\\
- x = math.ceil(math.ceil((w / 2) - (#text / 2)), 0)+1\\\
- term.setCursorPos(x, y)\\\
- print(text)\\\
- end\\\
- \\\
- function DoVanillaClose()\\\
- shell.run(\\\"/system/apps/drawer\\\")\\\
- end\\\
- \\\
- function Close()\\\
- if isQuitting or not Current.Document or not Current.Modified then\\\
- if not OneOS then\\\
- DoVanillaClose()\\\
- end\\\
- return true\\\
- else\\\
- local _w = ButtonDialougeWindow:Initialise('Quit Ink?', 'You have unsaved changes, do you want to quit anyway?', 'Quit', 'Cancel', function(window, success)\\\
- if success then\\\
- if OneOS then\\\
- OneOS.Close(true)\\\
- else\\\
- DoVanillaClose()\\\
- end\\\
- end\\\
- window:Close()\\\
- Draw()\\\
- end):Show()\\\
- --it's hacky but it works\\\
- os.queueEvent('mouse_click', 1, _w.X, _w.Y)\\\
- return false\\\
- end\\\
- end\\\
- \\\
- if OneOS then\\\
- OneOS.CanClose = function()\\\
- return Close()\\\
- end\\\
- end\\\
- \\\
- Initialise()\",\
- path = \"/rootfs/apps/Ink.app/main\",\
- },\
- {\
- text = \" 0c-80-80-80-80-80\\\
- 08-80I80n80k80-80\\\
- 0c-80-80-80-80-80\\\
- 08-80-80-80-80-80\",\
- path = \"/rootfs/apps/Ink.app/resources/icon.png\",\
- },\
- {\
- text = \"\\\
- -- \\\
- -- Lua IDE\\\
- -- Made by GravityScore\\\
- -- \\\
- \\\
- \\\
- -- -------- Variables\\\
- \\\
- -- Version\\\
- local version = \\\"1.0\\\"\\\
- local args = {...}\\\
- \\\
- -- Editing\\\
- local w, h = term.getSize()\\\
- local tabWidth = 2\\\
- \\\
- local autosaveInterval = 20\\\
- local allowEditorEvent = true\\\
- local keyboardShortcutTimeout = 0.4\\\
- \\\
- -- Clipboard\\\
- local clipboard = nil\\\
- \\\
- -- Theme\\\
- local theme = {}\\\
- \\\
- -- Language\\\
- local languages = {}\\\
- local curLanguage = {}\\\
- \\\
- -- Events\\\
- local event_distract = \\\"luaide_distractionEvent\\\"\\\
- \\\
- -- Locations\\\
- local updateURL = \\\"https://raw.github.com/GravityScore/LuaIDE/master/luaide.lua\\\"\\\
- local ideLocation = \\\"/\\\" .. shell.getRunningProgram()\\\
- local themeLocation = \\\"/.LuaIDE-Theme\\\"\\\
- \\\
- local function isAdvanced() return term.isColor and term.isColor() end\\\
- \\\
- \\\
- -- -------- Utilities\\\
- \\\
- local function modRead(properties)\\\
- local w, h = term.getSize()\\\
- local defaults = {replaceChar = nil, history = nil, visibleLength = nil, textLength = nil, \\\
- liveUpdates = nil, exitOnKey = nil}\\\
- if not properties then properties = {} end\\\
- for k, v in pairs(defaults) do if not properties[k] then properties[k] = v end end\\\
- if properties.replaceChar then properties.replaceChar = properties.replaceChar:sub(1, 1) end\\\
- if not properties.visibleLength then properties.visibleLength = w end\\\
- \\\
- local sx, sy = term.getCursorPos()\\\
- local line = \\\"\\\"\\\
- local pos = 0\\\
- local historyPos = nil\\\
- \\\
- local function redraw(repl)\\\
- local scroll = 0\\\
- if properties.visibleLength and sx + pos > properties.visibleLength + 1 then \\\
- scroll = (sx + pos) - (properties.visibleLength + 1)\\\
- end\\\
- \\\
- term.setCursorPos(sx, sy)\\\
- local a = repl or properties.replaceChar\\\
- if a then term.write(string.rep(a, line:len() - scroll))\\\
- else term.write(line:sub(scroll + 1, -1)) end\\\
- term.setCursorPos(sx + pos - scroll, sy)\\\
- end\\\
- \\\
- local function sendLiveUpdates(event, ...)\\\
- if type(properties.liveUpdates) == \\\"function\\\" then\\\
- local ox, oy = term.getCursorPos()\\\
- local a, data = properties.liveUpdates(line, event, ...)\\\
- if a == true and data == nil then\\\
- term.setCursorBlink(false)\\\
- return line\\\
- elseif a == true and data ~= nil then\\\
- term.setCursorBlink(false)\\\
- return data\\\
- end\\\
- term.setCursorPos(ox, oy)\\\
- end\\\
- end\\\
- \\\
- term.setCursorBlink(true)\\\
- while true do\\\
- local e, but, x, y, p4, p5 = os.pullEvent()\\\
- \\\
- if e == \\\"char\\\" then\\\
- local s = false\\\
- if properties.textLength and line:len() < properties.textLength then s = true\\\
- elseif not properties.textLength then s = true end\\\
- \\\
- local canType = true\\\
- if not properties.grantPrint and properties.refusePrint then\\\
- local canTypeKeys = {}\\\
- if type(properties.refusePrint) == \\\"table\\\" then\\\
- for _, v in pairs(properties.refusePrint) do\\\
- table.insert(canTypeKeys, tostring(v):sub(1, 1))\\\
- end\\\
- elseif type(properties.refusePrint) == \\\"string\\\" then\\\
- for char in properties.refusePrint:gmatch(\\\".\\\") do\\\
- table.insert(canTypeKeys, char)\\\
- end\\\
- end\\\
- for _, v in pairs(canTypeKeys) do if but == v then canType = false end end\\\
- elseif properties.grantPrint then\\\
- canType = false\\\
- local canTypeKeys = {}\\\
- if type(properties.grantPrint) == \\\"table\\\" then\\\
- for _, v in pairs(properties.grantPrint) do\\\
- table.insert(canTypeKeys, tostring(v):sub(1, 1))\\\
- end\\\
- elseif type(properties.grantPrint) == \\\"string\\\" then\\\
- for char in properties.grantPrint:gmatch(\\\".\\\") do\\\
- table.insert(canTypeKeys, char)\\\
- end\\\
- end\\\
- for _, v in pairs(canTypeKeys) do if but == v then canType = true end end\\\
- end\\\
- \\\
- if s and canType then\\\
- line = line:sub(1, pos) .. but .. line:sub(pos + 1, -1)\\\
- pos = pos + 1\\\
- redraw()\\\
- end\\\
- elseif e == \\\"key\\\" then\\\
- if but == keys.enter then break\\\
- elseif but == keys.left then if pos > 0 then pos = pos - 1 redraw() end\\\
- elseif but == keys.right then if pos < line:len() then pos = pos + 1 redraw() end\\\
- elseif (but == keys.up or but == keys.down) and properties.history then\\\
- redraw(\\\" \\\")\\\
- if but == keys.up then\\\
- if historyPos == nil and #properties.history > 0 then \\\
- historyPos = #properties.history\\\
- elseif historyPos > 1 then \\\
- historyPos = historyPos - 1\\\
- end\\\
- elseif but == keys.down then\\\
- if historyPos == #properties.history then historyPos = nil\\\
- elseif historyPos ~= nil then historyPos = historyPos + 1 end\\\
- end\\\
- \\\
- if properties.history and historyPos then\\\
- line = properties.history[historyPos]\\\
- pos = line:len()\\\
- else\\\
- line = \\\"\\\"\\\
- pos = 0\\\
- end\\\
- \\\
- redraw()\\\
- local a = sendLiveUpdates(\\\"history\\\")\\\
- if a then return a end\\\
- elseif but == keys.backspace and pos > 0 then\\\
- redraw(\\\" \\\")\\\
- line = line:sub(1, pos - 1) .. line:sub(pos + 1, -1)\\\
- pos = pos - 1\\\
- redraw()\\\
- local a = sendLiveUpdates(\\\"delete\\\")\\\
- if a then return a end\\\
- elseif but == keys.home then\\\
- pos = 0\\\
- redraw()\\\
- elseif but == keys.delete and pos < line:len() then\\\
- redraw(\\\" \\\")\\\
- line = line:sub(1, pos) .. line:sub(pos + 2, -1)\\\
- redraw()\\\
- local a = sendLiveUpdates(\\\"delete\\\")\\\
- if a then return a end\\\
- elseif but == keys[\\\"end\\\"] then\\\
- pos = line:len()\\\
- redraw()\\\
- elseif properties.exitOnKey then \\\
- if but == properties.exitOnKey or (properties.exitOnKey == \\\"control\\\" and \\\
- (but == 29 or but == 157)) then \\\
- term.setCursorBlink(false)\\\
- return nil\\\
- end\\\
- end\\\
- end\\\
- local a = sendLiveUpdates(e, but, x, y, p4, p5)\\\
- if a then return a end\\\
- end\\\
- \\\
- term.setCursorBlink(false)\\\
- if line ~= nil then line = line:gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\") end\\\
- return line\\\
- end\\\
- \\\
- \\\
- -- -------- Themes\\\
- \\\
- local defaultTheme = {\\\
- background = \\\"gray\\\",\\\
- backgroundHighlight = \\\"lightGray\\\",\\\
- prompt = \\\"cyan\\\",\\\
- promptHighlight = \\\"lightBlue\\\",\\\
- err = \\\"red\\\",\\\
- errHighlight = \\\"pink\\\",\\\
- \\\
- editorBackground = \\\"gray\\\",\\\
- editorLineHightlight = \\\"lightBlue\\\",\\\
- editorLineNumbers = \\\"gray\\\",\\\
- editorLineNumbersHighlight = \\\"lightGray\\\",\\\
- editorError = \\\"pink\\\",\\\
- editorErrorHighlight = \\\"red\\\",\\\
- \\\
- textColor = \\\"white\\\",\\\
- conditional = \\\"yellow\\\",\\\
- constant = \\\"orange\\\",\\\
- [\\\"function\\\"] = \\\"magenta\\\",\\\
- string = \\\"red\\\",\\\
- comment = \\\"lime\\\"\\\
- }\\\
- \\\
- local normalTheme = {\\\
- background = \\\"black\\\",\\\
- backgroundHighlight = \\\"black\\\",\\\
- prompt = \\\"black\\\",\\\
- promptHighlight = \\\"black\\\",\\\
- err = \\\"black\\\",\\\
- errHighlight = \\\"black\\\",\\\
- \\\
- editorBackground = \\\"black\\\",\\\
- editorLineHightlight = \\\"black\\\",\\\
- editorLineNumbers = \\\"black\\\",\\\
- editorLineNumbersHighlight = \\\"white\\\",\\\
- editorError = \\\"black\\\",\\\
- editorErrorHighlight = \\\"black\\\",\\\
- \\\
- textColor = \\\"white\\\",\\\
- conditional = \\\"white\\\",\\\
- constant = \\\"white\\\",\\\
- [\\\"function\\\"] = \\\"white\\\",\\\
- string = \\\"white\\\",\\\
- comment = \\\"white\\\"\\\
- }\\\
- \\\
- local availableThemes = {\\\
- {\\\"Water (Default)\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/default.txt\\\"},\\\
- {\\\"Fire\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/fire.txt\\\"},\\\
- {\\\"Sublime Text 2\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/st2.txt\\\"},\\\
- {\\\"Midnight\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/midnight.txt\\\"},\\\
- {\\\"TheOriginalBIT\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/bit.txt\\\"},\\\
- {\\\"Superaxander\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/superaxander.txt\\\"},\\\
- {\\\"Forest\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/forest.txt\\\"},\\\
- {\\\"Night\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/night.txt\\\"},\\\
- {\\\"Original\\\", \\\"https://raw.github.com/GravityScore/LuaIDE/master/themes/original.txt\\\"},\\\
- }\\\
- \\\
- local function loadTheme(path)\\\
- local f = io.open(path)\\\
- local l = f:read(\\\"*l\\\")\\\
- local config = {}\\\
- while l ~= nil do\\\
- local k, v = string.match(l, \\\"^(%a+)=(%a+)\\\")\\\
- if k and v then config[k] = v end\\\
- l = f:read(\\\"*l\\\")\\\
- end\\\
- f:close()\\\
- return config\\\
- end\\\
- \\\
- -- Load Theme\\\
- if isAdvanced() then theme = defaultTheme\\\
- else theme = normalTheme end\\\
- \\\
- \\\
- -- -------- Drawing\\\
- \\\
- local function centerPrint(text, ny)\\\
- if type(text) == \\\"table\\\" then for _, v in pairs(text) do centerPrint(v) end\\\
- else\\\
- local x, y = term.getCursorPos()\\\
- local w, h = term.getSize()\\\
- term.setCursorPos(w/2 - text:len()/2 + (#text % 2 == 0 and 1 or 0), ny or y)\\\
- print(text)\\\
- end\\\
- end\\\
- \\\
- local function title(t)\\\
- term.setTextColor(colors[theme.textColor])\\\
- term.setBackgroundColor(colors[theme.background])\\\
- term.clear()\\\
- \\\
- term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
- for i = 2, 4 do term.setCursorPos(1, i) term.clearLine() end\\\
- term.setCursorPos(3, 3)\\\
- term.write(t)\\\
- end\\\
- \\\
- local function centerRead(wid, begt)\\\
- local function liveUpdate(line, e, but, x, y, p4, p5)\\\
- if isAdvanced() and e == \\\"mouse_click\\\" and x >= w/2 - wid/2 and x <= w/2 - wid/2 + 10 \\\
- and y >= 13 and y <= 15 then\\\
- return true, \\\"\\\"\\\
- end\\\
- end\\\
- \\\
- if not begt then begt = \\\"\\\" end\\\
- term.setTextColor(colors[theme.textColor])\\\
- term.setBackgroundColor(colors[theme.promptHighlight])\\\
- for i = 8, 10 do\\\
- term.setCursorPos(w/2 - wid/2, i)\\\
- term.write(string.rep(\\\" \\\", wid))\\\
- end\\\
- \\\
- if isAdvanced() then\\\
- term.setBackgroundColor(colors[theme.errHighlight])\\\
- for i = 13, 15 do\\\
- term.setCursorPos(w/2 - wid/2 + 1, i)\\\
- term.write(string.rep(\\\" \\\", 10))\\\
- end\\\
- term.setCursorPos(w/2 - wid/2 + 2, 14)\\\
- term.write(\\\"> Cancel\\\")\\\
- end\\\
- \\\
- term.setBackgroundColor(colors[theme.promptHighlight])\\\
- term.setCursorPos(w/2 - wid/2 + 1, 9)\\\
- term.write(\\\"> \\\" .. begt)\\\
- return modRead({visibleLength = w/2 + wid/2, liveUpdates = liveUpdate})\\\
- end\\\
- \\\
- \\\
- -- -------- Prompt\\\
- \\\
- local function prompt(list, dir, isGrid)\\\
- local function draw(sel)\\\
- for i, v in ipairs(list) do\\\
- if i == sel then term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\\\
- else term.setBackgroundColor(v.bg or colors[theme.prompt]) end\\\
- term.setTextColor(v.tc or colors[theme.textColor])\\\
- for i = -1, 1 do\\\
- term.setCursorPos(v[2], v[3] + i)\\\
- term.write(string.rep(\\\" \\\", v[1]:len() + 4))\\\
- end\\\
- \\\
- term.setCursorPos(v[2], v[3])\\\
- if i == sel then\\\
- term.setBackgroundColor(v.highlight or colors[theme.promptHighlight])\\\
- term.write(\\\" > \\\")\\\
- else term.write(\\\" - \\\") end\\\
- term.write(v[1] .. \\\" \\\")\\\
- end\\\
- end\\\
- \\\
- local key1 = dir == \\\"horizontal\\\" and 203 or 200\\\
- local key2 = dir == \\\"horizontal\\\" and 205 or 208\\\
- local sel = 1\\\
- draw(sel)\\\
- \\\
- while true do\\\
- local e, but, x, y = os.pullEvent()\\\
- if e == \\\"key\\\" and but == 28 then\\\
- return list[sel][1]\\\
- elseif e == \\\"key\\\" and but == key1 and sel > 1 then\\\
- sel = sel - 1\\\
- draw(sel)\\\
- elseif e == \\\"key\\\" and but == key2 and ((err == true and sel < #list - 1) or (sel < #list)) then\\\
- sel = sel + 1\\\
- draw(sel)\\\
- elseif isGrid and e == \\\"key\\\" and but == 203 and sel > 2 then\\\
- sel = sel - 2\\\
- draw(sel)\\\
- elseif isGrid and e == \\\"key\\\" and but == 205 and sel < 3 then\\\
- sel = sel + 2\\\
- draw(sel)\\\
- elseif e == \\\"mouse_click\\\" then\\\
- for i, v in ipairs(list) do\\\
- if x >= v[2] - 1 and x <= v[2] + v[1]:len() + 3 and y >= v[3] - 1 and y <= v[3] + 1 then\\\
- return list[i][1]\\\
- end\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- local function scrollingPrompt(list)\\\
- local function draw(items, sel, loc)\\\
- for i, v in ipairs(items) do\\\
- local bg = colors[theme.prompt]\\\
- local bghigh = colors[theme.promptHighlight]\\\
- if v:find(\\\"Back\\\") or v:find(\\\"Return\\\") then\\\
- bg = colors[theme.err]\\\
- bghigh = colors[theme.errHighlight]\\\
- end\\\
- \\\
- if i == sel then term.setBackgroundColor(bghigh)\\\
- else term.setBackgroundColor(bg) end\\\
- term.setTextColor(colors[theme.textColor])\\\
- for x = -1, 1 do\\\
- term.setCursorPos(3, (i * 4) + x + 4)\\\
- term.write(string.rep(\\\" \\\", w - 13))\\\
- end\\\
- \\\
- term.setCursorPos(3, i * 4 + 4)\\\
- if i == sel then\\\
- term.setBackgroundColor(bghigh)\\\
- term.write(\\\" > \\\")\\\
- else term.write(\\\" - \\\") end\\\
- term.write(v .. \\\" \\\")\\\
- end\\\
- end\\\
- \\\
- local function updateDisplayList(items, loc, len)\\\
- local ret = {}\\\
- for i = 1, len do\\\
- local item = items[i + loc - 1]\\\
- if item then table.insert(ret, item) end\\\
- end\\\
- return ret\\\
- end\\\
- \\\
- -- Variables\\\
- local sel = 1\\\
- local loc = 1\\\
- local len = 3\\\
- local disList = updateDisplayList(list, loc, len)\\\
- draw(disList, sel, loc)\\\
- \\\
- -- Loop\\\
- while true do\\\
- local e, key, x, y = os.pullEvent()\\\
- \\\
- if e == \\\"mouse_click\\\" then\\\
- for i, v in ipairs(disList) do\\\
- if x >= 3 and x <= w - 11 and y >= i * 4 + 3 and y <= i * 4 + 5 then return v end\\\
- end\\\
- elseif e == \\\"key\\\" and key == 200 then\\\
- if sel > 1 then\\\
- sel = sel - 1\\\
- draw(disList, sel, loc)\\\
- elseif loc > 1 then\\\
- loc = loc - 1\\\
- disList = updateDisplayList(list, loc, len)\\\
- draw(disList, sel, loc)\\\
- end\\\
- elseif e == \\\"key\\\" and key == 208 then\\\
- if sel < len then\\\
- sel = sel + 1\\\
- draw(disList, sel, loc)\\\
- elseif loc + len - 1 < #list then\\\
- loc = loc + 1\\\
- disList = updateDisplayList(list, loc, len)\\\
- draw(disList, sel, loc)\\\
- end\\\
- elseif e == \\\"mouse_scroll\\\" then\\\
- os.queueEvent(\\\"key\\\", key == -1 and 200 or 208)\\\
- elseif e == \\\"key\\\" and key == 28 then\\\
- return disList[sel]\\\
- end\\\
- end\\\
- end\\\
- \\\
- function monitorKeyboardShortcuts()\\\
- local ta, tb = nil, nil\\\
- local allowChar = false\\\
- local shiftPressed = false\\\
- while true do\\\
- local event, char = os.pullEvent()\\\
- if event == \\\"key\\\" and (char == 42 or char == 52) then\\\
- shiftPressed = true\\\
- tb = os.startTimer(keyboardShortcutTimeout)\\\
- elseif event == \\\"key\\\" and (char == 29 or char == 157 or char == 219 or char == 220) then\\\
- allowEditorEvent = false\\\
- allowChar = true\\\
- ta = os.startTimer(keyboardShortcutTimeout)\\\
- elseif event == \\\"key\\\" and allowChar then\\\
- local name = nil\\\
- for k, v in pairs(keys) do\\\
- if v == char then\\\
- if shiftPressed then os.queueEvent(\\\"shortcut\\\", \\\"ctrl shift\\\", k:lower())\\\
- else os.queueEvent(\\\"shortcut\\\", \\\"ctrl\\\", k:lower()) end\\\
- sleep(0.005)\\\
- allowEditorEvent = true\\\
- end\\\
- end\\\
- if shiftPressed then os.queueEvent(\\\"shortcut\\\", \\\"ctrl shift\\\", char)\\\
- else os.queueEvent(\\\"shortcut\\\", \\\"ctrl\\\", char) end\\\
- elseif event == \\\"timer\\\" and char == ta then\\\
- allowEditorEvent = true\\\
- allowChar = false\\\
- elseif event == \\\"timer\\\" and char == tb then\\\
- shiftPressed = false\\\
- end\\\
- end\\\
- end\\\
- \\\
- \\\
- -- -------- Saving and Loading\\\
- \\\
- local function download(url, path)\\\
- for i = 1, 3 do\\\
- local response = http.get(url)\\\
- if response then\\\
- local data = response.readAll()\\\
- response.close()\\\
- if path then\\\
- local f = io.open(path, \\\"w\\\")\\\
- f:write(data)\\\
- f:close()\\\
- end\\\
- return true\\\
- end\\\
- end\\\
- \\\
- return false\\\
- end\\\
- \\\
- local function saveFile(path, lines)\\\
- local dir = path:sub(1, path:len() - fs.getName(path):len())\\\
- if not fs.exists(dir) then fs.makeDir(dir) end\\\
- if not fs.isDir(path) and not fs.isReadOnly(path) then\\\
- local a = \\\"\\\"\\\
- for _, v in pairs(lines) do a = a .. v .. \\\"\\\\n\\\" end\\\
- \\\
- local f = io.open(path, \\\"w\\\")\\\
- f:write(a)\\\
- f:close()\\\
- return true\\\
- else return false end\\\
- end\\\
- \\\
- local function loadFile(path)\\\
- if not fs.exists(path) then\\\
- local dir = path:sub(1, path:len() - fs.getName(path):len())\\\
- if not fs.exists(dir) then fs.makeDir(dir) end\\\
- local f = io.open(path, \\\"w\\\")\\\
- f:write(\\\"\\\")\\\
- f:close()\\\
- end\\\
- \\\
- local l = {}\\\
- if fs.exists(path) and not fs.isDir(path) then\\\
- local f = io.open(path, \\\"r\\\")\\\
- if f then\\\
- local a = f:read(\\\"*l\\\")\\\
- while a do\\\
- table.insert(l, a)\\\
- a = f:read(\\\"*l\\\")\\\
- end\\\
- f:close()\\\
- end\\\
- else return nil end\\\
- \\\
- if #l < 1 then table.insert(l, \\\"\\\") end\\\
- return l\\\
- end\\\
- \\\
- \\\
- -- -------- Languages\\\
- \\\
- languages.lua = {}\\\
- languages.brainfuck = {}\\\
- languages.none = {}\\\
- \\\
- -- Lua\\\
- \\\
- languages.lua.helpTips = {\\\
- \\\"A function you tried to call doesn't exist.\\\",\\\
- \\\"You made a typo.\\\",\\\
- \\\"The index of an array is nil.\\\",\\\
- \\\"The wrong variable type was passed.\\\",\\\
- \\\"A function/variable doesn't exist.\\\",\\\
- \\\"You missed an 'end'.\\\",\\\
- \\\"You missed a 'then'.\\\",\\\
- \\\"You declared a variable incorrectly.\\\",\\\
- \\\"One of your variables is mysteriously nil.\\\"\\\
- }\\\
- \\\
- languages.lua.defaultHelpTips = {\\\
- 2, 5\\\
- }\\\
- \\\
- languages.lua.errors = {\\\
- [\\\"Attempt to call nil.\\\"] = {1, 2},\\\
- [\\\"Attempt to index nil.\\\"] = {3, 2},\\\
- [\\\".+ expected, got .+\\\"] = {4, 2, 9},\\\
- [\\\"'end' expected\\\"] = {6, 2},\\\
- [\\\"'then' expected\\\"] = {7, 2},\\\
- [\\\"'=' expected\\\"] = {8, 2}\\\
- }\\\
- \\\
- languages.lua.keywords = {\\\
- [\\\"and\\\"] = \\\"conditional\\\",\\\
- [\\\"break\\\"] = \\\"conditional\\\",\\\
- [\\\"do\\\"] = \\\"conditional\\\",\\\
- [\\\"else\\\"] = \\\"conditional\\\",\\\
- [\\\"elseif\\\"] = \\\"conditional\\\",\\\
- [\\\"end\\\"] = \\\"conditional\\\",\\\
- [\\\"for\\\"] = \\\"conditional\\\",\\\
- [\\\"function\\\"] = \\\"conditional\\\",\\\
- [\\\"if\\\"] = \\\"conditional\\\",\\\
- [\\\"in\\\"] = \\\"conditional\\\",\\\
- [\\\"local\\\"] = \\\"conditional\\\",\\\
- [\\\"not\\\"] = \\\"conditional\\\",\\\
- [\\\"or\\\"] = \\\"conditional\\\",\\\
- [\\\"repeat\\\"] = \\\"conditional\\\",\\\
- [\\\"return\\\"] = \\\"conditional\\\",\\\
- [\\\"then\\\"] = \\\"conditional\\\",\\\
- [\\\"until\\\"] = \\\"conditional\\\",\\\
- [\\\"while\\\"] = \\\"conditional\\\",\\\
- \\\
- [\\\"true\\\"] = \\\"constant\\\",\\\
- [\\\"false\\\"] = \\\"constant\\\",\\\
- [\\\"nil\\\"] = \\\"constant\\\",\\\
- \\\
- [\\\"print\\\"] = \\\"function\\\",\\\
- [\\\"write\\\"] = \\\"function\\\",\\\
- [\\\"sleep\\\"] = \\\"function\\\",\\\
- [\\\"pairs\\\"] = \\\"function\\\",\\\
- [\\\"ipairs\\\"] = \\\"function\\\",\\\
- [\\\"loadstring\\\"] = \\\"function\\\",\\\
- [\\\"loadfile\\\"] = \\\"function\\\",\\\
- [\\\"dofile\\\"] = \\\"function\\\",\\\
- [\\\"rawset\\\"] = \\\"function\\\",\\\
- [\\\"rawget\\\"] = \\\"function\\\",\\\
- [\\\"setfenv\\\"] = \\\"function\\\",\\\
- [\\\"getfenv\\\"] = \\\"function\\\",\\\
- }\\\
- \\\
- languages.lua.parseError = function(e)\\\
- local ret = {filename = \\\"unknown\\\", line = -1, display = \\\"Unknown!\\\", err = \\\"\\\"}\\\
- if e and e ~= \\\"\\\" then\\\
- ret.err = e\\\
- if e:find(\\\":\\\") then\\\
- ret.filename = e:sub(1, e:find(\\\":\\\") - 1):gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\")\\\
- -- The \\\"\\\" is needed to circumvent a CC bug\\\
- e = (e:sub(e:find(\\\":\\\") + 1) .. \\\"\\\"):gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\")\\\
- if e:find(\\\":\\\") then\\\
- ret.line = e:sub(1, e:find(\\\":\\\") - 1)\\\
- e = e:sub(e:find(\\\":\\\") + 2):gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\") .. \\\"\\\"\\\
- end\\\
- end\\\
- ret.display = e:sub(1, 1):upper() .. e:sub(2, -1) .. \\\".\\\"\\\
- end\\\
- \\\
- return ret\\\
- end\\\
- \\\
- languages.lua.getCompilerErrors = function(code)\\\
- code = \\\"local function ee65da6af1cb6f63fee9a081246f2fd92b36ef2(...)\\\\n\\\\n\\\" .. code .. \\\"\\\\n\\\\nend\\\"\\\
- local fn, err = loadstring(code)\\\
- if not err then\\\
- local _, e = pcall(fn)\\\
- if e then err = e end\\\
- end\\\
- \\\
- if err then\\\
- local a = err:find(\\\"]\\\", 1, true)\\\
- if a then err = \\\"string\\\" .. err:sub(a + 1, -1) end\\\
- local ret = languages.lua.parseError(err)\\\
- if tonumber(ret.line) then ret.line = tonumber(ret.line) end\\\
- return ret\\\
- else return languages.lua.parseError(nil) end\\\
- end\\\
- \\\
- languages.lua.run = function(path, ar)\\\
- local fn, err = loadfile(path)\\\
- setfenv(fn, getfenv())\\\
- if not err then\\\
- _, err = pcall(function() fn(unpack(ar)) end)\\\
- end\\\
- return err\\\
- end\\\
- \\\
- \\\
- -- Brainfuck\\\
- \\\
- languages.brainfuck.helpTips = {\\\
- \\\"Well idk...\\\",\\\
- \\\"Isn't this the whole point of the language?\\\",\\\
- \\\"Ya know... Not being able to debug it?\\\",\\\
- \\\"You made a typo.\\\"\\\
- }\\\
- \\\
- languages.brainfuck.defaultHelpTips = {\\\
- 1, 2, 3\\\
- }\\\
- \\\
- languages.brainfuck.errors = {\\\
- [\\\"No matching '['\\\"] = {1, 2, 3, 4}\\\
- }\\\
- \\\
- languages.brainfuck.keywords = {}\\\
- \\\
- languages.brainfuck.parseError = function(e)\\\
- local ret = {filename = \\\"unknown\\\", line = -1, display = \\\"Unknown!\\\", err = \\\"\\\"}\\\
- if e and e ~= \\\"\\\" then\\\
- ret.err = e\\\
- ret.line = e:sub(1, e:find(\\\":\\\") - 1)\\\
- e = e:sub(e:find(\\\":\\\") + 2):gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\") .. \\\"\\\"\\\
- ret.display = e:sub(1, 1):upper() .. e:sub(2, -1) .. \\\".\\\"\\\
- end\\\
- \\\
- return ret\\\
- end\\\
- \\\
- languages.brainfuck.mapLoops = function(code)\\\
- -- Map loops\\\
- local loopLocations = {}\\\
- local loc = 1\\\
- local line = 1\\\
- for let in string.gmatch(code, \\\".\\\") do\\\
- if let == \\\"[\\\" then\\\
- loopLocations[loc] = true\\\
- elseif let == \\\"]\\\" then\\\
- local found = false\\\
- for i = loc, 1, -1 do \\\
- if loopLocations[i] == true then\\\
- loopLocations[i] = loc\\\
- found = true\\\
- end\\\
- end\\\
- \\\
- if not found then\\\
- return line .. \\\": No matching '['\\\"\\\
- end\\\
- end\\\
- \\\
- if let == \\\"\\\\n\\\" then line = line + 1 end\\\
- loc = loc + 1\\\
- end\\\
- return loopLocations\\\
- end\\\
- \\\
- languages.brainfuck.getCompilerErrors = function(code)\\\
- local a = languages.brainfuck.mapLoops(code)\\\
- if type(a) == \\\"string\\\" then return languages.brainfuck.parseError(a)\\\
- else return languages.brainfuck.parseError(nil) end\\\
- end\\\
- \\\
- languages.brainfuck.run = function(path)\\\
- -- Read from file\\\
- local f = io.open(path, \\\"r\\\")\\\
- local content = f:read(\\\"*a\\\")\\\
- f:close()\\\
- \\\
- -- Define environment\\\
- local dataCells = {}\\\
- local dataPointer = 1\\\
- local instructionPointer = 1\\\
- \\\
- -- Map loops\\\
- local loopLocations = languages.brainfuck.mapLoops(content)\\\
- if type(loopLocations) == \\\"string\\\" then return loopLocations end\\\
- \\\
- -- Execute code\\\
- while true do\\\
- local let = content:sub(instructionPointer, instructionPointer)\\\
- \\\
- if let == \\\">\\\" then\\\
- dataPointer = dataPointer + 1\\\
- if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
- elseif let == \\\"<\\\" then\\\
- if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
- dataPointer = dataPointer - 1\\\
- if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
- elseif let == \\\"+\\\" then\\\
- if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
- dataCells[tostring(dataPointer)] = dataCells[tostring(dataPointer)] + 1\\\
- elseif let == \\\"-\\\" then\\\
- if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
- dataCells[tostring(dataPointer)] = dataCells[tostring(dataPointer)] - 1\\\
- elseif let == \\\".\\\" then\\\
- if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
- if term.getCursorPos() >= w then print(\\\"\\\") end\\\
- write(string.char(math.max(1, dataCells[tostring(dataPointer)])))\\\
- elseif let == \\\",\\\" then\\\
- if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
- term.setCursorBlink(true)\\\
- local e, but = os.pullEvent(\\\"char\\\")\\\
- term.setCursorBlink(false)\\\
- dataCells[tostring(dataPointer)] = string.byte(but)\\\
- if term.getCursorPos() >= w then print(\\\"\\\") end\\\
- write(but)\\\
- elseif let == \\\"/\\\" then\\\
- if not dataCells[tostring(dataPointer)] then dataCells[tostring(dataPointer)] = 0 end\\\
- if term.getCursorPos() >= w then print(\\\"\\\") end\\\
- write(dataCells[tostring(dataPointer)])\\\
- elseif let == \\\"[\\\" then\\\
- if dataCells[tostring(dataPointer)] == 0 then\\\
- for k, v in pairs(loopLocations) do\\\
- if k == instructionPointer then instructionPointer = v end\\\
- end\\\
- end\\\
- elseif let == \\\"]\\\" then\\\
- for k, v in pairs(loopLocations) do\\\
- if v == instructionPointer then instructionPointer = k - 1 end\\\
- end\\\
- end\\\
- \\\
- instructionPointer = instructionPointer + 1\\\
- if instructionPointer > content:len() then print(\\\"\\\") break end\\\
- end\\\
- end\\\
- \\\
- -- None\\\
- \\\
- languages.none.helpTips = {}\\\
- languages.none.defaultHelpTips = {}\\\
- languages.none.errors = {}\\\
- languages.none.keywords = {}\\\
- \\\
- languages.none.parseError = function(err)\\\
- return {filename = \\\"\\\", line = -1, display = \\\"\\\", err = \\\"\\\"}\\\
- end\\\
- \\\
- languages.none.getCompilerErrors = function(code)\\\
- return languages.none.parseError(nil)\\\
- end\\\
- \\\
- languages.none.run = function(path) end\\\
- \\\
- \\\
- -- Load language\\\
- curLanguage = languages.lua\\\
- \\\
- \\\
- -- -------- Run GUI\\\
- \\\
- local function viewErrorHelp(e)\\\
- title(\\\"LuaIDE - Error Help\\\")\\\
- \\\
- local tips = nil\\\
- for k, v in pairs(curLanguage.errors) do\\\
- if e.display:find(k) then tips = v break end\\\
- end\\\
- \\\
- term.setBackgroundColor(colors[theme.err])\\\
- for i = 6, 8 do\\\
- term.setCursorPos(5, i)\\\
- term.write(string.rep(\\\" \\\", 35))\\\
- end\\\
- \\\
- term.setBackgroundColor(colors[theme.prompt])\\\
- for i = 10, 18 do\\\
- term.setCursorPos(5, i)\\\
- term.write(string.rep(\\\" \\\", 46))\\\
- end\\\
- \\\
- if tips then\\\
- term.setBackgroundColor(colors[theme.err])\\\
- term.setCursorPos(6, 7)\\\
- term.write(\\\"Error Help\\\")\\\
- \\\
- term.setBackgroundColor(colors[theme.prompt])\\\
- for i, v in ipairs(tips) do\\\
- term.setCursorPos(7, i + 10)\\\
- term.write(\\\"- \\\" .. curLanguage.helpTips[v])\\\
- end\\\
- else\\\
- term.setBackgroundColor(colors[theme.err])\\\
- term.setCursorPos(6, 7)\\\
- term.write(\\\"No Error Tips Available!\\\")\\\
- \\\
- term.setBackgroundColor(colors[theme.prompt])\\\
- term.setCursorPos(6, 11)\\\
- term.write(\\\"There are no error tips available, but\\\")\\\
- term.setCursorPos(6, 12)\\\
- term.write(\\\"you could see if it was any of these:\\\")\\\
- \\\
- for i, v in ipairs(curLanguage.defaultHelpTips) do\\\
- term.setCursorPos(7, i + 12)\\\
- term.write(\\\"- \\\" .. curLanguage.helpTips[v])\\\
- end\\\
- end\\\
- \\\
- prompt({{\\\"Back\\\", w - 8, 7}}, \\\"horizontal\\\")\\\
- end\\\
- \\\
- local function run(path, lines, useArgs)\\\
- local ar = {}\\\
- if useArgs then\\\
- title(\\\"LuaIDE - Run \\\" .. fs.getName(path))\\\
- local s = centerRead(w - 13, fs.getName(path) .. \\\" \\\")\\\
- for m in string.gmatch(s, \\\"[^ \\\\t]+\\\") do ar[#ar + 1] = m:gsub(\\\"^%s*(.-)%s*$\\\", \\\"%1\\\") end\\\
- end\\\
- \\\
- saveFile(path, lines)\\\
- term.setCursorBlink(false)\\\
- term.setBackgroundColor(colors.black)\\\
- term.setTextColor(colors.white)\\\
- term.clear()\\\
- term.setCursorPos(1, 1)\\\
- local err = curLanguage.run(path, ar)\\\
- \\\
- term.setBackgroundColor(colors.black)\\\
- print(\\\"\\\\n\\\")\\\
- if err then\\\
- if isAdvanced() then term.setTextColor(colors.red) end\\\
- centerPrint(\\\"The program has crashed!\\\")\\\
- end\\\
- term.setTextColor(colors.white)\\\
- centerPrint(\\\"Press any key to return to LuaIDE...\\\")\\\
- while true do\\\
- local e = os.pullEvent()\\\
- if e == \\\"key\\\" then break end\\\
- end\\\
- \\\
- -- To prevent key from showing up in editor\\\
- os.queueEvent(event_distract)\\\
- os.pullEvent()\\\
- \\\
- if err then\\\
- if curLanguage == languages.lua and err:find(\\\"]\\\") then\\\
- err = fs.getName(path) .. err:sub(err:find(\\\"]\\\", 1, true) + 1, -1)\\\
- end\\\
- \\\
- while true do\\\
- title(\\\"LuaIDE - Error!\\\")\\\
- \\\
- term.setBackgroundColor(colors[theme.err])\\\
- for i = 6, 8 do\\\
- term.setCursorPos(3, i)\\\
- term.write(string.rep(\\\" \\\", w - 5))\\\
- end\\\
- term.setCursorPos(4, 7)\\\
- term.write(\\\"The program has crashed!\\\")\\\
- \\\
- term.setBackgroundColor(colors[theme.prompt])\\\
- for i = 10, 14 do\\\
- term.setCursorPos(3, i)\\\
- term.write(string.rep(\\\" \\\", w - 5))\\\
- end\\\
- \\\
- local formattedErr = curLanguage.parseError(err)\\\
- term.setCursorPos(4, 11)\\\
- term.write(\\\"Line: \\\" .. formattedErr.line)\\\
- term.setCursorPos(4, 12)\\\
- term.write(\\\"Error:\\\")\\\
- term.setCursorPos(5, 13)\\\
- \\\
- local a = formattedErr.display\\\
- local b = nil\\\
- if a:len() > w - 8 then\\\
- for i = a:len(), 1, -1 do\\\
- if a:sub(i, i) == \\\" \\\" then\\\
- b = a:sub(i + 1, -1)\\\
- a = a:sub(1, i)\\\
- break\\\
- end\\\
- end\\\
- end\\\
- \\\
- term.write(a)\\\
- if b then\\\
- term.setCursorPos(5, 14)\\\
- term.write(b)\\\
- end\\\
- \\\
- local opt = prompt({{\\\"Error Help\\\", w/2 - 15, 17}, {\\\"Go To Line\\\", w/2 + 2, 17}},\\\
- \\\"horizontal\\\")\\\
- if opt == \\\"Error Help\\\" then\\\
- viewErrorHelp(formattedErr)\\\
- elseif opt == \\\"Go To Line\\\" then\\\
- -- To prevent key from showing up in editor\\\
- os.queueEvent(event_distract)\\\
- os.pullEvent()\\\
- \\\
- return \\\"go to\\\", tonumber(formattedErr.line)\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- \\\
- -- -------- Functions\\\
- \\\
- local function goto()\\\
- term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
- term.setCursorPos(2, 1)\\\
- term.clearLine()\\\
- term.write(\\\"Line: \\\")\\\
- local line = modRead({visibleLength = w - 2})\\\
- \\\
- local num = tonumber(line)\\\
- if num and num > 0 then return num\\\
- else\\\
- term.setCursorPos(2, 1)\\\
- term.clearLine()\\\
- term.write(\\\"Not a line number!\\\")\\\
- sleep(1.6)\\\
- return nil\\\
- end\\\
- end\\\
- \\\
- local function setsyntax()\\\
- local opts = {\\\
- \\\"[Lua] Brainfuck None \\\",\\\
- \\\" Lua [Brainfuck] None \\\",\\\
- \\\" Lua Brainfuck [None]\\\"\\\
- }\\\
- local sel = 1\\\
- \\\
- term.setCursorBlink(false)\\\
- term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
- term.setCursorPos(2, 1)\\\
- term.clearLine()\\\
- term.write(opts[sel])\\\
- while true do\\\
- local e, but, x, y = os.pullEvent(\\\"key\\\")\\\
- if but == 203 then\\\
- sel = math.max(1, sel - 1)\\\
- term.setCursorPos(2, 1)\\\
- term.clearLine()\\\
- term.write(opts[sel])\\\
- elseif but == 205 then\\\
- sel = math.min(#opts, sel + 1)\\\
- term.setCursorPos(2, 1)\\\
- term.clearLine()\\\
- term.write(opts[sel])\\\
- elseif but == 28 then\\\
- if sel == 1 then curLanguage = languages.lua\\\
- elseif sel == 2 then curLanguage = languages.brainfuck\\\
- elseif sel == 3 then curLanguage = languages.none end\\\
- term.setCursorBlink(true)\\\
- return\\\
- end\\\
- end\\\
- end\\\
- \\\
- \\\
- -- -------- Re-Indenting\\\
- \\\
- local tabWidth = 2\\\
- \\\
- local comments = {}\\\
- local strings = {}\\\
- \\\
- local increment = {\\\
- \\\"if%s+.+%s+then%s*$\\\",\\\
- \\\"for%s+.+%s+do%s*$\\\",\\\
- \\\"while%s+.+%s+do%s*$\\\",\\\
- \\\"repeat%s*$\\\",\\\
- \\\"function%s+[a-zA-Z_0-9]\\\\(.*\\\\)%s*$\\\"\\\
- }\\\
- \\\
- local decrement = {\\\
- \\\"end\\\",\\\
- \\\"until%s+.+\\\"\\\
- }\\\
- \\\
- local special = {\\\
- \\\"else%s*$\\\",\\\
- \\\"elseif%s+.+%s+then%s*$\\\"\\\
- }\\\
- \\\
- local function check(func)\\\
- for _, v in pairs(func) do\\\
- local cLineStart = v[\\\"lineStart\\\"]\\\
- local cLineEnd = v[\\\"lineEnd\\\"]\\\
- local cCharStart = v[\\\"charStart\\\"]\\\
- local cCharEnd = v[\\\"charEnd\\\"]\\\
- \\\
- if line >= cLineStart and line <= cLineEnd then\\\
- if line == cLineStart then return cCharStart < charNumb\\\
- elseif line == cLineEnd then return cCharEnd > charNumb\\\
- else return true end\\\
- end\\\
- end\\\
- end\\\
- \\\
- local function isIn(line, loc)\\\
- if check(comments) then return true end\\\
- if check(strings) then return true end\\\
- return false\\\
- end\\\
- \\\
- local function setComment(ls, le, cs, ce)\\\
- comments[#comments + 1] = {}\\\
- comments[#comments].lineStart = ls\\\
- comments[#comments].lineEnd = le\\\
- comments[#comments].charStart = cs\\\
- comments[#comments].charEnd = ce\\\
- end\\\
- \\\
- local function setString(ls, le, cs, ce)\\\
- strings[#strings + 1] = {}\\\
- strings[#strings].lineStart = ls\\\
- strings[#strings].lineEnd = le\\\
- strings[#strings].charStart = cs\\\
- strings[#strings].charEnd = ce\\\
- end\\\
- \\\
- local function map(contents)\\\
- local inCom = false\\\
- local inStr = false\\\
- \\\
- for i = 1, #contents do\\\
- if content[i]:find(\\\"%-%-%[%[\\\") and not inStr and not inCom then\\\
- local cStart = content[i]:find(\\\"%-%-%[%[\\\")\\\
- setComment(i, nil, cStart, nil)\\\
- inCom = true\\\
- elseif content[i]:find(\\\"%-%-%[=%[\\\") and not inStr and not inCom then\\\
- local cStart = content[i]:find(\\\"%-%-%[=%[\\\")\\\
- setComment(i, nil, cStart, nil)\\\
- inCom = true\\\
- elseif content[i]:find(\\\"%[%[\\\") and not inStr and not inCom then\\\
- local cStart = content[i]:find(\\\"%[%[\\\")\\\
- setString(i, nil, cStart, nil)\\\
- inStr = true\\\
- elseif content[i]:find(\\\"%[=%[\\\") and not inStr and not inCom then\\\
- local cStart = content[i]:find(\\\"%[=%[\\\")\\\
- setString(i, nil, cStart, nil)\\\
- inStr = true\\\
- end\\\
- \\\
- if content[i]:find(\\\"%]%]\\\") and inStr and not inCom then\\\
- local cStart, cEnd = content[i]:find(\\\"%]%]\\\")\\\
- strings[#strings].lineEnd = i\\\
- strings[#strings].charEnd = cEnd\\\
- inStr = false\\\
- elseif content[i]:find(\\\"%]=%]\\\") and inStr and not inCom then\\\
- local cStart, cEnd = content[i]:find(\\\"%]=%]\\\")\\\
- strings[#strings].lineEnd = i\\\
- strings[#strings].charEnd = cEnd\\\
- inStr = false\\\
- end\\\
- \\\
- if content[i]:find(\\\"%]%]\\\") and not inStr and inCom then\\\
- local cStart, cEnd = content[i]:find(\\\"%]%]\\\")\\\
- comments[#comments].lineEnd = i\\\
- comments[#comments].charEnd = cEnd\\\
- inCom = false\\\
- elseif content[i]:find(\\\"%]=%]\\\") and not inStr and inCom then\\\
- local cStart, cEnd = content[i]:find(\\\"%]=%]\\\")\\\
- comments[#comments].lineEnd = i\\\
- comments[#comments].charEnd = cEnd\\\
- inCom = false\\\
- end\\\
- \\\
- if content[i]:find(\\\"%-%-\\\") and not inStr and not inCom then\\\
- local cStart = content[i]:find(\\\"%-%-\\\")\\\
- setComment(i, i, cStart, -1)\\\
- elseif content[i]:find(\\\"'\\\") and not inStr and not inCom then\\\
- local cStart, cEnd = content[i]:find(\\\"'\\\")\\\
- local nextChar = content[i]:sub(cEnd + 1, string.len(content[i]))\\\
- local _, cEnd = nextChar:find(\\\"'\\\")\\\
- setString(i, i, cStart, cEnd)\\\
- elseif content[i]:find('\\\"') and not inStr and not inCom then\\\
- local cStart, cEnd = content[i]:find('\\\"')\\\
- local nextChar = content[i]:sub(cEnd + 1, string.len(content[i]))\\\
- local _, cEnd = nextChar:find('\\\"')\\\
- setString(i, i, cStart, cEnd)\\\
- end\\\
- end\\\
- end\\\
- \\\
- local function reindent(contents)\\\
- local err = nil\\\
- if curLanguage ~= languages.lua then\\\
- err = \\\"Cannot indent languages other than Lua!\\\"\\\
- elseif curLanguage.getCompilerErrors(table.concat(contents, \\\"\\\\n\\\")).line ~= -1 then\\\
- err = \\\"Cannot indent a program with errors!\\\"\\\
- end\\\
- \\\
- if err then\\\
- term.setCursorBlink(false)\\\
- term.setCursorPos(2, 1)\\\
- term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
- term.clearLine()\\\
- term.write(err)\\\
- sleep(1.6)\\\
- return contents\\\
- end\\\
- \\\
- local new = {}\\\
- local level = 0\\\
- for k, v in pairs(contents) do\\\
- local incrLevel = false\\\
- local foundIncr = false\\\
- for _, incr in pairs(increment) do\\\
- if v:find(incr) and not isIn(k, v:find(incr)) then\\\
- incrLevel = true\\\
- end\\\
- if v:find(incr:sub(1, -2)) and not isIn(k, v:find(incr)) then\\\
- foundIncr = true\\\
- end\\\
- end\\\
- \\\
- local decrLevel = false\\\
- if not incrLevel then\\\
- for _, decr in pairs(decrement) do\\\
- if v:find(decr) and not isIn(k, v:find(decr)) and not foundIncr then\\\
- level = math.max(0, level - 1)\\\
- decrLevel = true\\\
- end\\\
- end\\\
- end\\\
- \\\
- if not decrLevel then\\\
- for _, sp in pairs(special) do\\\
- if v:find(sp) and not isIn(k, v:find(sp)) then\\\
- incrLevel = true\\\
- level = math.max(0, level - 1)\\\
- end\\\
- end\\\
- end\\\
- \\\
- new[k] = string.rep(\\\" \\\", level * tabWidth) .. v\\\
- if incrLevel then level = level + 1 end\\\
- end\\\
- \\\
- return new\\\
- end\\\
- \\\
- \\\
- -- -------- Menu\\\
- \\\
- local menu = {\\\
- [1] = {\\\"File\\\",\\\
- -- \\\"About\\\",\\\
- -- \\\"Settings\\\",\\\
- -- \\\"\\\",\\\
- \\\"New File ^+N\\\",\\\
- \\\"Open File ^+O\\\",\\\
- \\\"Save File ^+S\\\",\\\
- \\\"Close ^+W\\\",\\\
- \\\"Print ^+P\\\",\\\
- \\\"Quit ^+Q\\\"\\\
- }, [2] = {\\\"Edit\\\",\\\
- \\\"Cut Line ^+X\\\",\\\
- \\\"Copy Line ^+C\\\",\\\
- \\\"Paste Line ^+V\\\",\\\
- \\\"Delete Line\\\",\\\
- \\\"Clear Line\\\"\\\
- }, [3] = {\\\"Functions\\\",\\\
- \\\"Go To Line ^+G\\\",\\\
- \\\"Re-Indent ^+I\\\",\\\
- \\\"Set Syntax ^+E\\\",\\\
- \\\"Start of Line ^+<\\\",\\\
- \\\"End of Line ^+>\\\"\\\
- }, [4] = {\\\"Run\\\",\\\
- \\\"Run Program ^+R\\\",\\\
- \\\"Run w/ Args ^+Shift+R\\\"\\\
- }\\\
- }\\\
- \\\
- local shortcuts = {\\\
- -- File\\\
- [\\\"ctrl n\\\"] = \\\"New File ^+N\\\",\\\
- [\\\"ctrl o\\\"] = \\\"Open File ^+O\\\",\\\
- [\\\"ctrl s\\\"] = \\\"Save File ^+S\\\",\\\
- [\\\"ctrl w\\\"] = \\\"Close ^+W\\\",\\\
- [\\\"ctrl p\\\"] = \\\"Print ^+P\\\",\\\
- [\\\"ctrl q\\\"] = \\\"Quit ^+Q\\\",\\\
- \\\
- -- Edit\\\
- [\\\"ctrl x\\\"] = \\\"Cut Line ^+X\\\",\\\
- [\\\"ctrl c\\\"] = \\\"Copy Line ^+C\\\",\\\
- [\\\"ctrl v\\\"] = \\\"Paste Line ^+V\\\",\\\
- \\\
- -- Functions\\\
- [\\\"ctrl g\\\"] = \\\"Go To Line ^+G\\\",\\\
- [\\\"ctrl i\\\"] = \\\"Re-Indent ^+I\\\",\\\
- [\\\"ctrl e\\\"] = \\\"Set Syntax ^+E\\\",\\\
- [\\\"ctrl 203\\\"] = \\\"Start of Line ^+<\\\",\\\
- [\\\"ctrl 205\\\"] = \\\"End of Line ^+>\\\",\\\
- \\\
- -- Run\\\
- [\\\"ctrl r\\\"] = \\\"Run Program ^+R\\\",\\\
- [\\\"ctrl shift r\\\"] = \\\"Run w/ Args ^+Shift+R\\\"\\\
- }\\\
- \\\
- local menuFunctions = {\\\
- -- File\\\
- -- [\\\"About\\\"] = function() end,\\\
- -- [\\\"Settings\\\"] = function() end,\\\
- [\\\"New File ^+N\\\"] = function(path, lines) saveFile(path, lines) return \\\"new\\\" end,\\\
- [\\\"Open File ^+O\\\"] = function(path, lines) saveFile(path, lines) return \\\"open\\\" end,\\\
- [\\\"Save File ^+S\\\"] = function(path, lines) saveFile(path, lines) end,\\\
- [\\\"Close ^+W\\\"] = function(path, lines) saveFile(path, lines) return \\\"menu\\\" end,\\\
- [\\\"Print ^+P\\\"] = function(path, lines) saveFile(path, lines) return nil end,\\\
- [\\\"Quit ^+Q\\\"] = function(path, lines) saveFile(path, lines) return \\\"exit\\\" end,\\\
- \\\
- -- Edit\\\
- [\\\"Cut Line ^+X\\\"] = function(path, lines, y)\\\
- clipboard = lines[y] table.remove(lines, y) return nil, lines end,\\\
- [\\\"Copy Line ^+C\\\"] = function(path, lines, y) clipboard = lines[y] end,\\\
- [\\\"Paste Line ^+V\\\"] = function(path, lines, y)\\\
- if clipboard then table.insert(lines, y, clipboard) end return nil, lines end,\\\
- [\\\"Delete Line\\\"] = function(path, lines, y) table.remove(lines, y) return nil, lines end,\\\
- [\\\"Clear Line\\\"] = function(path, lines, y) lines[y] = \\\"\\\" return nil, lines, \\\"cursor\\\" end,\\\
- \\\
- -- Functions\\\
- [\\\"Go To Line ^+G\\\"] = function() return nil, \\\"go to\\\", goto() end,\\\
- [\\\"Re-Indent ^+I\\\"] = function(path, lines)\\\
- local a = reindent(lines) saveFile(path, lines) return nil, a\\\
- end,\\\
- [\\\"Set Syntax ^+E\\\"] = function(path, lines)\\\
- setsyntax()\\\
- if curLanguage == languages.brainfuck and lines[1] ~= \\\"-- Syntax: Brainfuck\\\" then\\\
- table.insert(lines, 1, \\\"-- Syntax: Brainfuck\\\")\\\
- return nil, lines\\\
- end\\\
- end,\\\
- [\\\"Start of Line ^+<\\\"] = function() os.queueEvent(\\\"key\\\", 199) end,\\\
- [\\\"End of Line ^+>\\\"] = function() os.queueEvent(\\\"key\\\", 207) end,\\\
- \\\
- -- Run\\\
- [\\\"Run Program ^+R\\\"] = function(path, lines)\\\
- saveFile(path, lines)\\\
- return nil, run(path, lines, false)\\\
- end,\\\
- [\\\"Run w/ Args ^+Shift+R\\\"] = function(path, lines)\\\
- saveFile(path, lines)\\\
- return nil, run(path, lines, true)\\\
- end,\\\
- }\\\
- \\\
- local function drawMenu(open)\\\
- term.setCursorPos(1, 1)\\\
- term.setTextColor(colors[theme.textColor])\\\
- term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
- term.clearLine()\\\
- local curX = 0\\\
- for _, v in pairs(menu) do\\\
- term.setCursorPos(3 + curX, 1)\\\
- term.write(v[1])\\\
- curX = curX + v[1]:len() + 3\\\
- end\\\
- \\\
- if open then\\\
- local it = {}\\\
- local x = 1\\\
- for _, v in pairs(menu) do\\\
- if open == v[1] then\\\
- it = v\\\
- break\\\
- end\\\
- x = x + v[1]:len() + 3\\\
- end\\\
- x = x + 1\\\
- \\\
- local items = {}\\\
- for i = 2, #it do\\\
- table.insert(items, it[i])\\\
- end\\\
- \\\
- local len = 1\\\
- for _, v in pairs(items) do if v:len() + 2 > len then len = v:len() + 2 end end\\\
- \\\
- for i, v in ipairs(items) do\\\
- term.setCursorPos(x, i + 1)\\\
- term.write(string.rep(\\\" \\\", len))\\\
- term.setCursorPos(x + 1, i + 1)\\\
- term.write(v)\\\
- end\\\
- term.setCursorPos(x, #items + 2)\\\
- term.write(string.rep(\\\" \\\", len))\\\
- return items, len\\\
- end\\\
- end\\\
- \\\
- local function triggerMenu(cx, cy)\\\
- -- Determine clicked menu\\\
- local curX = 0\\\
- local open = nil\\\
- for _, v in pairs(menu) do\\\
- if cx >= curX + 3 and cx <= curX + v[1]:len() + 2 then\\\
- open = v[1]\\\
- break\\\
- end\\\
- curX = curX + v[1]:len() + 3\\\
- end\\\
- local menux = curX + 2\\\
- if not open then return false end\\\
- \\\
- -- Flash menu item\\\
- term.setCursorBlink(false)\\\
- term.setCursorPos(menux, 1)\\\
- term.setBackgroundColor(colors[theme.background])\\\
- term.write(string.rep(\\\" \\\", open:len() + 2))\\\
- term.setCursorPos(menux + 1, 1)\\\
- term.write(open)\\\
- sleep(0.1)\\\
- local items, len = drawMenu(open)\\\
- \\\
- local ret = true\\\
- \\\
- -- Pull events on menu\\\
- local ox, oy = term.getCursorPos()\\\
- while type(ret) ~= \\\"string\\\" do\\\
- local e, but, x, y = os.pullEvent()\\\
- if e == \\\"mouse_click\\\" then\\\
- -- If clicked outside menu\\\
- if x < menux - 1 or x > menux + len - 1 then break\\\
- elseif y > #items + 2 then break\\\
- elseif y == 1 then break end\\\
- \\\
- for i, v in ipairs(items) do\\\
- if y == i + 1 and x >= menux and x <= menux + len - 2 then\\\
- -- Flash when clicked\\\
- term.setCursorPos(menux, y)\\\
- term.setBackgroundColor(colors[theme.background])\\\
- term.write(string.rep(\\\" \\\", len))\\\
- term.setCursorPos(menux + 1, y)\\\
- term.write(v)\\\
- sleep(0.1)\\\
- drawMenu(open)\\\
- \\\
- -- Return item\\\
- ret = v\\\
- break\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- term.setCursorPos(ox, oy)\\\
- term.setCursorBlink(true)\\\
- return ret\\\
- end\\\
- \\\
- \\\
- -- -------- Editing\\\
- \\\
- local standardsCompletions = {\\\
- \\\"if%s+.+%s+then%s*$\\\",\\\
- \\\"for%s+.+%s+do%s*$\\\",\\\
- \\\"while%s+.+%s+do%s*$\\\",\\\
- \\\"repeat%s*$\\\",\\\
- \\\"function%s+[a-zA-Z_0-9]?\\\\(.*\\\\)%s*$\\\",\\\
- \\\"=%s*function%s*\\\\(.*\\\\)%s*$\\\",\\\
- \\\"else%s*$\\\",\\\
- \\\"elseif%s+.+%s+then%s*$\\\"\\\
- }\\\
- \\\
- local liveCompletions = {\\\
- [\\\"(\\\"] = \\\")\\\",\\\
- [\\\"{\\\"] = \\\"}\\\",\\\
- [\\\"[\\\"] = \\\"]\\\",\\\
- [\\\"\\\\\\\"\\\"] = \\\"\\\\\\\"\\\",\\\
- [\\\"'\\\"] = \\\"'\\\",\\\
- }\\\
- \\\
- local x, y = 0, 0\\\
- local edw, edh = 0, h - 1\\\
- local offx, offy = 0, 1\\\
- local scrollx, scrolly = 0, 0\\\
- local lines = {}\\\
- local liveErr = curLanguage.parseError(nil)\\\
- local displayCode = true\\\
- local lastEventClock = os.clock()\\\
- \\\
- local function attemptToHighlight(line, regex, col)\\\
- local match = string.match(line, regex)\\\
- if match then\\\
- if type(col) == \\\"number\\\" then term.setTextColor(col)\\\
- elseif type(col) == \\\"function\\\" then term.setTextColor(col(match)) end\\\
- term.write(match)\\\
- term.setTextColor(colors[theme.textColor])\\\
- return line:sub(match:len() + 1, -1)\\\
- end\\\
- return nil\\\
- end\\\
- \\\
- local function writeHighlighted(line)\\\
- if curLanguage == languages.lua then\\\
- while line:len() > 0 do \\\
- line = attemptToHighlight(line, \\\"^%-%-%[%[.-%]%]\\\", colors[theme.comment]) or\\\
- attemptToHighlight(line, \\\"^%-%-.*\\\", colors[theme.comment]) or\\\
- attemptToHighlight(line, \\\"^\\\\\\\".*[^\\\\\\\\]\\\\\\\"\\\", colors[theme.string]) or\\\
- attemptToHighlight(line, \\\"^\\\\'.*[^\\\\\\\\]\\\\'\\\", colors[theme.string]) or\\\
- attemptToHighlight(line, \\\"^%[%[.-%]%]\\\", colors[theme.string]) or\\\
- attemptToHighlight(line, \\\"^[%w_]+\\\", function(match)\\\
- if curLanguage.keywords[match] then\\\
- return colors[theme[curLanguage.keywords[match]]]\\\
- end\\\
- return colors[theme.textColor]\\\
- end) or\\\
- attemptToHighlight(line, \\\"^[^%w_]\\\", colors[theme.textColor])\\\
- end\\\
- else term.write(line) end\\\
- end\\\
- \\\
- local function draw()\\\
- -- Menu\\\
- term.setTextColor(colors[theme.textColor])\\\
- term.setBackgroundColor(colors[theme.editorBackground])\\\
- term.clear()\\\
- drawMenu()\\\
- \\\
- -- Line numbers\\\
- offx, offy = tostring(#lines):len() + 1, 1\\\
- edw, edh = w - offx, h - 1\\\
- \\\
- -- Draw text\\\
- for i = 1, edh do\\\
- local a = lines[scrolly + i]\\\
- if a then\\\
- local ln = string.rep(\\\" \\\", offx - 1 - tostring(scrolly + i):len()) .. tostring(scrolly + i) \\\
- local l = a:sub(scrollx + 1, edw + scrollx + 1)\\\
- ln = ln .. \\\":\\\"\\\
- \\\
- if liveErr.line == scrolly + i then ln = string.rep(\\\" \\\", offx - 2) .. \\\"!:\\\" end\\\
- \\\
- term.setCursorPos(1, i + offy)\\\
- term.setBackgroundColor(colors[theme.editorBackground])\\\
- if scrolly + i == y then\\\
- if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\\\
- term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
- else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\\\
- term.clearLine()\\\
- elseif scrolly + i == liveErr.line then\\\
- term.setBackgroundColor(colors[theme.editorError])\\\
- term.clearLine()\\\
- end\\\
- \\\
- term.setCursorPos(1 - scrollx + offx, i + offy)\\\
- if scrolly + i == y then\\\
- if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\\\
- term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
- else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\\\
- elseif scrolly + i == liveErr.line then term.setBackgroundColor(colors[theme.editorError])\\\
- else term.setBackgroundColor(colors[theme.editorBackground]) end\\\
- if scrolly + i == liveErr.line then\\\
- if displayCode then term.write(a)\\\
- else term.write(liveErr.display) end\\\
- else writeHighlighted(a) end\\\
- \\\
- term.setCursorPos(1, i + offy)\\\
- if scrolly + i == y then\\\
- if scrolly + i == liveErr.line and os.clock() - lastEventClock > 3 then\\\
- term.setBackgroundColor(colors[theme.editorError])\\\
- else term.setBackgroundColor(colors[theme.editorLineNumbersHighlight]) end\\\
- elseif scrolly + i == liveErr.line then\\\
- term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
- else term.setBackgroundColor(colors[theme.editorLineNumbers]) end\\\
- term.write(ln)\\\
- end\\\
- end\\\
- term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
- end\\\
- \\\
- local function drawLine(...)\\\
- local ls = {...}\\\
- offx = tostring(#lines):len() + 1\\\
- for _, ly in pairs(ls) do\\\
- local a = lines[ly]\\\
- if a then\\\
- local ln = string.rep(\\\" \\\", offx - 1 - tostring(ly):len()) .. tostring(ly) \\\
- local l = a:sub(scrollx + 1, edw + scrollx + 1)\\\
- ln = ln .. \\\":\\\"\\\
- \\\
- if liveErr.line == ly then ln = string.rep(\\\" \\\", offx - 2) .. \\\"!:\\\" end\\\
- \\\
- term.setCursorPos(1, (ly - scrolly) + offy)\\\
- term.setBackgroundColor(colors[theme.editorBackground])\\\
- if ly == y then\\\
- if ly == liveErr.line and os.clock() - lastEventClock > 3 then\\\
- term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
- else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\\\
- elseif ly == liveErr.line then\\\
- term.setBackgroundColor(colors[theme.editorError])\\\
- end\\\
- term.clearLine()\\\
- \\\
- term.setCursorPos(1 - scrollx + offx, (ly - scrolly) + offy)\\\
- if ly == y then\\\
- if ly == liveErr.line and os.clock() - lastEventClock > 3 then\\\
- term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
- else term.setBackgroundColor(colors[theme.editorLineHightlight]) end\\\
- elseif ly == liveErr.line then term.setBackgroundColor(colors[theme.editorError])\\\
- else term.setBackgroundColor(colors[theme.editorBackground]) end\\\
- if ly == liveErr.line then\\\
- if displayCode then term.write(a)\\\
- else term.write(liveErr.display) end\\\
- else writeHighlighted(a) end\\\
- \\\
- term.setCursorPos(1, (ly - scrolly) + offy)\\\
- if ly == y then\\\
- if ly == liveErr.line and os.clock() - lastEventClock > 3 then\\\
- term.setBackgroundColor(colors[theme.editorError])\\\
- else term.setBackgroundColor(colors[theme.editorLineNumbersHighlight]) end\\\
- elseif ly == liveErr.line then\\\
- term.setBackgroundColor(colors[theme.editorErrorHighlight])\\\
- else term.setBackgroundColor(colors[theme.editorLineNumbers]) end\\\
- term.write(ln)\\\
- end\\\
- end\\\
- term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
- end\\\
- \\\
- local function cursorLoc(x, y, force)\\\
- local sx, sy = x - scrollx, y - scrolly\\\
- local redraw = false\\\
- if sx < 1 then\\\
- scrollx = x - 1\\\
- sx = 1\\\
- redraw = true\\\
- elseif sx > edw then\\\
- scrollx = x - edw\\\
- sx = edw\\\
- redraw = true\\\
- end if sy < 1 then\\\
- scrolly = y - 1\\\
- sy = 1\\\
- redraw = true\\\
- elseif sy > edh then\\\
- scrolly = y - edh\\\
- sy = edh\\\
- redraw = true\\\
- end if redraw or force then draw() end\\\
- term.setCursorPos(sx + offx, sy + offy)\\\
- end\\\
- \\\
- local function executeMenuItem(a, path)\\\
- if type(a) == \\\"string\\\" and menuFunctions[a] then\\\
- local opt, nl, gtln = menuFunctions[a](path, lines, y)\\\
- if type(opt) == \\\"string\\\" then term.setCursorBlink(false) return opt end\\\
- if type(nl) == \\\"table\\\" then\\\
- if #lines < 1 then table.insert(lines, \\\"\\\") end\\\
- y = math.min(y, #lines)\\\
- x = math.min(x, lines[y]:len() + 1)\\\
- lines = nl\\\
- elseif type(nl) == \\\"string\\\" then\\\
- if nl == \\\"go to\\\" and gtln then\\\
- x, y = 1, math.min(#lines, gtln)\\\
- cursorLoc(x, y)\\\
- end\\\
- end\\\
- end\\\
- term.setCursorBlink(true)\\\
- draw()\\\
- term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
- end\\\
- \\\
- local function edit(path)\\\
- -- Variables\\\
- x, y = 1, 1\\\
- offx, offy = 0, 1\\\
- scrollx, scrolly = 0, 0\\\
- lines = loadFile(path)\\\
- if not lines then return \\\"menu\\\" end\\\
- \\\
- -- Enable brainfuck\\\
- if lines[1] == \\\"-- Syntax: Brainfuck\\\" then\\\
- curLanguage = languages.brainfuck\\\
- end\\\
- \\\
- -- Clocks\\\
- local autosaveClock = os.clock()\\\
- local scrollClock = os.clock() -- To prevent redraw flicker\\\
- local liveErrorClock = os.clock()\\\
- local hasScrolled = false\\\
- \\\
- -- Draw\\\
- draw()\\\
- term.setCursorPos(x + offx, y + offy)\\\
- term.setCursorBlink(true)\\\
- \\\
- -- Main loop\\\
- local tid = os.startTimer(3)\\\
- while true do\\\
- local e, key, cx, cy = os.pullEvent()\\\
- if e == \\\"key\\\" and allowEditorEvent then\\\
- if key == 200 and y > 1 then\\\
- -- Up\\\
- x, y = math.min(x, lines[y - 1]:len() + 1), y - 1\\\
- drawLine(y, y + 1)\\\
- cursorLoc(x, y)\\\
- elseif key == 208 and y < #lines then\\\
- -- Down\\\
- x, y = math.min(x, lines[y + 1]:len() + 1), y + 1\\\
- drawLine(y, y - 1)\\\
- cursorLoc(x, y)\\\
- elseif key == 203 and x > 1 then\\\
- -- Left\\\
- x = x - 1\\\
- local force = false\\\
- if y - scrolly + offy < offy + 1 then force = true end\\\
- cursorLoc(x, y, force)\\\
- elseif key == 205 and x < lines[y]:len() + 1 then\\\
- -- Right\\\
- x = x + 1\\\
- local force = false\\\
- if y - scrolly + offy < offy + 1 then force = true end\\\
- cursorLoc(x, y, force)\\\
- elseif (key == 28 or key == 156) and (displayCode and true or y + scrolly - 1 ==\\\
- liveErr.line) then\\\
- -- Enter\\\
- local f = nil\\\
- for _, v in pairs(standardsCompletions) do\\\
- if lines[y]:find(v) then f = v end\\\
- end\\\
- \\\
- local _, spaces = lines[y]:find(\\\"^[ ]+\\\")\\\
- if not spaces then spaces = 0 end\\\
- if f then\\\
- table.insert(lines, y + 1, string.rep(\\\" \\\", spaces + 2))\\\
- if not f:find(\\\"else\\\", 1, true) and not f:find(\\\"elseif\\\", 1, true) then\\\
- table.insert(lines, y + 2, string.rep(\\\" \\\", spaces) .. \\\
- (f:find(\\\"repeat\\\", 1, true) and \\\"until \\\" or f:find(\\\"{\\\", 1, true) and \\\"}\\\" or \\\
- \\\"end\\\"))\\\
- end\\\
- x, y = spaces + 3, y + 1\\\
- cursorLoc(x, y, true)\\\
- else\\\
- local oldLine = lines[y]\\\
- \\\
- lines[y] = lines[y]:sub(1, x - 1)\\\
- table.insert(lines, y + 1, string.rep(\\\" \\\", spaces) .. oldLine:sub(x, -1))\\\
- \\\
- x, y = spaces + 1, y + 1\\\
- cursorLoc(x, y, true)\\\
- end\\\
- elseif key == 14 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\\\
- -- Backspace\\\
- if x > 1 then\\\
- local f = false\\\
- for k, v in pairs(liveCompletions) do\\\
- if lines[y]:sub(x - 1, x - 1) == k then f = true end\\\
- end\\\
- \\\
- lines[y] = lines[y]:sub(1, x - 2) .. lines[y]:sub(x + (f and 1 or 0), -1)\\\
- drawLine(y)\\\
- x = x - 1\\\
- cursorLoc(x, y)\\\
- elseif y > 1 then\\\
- local prevLen = lines[y - 1]:len() + 1\\\
- lines[y - 1] = lines[y - 1] .. lines[y]\\\
- table.remove(lines, y)\\\
- x, y = prevLen, y - 1\\\
- cursorLoc(x, y, true)\\\
- end\\\
- elseif key == 199 then\\\
- -- Home\\\
- x = 1\\\
- local force = false\\\
- if y - scrolly + offy < offy + 1 then force = true end\\\
- cursorLoc(x, y, force)\\\
- elseif key == 207 then\\\
- -- End\\\
- x = lines[y]:len() + 1\\\
- local force = false\\\
- if y - scrolly + offy < offy + 1 then force = true end\\\
- cursorLoc(x, y, force)\\\
- elseif key == 211 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\\\
- -- Forward Delete\\\
- if x < lines[y]:len() + 1 then\\\
- lines[y] = lines[y]:sub(1, x - 1) .. lines[y]:sub(x + 1)\\\
- local force = false\\\
- if y - scrolly + offy < offy + 1 then force = true end\\\
- drawLine(y)\\\
- cursorLoc(x, y, force)\\\
- elseif y < #lines then\\\
- lines[y] = lines[y] .. lines[y + 1]\\\
- table.remove(lines, y + 1)\\\
- draw()\\\
- cursorLoc(x, y)\\\
- end\\\
- elseif key == 15 and (displayCode and true or y + scrolly - 1 == liveErr.line) then\\\
- -- Tab\\\
- lines[y] = string.rep(\\\" \\\", tabWidth) .. lines[y]\\\
- x = x + 2\\\
- local force = false\\\
- if y - scrolly + offy < offy + 1 then force = true end\\\
- drawLine(y)\\\
- cursorLoc(x, y, force)\\\
- elseif key == 201 then\\\
- -- Page up\\\
- y = math.min(math.max(y - edh, 1), #lines)\\\
- x = math.min(lines[y]:len() + 1, x)\\\
- cursorLoc(x, y, true)\\\
- elseif key == 209 then\\\
- -- Page down\\\
- y = math.min(math.max(y + edh, 1), #lines)\\\
- x = math.min(lines[y]:len() + 1, x)\\\
- cursorLoc(x, y, true)\\\
- end\\\
- elseif e == \\\"char\\\" and allowEditorEvent and (displayCode and true or \\\
- y + scrolly - 1 == liveErr.line) then\\\
- local shouldIgnore = false\\\
- for k, v in pairs(liveCompletions) do\\\
- if key == v and lines[y]:find(k, 1, true) and lines[y]:sub(x, x) == v then\\\
- shouldIgnore = true\\\
- end\\\
- end\\\
- \\\
- local addOne = false\\\
- if not shouldIgnore then\\\
- for k, v in pairs(liveCompletions) do\\\
- if key == k and lines[y]:sub(x, x) ~= k then key = key .. v addOne = true end\\\
- end\\\
- lines[y] = lines[y]:sub(1, x - 1) .. key .. lines[y]:sub(x, -1)\\\
- end\\\
- \\\
- x = x + (addOne and 1 or key:len())\\\
- local force = false\\\
- if y - scrolly + offy < offy + 1 then force = true end\\\
- drawLine(y)\\\
- cursorLoc(x, y, force)\\\
- elseif e == \\\"mouse_click\\\" and key == 1 then\\\
- if cy > 1 then\\\
- if cx <= offx and cy - offy == liveErr.line - scrolly then\\\
- displayCode = not displayCode\\\
- drawLine(liveErr.line)\\\
- else\\\
- local oldy = y\\\
- y = math.min(math.max(scrolly + cy - offy, 1), #lines)\\\
- x = math.min(math.max(scrollx + cx - offx, 1), lines[y]:len() + 1)\\\
- if oldy ~= y then drawLine(oldy, y) end\\\
- cursorLoc(x, y)\\\
- end\\\
- else\\\
- local a = triggerMenu(cx, cy)\\\
- if a then\\\
- local opt = executeMenuItem(a, path)\\\
- if opt then return opt end\\\
- end\\\
- end\\\
- elseif e == \\\"shortcut\\\" then\\\
- local a = shortcuts[key .. \\\" \\\" .. cx]\\\
- if a then\\\
- local parent = nil\\\
- local curx = 0\\\
- for i, mv in ipairs(menu) do\\\
- for _, iv in pairs(mv) do\\\
- if iv == a then\\\
- parent = menu[i][1]\\\
- break\\\
- end\\\
- end\\\
- if parent then break end\\\
- curx = curx + mv[1]:len() + 3\\\
- end\\\
- local menux = curx + 2\\\
- \\\
- -- Flash menu item\\\
- term.setCursorBlink(false)\\\
- term.setCursorPos(menux, 1)\\\
- term.setBackgroundColor(colors[theme.background])\\\
- term.write(string.rep(\\\" \\\", parent:len() + 2))\\\
- term.setCursorPos(menux + 1, 1)\\\
- term.write(parent)\\\
- sleep(0.1)\\\
- drawMenu()\\\
- \\\
- -- Execute item\\\
- local opt = executeMenuItem(a, path)\\\
- if opt then return opt end\\\
- end\\\
- elseif e == \\\"mouse_scroll\\\" then\\\
- if key == -1 and scrolly > 0 then\\\
- scrolly = scrolly - 1\\\
- if os.clock() - scrollClock > 0.0005 then\\\
- draw()\\\
- term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
- end\\\
- scrollClock = os.clock()\\\
- hasScrolled = true\\\
- elseif key == 1 and scrolly < #lines - edh then\\\
- scrolly = scrolly + 1\\\
- if os.clock() - scrollClock > 0.0005 then\\\
- draw()\\\
- term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
- end\\\
- scrollClock = os.clock()\\\
- hasScrolled = true\\\
- end\\\
- elseif e == \\\"timer\\\" and key == tid then\\\
- drawLine(y)\\\
- tid = os.startTimer(3)\\\
- end\\\
- \\\
- -- Draw\\\
- if hasScrolled and os.clock() - scrollClock > 0.1 then\\\
- draw()\\\
- term.setCursorPos(x - scrollx + offx, y - scrolly + offy)\\\
- hasScrolled = false\\\
- end\\\
- \\\
- -- Autosave\\\
- if os.clock() - autosaveClock > autosaveInterval then\\\
- saveFile(path, lines)\\\
- autosaveClock = os.clock()\\\
- end\\\
- \\\
- -- Errors\\\
- if os.clock() - liveErrorClock > 1 then\\\
- local prevLiveErr = liveErr\\\
- liveErr = curLanguage.parseError(nil)\\\
- local code = \\\"\\\"\\\
- for _, v in pairs(lines) do code = code .. v .. \\\"\\\\n\\\" end\\\
- \\\
- liveErr = curLanguage.getCompilerErrors(code)\\\
- liveErr.line = math.min(liveErr.line - 2, #lines)\\\
- if liveErr ~= prevLiveErr then draw() end\\\
- liveErrorClock = os.clock()\\\
- end\\\
- end\\\
- \\\
- return \\\"menu\\\"\\\
- end\\\
- \\\
- \\\
- -- -------- Open File\\\
- \\\
- local function newFile()\\\
- local wid = w - 13\\\
- \\\
- -- Get name\\\
- title(\\\"Lua IDE - New File\\\")\\\
- local name = centerRead(wid, \\\"/\\\")\\\
- if not name or name == \\\"\\\" then return \\\"menu\\\" end\\\
- name = \\\"/\\\" .. name\\\
- \\\
- -- Clear\\\
- title(\\\"Lua IDE - New File\\\")\\\
- term.setTextColor(colors[theme.textColor])\\\
- term.setBackgroundColor(colors[theme.promptHighlight])\\\
- for i = 8, 10 do\\\
- term.setCursorPos(w/2 - wid/2, i)\\\
- term.write(string.rep(\\\" \\\", wid))\\\
- end\\\
- term.setCursorPos(1, 9)\\\
- if fs.isDir(name) then\\\
- centerPrint(\\\"Cannot Edit a Directory!\\\")\\\
- sleep(1.6)\\\
- return \\\"menu\\\"\\\
- elseif fs.exists(name) then\\\
- centerPrint(\\\"File Already Exists!\\\")\\\
- local opt = prompt({{\\\"Open\\\", w/2 - 9, 14}, {\\\"Cancel\\\", w/2 + 2, 14}}, \\\"horizontal\\\")\\\
- if opt == \\\"Open\\\" then return \\\"edit\\\", name\\\
- elseif opt == \\\"Cancel\\\" then return \\\"menu\\\" end\\\
- else return \\\"edit\\\", name end\\\
- end\\\
- \\\
- local function openFile()\\\
- local wid = w - 13\\\
- \\\
- -- Get name\\\
- title(\\\"Lua IDE - Open File\\\")\\\
- local name = centerRead(wid, \\\"/\\\")\\\
- if not name or name == \\\"\\\" then return \\\"menu\\\" end\\\
- name = \\\"/\\\" .. name\\\
- \\\
- -- Clear\\\
- title(\\\"Lua IDE - New File\\\")\\\
- term.setTextColor(colors[theme.textColor])\\\
- term.setBackgroundColor(colors[theme.promptHighlight])\\\
- for i = 8, 10 do\\\
- term.setCursorPos(w/2 - wid/2, i)\\\
- term.write(string.rep(\\\" \\\", wid))\\\
- end\\\
- term.setCursorPos(1, 9)\\\
- if fs.isDir(name) then\\\
- centerPrint(\\\"Cannot Open a Directory!\\\")\\\
- sleep(1.6)\\\
- return \\\"menu\\\"\\\
- elseif not fs.exists(name) then\\\
- centerPrint(\\\"File Doesn't Exist!\\\")\\\
- local opt = prompt({{\\\"Create\\\", w/2 - 11, 14}, {\\\"Cancel\\\", w/2 + 2, 14}}, \\\"horizontal\\\")\\\
- if opt == \\\"Create\\\" then return \\\"edit\\\", name\\\
- elseif opt == \\\"Cancel\\\" then return \\\"menu\\\" end\\\
- else return \\\"edit\\\", name end\\\
- end\\\
- \\\
- \\\
- -- -------- Settings\\\
- \\\
- local function update()\\\
- local function draw(status)\\\
- title(\\\"LuaIDE - Update\\\")\\\
- term.setBackgroundColor(colors[theme.prompt])\\\
- term.setTextColor(colors[theme.textColor])\\\
- for i = 8, 10 do\\\
- term.setCursorPos(w/2 - (status:len() + 4), i)\\\
- write(string.rep(\\\" \\\", status:len() + 4))\\\
- end\\\
- term.setCursorPos(w/2 - (status:len() + 4), 9)\\\
- term.write(\\\" - \\\" .. status .. \\\" \\\")\\\
- \\\
- term.setBackgroundColor(colors[theme.errHighlight])\\\
- for i = 8, 10 do\\\
- term.setCursorPos(w/2 + 2, i)\\\
- term.write(string.rep(\\\" \\\", 10))\\\
- end\\\
- term.setCursorPos(w/2 + 2, 9)\\\
- term.write(\\\" > Cancel \\\")\\\
- end\\\
- \\\
- if not http then\\\
- draw(\\\"HTTP API Disabled!\\\")\\\
- sleep(1.6)\\\
- return \\\"settings\\\"\\\
- end\\\
- \\\
- draw(\\\"Updating...\\\")\\\
- local tID = os.startTimer(10)\\\
- http.request(updateURL)\\\
- while true do\\\
- local e, but, x, y = os.pullEvent()\\\
- if (e == \\\"key\\\" and but == 28) or\\\
- (e == \\\"mouse_click\\\" and x >= w/2 + 2 and x <= w/2 + 12 and y == 9) then\\\
- draw(\\\"Cancelled\\\")\\\
- sleep(1.6)\\\
- break\\\
- elseif e == \\\"http_success\\\" and but == updateURL then\\\
- local new = x.readAll()\\\
- local curf = io.open(ideLocation, \\\"r\\\")\\\
- local cur = curf:read(\\\"*a\\\")\\\
- curf:close()\\\
- \\\
- if cur ~= new then\\\
- draw(\\\"Update Found\\\")\\\
- sleep(1.6)\\\
- local f = io.open(ideLocation, \\\"w\\\")\\\
- f:write(new)\\\
- f:close()\\\
- \\\
- draw(\\\"Click to Exit\\\")\\\
- while true do\\\
- local e = os.pullEvent()\\\
- if e == \\\"mouse_click\\\" or (not isAdvanced() and e == \\\"key\\\") then break end\\\
- end\\\
- return \\\"exit\\\"\\\
- else\\\
- draw(\\\"No Updates Found!\\\")\\\
- sleep(1.6)\\\
- break\\\
- end\\\
- elseif e == \\\"http_failure\\\" or (e == \\\"timer\\\" and but == tID) then\\\
- draw(\\\"Update Failed!\\\")\\\
- sleep(1.6)\\\
- break\\\
- end\\\
- end\\\
- \\\
- return \\\"settings\\\"\\\
- end\\\
- \\\
- local function changeTheme()\\\
- title(\\\"LuaIDE - Theme\\\")\\\
- \\\
- if isAdvanced() then\\\
- local disThemes = {\\\"Back\\\"}\\\
- for _, v in pairs(availableThemes) do table.insert(disThemes, v[1]) end\\\
- local t = scrollingPrompt(disThemes)\\\
- local url = nil\\\
- for _, v in pairs(availableThemes) do if v[1] == t then url = v[2] end end\\\
- \\\
- if not url then return \\\"settings\\\" end\\\
- if t == \\\"Dawn (Default)\\\" then\\\
- term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
- term.setCursorPos(3, 3)\\\
- term.clearLine()\\\
- term.write(\\\"LuaIDE - Loaded Theme!\\\")\\\
- sleep(1.6)\\\
- \\\
- fs.delete(themeLocation)\\\
- theme = defaultTheme\\\
- return \\\"menu\\\"\\\
- end\\\
- \\\
- term.setBackgroundColor(colors[theme.backgroundHighlight])\\\
- term.setCursorPos(3, 3)\\\
- term.clearLine()\\\
- term.write(\\\"LuaIDE - Downloading...\\\")\\\
- \\\
- fs.delete(\\\"/.LuaIDE_temp_theme_file\\\")\\\
- download(url, \\\"/.LuaIDE_temp_theme_file\\\")\\\
- local a = loadTheme(\\\"/.LuaIDE_temp_theme_file\\\")\\\
- \\\
- term.setCursorPos(3, 3)\\\
- term.clearLine()\\\
- if a then\\\
- term.write(\\\"LuaIDE - Loaded Theme!\\\")\\\
- fs.delete(themeLocation)\\\
- fs.move(\\\"/.LuaIDE_temp_theme_file\\\", themeLocation)\\\
- theme = a\\\
- sleep(1.6)\\\
- return \\\"menu\\\"\\\
- end\\\
- \\\
- term.write(\\\"LuaIDE - Could Not Load Theme!\\\")\\\
- fs.delete(\\\"/.LuaIDE_temp_theme_file\\\")\\\
- sleep(1.6)\\\
- return \\\"settings\\\"\\\
- else\\\
- term.setCursorPos(1, 8)\\\
- centerPrint(\\\"Themes are not available on\\\")\\\
- centerPrint(\\\"normal computers!\\\")\\\
- end\\\
- end\\\
- \\\
- local function settings()\\\
- title(\\\"LuaIDE - Settings\\\")\\\
- \\\
- local opt = prompt({{\\\"Change Theme\\\", w/2 - 17, 8}, {\\\"Return to Menu\\\", w/2 - 22, 13},\\\
- {\\\"Check for Updates\\\", w/2 + 2, 8}, {\\\"Exit IDE\\\", w/2 + 2, 13, bg = colors[theme.err], \\\
- highlight = colors[theme.errHighlight]}}, \\\"vertical\\\", true)\\\
- if opt == \\\"Change Theme\\\" then return changeTheme()\\\
- elseif opt == \\\"Check for Updates\\\" then return update()\\\
- elseif opt == \\\"Return to Menu\\\" then return \\\"menu\\\"\\\
- elseif opt == \\\"Exit IDE\\\" then return \\\"exit\\\" end\\\
- end\\\
- \\\
- \\\
- -- -------- Menu\\\
- \\\
- local function menu()\\\
- title(\\\"Welcome to LuaIDE \\\" .. version)\\\
- \\\
- local opt = prompt({{\\\"New File\\\", w/2 - 13, 8}, {\\\"Open File\\\", w/2 - 14, 13},\\\
- {\\\"Settings\\\", w/2 + 2, 8}, {\\\"Exit IDE\\\", w/2 + 2, 13, bg = colors[theme.err],\\\
- highlight = colors[theme.errHighlight]}}, \\\"vertical\\\", true)\\\
- if opt == \\\"New File\\\" then return \\\"new\\\"\\\
- elseif opt == \\\"Open File\\\" then return \\\"open\\\"\\\
- elseif opt == \\\"Settings\\\" then return \\\"settings\\\"\\\
- elseif opt == \\\"Exit IDE\\\" then return \\\"exit\\\" end\\\
- end\\\
- \\\
- \\\
- -- -------- Main\\\
- \\\
- local function main(arguments)\\\
- local opt, data = \\\"menu\\\", nil\\\
- \\\
- -- Check arguments\\\
- if type(arguments) == \\\"table\\\" and #arguments > 0 then\\\
- local f = \\\"/\\\" .. shell.resolve(arguments[1])\\\
- if fs.isDir(f) then print(\\\"Cannot edit a directory.\\\") end\\\
- opt, data = \\\"edit\\\", f\\\
- end\\\
- \\\
- -- Main run loop\\\
- while true do\\\
- -- Menu\\\
- if opt == \\\"menu\\\" then opt = menu() end\\\
- \\\
- -- Other\\\
- if opt == \\\"new\\\" then opt, data = newFile()\\\
- elseif opt == \\\"open\\\" then opt, data = openFile()\\\
- elseif opt == \\\"settings\\\" then opt = settings()\\\
- end if opt == \\\"exit\\\" then break end\\\
- \\\
- -- Edit\\\
- if opt == \\\"edit\\\" and data then opt = edit(data) end\\\
- end\\\
- end\\\
- \\\
- -- Load Theme\\\
- if fs.exists(themeLocation) then theme = loadTheme(themeLocation) end\\\
- if not theme and isAdvanced() then theme = defaultTheme\\\
- elseif not theme then theme = normalTheme end\\\
- \\\
- -- Run\\\
- local _, err = pcall(function()\\\
- parallel.waitForAny(function() main(args) end, monitorKeyboardShortcuts)\\\
- end)\\\
- \\\
- -- Catch errors\\\
- if err and not err:find(\\\"Terminated\\\") then\\\
- term.setCursorBlink(false)\\\
- title(\\\"LuaIDE - Crash! D:\\\")\\\
- \\\
- term.setBackgroundColor(colors[theme.err])\\\
- for i = 6, 8 do\\\
- term.setCursorPos(5, i)\\\
- term.write(string.rep(\\\" \\\", 36))\\\
- end\\\
- term.setCursorPos(6, 7)\\\
- term.write(\\\"LuaIDE Has Crashed! D:\\\")\\\
- \\\
- term.setBackgroundColor(colors[theme.background])\\\
- term.setCursorPos(2, 10)\\\
- print(err)\\\
- \\\
- term.setBackgroundColor(colors[theme.prompt])\\\
- local _, cy = term.getCursorPos()\\\
- for i = cy + 1, cy + 4 do\\\
- term.setCursorPos(5, i)\\\
- term.write(string.rep(\\\" \\\", 36))\\\
- end\\\
- term.setCursorPos(6, cy + 2)\\\
- term.write(\\\"Please report this error to\\\")\\\
- term.setCursorPos(6, cy + 3)\\\
- term.write(\\\"GravityScore! \\\")\\\
- \\\
- term.setBackgroundColor(colors[theme.background])\\\
- if isAdvanced() then centerPrint(\\\"Click to Exit...\\\", h - 1)\\\
- else centerPrint(\\\"Press Any Key to Exit...\\\", h - 1) end\\\
- while true do\\\
- local e = os.pullEvent()\\\
- if e == \\\"mouse_click\\\" or (not isAdvanced() and e == \\\"key\\\") then break end\\\
- end\\\
- \\\
- -- Prevent key from being shown\\\
- os.queueEvent(event_distract)\\\
- os.pullEvent()\\\
- end\\\
- \\\
- -- Exit\\\
- term.setBackgroundColor(colors.black)\\\
- term.setTextColor(colors.white)\\\
- term.clear()\\\
- term.setCursorPos(1, 1)\\\
- centerPrint(\\\"Thank You for Using Lua IDE \\\" .. version)\\\
- centerPrint(\\\"Made by GravityScore\\\")\",\
- path = \"/rootfs/apps/LuaIDE.app/main\",\
- },\
- {\
- text = \" 37L37u37a37 37 37\\\
- 37 37Ie7De7Ee7 37\\\
- b7Gb7Sb7 b7 b7 b7\\\
- b7 b7 b7 b7 b7 b7\",\
- path = \"/rootfs/apps/LuaIDE.app/resources/icon.png\",\
- },\
- {\
- text = \"-----------------------ВСЯКпЕ ПОЛЕЗНОСТп----------------------\\\
- if not term.isColor() then error(\\\"This program will work only on advanced computer.\\\") end\\\
- local Args = {...}\\\
- os.loadAPI(\\\"System/api/context\\\")\\\
- os.loadAPI(\\\"System/api/image\\\")\\\
- os.loadAPI(\\\"System/api/filemanager\\\")\\\
- os.loadAPI(\\\"System/api/windows\\\")\\\
- \\\
- ----------------------ОБЪЯВЛЕНпЕ ПЕРЕМЕННЫХ----------------------\\\
- local xSize, ySize = term.getSize()\\\
- \\\
- --СУПЕР-ОПпЗДОХУЕННЫЙ АЛГОРпТМ СОЗДАНпЯ ОКОН - САМ УЖЕ СМУТНО ПОНпМАЮ, КАК ОНО РАБОТАЕТ, НО РАБОТАЕТ НОРМ\\\
- --СОЗДАНпЕ ОКНА ОТ ТЕКУЩЕГО ТЕРМпНАЛА ЧпСТО ДЛЯ СОЗДАНпЯ ПЕРЕМЕННОЙ DEFAULTTERM\\\
- local windowForDrawing = window.create(term.current(), 3, 2, xSize-12, ySize-1,true)\\\
- local defaultTerm = term.redirect(windowForDrawing)\\\
- --ВОССТАНОВЛЕНпЕ СТАНДАРТНОГО СОСТОЯНпЯ TERM\\\
- term.redirect(term.native())\\\
- --СОЗДАНпЕ ОКНА ДЛЯ РАБОТЫ С РпСУНКОМ, ФпНАЛ\\\
- windowForDrawing = window.create(term.native(), 3, 2, xSize-12, ySize-1,true)\\\
- \\\
- --МАССпВЫ ОБЪЕКТОВ\\\
- local Obj = {}\\\
- local ObjColor = {}\\\
- \\\
- --ВСЯКАЯ ХУЙНЯ С ПАРАМЕТРАМп СОЗДАВАЕМОГО пЗОБРАЖЕНпЯ\\\
- local imageSizeX = 36\\\
- local imageSizeY = 15\\\
- local transparentSymbol = \\\"+\\\"\\\
- local displayImageFromX = 4\\\
- local displayImageFromY = 3\\\
- local displayImageEndX = displayImageFromX + imageSizeX - 1\\\
- local displayImageEndY = displayImageFromY + imageSizeY - 1\\\
- \\\
- --МАСпВ СОКРАЩЕННЫХ В ОДпН СпМВОЛ ЦВЕТОВ ДЛЯ СОХРАНЕНпЯ пЗОБРАЖЕНпЯ В ФАЙЛ\\\
- local Colors = {\\\
- [\\\"0\\\"] = 1,\\\
- [\\\"1\\\"] = 2,\\\
- [\\\"2\\\"] = 4,\\\
- [\\\"3\\\"] = 8,\\\
- [\\\"4\\\"] = 16,\\\
- [\\\"5\\\"] = 32,\\\
- [\\\"6\\\"] = 64,\\\
- [\\\"7\\\"] = 128,\\\
- [\\\"8\\\"] = 256,\\\
- [\\\"9\\\"] = 512,\\\
- [\\\"a\\\"] = 1024,\\\
- [\\\"b\\\"] = 2048,\\\
- [\\\"c\\\"] = 4096,\\\
- [\\\"d\\\"] = 8192,\\\
- [\\\"e\\\"] = 16384,\\\
- [\\\"f\\\"] = 32768\\\
- }\\\
- \\\
- --МАССпВ СООТВЕТСТВпЯ ЦВЕТА НА ЭКРАНЕ БЛОКУ В МпРЕ МАЙНА\\\
- local Blocks = {\\\
- [1] = {[\\\"id\\\"]=\\\"quartz_block\\\",[\\\"data\\\"]=\\\"0\\\"},\\\
- [2] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"1\\\"},\\\
- [4] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"2\\\"},\\\
- [8] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"3\\\"},\\\
- [16] = {[\\\"id\\\"]=\\\"gold_block\\\",[\\\"data\\\"]=\\\"0\\\"},\\\
- [32] = {[\\\"id\\\"]=\\\"emerald_block\\\",[\\\"data\\\"]=\\\"0\\\"},\\\
- [64] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"6\\\"},\\\
- [128] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"7\\\"},\\\
- [256] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"8\\\"},\\\
- [512] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"9\\\"},\\\
- [1024] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"10\\\"},\\\
- [2048] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"11\\\"},\\\
- [4096] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"12\\\"},\\\
- [8192] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"13\\\"},\\\
- [16384] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"14\\\"},\\\
- [32768] = {[\\\"id\\\"]=\\\"wool\\\",[\\\"data\\\"]=\\\"15\\\"}\\\
- }\\\
- \\\
- --МАССпВ ПпКСЕЛЕЙ НА ЭКРАНЕ\\\
- local Pixels = {}\\\
- \\\
- --ВСЯКАЯ ХУЙНЯ, КАСАЮЩАЯСЯ пНСТРУМЕНТОВ, ЦВЕТОВ п ПРОЧЕГО\\\
- local currentInstrument = \\\"B\\\"\\\
- local currentTextColor = colors.white\\\
- local currentBackColor = colors.black\\\
- local currentSymbol = \\\" \\\"\\\
- \\\
- --ВСЯКАЯ ХУЙНЯ ПРО КОМАНДНЫЕ БЛОКп\\\
- local CommandBlockIsActive = false\\\
- local commandBlockAttachedAt = \\\"\\\"\\\
- local CommandBlock = {}\\\
- \\\
- --ГОВНЕЦО ДЛЯ ФАСТ СЕЙВА ФАЙЛпКОВ\\\
- local fastFileMode = false\\\
- local fastFilePath = nil\\\
- \\\
- local pathForFastSaving = nil\\\
- \\\
- ------------------------ОБЪЯВЛЕНпЕ ФУНКЦпЙ-----------------------\\\
- \\\
- --ПОпСК ПЕРпФЕРпп В ВпДЕ КОМАНДНОГО БЛОКА. ЕСЛп НЕ НАХОДпТ, ТО NIL\\\
- function findCommandBlock()\\\
- local PeriList = peripheral.getNames()\\\
- for i=1,#PeriList do\\\
- if peripheral.getType(PeriList[i]) == \\\"command\\\" then\\\
- return PeriList[i]\\\
- end\\\
- end\\\
- end\\\
- \\\
- --УСТАНОВКА п ЗАПУСК КОМАНДЫ В КОМАНДНЫЙ БЛОК\\\
- local function cb(command)\\\
- CommandBlock.setCommand(command)\\\
- CommandBlock.runCommand()\\\
- end\\\
- \\\
- --УСТАНОВКА БЛОКА В МпРЕ МАЙНА ПО КООРДпНАТАМ\\\
- local function setBlock(x,y,id,data)\\\
- cb(\\\"/setblock ~\\\"..(x-math.floor(imageSizeX/2))..\\\" ~\\\"..(ySize+3-y)..\\\" ~0 minecraft:\\\"..id..\\\" \\\"..data)\\\
- end\\\
- \\\
- --ОЧпСТКА ВСЕХ НАРпСОВАННЫХ БЛОКОВ В МпРЕ МАЙНА\\\
- local function clearAll()\\\
- for x=1,xSize do\\\
- for y=1,ySize do\\\
- setBlock(x,y,\\\"air\\\",\\\"0\\\")\\\
- end\\\
- end\\\
- end\\\
- \\\
- local function changeDisplayImageFromParameters(x,y)\\\
- displayImageFromX = x\\\
- displayImageFromY = y\\\
- displayImageEndX = displayImageFromX + imageSizeX - 1\\\
- displayImageEndY = displayImageFromY + imageSizeY - 1\\\
- end\\\
- \\\
- --СОЗДАНпЕ ОБЪЕКТОВ КНОПОК\\\
- local function newObj(name,x1,y1,width,height)\\\
- Obj[name]={}\\\
- Obj[name][\\\"x1\\\"]=x1\\\
- Obj[name][\\\"y1\\\"]=y1\\\
- Obj[name][\\\"x2\\\"]=x1+width-1\\\
- Obj[name][\\\"y2\\\"]=y1+height-1\\\
- end\\\
- \\\
- --СОЗДАНпЕ ОБЪЕКТА ЦВЕТОВ\\\
- local function newObjColor(name,x1,y1,width)\\\
- ObjColor[name]={}\\\
- ObjColor[name][\\\"x1\\\"]=x1\\\
- ObjColor[name][\\\"y1\\\"]=y1\\\
- ObjColor[name][\\\"x2\\\"]=x1+width-1\\\
- end\\\
- \\\
- --ПРОСТОЕ ОТОБРАЖЕНпЕ ТЕКСТА ПО КООРДпНАТАМ\\\
- local function usualText(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- --УНпВЕРСАЛЬНАЯ ФУНКЦпЯ ДЛЯ ОТОБРАЖЕНпЯ ТЕКСТА ПО ЦЕНТРУ ЭКРАНА\\\
- local function centerText(how,coord,text,textColor,backColor)\\\
- term.setTextColor(textColor)\\\
- term.setBackgroundColor(backColor)\\\
- if how == \\\"xy\\\" then\\\
- term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2))\\\
- elseif how == \\\"x\\\" then\\\
- term.setCursorPos(math.floor(xSize/2-#text/2),coord)\\\
- elseif how == \\\"y\\\" then\\\
- term.setCursorPos(coord,math.floor(ySize/2))\\\
- end\\\
- term.write(text)\\\
- end\\\
- \\\
- --РпСОВАНпЕ КВАДРАТА С ЗАЛпВКОЙ\\\
- local function square(x1,y1,width,height,color)\\\
- local string = string.rep(\\\" \\\",width)\\\
- term.setBackgroundColor(color)\\\
- for y=y1,(y1+height-1) do\\\
- usualText(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- --ЗАЛпВКА ЭКРАНА ЦВЕТОМ\\\
- local function clearScreen(color)\\\
- term.setBackgroundColor(color)\\\
- term.clear()\\\
- end\\\
- \\\
- --ПЛАВНОЕ ВКЛЮЧЕНпЕ ЭКРАНА\\\
- local function fadeIn(time)\\\
- clearScreen(colors.gray)\\\
- sleep(time)\\\
- clearScreen(colors.lightGray)\\\
- sleep(time)\\\
- clearScreen(colors.white)\\\
- sleep(time)\\\
- end\\\
- \\\
- --ПЛАВНОЕ ЗАТУХАНпЕ ЭКРАНА\\\
- local function fadeOut(time)\\\
- clearScreen(colors.lightGray)\\\
- sleep(time)\\\
- clearScreen(colors.gray)\\\
- sleep(time)\\\
- clearScreen(colors.black)\\\
- sleep(time)\\\
- term.setCursorPos(1,1)\\\
- term.setTextColor(colors.white)\\\
- end\\\
- \\\
- --ОТРпСОВКА ВЕРХНЕГО ТУЛБАРА\\\
- local function topBar()\\\
- local function topBarButton(x,y,text)\\\
- usualText(x,y,text)\\\
- newObj(text,x,y,#text,1)\\\
- end\\\
- \\\
- for i=1,xSize do\\\
- paintutils.drawPixel(i,1,colors.gray)\\\
- end\\\
- \\\
- term.setTextColor(colors.lightGray)\\\
- topBarButton(1,1,\\\"File\\\")\\\
- topBarButton(Obj[\\\"File\\\"][\\\"x2\\\"]+3,1,\\\"Edit\\\")\\\
- topBarButton(Obj[\\\"Edit\\\"][\\\"x2\\\"]+3,1,\\\"Quit\\\")\\\
- end\\\
- \\\
- --ОТРпСОВКА ВЫБРАННОГО ЦВЕТА п СпМВОЛА НА ЛЕВОМ ТУЛБАРЕ\\\
- local function leftBarColorBar()\\\
- square(1,ySize-2,2,2,currentTextColor)\\\
- paintutils.drawPixel(1,ySize-2,currentBackColor)\\\
- term.setTextColor(currentTextColor)\\\
- term.setCursorPos(1,ySize-2)\\\
- term.write(currentSymbol)\\\
- end\\\
- \\\
- --ОТРпСОВКА КНОПОК НА ЛЕВОМ ТУЛБАРЕ\\\
- local function leftBarButton(x,y,symbol)\\\
- if currentInstrument == symbol then\\\
- term.setTextColor(colors.white)\\\
- square(x,y,2,2,colors.blue)\\\
- else\\\
- term.setTextColor(colors.gray)\\\
- square(x,y,2,2,colors.black)\\\
- end\\\
- usualText(x,y+1,symbol)\\\
- newObj(symbol,x,y,2,2)\\\
- end\\\
- \\\
- --ОТРпСОВКА КАСТОМНЫХ КНОПОК НА ЛЕВОМ ТУЛБАРЕ\\\
- local function leftBarButtonPersonal(x,y,symbol,colorOfButton,colorOfText)\\\
- term.setTextColor(colorOfText)\\\
- square(x,y,2,2,colorOfButton)\\\
- usualText(x,y+1,symbol)\\\
- newObj(symbol,x,y,2,2)\\\
- end\\\
- \\\
- --ОТРпСОВКА ЛЕВОГО ТУЛБАРА\\\
- local function leftBar(activeInstrument)\\\
- square(1,2,2,ySize-1,colors.gray)\\\
- leftBarButton(1,2,\\\"M\\\")\\\
- leftBarButton(1,5,\\\"B\\\")\\\
- leftBarButton(1,8,\\\"E\\\")\\\
- leftBarButton(1,11,\\\"F\\\")\\\
- if CommandBlockIsActive then\\\
- leftBarButtonPersonal(1,14,\\\"CB\\\",colors.green,colors.white)\\\
- else\\\
- leftBarButtonPersonal(1,14,\\\"CB\\\",colors.black,colors.gray)\\\
- end\\\
- leftBarColorBar()\\\
- end\\\
- \\\
- --ОТРпСОВКА ПРАВОГО ТУЛБАРА\\\
- local function rightBar()\\\
- --НАРпСОВАТЬ КВАДРАТпК С УКАЗАННЫМ ЦВЕТОМ (ДЛЯ ПАЛпТРЫ)\\\
- local function drawColor(x,y,color)\\\
- for i=x,(x+1) do\\\
- paintutils.drawPixel(i,y,color)\\\
- newObjColor(color,x,y,2)\\\
- end\\\
- end\\\
- \\\
- square(xSize-9,2,10,ySize-1,colors.gray)\\\
- \\\
- for i=(xSize-9),xSize do\\\
- paintutils.drawPixel(i,2,colors.black)\\\
- end\\\
- term.setTextColor(colors.lightGray)\\\
- usualText(xSize-8,2,\\\"Colors\\\")\\\
- \\\
- --for i=(xSize-9),xSize do\\\
- -- paintutils.drawPixel(i,9,colors.black)\\\
- --end\\\
- --term.setTextColor(colors.lightGray)\\\
- --usualText(xSize-8,9,\\\"Layers\\\")\\\
- \\\
- --САМАЯ БОЛЬШАЯ ЖОПА, ОТОБРАЖЕНпЕ ЦВЕТОВОЙ ПАЛпТРЫ\\\
- local startXColor = 0\\\
- local startYColor = 0\\\
- for i=0,3 do\\\
- startXColor = xSize-8+i*2\\\
- startYColor = 4\\\
- drawColor(startXColor,startYColor,2^i)\\\
- newObjColor(2^i,startXColor,startYColor,2)\\\
- end\\\
- for i=4,7 do\\\
- startXColor = xSize-8+(i-4)*2\\\
- startYColor = 5\\\
- drawColor(startXColor,startYColor,2^i)\\\
- newObjColor(2^i,startXColor,startYColor,2)\\\
- end\\\
- for i=8,11 do\\\
- startXColor = xSize-8+(i-8)*2\\\
- startYColor = 6\\\
- drawColor(startXColor,startYColor,2^i)\\\
- newObjColor(2^i,startXColor,startYColor,2)\\\
- end\\\
- for i=12,15 do\\\
- startXColor = xSize-8+(i-12)*2\\\
- startYColor = 7\\\
- drawColor(startXColor,startYColor,2^i)\\\
- newObjColor(2^i,startXColor,startYColor,2)\\\
- end\\\
- end\\\
- \\\
- --ОТРпСОВКА РпСОВАЛЬНОЙ ЗОНЫ п САМОГО пЗОБРАЖЕНпЯ пЗ ПАМЯТп ПО МАССпВУ PIXELS\\\
- local function drawingArea()\\\
- \\\
- --ПЕРЕАДРЕСАЦпЯ С TERM НА СОЗДАННОЕ ОКНО\\\
- term.redirect(windowForDrawing)\\\
- \\\
- --ФУНКЦпЯ РпСОВАНпЯ \\\"ПРОЗРАЧНОЙ ЗОНЫ\\\" В ВпДЕ СпМВОЛОВ ПРОЗРАЧНОСТп, УКАЗАННЫХ РАНЕЕ\\\
- local function cresti(x1,y1,width,height,color)\\\
- local string = string.rep(transparentSymbol,width)\\\
- term.setBackgroundColor(color)\\\
- term.setTextColor(colors.lightGray)\\\
- for y=y1,(y1+height-1) do\\\
- usualText(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- --СМЕЩЕНпЕ ПО КООРДпНАТАМ ДЛЯ СТАРТОВОГО ОКНА\\\
- local smeshenieX = 2\\\
- local smeshenieY = 1\\\
- \\\
- --РпСОВАНпЕ БЕЛОЙ ПОДЛОЖКп п СпМВОЛОВ ПРОЗРАЧНОСТп (ТпПА ПРОЗРАЧНЫЙ ФОН)\\\
- square(1,1,xSize-12,ySize-1,colors.lightGray)\\\
- cresti(displayImageFromX-smeshenieX,displayImageFromY-smeshenieY,imageSizeX,imageSizeY,colors.white)\\\
- \\\
- --РпСОВАНпЕ \\\"ТЕНп\\\" пЗОБРАЖЕНпЯ\\\
- for i=1,imageSizeY do\\\
- paintutils.drawPixel(displayImageFromX+imageSizeX-smeshenieX,displayImageFromY+i-smeshenieY,colors.gray)\\\
- end\\\
- square(displayImageFromX+1-smeshenieX,displayImageFromY+imageSizeY-smeshenieY,imageSizeX,1,colors.gray)\\\
- \\\
- --РпСОВАНпЕ САМОГО пЗОБРАЖЕНпЯ пЗ ПАМЯТп\\\
- for y=1,#Pixels do\\\
- for x=1,#Pixels[y] do\\\
- if Pixels[y][x][\\\"symbol\\\"] ~= \\\"#\\\" then\\\
- term.setTextColor(Pixels[y][x][\\\"textColor\\\"])\\\
- term.setBackgroundColor(Pixels[y][x][\\\"backColor\\\"])\\\
- term.setCursorPos(displayImageFromX+x-1-smeshenieX,displayImageFromY+y-1-smeshenieY)\\\
- term.write(Pixels[y][x][\\\"symbol\\\"])\\\
- end\\\
- end\\\
- end\\\
- \\\
- --ПЕРЕАДРЕСАЦпЯ ОБРАТНО НА СТАНДАРТНЫЙ TERM\\\
- term.redirect(term.native())\\\
- end\\\
- \\\
- --ОТРпСОВКА ВСЕГО пНТЕРФЕЙСА\\\
- local function drawAllGui()\\\
- drawingArea()\\\
- topBar()\\\
- leftBar(currentInstrument)\\\
- rightBar()\\\
- end\\\
- \\\
- --пЗМЕНЕНпЕ ПАРАМЕТРОВ РАЗМЕРА пЗОБРАЖЕНпЯ В ПАМЯТп\\\
- local function changeImageSizeInMemory(width,height)\\\
- imageSizeX = width\\\
- imageSizeY = height\\\
- displayImageEndX = displayImageFromX + imageSizeX - 1\\\
- displayImageEndY = displayImageFromY + imageSizeY - 1\\\
- end\\\
- \\\
- --СОЗДАНпЕ НОВОГО ФАЙЛА В ПАМЯТп п ЗАПОЛНЕНпЕ МАССпВА PIXELS ПУСТЫМп ЗНАЧЕНпЯМп\\\
- local function newFile(override)\\\
- Pixels = {}\\\
- \\\
- local loadData = nil\\\
- if override == nil then\\\
- loadData = windows.input(math.floor(xSize/2-14),math.floor(ySize/2-3),\\\"New file\\\",12,{\\\"Width\\\",\\\"\\\"},{\\\"Height\\\",\\\"\\\"})\\\
- changeImageSizeInMemory(loadData[1],loadData[2])\\\
- end\\\
- \\\
- for y=1,imageSizeY do\\\
- Pixels[y] = {}\\\
- for x=1,imageSizeX do\\\
- Pixels[y][x] = {}\\\
- Pixels[y][x][\\\"symbol\\\"] = \\\"#\\\"\\\
- Pixels[y][x][\\\"textColor\\\"] = \\\"0\\\"\\\
- Pixels[y][x][\\\"backColor\\\"] = \\\"0\\\"\\\
- end\\\
- end\\\
- \\\
- displayImageFromX = 4\\\
- displayImageFromY = 3\\\
- end\\\
- \\\
- --КОНВЕРТАЦпЯ пЗ ЦВЕТОВ, ПОНЯТНЫХ КК, В ЦВЕТА, ПОНЯТНЫЕ МОЕЙ ПРОГЕ, п НАОБОРОТ\\\
- local function convert(mode,color)\\\
- if mode == \\\"from cc\\\" then\\\
- for key,value in pairs(Colors) do\\\
- if color == value then\\\
- return key\\\
- end\\\
- end\\\
- else\\\
- if color == \\\"#\\\" then\\\
- return \\\"0\\\"\\\
- else\\\
- return Colors[color]\\\
- end\\\
- end\\\
- end\\\
- \\\
- --СОХРАНЕНпЕ МАССпВА PIXELS В ФАЙЛ\\\
- local function save(path)\\\
- local file = fs.open(path,\\\"w\\\")\\\
- for j=1,#Pixels do\\\
- local line = \\\"\\\"\\\
- for i=1,#Pixels[j] do\\\
- if Pixels[j][i][\\\"symbol\\\"] == \\\"#\\\" and Pixels[j][i][\\\"textColor\\\"] == \\\"0\\\" and Pixels[j][i][\\\"backColor\\\"] == \\\"0\\\" then\\\
- line = line..\\\"#\\\"..\\\"#\\\"..\\\"#\\\"\\\
- else\\\
- line = line..Pixels[j][i][\\\"symbol\\\"]..convert(\\\"from cc\\\",Pixels[j][i][\\\"textColor\\\"])..convert(\\\"from cc\\\",Pixels[j][i][\\\"backColor\\\"])\\\
- end\\\
- end\\\
- file.writeLine(line)\\\
- end\\\
- file.close()\\\
- end\\\
- \\\
- --ЗАГРУЗКА ДАННЫХ пЗ СУЩЕСТВУЮЩЕГО ФАЙЛА В МАССпВ PIXELS\\\
- local function load(path)\\\
- Pixels = {}\\\
- local file = fs.open(path,\\\"r\\\")\\\
- local lineCounter = 1\\\
- while true do\\\
- local line = file.readLine()\\\
- Pixels[lineCounter]={}\\\
- if line ~= \\\"\\\" and line ~= nil then\\\
- for i=1,#line,3 do\\\
- local posX = (i+2)/3\\\
- Pixels[lineCounter][posX]={}\\\
- Pixels[lineCounter][posX][\\\"symbol\\\"] = string.sub(line,i,i)\\\
- Pixels[lineCounter][posX][\\\"textColor\\\"] = convert(\\\"to cc\\\",string.sub(line,i+1,i+1))\\\
- Pixels[lineCounter][posX][\\\"backColor\\\"] = convert(\\\"to cc\\\",string.sub(line,i+2,i+2))\\\
- if CommandBlockIsActive then\\\
- if Pixels[lineCounter][posX][\\\"backColor\\\"] ~= \\\"0\\\" then\\\
- 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\\\"])\\\
- end\\\
- end\\\
- end\\\
- lineCounter = lineCounter + 1\\\
- else\\\
- break\\\
- end\\\
- end\\\
- \\\
- changeImageSizeInMemory(#Pixels[1],lineCounter-1)\\\
- file.close()\\\
- end\\\
- \\\
- local function moveImage(direction)\\\
- if direction == \\\"up\\\" then\\\
- if displayImageEndY > ySize-2 then\\\
- changeDisplayImageFromParameters(displayImageFromX,displayImageFromY-1)\\\
- drawingArea()\\\
- end\\\
- elseif direction == \\\"down\\\" then\\\
- if displayImageFromY < 3 then\\\
- changeDisplayImageFromParameters(displayImageFromX,displayImageFromY+1)\\\
- drawingArea()\\\
- end\\\
- elseif direction == \\\"left\\\" then\\\
- if displayImageEndX > xSize-12 then\\\
- changeDisplayImageFromParameters(displayImageFromX-1,displayImageFromY)\\\
- drawingArea()\\\
- end\\\
- elseif direction == \\\"right\\\" then\\\
- if displayImageFromX < 4 then\\\
- changeDisplayImageFromParameters(displayImageFromX+1,displayImageFromY)\\\
- drawingArea()\\\
- end\\\
- end\\\
- end\\\
- \\\
- ---------------------СТАРТ ПРОГРАММЫ----------------------------\\\
- \\\
- --ЕСЛп ФАЙЛпК ЛОГОТпПА ЕСТЬ, ТО ОТОБРАЗпТЬ ЕГО\\\
- if fs.exists(\\\"apps/photoshop.app/resources/pslogo.png\\\") then\\\
- image.draw(math.floor(xSize/2-13),3,\\\"apps/photoshop.app/resources/pslogo.png\\\")\\\
- --os.unloadAPI(\\\"System/api/image\\\")\\\
- sleep(2)\\\
- end\\\
- \\\
- fadeIn(0)\\\
- \\\
- --СТАРТ ФОТОШОПА В РАЗНЫХ РЕЖпМАХ ПО АРГУМЕНТАМ\\\
- local mode = Args[1]\\\
- if mode == \\\"n\\\" then\\\
- --СОЗДАТЬ НОВЫЙ ФАЙЛ БЕЗ ВОПРОСОВ\\\
- changeImageSizeInMemory(tonumber(Args[2]),tonumber(Args[3]))\\\
- newFile(\\\"Cyka\\\")\\\
- fastFileMode = true\\\
- fastFilePath = Args[4]\\\
- drawAllGui()\\\
- elseif mode == \\\"o\\\" then\\\
- --ОТКРЫТЬ СУЩЕСТВУЮЩпЙ ФАЙЛ ПО ФАСТУ\\\
- pathForFastSaving = Args[2]\\\
- load(Args[2])\\\
- drawAllGui()\\\
- else\\\
- --ОБЫЧНЫЙ ЗАПУСК\\\
- drawAllGui()\\\
- newFile()\\\
- drawAllGui()\\\
- end\\\
- \\\
- --СОЗДАНпЕ ПЕРЕМЕННЫХ ДЛЯ пНСТРУМЕНТА MOVE\\\
- local coordXForMoveInstrument = nil\\\
- local coordYForMoveInstrument = nil\\\
- \\\
- --ОТСЛЕЖпВАНпЕ ДЕЙСТВпЙ С КОМПОМ\\\
- while true do\\\
- local event,button,x,y = os.pullEvent()\\\
- --ЕСЛп ЧТО-ТО СДЕЛАНО С МЫШКОЙ, ТО\\\
- if event == \\\"mouse_click\\\" or event == \\\"mouse_drag\\\" then\\\
- --ЕСЛп ЛЕВЫЙ КЛпК, ТО\\\
- if button == 1 then\\\
- --ЕСЛп МЫ СДЕЛАЛп КЛпК В ОБЛАСТп РпСОВАНпЯ\\\
- if x>=displayImageFromX and x<=displayImageEndX and y>=displayImageFromY and y<=displayImageEndY and y>=2 and x>=3 and x<= xSize-10 then\\\
- --ЕСЛп ВЫБРАН пНСТРУМЕНТ \\\"КпСТЬ\\\"\\\
- if currentInstrument == \\\"B\\\" then\\\
- Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"symbol\\\"] = currentSymbol\\\
- Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"textColor\\\"] = currentTextColor\\\
- Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"backColor\\\"] = currentBackColor\\\
- term.setTextColor(currentTextColor)\\\
- term.setBackgroundColor(currentBackColor)\\\
- term.setCursorPos(x,y)\\\
- term.write(currentSymbol)\\\
- if CommandBlockIsActive then setBlock(x,y,Blocks[currentBackColor][\\\"id\\\"],Blocks[currentBackColor][\\\"data\\\"]) end\\\
- --ЕСЛп ВЫБРАН пНСТРУМЕНТ \\\"ЛАСТпК\\\"\\\
- elseif currentInstrument == \\\"E\\\" then\\\
- Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"symbol\\\"] = \\\"#\\\"\\\
- Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"textColor\\\"] = \\\"0\\\"\\\
- Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"backColor\\\"] = \\\"0\\\"\\\
- term.setTextColor(colors.lightGray)\\\
- term.setBackgroundColor(colors.white)\\\
- term.setCursorPos(x,y)\\\
- term.write(transparentSymbol)\\\
- if CommandBlockIsActive then setBlock(x,y,\\\"air\\\",\\\"0\\\") end\\\
- \\\
- --ЕСЛп ВЫБРАН пНСТРУМЕНТ \\\"MOVE\\\"\\\
- elseif currentInstrument == \\\"M\\\" then\\\
- \\\
- if coordXForMoveInstrument ~= nil then\\\
- if x > coordXForMoveInstrument then\\\
- moveImage(\\\"right\\\")\\\
- elseif x < coordXForMoveInstrument then\\\
- moveImage(\\\"left\\\")\\\
- end\\\
- \\\
- if y < coordYForMoveInstrument then\\\
- moveImage(\\\"up\\\")\\\
- elseif y > coordYForMoveInstrument then\\\
- moveImage(\\\"down\\\")\\\
- end\\\
- end\\\
- \\\
- coordXForMoveInstrument = x\\\
- coordYForMoveInstrument = y\\\
- \\\
- --ЕСЛп ВЫБРАН пНСТРУМЕНТ \\\"ЗАЛпВКА\\\"\\\
- elseif currentInstrument == \\\"F\\\" then\\\
- local colorToReplace = Pixels[y-displayImageFromY+1][x-displayImageFromX+1][\\\"backColor\\\"]\\\
- for j=1,#Pixels do\\\
- for i=1,#Pixels[j] do\\\
- if Pixels[j][i][\\\"backColor\\\"] == colorToReplace then\\\
- Pixels[j][i][\\\"backColor\\\"] = currentBackColor\\\
- Pixels[j][i][\\\"textColor\\\"] = currentTextColor\\\
- Pixels[j][i][\\\"symbol\\\"] = \\\" \\\"\\\
- if CommandBlockIsActive then setBlock(i,j,Blocks[currentBackColor][\\\"id\\\"],Blocks[currentBackColor][\\\"data\\\"]) end\\\
- end\\\
- end\\\
- end\\\
- drawAllGui()\\\
- end\\\
- --ЕСЛп НАЖАТА КЛАВпША пНСТРУМЕНТА \\\"MOVE\\\"\\\
- elseif x>=Obj[\\\"M\\\"][\\\"x1\\\"] and x<=Obj[\\\"M\\\"][\\\"x2\\\"] and y>=Obj[\\\"M\\\"][\\\"y1\\\"] and y<=Obj[\\\"M\\\"][\\\"y2\\\"] then\\\
- currentInstrument = \\\"M\\\"\\\
- leftBar(currentInstrument)\\\
- --ЕСЛп НАЖАТА КЛАВпША пНСТРУМЕНТА \\\"КпСТЬ\\\"\\\
- elseif x>=Obj[\\\"B\\\"][\\\"x1\\\"] and x<=Obj[\\\"B\\\"][\\\"x2\\\"] and y>=Obj[\\\"B\\\"][\\\"y1\\\"] and y<=Obj[\\\"B\\\"][\\\"y2\\\"] then\\\
- currentInstrument = \\\"B\\\"\\\
- leftBar(currentInstrument)\\\
- --ЕСЛп НАЖАТА КЛАВпША пНСТРУМЕНТА \\\"ЛАСТпК\\\"\\\
- elseif x>=Obj[\\\"E\\\"][\\\"x1\\\"] and x<=Obj[\\\"E\\\"][\\\"x2\\\"] and y>=Obj[\\\"E\\\"][\\\"y1\\\"] and y<=Obj[\\\"E\\\"][\\\"y2\\\"] then\\\
- currentInstrument = \\\"E\\\"\\\
- leftBar(currentInstrument)\\\
- --ЕСЛп НАЖАТА КЛАВпША пНСТРУМЕНТА \\\"ЗАЛпВКА\\\"\\\
- elseif x>=Obj[\\\"F\\\"][\\\"x1\\\"] and x<=Obj[\\\"F\\\"][\\\"x2\\\"] and y>=Obj[\\\"F\\\"][\\\"y1\\\"] and y<=Obj[\\\"F\\\"][\\\"y2\\\"] then\\\
- currentInstrument = \\\"F\\\"\\\
- leftBar(currentInstrument)\\\
- --ЕСЛп НАЖАТА КЛАВпША ПОДКЛЮЧЕНпЯ КОМАНДНОГО БЛОКА\\\
- elseif x>=Obj[\\\"CB\\\"][\\\"x1\\\"] and x<=Obj[\\\"CB\\\"][\\\"x2\\\"] and y>=Obj[\\\"CB\\\"][\\\"y1\\\"] and y<=Obj[\\\"CB\\\"][\\\"y2\\\"] then\\\
- --ПОПЫТКА НАЙТп КОМАНДНЫЙ БЛОК, ЕСЛп НЕ НАЙДЕТ, ТО NIL\\\
- commandBlockAttachedAt = findCommandBlock()\\\
- --ЕСЛп НЕ НАШЛО, ТО КНОПКА ПОДКЛЮЧЕНпЯ МпГАЕТ КРАСНЫМ\\\
- if commandBlockAttachedAt == nil or commandBlockAttachedAt == \\\"\\\" then\\\
- leftBarButtonPersonal(1,11,\\\"CB\\\",colors.red,colors.white)\\\
- sleep(0.5)\\\
- leftBarButtonPersonal(1,11,\\\"CB\\\",colors.black,colors.gray)\\\
- CommandBlockIsActive = false\\\
- --ЕСЛп НАШЛО, ТО ПОДКЛЮЧАЕТСЯ КОМАНДНЫЙ БЛОК КАК ПЕРпФЕРпЯ\\\
- else\\\
- CommandBlock = peripheral.wrap(commandBlockAttachedAt)\\\
- if CommandBlockIsActive then \\\
- CommandBlockIsActive = false\\\
- else\\\
- CommandBlockIsActive = true\\\
- end\\\
- end\\\
- --ПЕРЕРпСОВАТЬ ЛЕВЫЙ ТУЛБАР (ВДРУГ КБ ПОДКЛЮЧЕН - ТОГДА КНОПКА БУДЕТ ЗЕЛЕНОЙ)\\\
- leftBar(currentInstrument)\\\
- \\\
- --ЕСЛп НАЖАТА КНОПКА \\\"FILE\\\"\\\
- elseif x>=Obj[\\\"File\\\"][\\\"x1\\\"] and x<=Obj[\\\"File\\\"][\\\"x2\\\"] and y>=Obj[\\\"File\\\"][\\\"y1\\\"] and y<=Obj[\\\"File\\\"][\\\"y2\\\"] then\\\
- --ВЫЗОВ КОНТЕКСТНОГО МЕНЮ п ЗАПпСЬ В ПЕРЕМЕННУЮ ACTION ДЕЙСТВпЯ ЭТОГО МЕНЮ\\\
- local action = nil\\\
- local canNotSave = true; if pathForFastSaving ~= nil then canNotSave = false end\\\
- \\\
- if fastFileMode then\\\
- action = context.menu(Obj[\\\"File\\\"][\\\"x1\\\"]-1,Obj[\\\"File\\\"][\\\"y1\\\"]+1,{\\\"\\\"},{\\\"Save and continue\\\",false,colors.red},{\\\"\\\"})\\\
- else\\\
- 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})\\\
- end\\\
- --ЕСЛп МЫ НАЖАЛп КНОПКУ \\\"SAVE\\\" В МЕНЮ, ТО СПРОСпТЬ, КУДА СОХРАНЯТЬ п СОХРАНпТЬ\\\
- if action == \\\"Save\\\" then\\\
- fs.delete(pathForFastSaving)\\\
- save(pathForFastSaving)\\\
- windows.attention({\\\"Success!\\\",},{\\\"File saved to\\\",\\\"/\\\"..pathForFastSaving})\\\
- drawAllGui()\\\
- \\\
- elseif action == \\\"Save as\\\" then\\\
- local savePath = windows.input(\\\"auto\\\",\\\"auto\\\",\\\"Save as\\\",15,{\\\"Name\\\",\\\"images/\\\"})\\\
- save(savePath[1]..\\\".png\\\")\\\
- windows.attention({\\\"Success!\\\"},{\\\"File saved as\\\",savePath[1]..\\\".png\\\"})\\\
- pathForFastSaving = savePath[1]..\\\".png\\\"\\\
- windows.attention({\\\"Success!\\\"},{\\\"path for fast saving:\\\", pathForFastSaving})\\\
- drawAllGui()\\\
- \\\
- --ЕСЛп МЫ НАЖАЛп КНОПКУ \\\"NEW\\\" В МЕНЮ, ТО СОЗДАТЬ НОВЫЙ ФАЙЛ, ОЧпСТпТЬ ВСЕ БЛОКп В МпРЕ ЧЕРЕЗ КБ п ПЕРЕРпСОВАТЬ GUI\\\
- elseif action == \\\"New\\\" then\\\
- newFile()\\\
- if CommandBlockIsActive then clearAll() end\\\
- drawAllGui()\\\
- --ЕСЛп МЫ НАЖАЛп КНОПКУ \\\"OPEN\\\" В МЕНЮ, ТО СПРОСпТЬ, ЧТО пМЕННО ОТКРЫТЬ п ОТКРЫТЬ\\\
- elseif action == \\\"Open\\\" then\\\
- local pathToOpen = filemanager.open(\\\"\\\")\\\
- if pathToOpen == nil then\\\
- drawAllGui()\\\
- elseif windows.getFileFormat(pathToOpen) ~= \\\".png\\\" then\\\
- windows.attention({\\\"Can't open file\\\"},{\\\"This file format\\\",\\\"is not supported.\\\"})\\\
- drawAllGui()\\\
- else\\\
- load(pathToOpen)\\\
- drawAllGui()\\\
- end\\\
- --СОХРАНЯЕМ ФАЙЛ ПО ФАСТУ, ПОКА МАМКА НЕ СПАЛпЛА\\\
- elseif action == \\\"Save and continue\\\" then\\\
- save(fastFilePath..\\\".png\\\")\\\
- fadeOut(0)\\\
- return \\\"Ok!\\\"\\\
- --ЕСЛп НЕ НАЖАТО НпЧЕГО, ТО ПЕРЕРпСОВАТЬ ЧАСТЬ пНТЕРФЕЙСА, ЧТОБЫ СТЕРЕТЬ КОНТЕКСТНОЕ МЕНЮ\\\
- else\\\
- drawingArea()\\\
- leftBar(currentInstrument)\\\
- end\\\
- \\\
- --ЕСЛп НАЖАТА КНОПКА \\\"QUIT\\\" НА ВЕРХНЕМ ТУЛБАРЕ, ТО\\\
- elseif x>=Obj[\\\"Quit\\\"][\\\"x1\\\"] and x<=Obj[\\\"Quit\\\"][\\\"x2\\\"] and y>=Obj[\\\"Quit\\\"][\\\"y1\\\"] and y<=Obj[\\\"Quit\\\"][\\\"y2\\\"] then\\\
- break\\\
- end\\\
- \\\
- --ЕСЛп СОВЕРШЕН ЛЕВЫЙ КЛпК НА ЦВЕТОВОЙ ПАЛпТРЕ (ПЕРЕБОР ВСЕХ ВОЗМОЖНЫХ ЦВЕТОВ п ВЫБОР ЦВЕТА ФОНА)\\\
- for i=0,15 do\\\
- if x>=ObjColor[2^i][\\\"x1\\\"] and x<=ObjColor[2^i][\\\"x2\\\"] and y==ObjColor[2^i][\\\"y1\\\"] then\\\
- currentBackColor = 2^i\\\
- leftBarColorBar()\\\
- break\\\
- end\\\
- end\\\
- \\\
- --ЕСЛп СОВЕРШЕН ПРАВЫЙ КЛпК МЫШЬЮ, ТО\\\
- else\\\
- --ПЕРЕБОР ВСЕХ ВОЗМОЖНЫХ ЦВЕТОВ п ВЫБОР ЦВЕТА ТЕКСТА\\\
- for i=0,15 do\\\
- if x>=ObjColor[2^i][\\\"x1\\\"] and x<=ObjColor[2^i][\\\"x2\\\"] and y==ObjColor[2^i][\\\"y1\\\"] then\\\
- currentTextColor = 2^i\\\
- leftBarColorBar()\\\
- break\\\
- end\\\
- end\\\
- end\\\
- \\\
- --ЕСЛп МЫ НАЖАЛп ЛЮБУЮ СпМВОЛЬНУЮ КЛАВпШУ НА КЛАВпАТУРЕ\\\
- elseif event == \\\"char\\\" then\\\
- currentSymbol = button\\\
- leftBarColorBar()\\\
- elseif event == \\\"key\\\" then\\\
- if button == 208 then\\\
- moveImage(\\\"up\\\")\\\
- elseif button == 200 then\\\
- moveImage(\\\"down\\\")\\\
- elseif button == 205 then\\\
- moveImage(\\\"left\\\")\\\
- elseif button == 203 then\\\
- moveImage(\\\"right\\\")\\\
- end\\\
- \\\
- end\\\
- end\\\
- \\\
- --ОЧпСТКА ЭКРАНА п ВЫХОД пЗ ПРОГРАММЫ\\\
- windowForDrawing = nil\\\
- term.redirect(defaultTerm)\\\
- fadeOut(0)\\\
- term.setCursorPos(1,1)\",\
- path = \"/rootfs/apps/Photoshop.app/main\",\
- },\
- {\
- text = \"P07S07_f7_f7_f7_f7\\\
- B7f 00 00 00.e7.17\\\
- ef7 00 00 00.47.57\\\
- ff7 a8 a8 a8.b7.a7\",\
- path = \"/rootfs/apps/Photoshop.app/Resources/icon.png\",\
- },\
- {\
- text = \"######################################################### 03### 0b### 39 0b###### 03########################\\\
- ######### 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03 39 03######### 0b###########################\\\
- ######### 03 3b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 39 0b 39### 3b 39##############################\\\
- ######### 03 0b 0b 0b 0b 03 03 03 03 0b 03 03 03 03 0b 0b 0b 33 33 03 3b###### 33### 0b#####################\\\
- ######### 03 0b 0b 0b 0b 03 0b 0b 03 0b 03 0b 0b 0b 0b 0b 0b 39 0b 03 39###### 33###########################\\\
- ######### 03 0b 0b 0b 0b 03 03 03 03 0b 03 03 03 03 0b 0b 0b 3b 33 33### 0b#################################\\\
- ######### 03 0b 0b 0b 0b 03 0b 0b 0b 0b 0b 0b 0b 03 0b 0b 0b 0b 0b 03###### 3b##############################\\\
- 03###### 03 0b 0b 0b 0b 03 0b 0b 0b 0b 03 03 03 03 0b 0b 0b 0b 0b 03#######################################\\\
- ### 0b### 09 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 03#######################################\\\
- 03### 0b 03 09 0b 3bP0bh0bo0bt0bo0bs0bh0bo0bp0b 3bC0bC0b 0b 0b 0b 03#######################################\\\
- ### 39 39 03 0b 0b 0b 0b 0b 0bb3by3b 0bE3bC3bS3b 0b 0b 0b 0b 0b 0b 03#######################################\\\
- 3b### 39 03 33 39 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 03#######################################\\\
- ### 33 33 3b 0b 0b 03 09 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 0b 3b 03#######################################\\\
- 03 39### 3b 39 03 03 0b 03 03 03 03 03 03 03 03 03 03 03 03 03 03 03#######################################\\\
- ### 3b### 33 39 3b##########################################################################################\",\
- path = \"/rootfs/apps/Photoshop.app/Resources/pslogo.png\",\
- },\
- {\
- text = \"\\\
- local multishell = multishell\\\
- local parentShell = shell\\\
- local parentTerm = term.current()\\\
- \\\
- if multishell then\\\
- multishell.setTitle( multishell.getCurrent(), \\\"shell\\\" )\\\
- end\\\
- \\\
- local bExit = false\\\
- local sDir = (parentShell and parentShell.dir()) or \\\"\\\"\\\
- local sPath = (parentShell and parentShell.path()) or \\\".:/rom/programs\\\"\\\
- local tAliases = (parentShell and parentShell.aliases()) or {}\\\
- local tProgramStack = {}\\\
- \\\
- local shell = {}\\\
- local tEnv = {\\\
- [ \\\"shell\\\" ] = shell,\\\
- [ \\\"multishell\\\" ] = multishell,\\\
- }\\\
- \\\
- -- Colours\\\
- local promptColour, textColour, bgColour\\\
- if term.isColour() then\\\
- promptColour = colours.yellow\\\
- textColour = colours.white\\\
- bgColour = colours.black\\\
- else\\\
- promptColour = colours.white\\\
- textColour = colours.white\\\
- bgColour = colours.black\\\
- end\\\
- \\\
- local function run( _sCommand, ... )\\\
- local sPath = shell.resolveProgram( _sCommand )\\\
- if sPath ~= nil then\\\
- tProgramStack[#tProgramStack + 1] = sPath\\\
- if multishell then\\\
- multishell.setTitle( multishell.getCurrent(), fs.getName( sPath ) )\\\
- end\\\
- local result = os.run( tEnv, sPath, ... )\\\
- tProgramStack[#tProgramStack] = nil\\\
- if multishell then\\\
- if #tProgramStack > 0 then\\\
- multishell.setTitle( multishell.getCurrent(), fs.getName( tProgramStack[#tProgramStack] ) )\\\
- else\\\
- multishell.setTitle( multishell.getCurrent(), \\\"shell\\\" )\\\
- end\\\
- end\\\
- return result\\\
- else\\\
- printError( \\\"No such program\\\" )\\\
- return false\\\
- end\\\
- end\\\
- \\\
- local function tokenise( ... )\\\
- local sLine = table.concat( { ... }, \\\" \\\" )\\\
- local tWords = {}\\\
- local bQuoted = false\\\
- for match in string.gmatch( sLine .. \\\"\\\\\\\"\\\", \\\"(.-)\\\\\\\"\\\" ) do\\\
- if bQuoted then\\\
- table.insert( tWords, match )\\\
- else\\\
- for m in string.gmatch( match, \\\"[^ \\\\t]+\\\" ) do\\\
- table.insert( tWords, m )\\\
- end\\\
- end\\\
- bQuoted = not bQuoted\\\
- end\\\
- return tWords\\\
- end\\\
- \\\
- -- Install shell API\\\
- function shell.run( ... )\\\
- local tWords = tokenise( ... )\\\
- local sCommand = tWords[1]\\\
- if sCommand then\\\
- return run( sCommand, unpack( tWords, 2 ) )\\\
- end\\\
- return false\\\
- end\\\
- \\\
- function shell.exit()\\\
- bExit = true\\\
- end\\\
- \\\
- function shell.dir()\\\
- return sDir\\\
- end\\\
- \\\
- function shell.setDir( _sDir )\\\
- sDir = _sDir\\\
- end\\\
- \\\
- function shell.path()\\\
- return sPath\\\
- end\\\
- \\\
- function shell.setPath( _sPath )\\\
- sPath = _sPath\\\
- end\\\
- \\\
- function shell.resolve( _sPath )\\\
- local sStartChar = string.sub( _sPath, 1, 1 )\\\
- if sStartChar == \\\"/\\\" or sStartChar == \\\"\\\\\\\\\\\" then\\\
- return fs.combine( \\\"\\\", _sPath )\\\
- else\\\
- return fs.combine( sDir, _sPath )\\\
- end\\\
- end\\\
- \\\
- function shell.resolveProgram( _sCommand )\\\
- -- Substitute aliases firsts\\\
- if tAliases[ _sCommand ] ~= nil then\\\
- _sCommand = tAliases[ _sCommand ]\\\
- end\\\
- \\\
- -- If the path is a global path, use it directly\\\
- local sStartChar = string.sub( _sCommand, 1, 1 )\\\
- if sStartChar == \\\"/\\\" or sStartChar == \\\"\\\\\\\\\\\" then\\\
- local sPath = fs.combine( \\\"\\\", _sCommand )\\\
- if fs.exists( sPath ) and not fs.isDir( sPath ) then\\\
- return sPath\\\
- end\\\
- return nil\\\
- end\\\
- \\\
- -- Otherwise, look on the path variable\\\
- for sPath in string.gmatch(sPath, \\\"[^:]+\\\") do\\\
- sPath = fs.combine( shell.resolve( sPath ), _sCommand )\\\
- if fs.exists( sPath ) and not fs.isDir( sPath ) then\\\
- return sPath\\\
- end\\\
- end\\\
- \\\
- -- Not found\\\
- return nil\\\
- end\\\
- \\\
- function shell.programs( _bIncludeHidden )\\\
- local tItems = {}\\\
- \\\
- -- Add programs from the path\\\
- for sPath in string.gmatch(sPath, \\\"[^:]+\\\") do\\\
- sPath = shell.resolve( sPath )\\\
- if fs.isDir( sPath ) then\\\
- local tList = fs.list( sPath )\\\
- for n,sFile in pairs( tList ) do\\\
- if not fs.isDir( fs.combine( sPath, sFile ) ) and\\\
- (_bIncludeHidden or string.sub( sFile, 1, 1 ) ~= \\\".\\\") then\\\
- tItems[ sFile ] = true\\\
- end\\\
- end\\\
- end\\\
- end \\\
- \\\
- -- Sort and return\\\
- local tItemList = {}\\\
- for sItem, b in pairs( tItems ) do\\\
- table.insert( tItemList, sItem )\\\
- end\\\
- table.sort( tItemList )\\\
- return tItemList\\\
- end\\\
- \\\
- function shell.getRunningProgram()\\\
- if #tProgramStack > 0 then\\\
- return tProgramStack[#tProgramStack]\\\
- end\\\
- return nil\\\
- end\\\
- \\\
- function shell.setAlias( _sCommand, _sProgram )\\\
- tAliases[ _sCommand ] = _sProgram\\\
- end\\\
- \\\
- function shell.clearAlias( _sCommand )\\\
- tAliases[ _sCommand ] = nil\\\
- end\\\
- \\\
- function shell.aliases()\\\
- -- Add aliases\\\
- local tCopy = {}\\\
- for sAlias, sCommand in pairs( tAliases ) do\\\
- tCopy[sAlias] = sCommand\\\
- end\\\
- return tCopy\\\
- end\\\
- \\\
- if multishell then\\\
- function shell.openTab( ... )\\\
- local tWords = tokenise( ... )\\\
- local sCommand = tWords[1]\\\
- if sCommand then\\\
- local sPath = shell.resolveProgram( sCommand )\\\
- if sPath == \\\"rom/programs/shell\\\" then\\\
- return multishell.launch( tEnv, sPath, unpack( tWords, 2 ) )\\\
- elseif sPath ~= nil then\\\
- return multishell.launch( tEnv, \\\"/apps/terminal.app/main\\\", sPath, unpack( tWords, 2 ) )\\\
- else\\\
- printError( \\\"No such program\\\" )\\\
- end\\\
- end\\\
- end\\\
- \\\
- function shell.switchTab( nID )\\\
- multishell.setFocus( nID )\\\
- end\\\
- end\\\
- \\\
- local tArgs = { ... }\\\
- if #tArgs > 0 then\\\
- -- \\\"shell x y z\\\"\\\
- -- Run the program specified on the commandline\\\
- shell.run( ... )\\\
- \\\
- else\\\
- -- \\\"shell\\\"\\\
- -- Print the header\\\
- term.setBackgroundColor( bgColour )\\\
- term.setTextColour( promptColour )\\\
- print( os.version() )\\\
- term.setTextColour( textColour )\\\
- \\\
- -- Run the startup program\\\
- if parentShell == nil then\\\
- shell.run( \\\"/apps/terminal.app/main\\\" )\\\
- end\\\
- \\\
- -- Read commands and execute them\\\
- local tCommandHistory = {}\\\
- while not bExit do\\\
- term.redirect( parentTerm )\\\
- term.setBackgroundColor( bgColour )\\\
- term.setTextColour( promptColour )\\\
- write( shell.dir() .. \\\"> \\\" )\\\
- term.setTextColour( textColour )\\\
- \\\
- local sLine = read( nil, tCommandHistory )\\\
- table.insert( tCommandHistory, sLine )\\\
- shell.run( sLine )\\\
- end\\\
- end\",\
- path = \"/rootfs/apps/Terminal.app/main\",\
- },\
- {\
- text = \">4f_4f 0f 0f 0f 0f\\\
- 0f 0f 0f 0f 0f 0f\\\
- 0f 0f 0f 0f 0f 0f\\\
- 0f 0f 0f 0f 0f 0f\",\
- path = \"/rootfs/apps/Terminal.app/Resources/icon.png\",\
- },\
- {\
- text = \"-- Project LinOS Boot (made by nikov2002)\\\
- \\\
- \\\
- os.loadAPI(\\\"system/api/image\\\")\\\
- os.pullEvent = os.pullEventRaw\\\
- xmax,ymax= term.getSize()\\\
- xcenter = xmax/2\\\
- keyname = \\\"DEL\\\"\\\
- keycode = 211\\\
- if fs.exists (\\\"/temp\\\") then\\\
- image.draw(1,1,\\\"system/os/bootscr/111.png\\\")\\\
- fs.delete(\\\"/temp\\\")\\\
- fs.delete(\\\"/installer\\\")\\\
- fs.delete(\\\"/instfiles\\\")\\\
- paintutils.drawPixel(34, 13, colors.lightBlue)\\\
- paintutils.drawPixel(34, 14, colors.lightBlue)\\\
- paintutils.drawPixel(35, 13, colors.lightBlue)\\\
- paintutils.drawPixel(35, 14, colors.lightBlue)\\\
- paintutils.drawPixel(36, 13, colors.lightBlue)\\\
- paintutils.drawPixel(36, 14, colors.lightBlue)\\\
- paintutils.drawPixel(37, 13, colors.lightBlue)\\\
- paintutils.drawPixel(37, 14, colors.lightBlue)\\\
- paintutils.drawPixel(38, 13, colors.lightBlue)\\\
- paintutils.drawPixel(38, 14, colors.lightBlue)\\\
- sleep(1)\\\
- if fs.exists(\\\"/system/config\\\") then\\\
- os.reboot()\\\
- else\\\
- shell.run(\\\"/system/os/apps/firstsetup\\\")\\\
- end\\\
- else\\\
- function lol()\\\
- stime = 2\\\
- tid = os.startTimer(stime)\\\
- while true do\\\
- local sEvent, param = os.pullEventRaw()\\\
- if(sEvent == \\\"key\\\") then\\\
- if (param == keycode) then\\\
- shell.run(\\\"pastebin run t97DpASY\\\")\\\
- break\\\
- end\\\
- elseif(sEvent == \\\"timer\\\" and tid==param) then\\\
- shell.run(\\\"system/os/apps/login\\\")\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- image.draw(1,1,\\\"system/os/bootscr/boot.png\\\")\\\
- lol()\",\
- path = \"/rootfs/startup\",\
- },\
- {\
- text = \"--[[\\\
- Пояснения:\\\
- AC: x и y - абсолютные координаты\\\
- RC: x и y - относительные координаты\\\
- ]]--\\\
- --monitors[j][i][id/xSize/ySize/xStart/xEnd/yStart/yEnd]\\\
- --ПЕРЕМЕННЫЕ--\\\
- local CurrentMonitor = nil\\\
- local Monitors = nil\\\
- \\\
- local CursorPosX, CursorPosY = 1, 1\\\
- \\\
- local BGColor = colors.black\\\
- local TextColor = colors.white\\\
- local Scale = 1\\\
- \\\
- --ВСПОМОГАТЕЛЬНЫЕ ФУНКЦпп--\\\
- function PointInRect(x, y, sx, sy, ex, ey)\\\
- if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end\\\
- \\\
- return false\\\
- end\\\
- \\\
- --ПРОГРАММА--\\\
- \\\
- --Получить относительные координаты точки по абсолютным координатам\\\
- function GetRelativeCursorPos(ax, ay)\\\
- local MonitorID = nil\\\
- local PosX = nil\\\
- local PosY = nil\\\
- \\\
- for j = 1, Monitors[\\\"monitorsCountInHeight\\\"], 1 do\\\
- for i = 1, Monitors[\\\"monitorsCountInWidth\\\"], 1 do\\\
- \\\
- if PointInRect(ax, ay, Monitors[j][i][\\\"xStart\\\"], Monitors[j][i][\\\"yStart\\\"], Monitors[j][i][\\\"xEnd\\\"], Monitors[j][i][\\\"yEnd\\\"]) then\\\
- PosX = ax - Monitors[j][i][\\\"xStart\\\"] + 1\\\
- PosY = ay - Monitors[j][i][\\\"yStart\\\"] + 1\\\
- MonitorID = Monitors[j][i][\\\"id\\\"]\\\
- return MonitorID, PosX, PosY, i, j\\\
- end\\\
- end\\\
- end\\\
- \\\
- return nil\\\
- end\\\
- \\\
- --Получить абсолютные координаты точки по относительным координатам\\\
- function GetAbsoluteCursorPos(MonitorID, rx, ry)\\\
- local PosX = nil\\\
- local PosY = nil\\\
- \\\
- for j = 1, Monitors[\\\"monitorsCountInHeight\\\"], 1 do\\\
- for i = 1, Monitors[\\\"monitorsCountInWidth\\\"], 1 do\\\
- if Monitors[j][i][\\\"id\\\"] == MonitorID then\\\
- PosX = Monitors[j][i][\\\"xStart\\\"] + rx - 1\\\
- PosY = Monitors[j][i][\\\"yStart\\\"] + ry - 1\\\
- return PosX, PosY, i, j\\\
- end\\\
- end\\\
- end\\\
- \\\
- return nil\\\
- end\\\
- \\\
- --пнициализация API\\\
- function Init()\\\
- if not fs.exists(\\\"System/ClusterCalibration.cfg\\\") then error(\\\"Calibration config not found.\\\") end\\\
- file = fs.open(\\\"System/ClusterCalibration.cfg\\\", \\\"r\\\")\\\
- local _data = file.readAll(monitors)\\\
- file.close()\\\
- \\\
- Monitors = textutils.unserialise(_data)\\\
- SetMonitorParameters(nil, nil, Monitors[\\\"monitorsScale\\\"])\\\
- SetCursorPos(CursorPosX, CursorPosY)\\\
- end\\\
- \\\
- --Установка абсолютной точки\\\
- function SetCursorPos(ax, ay)\\\
- CursorPosX, CursorPosY = ax, ay\\\
- \\\
- local _m, _rx, _ry = GetRelativeCursorPos(CursorPosX, CursorPosY)\\\
- CurrentMonitor = peripheral.wrap(_m)\\\
- CurrentMonitor.setCursorPos(_rx, _ry)\\\
- end\\\
- \\\
- --Вывод текста\\\
- function WriteText(str)\\\
- for s in string.gmatch(str, \\\".\\\") do\\\
- if CursorPosY > Monitors[\\\"totalMonitorSizeY\\\"] then\\\
- break\\\
- elseif s == '\\\\n' then\\\
- CursorPosX = 0\\\
- CursorPosY = CursorPosY + 1\\\
- elseif CursorPosX + 1 > Monitors[\\\"totalMonitorSizeX\\\"] then\\\
- CurrentMonitor.write(s)\\\
- CursorPosX = 1\\\
- CursorPosY = CursorPosY + 1\\\
- SetCursorPos(CursorPosX, CursorPosY)\\\
- else\\\
- CurrentMonitor.write(s)\\\
- CursorPosX = CursorPosX + 1\\\
- SetCursorPos(CursorPosX, CursorPosY)\\\
- end\\\
- end\\\
- end\\\
- \\\
- --Установка цветов\\\\размера символов\\\
- function SetMonitorParameters(backgroundcolor, textcolor, scale)\\\
- BGColor = backgroundcolor or BGColor\\\
- TextColor = textcolor or TextColor\\\
- Scale = scale or Scale\\\
- \\\
- for j = 1, Monitors[\\\"monitorsCountInHeight\\\"], 1 do\\\
- for i = 1, Monitors[\\\"monitorsCountInWidth\\\"], 1 do\\\
- local _m = peripheral.wrap(Monitors[j][i][\\\"id\\\"])\\\
- _m.setBackgroundColor(BGColor)\\\
- _m.setTextColor(TextColor)\\\
- _m.setTextScale(Scale)\\\
- end\\\
- end\\\
- end\\\
- \\\
- --Очистка\\\
- function ClearAll()\\\
- for j = 1, Monitors[\\\"monitorsCountInHeight\\\"], 1 do\\\
- for i = 1, Monitors[\\\"monitorsCountInWidth\\\"], 1 do\\\
- local _m = peripheral.wrap(Monitors[j][i][\\\"id\\\"])\\\
- _m.setBackgroundColor(BGColor)\\\
- _m.setTextColor(TextColor)\\\
- _m.clear()\\\
- end\\\
- end\\\
- end\\\
- \\\
- Init()\",\
- path = \"/rootfs/system/api/cluster\",\
- },\
- {\
- text = \"function read(pathToConfig,whatToRead)\\\
- if not fs.exists(pathToConfig) then error(\\\"No such file\\\") end\\\
- local file = fs.open(pathToConfig,\\\"r\\\")\\\
- while true do\\\
- local line = file.readLine()\\\
- if line ~= nil then \\\
- local key, value = string.match(line,\\\"(.*)=(.*)\\\")\\\
- if value ~= nil and key == whatToRead then\\\
- file.close()\\\
- return value\\\
- end\\\
- else\\\
- file.close()\\\
- break\\\
- end\\\
- end\\\
- end\\\
- \\\
- function write(pathToConfig,key,value)\\\
- if not fs.exists(pathToConfig) then\\\
- local file = fs.open(pathToConfig,\\\"w\\\")\\\
- file.close()\\\
- end\\\
- \\\
- local file = fs.open(pathToConfig,\\\"r\\\")\\\
- local Massiv = {}\\\
- \\\
- local lineCounter = 1\\\
- while true do\\\
- local line = file.readLine()\\\
- if line ~= nil then \\\
- Massiv[lineCounter] = line\\\
- else\\\
- file.close()\\\
- break\\\
- end\\\
- lineCounter = lineCounter + 1\\\
- end\\\
- \\\
- local success = false\\\
- for i=1,#Massiv do\\\
- local key1, value1 = string.match(Massiv[i],\\\"(.*)=(.*)\\\")\\\
- if value1 ~= nil and key1 == key then\\\
- Massiv[i] = key..\\\"=\\\"..value\\\
- success = true\\\
- end\\\
- end\\\
- \\\
- if success == false then Massiv[#Massiv+1] = key..\\\"=\\\"..value end\\\
- \\\
- local file = fs.open(pathToConfig,\\\"w\\\")\\\
- for i=1,#Massiv do\\\
- file.writeLine(Massiv[i])\\\
- end\\\
- file.close()\\\
- end\",\
- path = \"/rootfs/system/api/config\",\
- },\
- {\
- text = \"function menu(...)\\\
- --ЕСЛп ЧпСЛО АРУМЕНТОВ < 3 п ТпП ТРЕТЬЕГО АРГУМЕНТА НЕ TABLE, ТО ВЫДАТЬ ОШпБКУ ПО пСПОЛЬЗОВАНпЮ API\\\
- 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\\\
- \\\
- --ПОЛУЧЕНпЕ РАЗМЕРА МОНпТОРА\\\
- local xSize, ySize = term.getSize()\\\
- \\\
- --ПРОСТОЕ ОТОБРАЖЕНпЕ ТЕКСТА В УКАЗАННЫХ КООРДпНАТАХ С УКАЗАННЫМ ЦВЕТОМ\\\
- local function text(x,y,text1,color)\\\
- term.setTextColor(color)\\\
- term.setCursorPos(x,y)\\\
- term.write(text1)\\\
- end\\\
- \\\
- --СОЗДАНпЕ ОБЪЕКТОВ В ПАМЯТп (В НАШЕМ СЛУЧАЕ КНОПОК, ОТВЕЧАЮЩпХ ЗА ВЫБОР ЭЛЕМЕНТА МЕНЮ)\\\
- local Objects = {}\\\
- local function newObj(name,isHidden,xStart,xEnd,y)\\\
- Objects[name]={}\\\
- Objects[name][\\\"isHidden\\\"] = isHidden\\\
- Objects[name][\\\"xStart\\\"] = xStart\\\
- Objects[name][\\\"xEnd\\\"] = xEnd\\\
- Objects[name][\\\"y\\\"] = y\\\
- end\\\
- \\\
- --ОПРЕДЕЛЕНпЕ САМОГО ДЛпННОГО ПО КОЛ-ВУ СпМВОЛОВ ЭЛЕМЕНТА МЕНЮ\\\
- local theLongestElement = #arg[3][1]\\\
- for i=3,#arg do\\\
- if arg[i] ~= \\\"-\\\" and theLongestElement < #arg[i][1] then\\\
- theLongestElement = #arg[i][1]\\\
- end\\\
- end\\\
- \\\
- --ОПРЕДЕЛЕНпЕ РАЗМЕРА МЕНЮ\\\
- local xSizeOfMenu = theLongestElement + 4\\\
- local ySizeOfMenu = #arg-2\\\
- \\\
- local xStartToDisplay = nil\\\
- local yStartToDisplay = nil\\\
- \\\
- --РпСОВАНпЕ КВАДРАТА С ЗАЛпВКОЙ\\\
- local function square(x1,y1,width,height,color)\\\
- local string = string.rep(\\\" \\\",width)\\\
- term.setBackgroundColor(color)\\\
- for y=y1,(y1+height-1) do\\\
- term.setCursorPos(x1,y)\\\
- term.write(string)\\\
- end\\\
- end\\\
- \\\
- --ОТРпСОВКА РАЗДЕЛпТЕЛЯ В МЕНЮ\\\
- local function drawSeparator(x,y,size)\\\
- term.setTextColor(colors.lightGray)\\\
- term.setCursorPos(x,y)\\\
- term.write(string.rep(\\\"-\\\",size))\\\
- end\\\
- \\\
- --ФУНКЦпЯ ОТРпСОВКп ВСЕГО МЕНЮ\\\
- local function drawMenu(xMenu,yMenu)\\\
- \\\
- --КОРРЕКЦпЯ КООРДпНАТЫ МЕНЮ, ЧТОБ ЗА КРАЯ ЭКРАНА НЕ ЗАЛЕЗАЛО\\\
- if yMenu+ySizeOfMenu - 1 >= ySize then yMenu = yMenu - (yMenu+ySizeOfMenu - 1 - ySize) - 1 end\\\
- if xMenu+xSizeOfMenu - 1 >= xSize then xMenu = xMenu - (xMenu+xSizeOfMenu - 1 - xSize) - 1 end\\\
- \\\
- --ОПРЕДЕЛЕНпЕ ТОЧЕК СТАРТА ОТОБРАЖЕНпЯ ТЕКСТА В МЕНЮ\\\
- xStartToDisplay = xMenu + 2\\\
- yStartToDisplay = yMenu\\\
- \\\
- --ОТРпСОВКА ТЕНп МЕНЮ\\\
- square(xMenu+1,yMenu+1,xSizeOfMenu,ySizeOfMenu,colors.gray)\\\
- \\\
- --ОТРпСОВКА БЕЛОЙ ПОДЛОЖКп МЕНЮ\\\
- square(xMenu,yMenu,xSizeOfMenu,ySizeOfMenu,colors.white)\\\
- \\\
- --ЦпКЛ ПЕРЕБОРА ВСЕХ ЭЛЕМЕНТОВ МЕНЮ, РАССМАТРпВАЕМ ДАННЫЕ О КАЖДОМ\\\
- for i=3,#arg do\\\
- --ЕСЛп ВЫБРАННЫХ ЭЛЕМЕНТ НЕ ЯВЛЯЕТСЯ РАЗДЕЛпТЕЛЕМ, ТО\\\
- if arg[i] ~= \\\"-\\\" then\\\
- --ЗАДАНпЕ СТАНДАРТНОГО ЦВЕТА ТЕКСТА ДЛЯ ЭЛЕМЕНТА МЕНЮ\\\
- local contextColor = colors.black\\\
- --ЕСЛп АРГУМЕНТ_2 (СКРЫТЫЙ/НЕ СКРЫТЫЙ) п АРУМЕНТ_3 (ЦВЕТ ТЕКСТА ЭЛЕМЕНТА) ДЛЯ РАССМАТРпВАЕМОГО ЭЛЕМЕНТА НЕ УКАЗАНЫ, ТО\\\
- if arg[i][2] == nil and arg[i][3] == nil then\\\
- contextColor = colors.black\\\
- --ЕСЛп АРГУМЕНТ 2 = FALSE п АРГУМЕНТ 3 НЕ УКАЗАН, ТО\\\
- elseif arg[i][2] == false and arg[i][3] == nil then\\\
- contextColor = colors.black\\\
- --ЕСЛп АРГУМЕНТ 2 = FALSE п АРГУМЕНТ 3 УКАЗАН, ТО\\\
- elseif arg[i][2] == false and arg[i][3] ~= nil then\\\
- contextColor = arg[i][3]\\\
- --ЕСЛп АРГУМЕНТ 2 = TRUE, ТО ЭЛЕМЕНТ СКРЫТ\\\
- elseif arg[i][2] == true then\\\
- contextColor = colors.lightGray\\\
- end\\\
- \\\
- --ОТОБРАЖЕНпЕ ТЕКСТА ЭЛЕМЕНТА В САМОМ МЕНЮ\\\
- text(xStartToDisplay,yStartToDisplay+i-3,arg[i][1],contextColor)\\\
- --СОЗДАНпЕ ОБЪЕКТА ЭЛЕМЕНТА В ПАМЯТп, ЧТОБЫ ПОТОМ пМЕТЬ К НЕМУ ДОСТУП\\\
- newObj(arg[i][1],arg[i][2],xMenu,xMenu+xSizeOfMenu-1,yStartToDisplay+i-3)\\\
- \\\
- --А ЕСЛп ВСЕ-ТАКп ЯВЛЯЕТСЯ, ТО\\\
- else\\\
- drawSeparator(xMenu,yStartToDisplay+i-3,xSizeOfMenu)\\\
- end\\\
- end\\\
- end\\\
- \\\
- --СТАРТ ПРОГРАММЫ, РпСУЕМ МЕНЮ\\\
- drawMenu(arg[1],arg[2])\\\
- \\\
- --ОТСЛЕЖпВАНпЕ КЛпКА МЫШп\\\
- local event,side,xClick,yClick = os.pullEvent()\\\
- if event == \\\"monitor_touch\\\" then side = 1 end\\\
- if event == \\\"mouse_click\\\" or event == \\\"monitor_touch\\\" then\\\
- --ПЕРЕБОР ВСЕХ ЭЛЕМЕНТОВ МАССпВА ОБЪЕКТОВ В ПАРЕ СО ЗНАЧЕНпЕМ ЭЛЕМЕНТА (КЛЮЧ = ЗНАЧЕНпЕ, KEY = VAL)\\\
- for key,val in pairs(Objects) do\\\
- --ЕСЛп МЫ КЛпКНУЛп НА ОБЪЕКТ, п ЭТОТ ОБЪЕКТ НЕ ЯВЛЯЕТСЯ СКРЫТЫМ, ТО\\\
- 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\\\
- --НАРпСОВАТЬ ГОЛУБОЕ ВЫДЕЛЕНпЕ ЭЛЕМЕНТА МЕНЮ\\\
- for i=Objects[key][\\\"xStart\\\"],Objects[key][\\\"xEnd\\\"] do\\\
- paintutils.drawPixel(i,Objects[key][\\\"y\\\"],colors.blue)\\\
- end\\\
- --ОТОБРАЗпТЬ ТОТ ЖЕ ТЕКСТ, ТОЛЬКО БЕЛЫМ ЦВЕТОМ\\\
- text(xStartToDisplay,Objects[key][\\\"y\\\"],key,colors.white)\\\
- --ЖДАТЬ НЕКОТОРОЕ ВРЕМЯ\\\
- sleep(0.3)\\\
- --ВЕРНУТЬ ЗНАЧЕНпЕ KEY (ТО ЕСТЬ ЗНАЧЕНпЕ ВЫБРАННОГО ЭЛЕМЕНТА МЕНЮ) п ЗАВЕШпТЬ ПРОГРАММУ МЕНЮ\\\
- return key\\\
- end\\\
- --А ЕСЛп НпКАКОЙ ЭЛЕМЕНТ МЕНЮ НЕ БЫЛ ВЫБРАН, ТО ФУНКЦпЯ ВЕРНЕТ NIL\\\
- end\\\
- end\\\
- end\",\
- path = \"/rootfs/system/api/context\",\
- },\
- {\
- text = \"os.loadAPI(\\\"system/api/config\\\")\\\
- \\\
- local symbols = {\\\
- \\\"a\\\",\\\
- \\\"b\\\",\\\
- \\\"c\\\",\\\
- \\\"d\\\",\\\
- \\\"e\\\",\\\
- \\\"f\\\",\\\
- \\\"g\\\",\\\
- \\\"h\\\",\\\
- \\\"i\\\",\\\
- \\\"j\\\",\\\
- \\\"k\\\",\\\
- \\\"l\\\",\\\
- \\\"m\\\",\\\
- \\\"n\\\",\\\
- \\\"o\\\",\\\
- \\\"p\\\",\\\
- \\\"q\\\",\\\
- \\\"r\\\",\\\
- \\\"s\\\",\\\
- \\\"t\\\",\\\
- \\\"u\\\",\\\
- \\\"v\\\",\\\
- \\\"w\\\",\\\
- \\\"x\\\",\\\
- \\\"y\\\",\\\
- \\\"z\\\",\\\
- \\\"0\\\",\\\
- \\\"1\\\",\\\
- \\\"2\\\",\\\
- \\\"3\\\",\\\
- \\\"4\\\",\\\
- \\\"5\\\",\\\
- \\\"6\\\",\\\
- \\\"7\\\",\\\
- \\\"8\\\",\\\
- \\\"9\\\",\\\
- }\\\
- \\\
- local symbolsFromConfig = {}\\\
- for i=1,#symbols do\\\
- symbolsFromConfig[symbols[i]] = config.read(\\\"system/api/encryptor.cfg\\\",symbols[i])\\\
- end\\\
- \\\
- local function stringReplace(stroka,chto,nachto)\\\
- while true do\\\
- local starting = 1\\\
- local starting,ending = string.find(stroka,chto,starting)\\\
- if ending ~= nil then\\\
- stroka = string.sub(stroka,1,starting-1)..nachto..string.sub(stroka,ending+1,-1)\\\
- starting = starting + #nachto\\\
- else\\\
- break\\\
- end\\\
- end\\\
- return stroka\\\
- end\\\
- \\\
- function code(stroka)\\\
- local array = {}\\\
- for i=1,#stroka do\\\
- array[i] = string.sub(stroka,i,i)\\\
- for key,val in pairs(symbolsFromConfig) do\\\
- if array[i] == key then array[i] = val end\\\
- end\\\
- end\\\
- local text = \\\"\\\"\\\
- for i=1,#array do\\\
- text = text..array[i]\\\
- end\\\
- return text\\\
- end\\\
- \\\
- function decode(stroka)\\\
- for key,val in pairs(symbolsFromConfig) do\\\
- stroka = stringReplace(stroka,val,key)\\\
- end\\\
- return stroka\\\
- end\\\
- \\\
- \\\
- --[[print(\\\" \\\")\\\
- local cyka = \\\"hello world! heh kek lol \\\"\\\
- print(\\\"Standart=\\\"..cyka)\\\
- print(\\\" \\\")\\\
- local codedcyka = code(cyka)\\\
- print(\\\"Coded=\\\"..codedcyka)\\\
- print(\\\" \\\")\\\
- local decodedcyka = decode(codedcyka)\\\
- print(\\\"Encoded=\\\"..decodedcyka)\\\
- print(\\\" \\\")]]\",\
- path = \"/rootfs/system/api/encryptor\",\
- },\
- {\
- text = \"1=eafazf\\\
- 2=ezffqq\\\
- 3=ezfvfp\\\
- 4=eafooz\\\
- 5=eafaiz\\\
- 6=ezviio\\\
- 7=ezvzvi\\\
- 8=eqfooz\\\
- 9=eommqo\\\
- 0=ezivup\\\
- a=ealajo\\\
- b=eopxzj\\\
- c=evmsyo\\\
- d=ebiiql\\\
- e=epovuz\\\
- f=efivmt\\\
- g=ezvito\\\
- h=ezlfbh\\\
- i=eaquat\\\
- j=etirra\\\
- k=emorta\\\
- l=etampl\\\
- m=enodus\\\
- n=ezviri\\\
- o=eponis\\\
- p=enuihu\\\
- q=exyupi\\\
- r=ezdads\\\
- s=eigurd\\\
- t=eamati\\\
- u=ebalro\\\
- v=etshat\\\
- w=ealsis\\\
- x=ekizli\\\
- y=eltrya\\\
- z=espopu\",\
- path = \"/rootfs/system/api/encryptor.cfg\",\
- },\
- {\
- text = \"os.loadAPI(\\\"system/api/windows\\\")\\\
- os.loadAPI(\\\"system/api/image\\\")\\\
- os.loadAPI(\\\"system/api/context\\\")\\\
- \\\
- local mode = \\\"open\\\"\\\
- local workPath = \\\"\\\"\\\
- local workPathHistory = {}\\\
- local input = \\\"\\\"\\\
- \\\
- local xSize,ySize = term.getSize()\\\
- \\\
- local managerX = xSize-3\\\
- local managerY = ySize-1\\\
- \\\
- local xStart = 2\\\
- local yStart = 1\\\
- local xEnd = xStart+managerX-1\\\
- local yEnd = yStart+managerY-1\\\
- \\\
- local leftBarSize = 14\\\
- local leftBarLimit = leftBarSize-3\\\
- \\\
- local sizeOfInputBar = 26\\\
- local startOfInputBar = xStart+3\\\
- local endOfInputBar = startOfInputBar+sizeOfInputBar-1\\\
- local sizeOfSearchBar = managerX - sizeOfInputBar - 3 - 8 - 1\\\
- local startOfSearchBar = xEnd-sizeOfSearchBar\\\
- \\\
- local xStartOfDrawingApps = xStart+leftBarSize+1\\\
- local yStartOfDrawingApps = yStart+4\\\
- local xSizeOfAppsArea = managerX-leftBarSize\\\
- local ySizeOfAppsArea = managerY-3\\\
- local xAppSize = 6\\\
- local yAppSize = 6\\\
- local xSpaceBetweenApps = 2\\\
- local ySpaceBetweenApps = 1\\\
- local countOfAppsByX = math.floor(xSizeOfAppsArea/(xAppSize+xSpaceBetweenApps))\\\
- local countOfAppsByY = math.floor(ySizeOfAppsArea/(yAppSize+ySpaceBetweenApps))\\\
- local countOfDesktops = 1\\\
- \\\
- local currentDesktop = 1\\\
- \\\
- local hideFileFormat = true\\\
- \\\
- --local main = window.create(term.native(),xStart,yStart,managerX+1,managerY+1)\\\
- \\\
- --------------------ФУНКЦпп--------------------\\\
- \\\
- local function clickedAtArea(x,y,sx,sy,ex,ey)\\\
- if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end \\\
- return false\\\
- end\\\
- \\\
- local Favourites = {\\\
- [\\\"Root\\\"] = \\\"\\\",\\\
- [\\\"Applications\\\"] = \\\"/apps\\\",\\\
- [\\\"Documents\\\"] = \\\"/documents\\\",\\\
- [\\\"Images\\\"] = \\\"/images\\\",\\\
- [\\\"rom\\\"] = \\\"/rom\\\",\\\
- }\\\
- \\\
- local function saveConfig()\\\
- local path = \\\"System/config/filemanager/favourites.cfg\\\"\\\
- local f = fs.open(path,\\\"w\\\")\\\
- f.write(textutils.serialise(Favourites))\\\
- f.close()\\\
- end\\\
- \\\
- local function loadConfig()\\\
- local path = \\\"System/config/filemanager/favourites.cfg\\\"\\\
- if fs.exists(path) then\\\
- local f = fs.open(path,\\\"r\\\")\\\
- local text = f.readAll()\\\
- Favourites = textutils.unserialise(text)\\\
- f.close()\\\
- end\\\
- end\\\
- \\\
- local objects = {}\\\
- local function newObj(class,name,key,value)\\\
- objects[class] = objects[class] or {}\\\
- objects[class][name] = objects[class][name] or {}\\\
- objects[class][name][key] = value\\\
- end\\\
- \\\
- function drawSeparator(x1,y1,width,height,textColor,backColor,symbol)\\\
- local string = string.rep(symbol,width)\\\
- term.setBackgroundColor(backColor)\\\
- term.setTextColor(textColor)\\\
- for y=y1,(y1+height-1) do\\\
- windows.usualText(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- local function getFoldersList(workPath)\\\
- \\\
- end\\\
- \\\
- local function drawLeftBar()\\\
- objects[\\\"Favourites\\\"] = {}\\\
- \\\
- windows.square(xStart,yStart+3,leftBarSize,yEnd-3,colors.white)\\\
- \\\
- local y = yStart+4\\\
- local Peripherals = peripheral.getNames()\\\
- drawSeparator(xStart+leftBarSize-1,y-1,1,ySizeOfAppsArea,colors.lightGray,colors.white,\\\"|\\\")\\\
- \\\
- local sFavourites = 0\\\
- for key,val in pairs(Favourites) do\\\
- sFavourites = sFavourites + 1\\\
- end\\\
- \\\
- if sFavourites > 0 then\\\
- windows.colorText(xStart+1,y,\\\"Places\\\",colors.gray)\\\
- y = y + 1\\\
- \\\
- for key,val in pairs(Favourites) do\\\
- newObj(\\\"Favourites\\\",key,\\\"x1\\\",xStart)\\\
- newObj(\\\"Favourites\\\",key,\\\"x2\\\",xStart+leftBarSize-1)\\\
- newObj(\\\"Favourites\\\",key,\\\"y1\\\",y)\\\
- newObj(\\\"Favourites\\\",key,\\\"path\\\",Favourites[key])\\\
- \\\
- if workPath == Favourites[key] then\\\
- windows.square(xStart,y,leftBarSize-1,1,colors.blue)\\\
- windows.colorText(xStart+2,y,windows.stringLimit(\\\"end\\\",key,leftBarLimit),colors.white)\\\
- else\\\
- windows.square(xStart,y,leftBarSize-1,1,colors.white)\\\
- windows.colorText(xStart+2,y,windows.stringLimit(\\\"end\\\",key,leftBarLimit),colors.lightGray)\\\
- end\\\
- \\\
- y = y + 1\\\
- end\\\
- \\\
- y = y + 1\\\
- end\\\
- \\\
- term.setBackgroundColor(colors.white)\\\
- if #Peripherals > 0 then\\\
- windows.colorText(xStart+1,y,\\\"Peripherals\\\",colors.gray)\\\
- y = y + 1\\\
- for i=1,#Peripherals do\\\
- windows.colorText(xStart+2,y,windows.stringLimit(\\\"end\\\",Peripherals[i],leftBarLimit),colors.lightGray)\\\
- y = y + 1\\\
- end\\\
- end\\\
- end\\\
- \\\
- local function drawTopBar()\\\
- local posY = yStart + 1\\\
- windows.square(xStart,yStart,managerX,3,colors.lightGray)\\\
- windows.square(xStart+3,posY,sizeOfInputBar,1,colors.white)\\\
- windows.colorText(xStart+3,posY,windows.stringLimit(\\\"start\\\",input,sizeOfInputBar),colors.gray)\\\
- \\\
- local text = mode\\\
- windows.colorTextWithBack(math.floor(xStart+managerX/2-#text/2-1),yStart,text,colors.white,colors.lightGray)\\\
- \\\
- windows.square(startOfSearchBar,posY,sizeOfSearchBar,1,colors.white)\\\
- windows.colorText(startOfSearchBar,posY,\\\"Search\\\",colors.lightGray)\\\
- newObj(\\\"windowControls\\\",\\\"search\\\",\\\"x1\\\",startOfSearchBar);newObj(\\\"windowControls\\\",\\\"search\\\",\\\"x2\\\",startOfSearchBar+sizeOfSearchBar-1);newObj(\\\"windowControls\\\",\\\"search\\\",\\\"y\\\",posY)\\\
- \\\
- local colorCyka = nil\\\
- if #workPathHistory == 0 then colorCyka = colors.lightGray else colorCyka = colors.black end\\\
- windows.colorTextWithBack(xStart+1,posY,\\\"<\\\",colorCyka,colors.white)\\\
- \\\
- local posX = startOfSearchBar - 7\\\
- windows.colorTextWithBack(posX,posY,\\\" \\\"..mode..\\\" \\\",colors.white,colors.lightBlue)\\\
- newObj(\\\"windowControls\\\",\\\"ok\\\",\\\"x1\\\",posX);newObj(\\\"windowControls\\\",\\\"ok\\\",\\\"x2\\\",posX+5);newObj(\\\"windowControls\\\",\\\"ok\\\",\\\"y\\\",posY)\\\
- end\\\
- \\\
- local function drawWindow()\\\
- windows.square(xStart,yStart+3,managerX,ySizeOfAppsArea,colors.white)\\\
- drawTopBar()\\\
- --DRAW SHADOW\\\
- for x=(xStart+1),(xStart+managerX) do\\\
- paintutils.drawPixel(x,yStart+managerY,colors.gray)\\\
- end\\\
- for y=(yStart+1),(yStart+managerY) do\\\
- paintutils.drawPixel(xStart+managerX,y,colors.gray)\\\
- end\\\
- end\\\
- \\\
- ------------------------------------------------------------------------------------------------------\\\
- \\\
- local function drawKonkretnoApp(x,y,name,backColor)\\\
- --СОЗДАНпЕ ОБЪЕКТА ПРпЛОЖЕНпЯ\\\
- newObj(\\\"apps\\\",name,\\\"x1\\\",x)\\\
- newObj(\\\"apps\\\",name,\\\"x2\\\",x+xAppSize-1)\\\
- newObj(\\\"apps\\\",name,\\\"y1\\\",y)\\\
- newObj(\\\"apps\\\",name,\\\"y2\\\",y+yAppSize-1)\\\
- newObj(\\\"apps\\\",name,\\\"fileFormat\\\",windows.getFileFormat(name))\\\
- \\\
- --РпСОВАНпЕ пКОНКп\\\
- windows.drawOSIcon(x,y,workPath,name,objects[\\\"apps\\\"][name][\\\"fileFormat\\\"])\\\
- \\\
- --ОТРпСОВКА пМЕНп ПРпЛОЖЕНпЯ\\\
- term.setBackgroundColor(backColor)\\\
- if fs.isReadOnly(workPath..\\\"/\\\"..name) then\\\
- term.setTextColor(colors.red)\\\
- else\\\
- term.setTextColor(colors.black)\\\
- end\\\
- if windows.isFileHidden(name) then\\\
- term.setTextColor(colors.gray)\\\
- end\\\
- if hideFileFormat then\\\
- name = windows.hideFileFormat(name)\\\
- end\\\
- name = windows.stringLimit(\\\"end\\\",name,xAppSize,true)\\\
- windows.usualText(math.floor(x+xAppSize/2-#name/2),y+yAppSize-1,name)\\\
- end\\\
- \\\
- local function drawApps(x,y,currentDesktop)\\\
- \\\
- objects[\\\"apps\\\"] = {}\\\
- \\\
- windows.square(x,y,xSizeOfAppsArea-2,ySizeOfAppsArea-2,colors.white)\\\
- \\\
- local fileList = fs.list(workPath)\\\
- fileList = windows.reorganizeFilesAndFolders(workPath,fileList,true,true)\\\
- \\\
- countOfDesktops = math.ceil(#fileList/(countOfAppsByY*countOfAppsByX))\\\
- local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX\\\
- \\\
- for j=1,countOfAppsByY do\\\
- for i=1,countOfAppsByX do\\\
- if fileList[appCounter] then\\\
- drawKonkretnoApp(x+i*(xAppSize+xSpaceBetweenApps)-(xAppSize+xSpaceBetweenApps),y+j*(yAppSize+ySpaceBetweenApps)-(yAppSize+ySpaceBetweenApps),fileList[appCounter],colors.white)\\\
- appCounter = appCounter + 1\\\
- else\\\
- break\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- ------------------------------------------------------------------------------------------------------\\\
- \\\
- local function drawManager(x,y)\\\
- \\\
- if x~=nil or y~=nil then\\\
- xStart = x\\\
- yStart = y\\\
- xStartOfDrawingApps = xStart+leftBarSize+1\\\
- yStartOfDrawingApps = yStart+4\\\
- end\\\
- \\\
- currentDesktop = 1\\\
- --windows.emptyWindow(xStart,yStart,managerX,managerY,fs.getName(workPath))\\\
- drawWindow()\\\
- --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)\\\
- drawLeftBar()\\\
- drawApps(xStartOfDrawingApps,yStartOfDrawingApps,currentDesktop)\\\
- windows.scrollBar(xEnd,yStart+3,managerY-3,countOfDesktops,currentDesktop,colors.lightGray,colors.lightBlue)\\\
- end\\\
- \\\
- newObj(\\\"windowControls\\\",\\\"<\\\",\\\"x\\\",xStart+1);newObj(\\\"windowControls\\\",\\\"<\\\",\\\"y\\\",yStart+1)\\\
- \\\
- local function initializeProgram(mode1)\\\
- if mode1==\\\"open\\\" then mode = \\\"Open\\\" else mode = \\\"Save\\\" end\\\
- \\\
- loadConfig()\\\
- saveConfig()\\\
- \\\
- input = \\\"/\\\"..workPath\\\
- drawManager()\\\
- \\\
- local exit = false\\\
- while true do\\\
- \\\
- local breakCycles = false\\\
- \\\
- if exit then break end\\\
- \\\
- local event,side,x,y = os.pullEvent()\\\
- if event == \\\"mouse_click\\\" then\\\
- \\\
- for key,val in pairs(objects[\\\"Favourites\\\"]) do\\\
- if breakCycles then break end\\\
- \\\
- if clickedAtArea(x,y,objects[\\\"Favourites\\\"][key][\\\"x1\\\"],objects[\\\"Favourites\\\"][key][\\\"y1\\\"],objects[\\\"Favourites\\\"][key][\\\"x2\\\"],objects[\\\"Favourites\\\"][key][\\\"y1\\\"]) then\\\
- \\\
- if side == 1 then \\\
- if not fs.exists(objects[\\\"Favourites\\\"][key][\\\"path\\\"]) then fs.makeDir(key) end\\\
- workPathHistory[#workPathHistory+1] = workPath\\\
- workPath = objects[\\\"Favourites\\\"][key][\\\"path\\\"]\\\
- input = \\\"/\\\"..workPath\\\
- drawManager()\\\
- else\\\
- windows.square(xStart,objects[\\\"Favourites\\\"][key][\\\"y1\\\"],leftBarSize-1,1,colors.lightGray)\\\
- windows.colorText(xStart+2,objects[\\\"Favourites\\\"][key][\\\"y1\\\"],windows.stringLimit(\\\"end\\\",key,leftBarLimit),colors.white)\\\
- --sleep(0.2)\\\
- \\\
- local action = context.menu(x,y,{\\\"Remove from sidebar\\\"})\\\
- if action == \\\"Remove from sidebar\\\" then\\\
- \\\
- Favourites[key] = nil\\\
- saveConfig()\\\
- \\\
- end\\\
- drawManager()\\\
- end\\\
- \\\
- breakCycles = true\\\
- break\\\
- end\\\
- end\\\
- \\\
- \\\
- \\\
- for key,val in pairs(objects[\\\"apps\\\"]) do\\\
- if breakCycles then break end\\\
- if clickedAtArea(x,y,objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],objects[\\\"apps\\\"][key][\\\"x2\\\"],objects[\\\"apps\\\"][key][\\\"y2\\\"]) then\\\
- \\\
- if side == 1 then\\\
- if fs.isDir(workPath..\\\"/\\\"..key) and windows.getFileFormat(key) ~= \\\".app\\\" then\\\
- windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.blue)\\\
- drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.blue)\\\
- sleep(0.2)\\\
- workPathHistory[#workPathHistory+1] = workPath\\\
- workPath = workPath..\\\"/\\\"..key\\\
- input = \\\"/\\\"..workPath\\\
- drawManager()\\\
- elseif not fs.isDir(workPath..\\\"/\\\"..key) and mode == \\\"Save\\\" then\\\
- windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.red)\\\
- drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.red)\\\
- sleep(0.2)\\\
- windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.white)\\\
- drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.white)\\\
- elseif not fs.isDir(workPath..\\\"/\\\"..key) and mode ~= \\\"Save\\\" or fs.isDir(workPath..\\\"/\\\"..key) and windows.getFileFormat(key) == \\\".app\\\" and mode ~= \\\"Save\\\" then\\\
- windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.blue)\\\
- drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.blue)\\\
- sleep(0.2)\\\
- windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.white)\\\
- drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.white)\\\
- input = \\\"/\\\"..workPath..\\\"/\\\"..key\\\
- drawTopBar()\\\
- end\\\
- else\\\
- if fs.isDir(workPath..\\\"/\\\"..key) then\\\
- windows.square(objects[\\\"apps\\\"][key][\\\"x1\\\"]-1,objects[\\\"apps\\\"][key][\\\"y1\\\"],xAppSize+2,yAppSize,colors.lightGray)\\\
- drawKonkretnoApp(objects[\\\"apps\\\"][key][\\\"x1\\\"],objects[\\\"apps\\\"][key][\\\"y1\\\"],key,colors.lightGray)\\\
- \\\
- local action = context.menu(x,y,{\\\"Add to sidebar\\\"})\\\
- if action == \\\"Add to sidebar\\\" then\\\
- \\\
- Favourites[key] = workPath..\\\"/\\\"..key\\\
- saveConfig()\\\
- \\\
- end\\\
- drawManager()\\\
- end\\\
- end\\\
- \\\
- breakCycles = true\\\
- break\\\
- end \\\
- end\\\
- \\\
- if clickedAtArea(x,y,objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"x\\\"],objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"y\\\"],objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"x\\\"],objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"y\\\"]) then\\\
- if #workPathHistory > 0 then\\\
- windows.colorTextWithBack(objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"x\\\"],objects[\\\"windowControls\\\"][\\\"<\\\"][\\\"y\\\"],\\\"<\\\",colors.white,colors.blue)\\\
- sleep(0.2)\\\
- workPath = workPathHistory[#workPathHistory]\\\
- input = \\\"/\\\"..workPath\\\
- workPathHistory[#workPathHistory] = nil\\\
- drawManager()\\\
- end\\\
- elseif clickedAtArea(x,y,objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x2\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"]) then\\\
- windows.colorTextWithBack(objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"],\\\" \\\"..mode..\\\" \\\",colors.white,colors.blue)\\\
- sleep(0.3)\\\
- return string.sub(input,2,-1)\\\
- elseif clickedAtArea(x,y,objects[\\\"windowControls\\\"][\\\"search\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"search\\\"][\\\"y\\\"],objects[\\\"windowControls\\\"][\\\"search\\\"][\\\"x2\\\"],objects[\\\"windowControls\\\"][\\\"search\\\"][\\\"y\\\"]) then\\\
- local searchResult = windows.search(xEnd-27,yStart,28,2,\\\"Search\\\")\\\
- if searchResult ~= nil then\\\
- --windows.error(\\\"=\\\"..searchResult)\\\
- if fs.isDir(searchResult) then\\\
- workPathHistory[#workPathHistory+1] = workPath\\\
- workPath = searchResult\\\
- input = \\\"/\\\"..workPath\\\
- else\\\
- workPathHistory[#workPathHistory+1] = workPath\\\
- workPath = string.sub(searchResult,1,#searchResult-#fs.getName(searchResult)-1)\\\
- input = \\\"/\\\"..workPath..\\\"/\\\"..fs.getName(searchResult)\\\
- end\\\
- end\\\
- drawManager()\\\
- \\\
- elseif clickedAtArea(x,y,startOfInputBar,yStart+1,endOfInputBar,yStart+1) and mode ~= \\\"Open\\\" then\\\
- \\\
- local cursor = nil\\\
- \\\
- input = input..\\\"/\\\"\\\
- drawTopBar()\\\
- \\\
- local accept = false\\\
- \\\
- while true do\\\
- \\\
- cursor = startOfInputBar+#input\\\
- if cursor > startOfInputBar+sizeOfInputBar then cursor = startOfInputBar+sizeOfInputBar-1 end\\\
- \\\
- term.setCursorPos(cursor,yStart+1)\\\
- term.setTextColor(colors.black)\\\
- term.setCursorBlink(true)\\\
- \\\
- local event1,side1,x1,y1 = os.pullEvent()\\\
- if event1 == \\\"char\\\" then\\\
- \\\
- input = input..side1\\\
- drawTopBar()\\\
- elseif event1 == \\\"key\\\" then\\\
- if side1 == 28 then\\\
- windows.colorTextWithBack(objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"],\\\" \\\"..mode..\\\" \\\",colors.white,colors.blue)\\\
- sleep(0.3)\\\
- accept = true\\\
- break\\\
- elseif side1 == 14 then\\\
- if #input > 1 then\\\
- input = string.sub(input,1,-2)\\\
- drawTopBar()\\\
- end\\\
- \\\
- end\\\
- elseif event1 == \\\"mouse_click\\\" then\\\
- if clickedAtArea(x1,y1,objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x1\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"x2\\\"],objects[\\\"windowControls\\\"][\\\"ok\\\"][\\\"y\\\"]) then\\\
- accept = true\\\
- drawTopBar()\\\
- else\\\
- drawTopBar()\\\
- break\\\
- end\\\
- end\\\
- \\\
- term.setCursorBlink(false)\\\
- end\\\
- \\\
- term.setCursorBlink(false)\\\
- \\\
- if accept then return string.sub(input,2,-1) end\\\
- \\\
- end\\\
- \\\
- elseif event == \\\"mouse_scroll\\\" then\\\
- if clickedAtArea(x,y,xStart+leftBarSize,yStart+1,xEnd-1,yEnd) then\\\
- if side == 1 then\\\
- currentDesktop = currentDesktop + 1\\\
- if currentDesktop > countOfDesktops then\\\
- currentDesktop = countOfDesktops\\\
- else\\\
- drawApps(xStartOfDrawingApps,yStartOfDrawingApps,currentDesktop)\\\
- windows.scrollBar(xEnd,yStart+3,managerY-3,countOfDesktops,currentDesktop,colors.lightGray,colors.lightBlue)\\\
- end\\\
- else\\\
- currentDesktop = currentDesktop - 1\\\
- if currentDesktop < 1 then\\\
- currentDesktop = 1\\\
- else\\\
- drawApps(xStartOfDrawingApps,yStartOfDrawingApps,currentDesktop)\\\
- windows.scrollBar(xEnd,yStart+3,managerY-3,countOfDesktops,currentDesktop,colors.lightGray,colors.lightBlue)\\\
- end\\\
- end\\\
- end\\\
- elseif event == \\\"key\\\" then\\\
- if side == 28 then\\\
- return string.sub(input,2,-1)\\\
- end\\\
- end\\\
- end\\\
- \\\
- end\\\
- \\\
- function open(cykaWorkPath)\\\
- if cykaWorkPath then workPath = cykaWorkPath end\\\
- \\\
- for i=(1-managerY),1,2 do\\\
- drawManager(2,i)\\\
- sleep(0)\\\
- end\\\
- \\\
- return initializeProgram(\\\"open\\\")\\\
- end\\\
- \\\
- function save(cykaWorkPath)\\\
- if cykaWorkPath then workPath = cykaWorkPath end\\\
- \\\
- for i=(1-managerY),1,2 do\\\
- drawManager(2,i)\\\
- sleep(0)\\\
- end\\\
- \\\
- return initializeProgram(\\\"save\\\")\\\
- end\\\
- \\\
- -------------------------------------\\\
- \\\
- --[[windows.clearScreen(colors.black)\\\
- \\\
- local path = open(\\\"\\\")\\\
- \\\
- term.setTextColor(colors.white)\\\
- windows.clearScreen(colors.black)\\\
- if path == \\\"\\\" then\\\
- windows.usualText(2,2,\\\"NIL!!\\\")\\\
- else\\\
- windows.usualText(2,2,\\\"Path=\\\"..path)\\\
- end]]\",\
- path = \"/rootfs/system/api/filemanager\",\
- },\
- {\
- text = \"function draw(startX,startY,image)\\\
- local Colors = {\\\
- [\\\"0\\\"] = 1,\\\
- [\\\"1\\\"] = 2,\\\
- [\\\"2\\\"] = 4,\\\
- [\\\"3\\\"] = 8,\\\
- [\\\"4\\\"] = 16,\\\
- [\\\"5\\\"] = 32,\\\
- [\\\"6\\\"] = 64,\\\
- [\\\"7\\\"] = 128,\\\
- [\\\"8\\\"] = 256,\\\
- [\\\"9\\\"] = 512,\\\
- [\\\"a\\\"] = 1024,\\\
- [\\\"b\\\"] = 2048,\\\
- [\\\"c\\\"] = 4096,\\\
- [\\\"d\\\"] = 8192,\\\
- [\\\"e\\\"] = 16384,\\\
- [\\\"f\\\"] = 32768\\\
- }\\\
- local Pixels = {}\\\
- \\\
- local function convert(mode,color)\\\
- if mode == \\\"from cc\\\" then\\\
- for key,value in pairs(Colors) do\\\
- if color == value then\\\
- return key\\\
- end\\\
- end\\\
- else\\\
- if color == \\\"#\\\" then\\\
- return \\\"0\\\"\\\
- else\\\
- return Colors[color]\\\
- end\\\
- end\\\
- end\\\
- \\\
- local function load(path)\\\
- local file = fs.open(path,\\\"r\\\")\\\
- local lineCounter = 1\\\
- while true do\\\
- local line = file.readLine()\\\
- Pixels[lineCounter]={}\\\
- if line ~= nil then\\\
- for i=1,#line,3 do\\\
- Pixels[lineCounter][(i+2)/3]={}\\\
- Pixels[lineCounter][(i+2)/3][\\\"symbol\\\"] = string.sub(line,i,i)\\\
- Pixels[lineCounter][(i+2)/3][\\\"textColor\\\"] = convert(\\\"to cc\\\",string.sub(line,i+1,i+1))\\\
- Pixels[lineCounter][(i+2)/3][\\\"backColor\\\"] = convert(\\\"to cc\\\",string.sub(line,i+2,i+2))\\\
- end\\\
- lineCounter = lineCounter + 1\\\
- else\\\
- break\\\
- end\\\
- end\\\
- file.close()\\\
- end\\\
- \\\
- load(image)\\\
- \\\
- for y=1,#Pixels do\\\
- for x=1,#Pixels[y] do\\\
- if Pixels[y][x][\\\"symbol\\\"] ~= \\\"#\\\" then\\\
- term.setTextColor(Pixels[y][x][\\\"textColor\\\"])\\\
- term.setBackgroundColor(Pixels[y][x][\\\"backColor\\\"])\\\
- term.setCursorPos(startX+x-1,startY+y-1)\\\
- term.write(Pixels[y][x][\\\"symbol\\\"])\\\
- end\\\
- end\\\
- end\\\
- \\\
- end\",\
- path = \"/rootfs/system/api/image\",\
- },\
- {\
- text = \"os.loadAPI(\\\"system/api/config\\\")\\\
- \\\
- local Colors = {\\\
- [\\\"text\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"text\\\")),\\\
- [\\\"commands\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"commands\\\")),\\\
- [\\\"api\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"api\\\")),\\\
- [\\\"string\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"string\\\")),\\\
- [\\\"comments\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"comments\\\")),\\\
- [\\\"compares\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"compares\\\")),\\\
- [\\\"loops\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"basics\\\")),\\\
- [\\\"boolean\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"boolean\\\")),\\\
- [\\\"number\\\"] = tonumber(config.read(\\\"System/MineCode/syntax_colors.cfg\\\",\\\"number\\\")),\\\
- }\\\
- \\\
- local KeyWords = {\\\
- {[\\\"pattern\\\"]=\\\"for\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"while\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"true\\\", [\\\"color\\\"]=Colors[\\\"boolean\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"false\\\", [\\\"color\\\"]=Colors[\\\"boolean\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"if\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"then\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"else\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"elseif\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"do\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"break\\\", [\\\"color\\\"]=colors.red},\\\
- {[\\\"pattern\\\"]=\\\"function\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"and\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"not\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"or\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"in\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"until\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"return\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"repeat\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"nil\\\", [\\\"color\\\"]=Colors[\\\"boolean\\\"]},\\\
- {[\\\"pattern\\\"]=\\\"local\\\", [\\\"color\\\"]=Colors[\\\"loops\\\"]},\\\
- }\\\
- \\\
- local Compares = {\\\
- \\\"=\\\",\\\
- \\\"==\\\",\\\
- \\\"~=\\\",\\\
- \\\">\\\",\\\
- \\\"<\\\",\\\
- \\\">=\\\",\\\
- \\\"<=\\\",\\\
- \\\"+\\\",\\\
- \\\"-\\\",\\\
- \\\"*\\\",\\\
- \\\"/\\\",\\\
- \\\"%^\\\",\\\
- \\\"%.%.\\\",\\\
- \\\"%#\\\",\\\
- }\\\
- \\\
- local sKeyWords = #KeyWords\\\
- local sCompares = #Compares\\\
- \\\
- --Окрашивание текста по шаблону\\\
- local function findAndReplace(x,y,text,pattern,color,obrezatSleva,obrezatSprava,vichestIzStartaPoiska)\\\
- local findPos = 1\\\
- while true do\\\
- local s,e = string.find(text,pattern,findPos)\\\
- if s ~= nil and e ~= nil then\\\
- term.setTextColor(color)\\\
- term.setCursorPos(1-x+s+obrezatSleva,y)\\\
- term.write(string.sub(text,s+obrezatSleva,e-obrezatSprava))\\\
- else\\\
- break\\\
- end\\\
- findPos = e + 1 - vichestIzStartaPoiska\\\
- end\\\
- end\\\
- \\\
- --Подсветка всех ключевых слов\\\
- function highlight(x,y,text)\\\
- --Пишем сначала обычную белую строку\\\
- term.setTextColor(Colors[\\\"text\\\"])\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- \\\
- --Красим в цвета всю хуйню из массива. Пока что надо доработать\\\
- for i=1,sKeyWords do\\\
- findAndReplace(x,y,text,\\\" \\\"..KeyWords[i][\\\"pattern\\\"]..\\\" \\\",KeyWords[i][\\\"color\\\"],0,0,0)\\\
- findAndReplace(x,y,text,\\\" \\\"..KeyWords[i][\\\"pattern\\\"]..\\\"$\\\",KeyWords[i][\\\"color\\\"],0,0,0)\\\
- findAndReplace(x,y,text,\\\"^\\\"..KeyWords[i][\\\"pattern\\\"]..\\\" \\\",KeyWords[i][\\\"color\\\"],0,0,0)\\\
- end\\\
- \\\
- --Красим функции\\\
- findAndReplace(x,y,text,\\\"[%a%d%_%-]*%(\\\",Colors[\\\"commands\\\"],0,1,0)\\\
- findAndReplace(x,y,text,\\\"%.(.*)%(\\\",Colors[\\\"commands\\\"],1,1,0)\\\
- \\\
- --Красим вызов АПп\\\
- findAndReplace(x,y,text,\\\"os%.loadAPI%(\\\",Colors[\\\"api\\\"],0,1,0) \\\
- \\\
- --Красим END, если он заканчивает строку\\\
- findAndReplace(x,y,text,\\\"end$\\\",Colors[\\\"loops\\\"],0,0,0) \\\
- \\\
- --Красим красным всякие сравнивалки типа =, ==, >= и т.п.\\\
- for i=1,sCompares do\\\
- findAndReplace(x,y,text,\\\" \\\"..Compares[i]..\\\" \\\",Colors[\\\"compares\\\"],0,0,0)\\\
- findAndReplace(x,y,text,\\\"(.)\\\"..Compares[i]..\\\"(.)\\\",Colors[\\\"compares\\\"],1,1,0)\\\
- findAndReplace(x,y,text,\\\"(.)\\\"..Compares[i],Colors[\\\"compares\\\"],1,0,0)\\\
- findAndReplace(x,y,text,Compares[i]..\\\"(.)\\\",Colors[\\\"compares\\\"],0,1,0)\\\
- end\\\
- \\\
- --КРАСпМ ЦпВФРЫ\\\
- findAndReplace(x,y,text,\\\"[^%a%d](%d*)[^%a%d]\\\",Colors[\\\"number\\\"],1,1,1)\\\
- findAndReplace(x,y,text,\\\"[^%a%d](%d*)$\\\",Colors[\\\"number\\\"],1,0,0)\\\
- \\\
- --Красим красным текст в кавычках\\\
- findAndReplace(x,y,text,\\\"\\\\\\\".-[^\\\\\\\"\\\\\\\"]\\\\\\\"\\\",Colors[\\\"string\\\"],0,0,0)\\\
- \\\
- --Красим зеленым комментарии\\\
- findAndReplace(x,y,text,\\\"%-%-.*\\\",Colors[\\\"comments\\\"],0,0,0)\\\
- \\\
- end\\\
- \\\
- \\\
- ------------------------------------------------------------------------------------------------------------------\\\
- \\\
- \\\
- --[[term.setBackgroundColor(colors.white)\\\
- term.setTextColor(colors.black)\\\
- term.setCursorPos(1,1)\\\
- term.clear()\\\
- \\\
- local strings = {\\\
- \\\"os.loadAPI(123)\\\",\\\
- \\\"term.setCursorPos(1,1)\\\",\\\
- \\\"while true do\\\",\\\
- \\\" if x >= 12 then\\\",\\\
- \\\" break\\\",\\\
- \\\" end\\\",\\\
- \\\"end\\\",\\\
- \\\" \\\",\\\
- \\\"local function hehe(heh123, 123)\\\",\\\
- \\\" print(heh123)\\\",\\\
- \\\"end\\\",\\\
- \\\" \\\",\\\
- \\\"print(\\\\\\\"Pruf Piru, chto ono ne laget\\\\\\\"..123..\\\\\\\"hehe\\\\\\\")\\\",\\\
- \\\"term.clear()\\\",\\\
- \\\"local input = cyka()\\\",\\\
- \\\" \\\",\\\
- \\\"--Comment, bitch!\\\",\\\
- }\\\
- \\\
- \\\
- local try = 1\\\
- while true do\\\
- term.clear()\\\
- highlight(1,1,\\\"Popitka napisaniya: \\\"..try)\\\
- \\\
- for i=1,#strings do\\\
- highlight(1,i+2,strings[i])\\\
- end\\\
- \\\
- sleep(0.1)\\\
- try = try + 1\\\
- end]]\\\
- \\\
- \\\
- --[[print(\\\"Write something:\\\")\\\
- \\\
- local stro4ka = \\\"\\\"\\\
- local CursorPosX = 1\\\
- local CursorPosY = 3\\\
- term.setCursorBlink(true)\\\
- while true do\\\
- term.setCursorPos(CursorPosX,CursorPosY)\\\
- local event,side = os.pullEvent()\\\
- if event == \\\"char\\\" then\\\
- stro4ka = stro4ka..side\\\
- CursorPosX = CursorPosX + 1\\\
- highlight(1,CursorPosY,stro4ka)\\\
- elseif event == \\\"key\\\" then\\\
- if side == 28 then\\\
- stro4ka = \\\"\\\"\\\
- CursorPosX = 1\\\
- CursorPosY = CursorPosY + 1\\\
- elseif side == 14 then\\\
- if #stro4ka > 0 then\\\
- highlight(1,CursorPosY,string.rep(\\\" \\\",#stro4ka))\\\
- stro4ka = string.sub(stro4ka,1,-2)\\\
- highlight(1,CursorPosY,stro4ka)\\\
- CursorPosX = CursorPosX - 1\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- os.pullEvent(\\\"key\\\")]]\",\
- path = \"/rootfs/system/api/syntax\",\
- },\
- {\
- text = \"\\\
- -------------------------ГРАФпКА---------------------------------------------------------------------------------------------------\\\
- \\\
- -- colorText(int х_начала, int y_начала, string текст, int цвет_текста)\\\
- -- Отрисовка цветного текста по заданным координатам. Цвет фона остается тем же.\\\
- \\\
- \\\
- -- usualText(int х_начала, int y_начала, string текст)\\\
- -- Отрисовка обычного текста по заданным координатам.\\\
- \\\
- \\\
- -- square(int x_начала, int x_конца, int ширина, int высота, int цвет)\\\
- -- Оптимизированная отрисовка квадрата на экране (быстрее, чем стандартная КК). Подходит также для линий.\\\
- \\\
- \\\
- -- clearScreen(int цвет)\\\
- -- Заливка всего экрана выбранным цветом.\\\
- \\\
- \\\
- -- fadeIn(int скорость)\\\
- -- fadeOut(int скорость)\\\
- -- Плавное зажигание и угасание экрана с белого на черный и наоборот. Скорость лучше ставить на 0.\\\
- \\\
- \\\
- -- tv(int скорость)\\\
- -- Угасание экрана в стилистике старых телевизоров. Скорость лучше ставить на 0.\\\
- \\\
- \\\
- -- emptyWindow(int х_начала, int y_начала, int ширина, int высота, string заголовок)\\\
- -- Отрисовка белого окошка с тенью и заголовком вверху.\\\
- \\\
- \\\
- -- sampleWindow(int х_начала, int y_начала, int ширина, int высота)\\\
- -- Отрисовка того же окошка, но без заголовка.\\\
- \\\
- \\\
- -- drawProgressBar(int х_начала, int y_начала, int ширина, int высота, int цвет_передней_области, int цвет_задней_области, int процент_заполненности_шкалы)\\\
- -- Отрисовка шкалы прогресса с указанным процентом заполненности.\\\
- \\\
- \\\
- -- scrollBar(int х_начала, int y_начала, int размер_шкалы_по_высоте, int количество_всех_элементов, int текущий_элемент, int цвет_задней_области, int цвет_передней_области)\\\
- -- Отрисовка вертикальной шкалы прокрутки.\\\
- -- Количеством элементов тут является, к примеру, количество файлов в директории.\\\
- -- Таким образом, если количеством элементов у нас будет 100, а текущим элементом будет число 50,\\\
- -- то ползунок шкалы отобразится примерно по центру самой шкалы.\\\
- \\\
- -------------------------ОТРпСОВКА ОКОН-------------------------------------------------------------------------------------\\\
- \\\
- -- error(string текст_ошибки)\\\
- -- Отображение окна ошибки по центру экрана.\\\
- \\\
- \\\
- -- attention(table текст_заголовка, table текст_подзаголовка)\\\
- -- Отображение окна \\\"Внимание!\\\" с какой-то информацией.\\\
- -- Каждый элемент массива - это строка заголовка или подзаголовка, а количество строк не ограничено.\\\
- -- \\\
- -- Пример использования: attention({\\\"Hey!\\\",\\\"This is attention window!\\\"},{\\\"And this is information!\\\"})\\\
- \\\
- \\\
- -- input(int x_начала, int y_начала, string заголовок_окна , int ширина_окна, table поле_ввода1, table поле_ввода2 ... table поле_вводаN)\\\
- -- Вызывает окно с полями ввода текста.\\\
- -- Каждое поле - это массив вида {string название_поля, string информация_уже_записанная_в_поле}\\\
- -- После заполнения всех полей с клавиатуры, функция возвращает массив с введенными данными.\\\
- --\\\
- -- Если x_начала или y_начала будет равен \\\"auto\\\", то соответствующая координата\\\
- -- будет рассчитана автоматически и окно расположится по центру экрана по этой координате.\\\
- --\\\
- -- Пример использования: myData = input(\\\"auto\\\",\\\"auto\\\",\\\"Login\\\",20,{\\\"Username\\\",\\\"\\\"},{\\\"Password\\\",\\\"\\\"})\\\
- -- Если мы введем в поле Username \\\"Igor\\\", а в поле Password \\\"12345\\\",\\\
- -- то функция вовзратит массив вида {\\\"Igor\\\",\\\"12345\\\"}\\\
- --\\\
- -- К слову, в поле можно вставлять данные с помощью ctrl+v\\\
- \\\
- \\\
- -- select(table заголовок, table подзаголовок, table кнопка1, table кнопка2 ... table кнопкаN)\\\
- -- Функция вызывает окно с текстом и кнопками выбора. \\\
- --\\\
- -- Структура массива заголовка и подзаголовка: {string текст1, string текст2 ... string текстN}\\\
- -- Структура массива кнопки: {string имя_кнопки, int цвет_кнопки, int цвет_текста_кнопки}\\\
- --\\\
- -- При нажатии на кнопку функция возвращает имя нажатой кнопки.\\\
- --\\\
- -- Пример использования: pressedButton = windows.select({\\\"Hello!\\\"},{\\\"Do you want to load OS\\\",\\\"when computer starts?\\\"},{\\\"No\\\",colors.lightGray,colors.black},{\\\"Yes\\\",colors.lightBlue,colors.black})\\\
- \\\
- \\\
- -- aboutFile(int х_начала, int y_начала, int ширина_окна, string путь_к_файлу)\\\
- -- Наглядно отображает информацию о файле в красивом окошке.\\\
- -- Координаты корректируются автоматически.\\\
- \\\
- \\\
- -- progressBar(int х_начала, int y_начала, int ширина_окна, string заголовок, string информация, int скорость)\\\
- -- Функция отрисовывает окно с информацией и имитирует продолжительный процесс, рисуя шкалу прогресса.\\\
- \\\
- \\\
- -- search(int х_начала, int y_начала, int ширина_окна, int количество_элементов_по_высоте, string текст_для_поиска)\\\
- -- Функция рисует красивое окошка поиска по файловой системе.\\\
- -- Также отображается информация о файлах.\\\
- -- При вводе любой информации начинается поиск совпадений с именами файлов.\\\
- -- К регистру букв не чувствительна.\\\
- -- После выбора любого найденного элемента с помощью мыши, функция вовзращает путь к выбранному файлу.\\\
- \\\
- -------------------------РАБОТА С ФАЙЛАМп-------------------------------------------------------------------------------------\\\
- \\\
- -- getFileFormat(string путь_к_файлу)\\\
- -- Функция возвращает расширение файла по типу .zip, .app и прочие. Если расширение отсутствует, возвращает nil.\\\
- \\\
- -- hideFileFormat(string путь_к_файлу)\\\
- -- Если файл имеет расширение, то функция возвращает имя файла без этого расширения. Если расширения нет, возвращается то же имя.\\\
- \\\
- -- isFileHidden(string путь_к_файлу)\\\
- -- Если в начале имени файла есть символ \\\".\\\", то функция возвращает true. Если нет, то false.\\\
- \\\
- -- getFileSize(string путь_к_файлу)\\\
- -- Функция возвращает суммарный размер всех файлов в указанном пути. В том числе и размер подфайлов и поддиректорий.\\\
- \\\
- -- getFileType(string путь_к_файлу)\\\
- -- Функция возвращает тип файла. Например, если расширение файла .zip, то его тип - Application.\\\
- \\\
- -- stringLimit(string режим, string строка, int ограничение_строки)\\\
- -- Ограничитель строки с двумя режимами работы. Вот примеры:\\\
- --\\\
- -- local s = \\\"HelloWorldBitches!\\\"\\\
- -- print(stringLimit(\\\"start\\\", s, 10))\\\
- -- print(stringLimit(\\\"end\\\", s, 10))\\\
- --\\\
- -- На экране будет отображено:\\\
- -- ...itches!\\\
- -- HelloWo...\\\
- \\\
- -----------------------------------------------------------------------------------------------------------------------------------\\\
- \\\
- \\\
- local xSize,ySize = term.getSize()\\\
- local centerX,centerY = math.floor(xSize/2),math.floor(ySize/2)\\\
- \\\
- --ПОпСК ПЕРпФЕРпп\\\
- function findPeripheral(whatToFind)\\\
- local PeriList = peripheral.getNames()\\\
- for i=1,#PeriList do\\\
- if peripheral.getType(PeriList[i]) == whatToFind then\\\
- return PeriList[i]\\\
- end\\\
- end\\\
- end\\\
- \\\
- --ПОпСК БЕСПРОВОДНОГО МОДЕМА\\\
- function findWirelessModem()\\\
- local periList = peripheral.getNames()\\\
- for i=1,#periList do\\\
- if peripheral.getType(periList[i]) == \\\"modem\\\" then\\\
- local govno = peripheral.wrap(periList[i])\\\
- if govno.isWireless() then\\\
- return periList[i]\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- --КЛпКНУЛп Лп В ЗОНУ\\\
- function clickedAtArea(x,y,sx,sy,ex,ey)\\\
- if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end \\\
- return false\\\
- end\\\
- \\\
- --В БУЛпН, ЕПТЫ БЛЯ\\\
- function toboolean(s)\\\
- if s == \\\"true\\\" then\\\
- return true\\\
- else\\\
- return false\\\
- end\\\
- end\\\
- \\\
- --ЦВЕТНОЙ ТЕКСТ\\\
- function colorText(x,y,text,textColor)\\\
- term.setTextColor(textColor)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- --ЦВЕТНОЙ ТЕКСТ С ФОНОМ\\\
- function colorTextWithBack(x,y,text,textColor,backColor)\\\
- term.setTextColor(textColor)\\\
- term.setBackgroundColor(backColor)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- --ПРОСТОЕ ОТОБРАЖЕНпЕ ТЕКСТА ПО КООРДпНАТАМ\\\
- function usualText(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- --УНпВЕРСАЛЬНАЯ ФУНКЦпЯ ДЛЯ ОТОБРАЖЕНпЯ ТЕКСТА ПО ЦЕНТРУ ЭКРАНА\\\
- function centerText(how,coord,text,textColor,backColor)\\\
- term.setTextColor(textColor)\\\
- term.setBackgroundColor(backColor)\\\
- if how == \\\"xy\\\" then\\\
- term.setCursorPos(math.floor(xSize/2-#text/2),math.floor(ySize/2))\\\
- elseif how == \\\"x\\\" then\\\
- term.setCursorPos(math.floor(xSize/2-#text/2),coord)\\\
- elseif how == \\\"y\\\" then\\\
- term.setCursorPos(coord,math.floor(ySize/2))\\\
- end\\\
- term.write(text)\\\
- end\\\
- \\\
- --РпСОВАНпЕ КВАДРАТА С ЗАЛпВКОЙ\\\
- function square(x1,y1,width,height,color)\\\
- local string = string.rep(\\\" \\\",width)\\\
- term.setBackgroundColor(color)\\\
- for y=y1,(y1+height-1) do\\\
- usualText(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- --РпСОВАНпЕ КРУГА\\\
- function circle(cx, cy, radius, char, backColor, textColor)\\\
- local x = radius\\\
- local y = 0\\\
- local radiusError = 1 - x\\\
- term.setTextColor(textColor)\\\
- term.setBackgroundColor(backColor)\\\
- while (x >= y) do\\\
- usualText(x + cx, y + cy, char)\\\
- usualText(y + cx, x + cy, char)\\\
- usualText(-x + cx, y + cy, char)\\\
- usualText(-y + cx, x + cy, char)\\\
- usualText(-x + cx, -y + cy, char)\\\
- usualText(-y + cx, -x + cy, char)\\\
- usualText(x + cx, -y + cy, char)\\\
- usualText(y + cx, -x + cy, char)\\\
- y = y + 1\\\
- if (radiusError < 0) then\\\
- radiusError = radiusError + (2 * y + 1)\\\
- else\\\
- x = x - 1\\\
- radiusError = radiusError + (2 * (y - x + 1))\\\
- end\\\
- end\\\
- end\\\
- \\\
- --ЗАЛпВКА ЭКРАНА ЦВЕТОМ\\\
- function clearScreen(color)\\\
- term.setBackgroundColor(color)\\\
- term.clear()\\\
- end\\\
- \\\
- --ПЛАВНОЕ ВКЛЮЧЕНпЕ ЭКРАНА\\\
- function fadeIn(time)\\\
- clearScreen(colors.gray)\\\
- sleep(time)\\\
- clearScreen(colors.lightGray)\\\
- sleep(time)\\\
- clearScreen(colors.white)\\\
- sleep(time)\\\
- end\\\
- \\\
- --ПЛАВНОЕ ЗАТУХАНпЕ ЭКРАНА\\\
- function fadeOut(time)\\\
- clearScreen(colors.lightGray)\\\
- sleep(time)\\\
- clearScreen(colors.gray)\\\
- sleep(time)\\\
- clearScreen(colors.black)\\\
- sleep(time)\\\
- term.setCursorPos(1,1)\\\
- term.setTextColor(colors.white)\\\
- end\\\
- \\\
- --ПРОСТОЕ ОКНО С ПОЛОСКОЙ НАВЕРХУ\\\
- function emptyWindow(xStart,yStart,xWindowSize,yWindowSize,title)\\\
- --DRAW WINDOW\\\
- square(xStart,yStart,xWindowSize,1,colors.lightGray)\\\
- colorText(math.floor(xStart+xWindowSize/2-#title/2),yStart,title,colors.white)\\\
- \\\
- square(xStart,yStart+1,xWindowSize,yWindowSize-1,colors.white)\\\
- \\\
- --DRAW SHADOW\\\
- for x=(xStart+1),(xStart+xWindowSize) do\\\
- paintutils.drawPixel(x,yStart+yWindowSize,colors.gray)\\\
- end\\\
- for y=(yStart+1),(yStart+yWindowSize) do\\\
- paintutils.drawPixel(xStart+xWindowSize,y,colors.gray)\\\
- end\\\
- end\\\
- \\\
- --ПРОСТОЕ ОКНО БЕЗ ПОЛОСКп\\\
- function sampleWindow(xStart,yStart,xWindowSize,yWindowSize)\\\
- square(xStart,yStart,xWindowSize,yWindowSize,colors.white)\\\
- --DRAW SHADOW\\\
- for x=(xStart+1),(xStart+xWindowSize) do\\\
- paintutils.drawPixel(x,yStart+yWindowSize,colors.gray)\\\
- end\\\
- for y=(yStart+1),(yStart+yWindowSize) do\\\
- paintutils.drawPixel(xStart+xWindowSize,y,colors.gray)\\\
- end\\\
- end\\\
- \\\
- --ОГРАНпЧЕНпЕ ДЛпНЫ СТРОКп\\\
- function stringLimit(mode,text,size,noDots)\\\
- if string.len(text)<=size then return text end\\\
- if mode == \\\"start\\\" then\\\
- if noDots then\\\
- return string.sub(text,#text-size+1,-1)\\\
- else\\\
- return \\\"...\\\"..string.sub(text,#text-size+4,-1)\\\
- end\\\
- else\\\
- if noDots then\\\
- return string.sub(text,1,size)\\\
- else\\\
- return string.sub(text,1,size-3)..\\\"...\\\"\\\
- end\\\
- end\\\
- end\\\
- \\\
- --ПОЛУЧЕНпЕ ФОРМАТА ФАЙЛА\\\
- function getFileFormat(path)\\\
- local name = fs.getName(path)\\\
- local starting,ending = string.find(name,\\\"(.)%.[%d%w]*$\\\")\\\
- if starting == nil then\\\
- return nil\\\
- else\\\
- return string.sub(name,starting+1,-1)\\\
- end\\\
- end\\\
- \\\
- --ПРОВЕРКА, СКРЫТЫЙ Лп ФАЙЛ\\\
- function isFileHidden(path)\\\
- local name = fs.getName(path)\\\
- local starting,ending = string.find(name,\\\"^%.(.*)$\\\")\\\
- if starting == nil then\\\
- return false\\\
- else\\\
- return true\\\
- end\\\
- end\\\
- \\\
- --СКРЫТЬ РАСШпРЕНпЕ ФАЙЛА\\\
- function hideFileFormat(path)\\\
- local name = fs.getName(path)\\\
- local fileFormat = getFileFormat(name)\\\
- if fileFormat == nil then\\\
- return name\\\
- else\\\
- return string.sub(name,1,#name-#fileFormat)\\\
- end\\\
- end\\\
- \\\
- --ПОЛУЧЕНпЕ РАЗМЕРА ФАЙЛА пЛп ПАПКп\\\
- function getFileSize(path)\\\
- local allFilesSize = 0\\\
- if fs.isDir(path) then\\\
- local fileList = fs.list(path)\\\
- for i=1,#fileList do\\\
- allFilesSize = allFilesSize + getFileSize(path..\\\"/\\\"..fileList[i])\\\
- end\\\
- else\\\
- allFilesSize = allFilesSize + fs.getSize(path)\\\
- end\\\
- return allFilesSize\\\
- end\\\
- \\\
- --ПОЛУЧпТЬ ТпП ФАЙЛА\\\
- function getFileType(path)\\\
- local fileTypes = {\\\
- [\\\".png\\\"] = \\\"Image\\\",\\\
- [\\\".cfg\\\"] = \\\"Config\\\",\\\
- [\\\".zip\\\"] = \\\"Archive\\\",\\\
- [\\\".app\\\"] = \\\"Application\\\",\\\
- }\\\
- \\\
- local currentFileType = nil\\\
- \\\
- local fileFormat = getFileFormat(path)\\\
- if fileFormat == nil then\\\
- if fs.isDir(path) then\\\
- currentFileType = \\\"Folder\\\"\\\
- else\\\
- currentFileType = \\\"Lua script\\\"\\\
- end\\\
- else\\\
- currentFileType = fileTypes[fileFormat] or fileFormat\\\
- end\\\
- \\\
- return currentFileType\\\
- end\\\
- \\\
- --РЕОРГАНпЗМАЦпЯ МАССпВА ДЛЯ ОС-Кп\\\
- function reorganizeFilesAndFolders(workPath,massivSudaPihay,showHiddenFiles,showSystemFolders)\\\
- local reorganizedMassiv = {}\\\
- local function doGovno(i)\\\
- if showHiddenFiles then\\\
- reorganizedMassiv[#reorganizedMassiv+1] = massivSudaPihay[i]\\\
- else\\\
- if not windows.isFileHidden(workPath..\\\"/\\\"..massivSudaPihay[i]) then\\\
- reorganizedMassiv[#reorganizedMassiv+1] = massivSudaPihay[i]\\\
- end\\\
- end\\\
- end\\\
- local filePath = nil\\\
- for i=1,#massivSudaPihay do\\\
- filePath = workPath..\\\"/\\\"..massivSudaPihay[i]\\\
- if fs.isDir(filePath) and windows.getFileFormat(filePath) ~= \\\".app\\\" then\\\
- if showSystemFolders then\\\
- doGovno(i)\\\
- else\\\
- if massivSudaPihay[i] ~= \\\"rom\\\" and massivSudaPihay[i] ~= \\\"System\\\" then\\\
- --windows.attention({\\\"massiv[i] = \\\"..massivSudaPihay[i]},{\\\"heh\\\"})\\\
- doGovno(i)\\\
- end\\\
- end\\\
- end\\\
- end\\\
- for i=1,#massivSudaPihay do\\\
- filePath = workPath..\\\"/\\\"..massivSudaPihay[i]\\\
- if not fs.isDir(filePath) and massivSudaPihay[i] ~= \\\"OS\\\" or fs.isDir(filePath) and windows.getFileFormat(filePath) == \\\".app\\\" then\\\
- doGovno(i)\\\
- end\\\
- end\\\
- return reorganizedMassiv\\\
- end\\\
- \\\
- --ОТРпСОВКА пКОНКп ДЛЯ ОС\\\
- function drawOSIcon(xIconPos,yIconPos,workPath,name,fileFormat)\\\
- --ЕСЛп ЭТО НЕ ПАПКА\\\
- if not fs.isDir(workPath..\\\"/\\\"..name) then\\\
- if fileFormat == \\\".png\\\" then\\\
- image.draw(xIconPos,yIconPos,\\\"system/os/Icons/image.png\\\")\\\
- elseif fileFormat == \\\".cfg\\\" then\\\
- image.draw(xIconPos,yIconPos,\\\"system/os/Icons/config.png\\\")\\\
- elseif fileFormat == \\\".zip\\\" then\\\
- image.draw(xIconPos,yIconPos,\\\"system/os/Icons/zip.png\\\")\\\
- else\\\
- image.draw(xIconPos,yIconPos,\\\"system/os/Icons/default.png\\\")\\\
- end\\\
- --ЕСЛп ЭТО ПАПКА\\\
- else\\\
- local iconPath = workPath..\\\"/\\\"..name..\\\"/resources/icon.png\\\"\\\
- if fileFormat == \\\".app\\\" and fs.exists(iconPath) then\\\
- image.draw(xIconPos,yIconPos,iconPath)\\\
- elseif string.sub(name,1,4)==\\\"disk\\\" then\\\
- image.draw(xIconPos,yIconPos,\\\"system/os/Icons/disk.png\\\")\\\
- else\\\
- image.draw(xIconPos,yIconPos,\\\"system/os/Icons/folder.png\\\")\\\
- end\\\
- end\\\
- end\\\
- \\\
- --КОРРЕКТпРОВКА СТАРТОВЫХ КООРДпНАТ\\\
- local function correctStartCoords(xStart,yStart,xWindowSize,yWindowSize)\\\
- if xStart == \\\"auto\\\" then\\\
- xStart = math.floor(xSize/2 - xWindowSize/2)\\\
- end\\\
- if yStart == \\\"auto\\\" then\\\
- yStart = math.floor(ySize/2 - yWindowSize/2)\\\
- end\\\
- return xStart,yStart\\\
- end\\\
- \\\
- --РпСОВАНпЕ КНОПКп\\\
- function button(x,y,xOffset,yOffset,text,textColor,backColor)\\\
- local width = xOffset*2+#text\\\
- local height = yOffset*2+1\\\
- x,y = correctStartCoords(x,y,width,height)\\\
- square(x,y,width,height,backColor)\\\
- colorText(x+xOffset,y+yOffset,text,textColor)\\\
- return x,y,x+width-1,y+height-1\\\
- end\\\
- \\\
- --ОТРпСОВКА ШКАЛЫ ПРОГРЕССА\\\
- local function drawProgressBar(xStart,yStart,width,height,frontColor,backColor,percent)\\\
- local doneSize = math.ceil(percent/100*width)\\\
- \\\
- square(xStart,yStart,width,height,backColor)\\\
- square(xStart,yStart,doneSize,height,frontColor)\\\
- end\\\
- \\\
- --ОТРпСОВКА ПОЛОСЫ ПРОКРУТКп\\\
- function scrollBar(xStart,yStart,height,countOfAllElements,currentElement,backColor,frontColor)\\\
- local percent = 1/countOfAllElements\\\
- local sizeOfScrollBar = math.ceil(percent * height)\\\
- local displayBarFrom = math.floor(yStart + height*((currentElement-1)/countOfAllElements))\\\
- \\\
- for i=yStart,(yStart+height-1) do\\\
- paintutils.drawPixel(xStart,i,backColor)\\\
- end\\\
- \\\
- for i=displayBarFrom,(displayBarFrom+sizeOfScrollBar-1) do\\\
- paintutils.drawPixel(xStart,i,frontColor)\\\
- end\\\
- end\\\
- \\\
- --ПОпСК ЧЕГО-ЛпБО В ФАЙЛОВОЙ СпСТЕМЕ\\\
- local function searchInAllFiles(path,whatToFind)\\\
- \\\
- local function poiskSovpadeniya(name)\\\
- local starting,ending = string.find(string.lower(name),string.lower(whatToFind))\\\
- if starting == nil then\\\
- return false\\\
- else\\\
- return true\\\
- end\\\
- end\\\
- \\\
- local searchMassiv = {}\\\
- \\\
- local function createFileMassiv(path,whatToFind)\\\
- local fileList = fs.list(path)\\\
- for i=1,#fileList do\\\
- if fs.isDir(path..\\\"/\\\"..fileList[i]) then\\\
- if poiskSovpadeniya(fileList[i]) then\\\
- 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])}\\\
- end\\\
- createFileMassiv(path..\\\"/\\\"..fileList[i],whatToFind)\\\
- else\\\
- if poiskSovpadeniya(fileList[i]) then\\\
- 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])}\\\
- end\\\
- end\\\
- end\\\
- end\\\
- createFileMassiv(path,whatToFind)\\\
- return searchMassiv\\\
- \\\
- end\\\
- \\\
- --ФОРМАТпРОВАННЫЙ ТЕКСТ КАК В ЧАТЕ МАЙНА ЧЕРЕЗ &6, &c, &a п Т.П.\\\
- local colorCodes = {\\\
- {[\\\"code\\\"] = \\\"&0\\\", [\\\"color\\\"] = 1},\\\
- {[\\\"code\\\"] = \\\"&1\\\", [\\\"color\\\"] = 2},\\\
- {[\\\"code\\\"] = \\\"&2\\\", [\\\"color\\\"] = 4},\\\
- {[\\\"code\\\"] = \\\"&3\\\", [\\\"color\\\"] = 8},\\\
- {[\\\"code\\\"] = \\\"&4\\\", [\\\"color\\\"] = 16},\\\
- {[\\\"code\\\"] = \\\"&5\\\", [\\\"color\\\"] = 32},\\\
- {[\\\"code\\\"] = \\\"&6\\\", [\\\"color\\\"] = 64},\\\
- {[\\\"code\\\"] = \\\"&7\\\", [\\\"color\\\"] = 128},\\\
- {[\\\"code\\\"] = \\\"&8\\\", [\\\"color\\\"] = 256},\\\
- {[\\\"code\\\"] = \\\"&9\\\", [\\\"color\\\"] = 512},\\\
- {[\\\"code\\\"] = \\\"&a\\\", [\\\"color\\\"] = 1024},\\\
- {[\\\"code\\\"] = \\\"&b\\\", [\\\"color\\\"] = 2048},\\\
- {[\\\"code\\\"] = \\\"&c\\\", [\\\"color\\\"] = 4096},\\\
- {[\\\"code\\\"] = \\\"&d\\\", [\\\"color\\\"] = 8192},\\\
- {[\\\"code\\\"] = \\\"&e\\\", [\\\"color\\\"] = 16384},\\\
- {[\\\"code\\\"] = \\\"&f\\\", [\\\"color\\\"] = 32768},\\\
- }\\\
- \\\
- function foramattedText(text)\\\
- local color = colors.white\\\
- term.setTextColor(color)\\\
- local sText = #text\\\
- local searchFrom = 1\\\
- \\\
- local exit = false\\\
- while true do\\\
- if exit then break end\\\
- local founded = false\\\
- local s,e = string.find(text,\\\"&\\\",searchFrom)\\\
- if s then\\\
- local code = string.sub(text,s,s+1)\\\
- for i=1,16 do\\\
- if code == colorCodes[i][\\\"code\\\"] then\\\
- \\\
- local cyka = string.sub(text,searchFrom,s-1)\\\
- term.write(cyka)\\\
- \\\
- color = colorCodes[i][\\\"color\\\"]\\\
- term.setTextColor(color)\\\
- \\\
- founded = true\\\
- searchFrom = searchFrom + #cyka + 2\\\
- break\\\
- end\\\
- end\\\
- end\\\
- \\\
- if not founded then\\\
- term.write(string.sub(text,searchFrom,-1))\\\
- exit = true\\\
- end\\\
- end\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------\\\
- \\\
- function error(text1)\\\
- \\\
- local title = \\\"Error\\\"\\\
- local limit = xSize - 16 - 11\\\
- local sizeOfText1 = #text1\\\
- \\\
- local parsedErr = {}\\\
- for i=1,(math.ceil(sizeOfText1/limit)) do\\\
- parsedErr[#parsedErr+1] = string.sub(text1,i*limit+1-limit,i*limit)\\\
- end\\\
- \\\
- local theLongestElement = #title\\\
- for i=1,#parsedErr do\\\
- local size = #parsedErr[i]\\\
- if size > theLongestElement then theLongestElement = size end\\\
- end\\\
- \\\
- local xWindowSize = 9 + theLongestElement + 2\\\
- local yWindowSize = 2 + 1 + 1 + #parsedErr + 3\\\
- local xStart = math.floor(xSize/2-xWindowSize/2)\\\
- local yStart = math.floor(ySize/2-yWindowSize/2)\\\
- \\\
- --РпСОВАНпЕ ПУСТОГО ОКНА\\\
- emptyWindow(xStart,yStart,xWindowSize,yWindowSize,\\\" \\\")\\\
- \\\
- --DRAW ICON\\\
- paintutils.drawPixel(xStart+4,yStart+2,colors.red)\\\
- paintutils.drawPixel(xStart+3,yStart+3,colors.red)\\\
- paintutils.drawPixel(xStart+4,yStart+3,colors.red)\\\
- paintutils.drawPixel(xStart+5,yStart+3,colors.red)\\\
- paintutils.drawPixel(xStart+2,yStart+4,colors.red)\\\
- paintutils.drawPixel(xStart+3,yStart+4,colors.red)\\\
- paintutils.drawPixel(xStart+4,yStart+4,colors.red)\\\
- paintutils.drawPixel(xStart+5,yStart+4,colors.red)\\\
- \\\
- paintutils.drawPixel(xStart+6,yStart+4,colors.red)\\\
- colorText(xStart+4,yStart+3,\\\"!\\\",colors.white)\\\
- \\\
- --ERROR TEXT\\\
- term.setBackgroundColor(colors.white)\\\
- \\\
- colorText(xStart+9,yStart+2,title,colors.gray)\\\
- \\\
- for i=1,#parsedErr do\\\
- colorText(xStart+9,yStart+3+i,parsedErr[i],colors.lightGray)\\\
- end\\\
- \\\
- --BUTTON\\\
- local function drawButton(color,color2)\\\
- for x=(xStart+xWindowSize-8),(xStart+xWindowSize-3) do\\\
- paintutils.drawPixel(x,yStart+yWindowSize-2,color)\\\
- end\\\
- colorText(xStart+xWindowSize-6,yStart+yWindowSize-2,\\\"OK\\\",color2)\\\
- end\\\
- drawButton(colors.lightBlue,colors.black)\\\
- \\\
- while true do\\\
- local event,side,x,y = os.pullEvent()\\\
- if event == \\\"mouse_click\\\" then\\\
- if x>=xStart+xWindowSize-8 and x<=xStart+xWindowSize-3 and y == yStart+yWindowSize-2 then\\\
- drawButton(colors.blue,colors.white)\\\
- sleep(0.2)\\\
- break\\\
- end\\\
- elseif event == \\\"key\\\" then\\\
- if side == 28 then\\\
- drawButton(colors.blue,colors.white)\\\
- sleep(0.2)\\\
- break\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------\\\
- \\\
- function attention(text1,text2)\\\
- \\\
- local sizeOfText1 = #text1\\\
- local sizeOfText2 = #text2\\\
- \\\
- local theLongestElement = 0\\\
- for i=1,sizeOfText1 do\\\
- if #text1[i] > theLongestElement then theLongestElement = #text1[i] end\\\
- end\\\
- for i=1,sizeOfText2 do\\\
- if #text2[i] > theLongestElement then theLongestElement = #text2[i] end\\\
- end\\\
- \\\
- local xWindowSize = 9 + theLongestElement + 2\\\
- local yWindowSize = 2 + sizeOfText1 + 1 + sizeOfText2 + 3\\\
- local xStart = math.floor(xSize/2-xWindowSize/2)\\\
- local yStart = math.floor(ySize/2-yWindowSize/2)\\\
- \\\
- --РпСОВАНпЕ ПУСТОГО ОКНА\\\
- emptyWindow(xStart,yStart,xWindowSize,yWindowSize,\\\" \\\")\\\
- \\\
- --DRAW ICON\\\
- paintutils.drawPixel(xStart+4,yStart+2,colors.yellow)\\\
- paintutils.drawPixel(xStart+3,yStart+3,colors.yellow)\\\
- paintutils.drawPixel(xStart+4,yStart+3,colors.yellow)\\\
- paintutils.drawPixel(xStart+5,yStart+3,colors.yellow)\\\
- paintutils.drawPixel(xStart+2,yStart+4,colors.yellow)\\\
- paintutils.drawPixel(xStart+3,yStart+4,colors.yellow)\\\
- paintutils.drawPixel(xStart+4,yStart+4,colors.yellow)\\\
- paintutils.drawPixel(xStart+5,yStart+4,colors.yellow)\\\
- paintutils.drawPixel(xStart+6,yStart+4,colors.yellow)\\\
- colorText(xStart+4,yStart+3,\\\"!\\\",colors.white)\\\
- \\\
- --ERROR TEXT\\\
- term.setBackgroundColor(colors.white)\\\
- for i=1,sizeOfText1 do\\\
- colorText(xStart+9,yStart+1+i,text1[i],colors.gray)\\\
- end\\\
- for i=1,sizeOfText2 do\\\
- colorText(xStart+9,yStart+3+i,text2[i],colors.lightGray)\\\
- end\\\
- \\\
- --BUTTON\\\
- local function drawButton(color,color2)\\\
- for x=(xStart+xWindowSize-8),(xStart+xWindowSize-3) do\\\
- paintutils.drawPixel(x,yStart+yWindowSize-2,color)\\\
- end\\\
- colorText(xStart+xWindowSize-6,yStart+yWindowSize-2,\\\"OK\\\",color2)\\\
- end\\\
- drawButton(colors.lightBlue,colors.black)\\\
- \\\
- while true do\\\
- local event,side,x,y = os.pullEvent()\\\
- if event == \\\"mouse_click\\\" then\\\
- if x>=xStart+xWindowSize-8 and x<=xStart+xWindowSize-3 and y == yStart+yWindowSize-2 then\\\
- drawButton(colors.blue,colors.white)\\\
- sleep(0.2)\\\
- break\\\
- end\\\
- elseif event == \\\"key\\\" then\\\
- if side == 28 then\\\
- drawButton(colors.blue,colors.white)\\\
- sleep(0.2)\\\
- break\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------\\\
- \\\
- function input(...)\\\
- \\\
- local xStart = arg[1]\\\
- local yStart = arg[2]\\\
- local title = arg[3]\\\
- local sizeOfInputRow = arg[4]\\\
- \\\
- local sizeOfText1 = #arg-4\\\
- \\\
- local Inputs = {}\\\
- \\\
- local allowToPressOk = true\\\
- \\\
- local inputCounter = 1\\\
- \\\
- local theLongestElement = 0\\\
- for i=1,sizeOfText1 do\\\
- if #arg[i+4][1] > theLongestElement then theLongestElement = #arg[i+4][1] end\\\
- end\\\
- \\\
- local xWindowSize = 2 + theLongestElement + 1 + sizeOfInputRow + 2\\\
- local yWindowSize = 2 + sizeOfText1 * 2 + 1 + 1\\\
- \\\
- xStart, yStart = correctStartCoords(xStart,yStart,xWindowSize,yWindowSize)\\\
- \\\
- --ЗАНОСпМ СТАРТОВОЕ ГОВНО В пНПУТС, БпЧ\\\
- for i=1,sizeOfText1 do\\\
- Inputs[i]=arg[i+4][2]\\\
- end\\\
- \\\
- --СОЗДАНпЕ ОБЪЕКТОВ\\\
- local Objects = {}\\\
- local function newObj(class,name,x1,y1,width,height)\\\
- Objects[class] = Objects[class] or {}\\\
- Objects[class][name] = {}\\\
- Objects[class][name][\\\"x1\\\"]=x1\\\
- Objects[class][name][\\\"y1\\\"]=y1\\\
- Objects[class][name][\\\"x2\\\"]=x1+width-1\\\
- Objects[class][name][\\\"y2\\\"]=y1+height-1\\\
- end\\\
- \\\
- --РпСОВАНпЕ ПУСТОГО ОКНА\\\
- emptyWindow(xStart,yStart,xWindowSize,yWindowSize,title)\\\
- \\\
- --BUTTON\\\
- local function drawButton(color,color2)\\\
- for x=(xStart+xWindowSize-8),(xStart+xWindowSize-3) do\\\
- paintutils.drawPixel(x,yStart+yWindowSize-2,color)\\\
- end\\\
- colorText(xStart+xWindowSize-6,yStart+yWindowSize-2,\\\"OK\\\",color2)\\\
- end\\\
- \\\
- local function drawInputs()\\\
- for i=1,sizeOfText1 do\\\
- local xPosOfInput = xStart+xWindowSize - 2 - sizeOfInputRow\\\
- local yPosOfInput = yStart+i*2\\\
- \\\
- local inputArgument = arg[i+4]\\\
- \\\
- term.setBackgroundColor(colors.white)\\\
- if inputCounter == i then\\\
- colorText(xStart+2,yPosOfInput,inputArgument[1],colors.gray)\\\
- else\\\
- colorText(xStart+2,yPosOfInput,inputArgument[1],colors.lightGray)\\\
- end\\\
- \\\
- square(xPosOfInput,yPosOfInput,sizeOfInputRow,1,colors.lightGray)\\\
- newObj(\\\"inputs\\\",i,xPosOfInput,yPosOfInput,sizeOfInputRow,1)\\\
- \\\
- if Inputs[i] ~= nil then\\\
- if inputArgument[3] == nil then\\\
- colorText(xPosOfInput,yPosOfInput,stringLimit(\\\"start\\\",Inputs[i],sizeOfInputRow),colors.black)\\\
- else\\\
- colorText(xPosOfInput,yPosOfInput,stringLimit(\\\"start\\\",string.rep(\\\"*\\\",#Inputs[i]),sizeOfInputRow),colors.black)\\\
- end\\\
- end\\\
- \\\
- if inputCounter > sizeOfText1 then allowToPressOk = true end\\\
- end\\\
- \\\
- if allowToPressOk then\\\
- drawButton(colors.lightBlue,colors.black)\\\
- else\\\
- drawButton(colors.lightGray,colors.black)\\\
- end\\\
- end\\\
- \\\
- drawInputs()\\\
- \\\
- local currentInput = \\\"\\\"\\\
- \\\
- while true do\\\
- if Inputs[inputCounter] ~= nil then currentInput = Inputs[inputCounter] end\\\
- \\\
- term.setCursorBlink(false)\\\
- drawInputs(inputCounter)\\\
- term.setCursorBlink(true)\\\
- \\\
- if #currentInput < sizeOfInputRow and inputCounter <= sizeOfText1 then\\\
- term.setCursorPos(xStart+xWindowSize-2-sizeOfInputRow+#currentInput,yStart+inputCounter*2)\\\
- elseif #currentInput >= sizeOfInputRow and inputCounter <= sizeOfText1 then\\\
- term.setCursorPos(xStart+xWindowSize-3,yStart+inputCounter*2)\\\
- else\\\
- term.setCursorBlink(false)\\\
- end\\\
- \\\
- local event,side,x,y = os.pullEvent()\\\
- if event == \\\"key\\\" then\\\
- --ЕНТЕР\\\
- if side == 28 then\\\
- if currentInput ~= \\\"\\\" then\\\
- currentInput = \\\"\\\"\\\
- else\\\
- Inputs[inputCounter] = currentInput \\\
- end\\\
- \\\
- if inputCounter < sizeOfText1 then\\\
- inputCounter = inputCounter + 1\\\
- else\\\
- term.setCursorBlink(false)\\\
- drawButton(colors.blue,colors.white)\\\
- sleep(0.2)\\\
- return Inputs\\\
- end\\\
- --БЕКСПЕЙС\\\
- elseif side == 14 then\\\
- currentInput = string.sub(currentInput,1,-2)\\\
- Inputs[inputCounter] = currentInput\\\
- --КНОПОЧКп ВВЕРХ-ВНпЗ\\\
- elseif side == 200 then\\\
- inputCounter = inputCounter - 1\\\
- if inputCounter < 1 then inputCounter = 1 end\\\
- elseif side == 208 then\\\
- inputCounter = inputCounter + 1\\\
- if inputCounter > #Inputs then inputCounter = #Inputs end\\\
- end\\\
- elseif event == \\\"mouse_click\\\" then\\\
- term.setCursorBlink(false)\\\
- if x>=xStart+xWindowSize-8 and x<=xStart+xWindowSize-3 and y == yStart+yWindowSize-2 and allowToPressOk == true then\\\
- drawButton(colors.blue,colors.white)\\\
- sleep(0.2)\\\
- return Inputs\\\
- end\\\
- for key,val in pairs(Objects[\\\"inputs\\\"]) do\\\
- if x>=Objects[\\\"inputs\\\"][key][\\\"x1\\\"] and x<=Objects[\\\"inputs\\\"][key][\\\"x2\\\"] and y==Objects[\\\"inputs\\\"][key][\\\"y1\\\"] then\\\
- inputCounter = key\\\
- break\\\
- end\\\
- end\\\
- elseif event == \\\"char\\\" then\\\
- currentInput = currentInput..side\\\
- Inputs[inputCounter] = currentInput\\\
- elseif event == \\\"paste\\\" then\\\
- currentInput = currentInput..side\\\
- Inputs[inputCounter] = currentInput\\\
- end\\\
- end\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------------\\\
- \\\
- function tv(speed)\\\
- term.setBackgroundColor(colors.black)\\\
- for i=1,centerY do\\\
- term.setCursorPos(1,i)\\\
- term.clearLine()\\\
- term.setCursorPos(1,ySize-i+1)\\\
- term.clearLine()\\\
- sleep(speed)\\\
- end\\\
- for i=1,centerX do\\\
- paintutils.drawPixel(i,centerY+1,colors.black)\\\
- paintutils.drawPixel(xSize-i+1,centerY+1,colors.black)\\\
- sleep(speed)\\\
- end\\\
- sleep(0.2)\\\
- clearScreen(colors.black)\\\
- term.setTextColor(colors.white)\\\
- term.setCursorPos(1,1)\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------------\\\
- \\\
- function select(...)\\\
- \\\
- --СОЗДАНпЕ ОБЪЕКТОВ\\\
- local Objects = {}\\\
- local function newObj(class,name,x1,y1,width,height)\\\
- --if not Objects[class] then Objects[class] = {} end\\\
- Objects[class] = Objects[class] or {}\\\
- Objects[class][name] = {}\\\
- Objects[class][name][\\\"x1\\\"]=x1\\\
- Objects[class][name][\\\"y1\\\"]=y1\\\
- Objects[class][name][\\\"x2\\\"]=x1+width-1\\\
- Objects[class][name][\\\"y2\\\"]=y1+height-1\\\
- end\\\
- \\\
- local function drawButton(x,y,name,textColor,backColor)\\\
- local sizeOfButton = 2+#name+2\\\
- square(x,y,sizeOfButton,1,backColor)\\\
- colorText(x+2,y,name,textColor)\\\
- newObj(\\\"buttons\\\",name,x,y,sizeOfButton,1)\\\
- end\\\
- \\\
- local text1 = arg[1]\\\
- local text2 = arg[2]\\\
- \\\
- local sizeOfText1 = #text1\\\
- local sizeOfText2 = #text2\\\
- local hereIsOnlyOneElement = false\\\
- if sizeOfText1 == 0 then hereIsOnlyOneElement = true end\\\
- \\\
- --ВЫЧпСЛЕНпЕ ДЛпНЫ ОКНА НА ОСНОВЕ ТЕКСТА\\\
- local theLongestElement = 0\\\
- for i=1,sizeOfText1 do\\\
- if #text1[i] > theLongestElement then theLongestElement = #text1[i] end\\\
- end\\\
- for i=1,sizeOfText2 do\\\
- if #text2[i] > theLongestElement then theLongestElement = #text2[i] end\\\
- end\\\
- \\\
- --ПЕРЕСЧЕТ ДЛпНЫ ОКНА НА ОСНОВЕ КОЛпЧЕСТВА КНОПОК\\\
- local countOfButtons = #arg-2\\\
- local sizeOfAllButtons = 0\\\
- for i=1,countOfButtons do\\\
- sizeOfAllButtons = sizeOfAllButtons + 2+#arg[2+i][1]+2 + 1\\\
- end\\\
- sizeOfAllButtons = sizeOfAllButtons - 1\\\
- if sizeOfAllButtons>theLongestElement then theLongestElement=sizeOfAllButtons end\\\
- \\\
- --ЗАДАНпЕ КОНКРЕТНЫХ РАЗМЕРОВ ОКНА ПОСЛЕ ВЫЧпСЛЕНпЙ\\\
- local xWindowSize = 2 + theLongestElement + 2\\\
- local yWindowSize = nil\\\
- if hereIsOnlyOneElement then\\\
- yWindowSize = 2 + sizeOfText2 + 3\\\
- else\\\
- yWindowSize = 2 + sizeOfText1 + 1 + sizeOfText2 + 3\\\
- end\\\
- \\\
- local xStart = math.floor(xSize/2-xWindowSize/2)\\\
- local yStart = math.floor(ySize/2-yWindowSize/2)\\\
- \\\
- --РпСОВАНпЕ ПУСТОГО ОКНА\\\
- emptyWindow(xStart,yStart,xWindowSize,yWindowSize,\\\" \\\")\\\
- \\\
- --TEXTS\\\
- term.setBackgroundColor(colors.white)\\\
- for i=1,sizeOfText1 do\\\
- colorText(xStart+2,yStart+1+i,text1[i],colors.gray)\\\
- end\\\
- for i=1,sizeOfText2 do\\\
- if hereIsOnlyOneElement then\\\
- colorText(xStart+2,yStart+1+sizeOfText1+i,text2[i],colors.lightGray)\\\
- else\\\
- colorText(xStart+2,yStart+2+sizeOfText1+i,text2[i],colors.lightGray)\\\
- end\\\
- end\\\
- \\\
- local xStartForButtons = xStart+xWindowSize-1 - sizeOfAllButtons - 1\\\
- local yStartForButtons = yStart+yWindowSize-2\\\
- for i=1,countOfButtons do\\\
- local text = arg[2+i][1]\\\
- local textColor = tonumber(arg[2+i][3])\\\
- local backColor = tonumber(arg[2+i][2])\\\
- \\\
- drawButton(xStartForButtons,yStartForButtons,text,textColor,backColor)\\\
- xStartForButtons = xStartForButtons + 2+#arg[2+i][1]+2+1\\\
- end\\\
- \\\
- while true do\\\
- local event,side,x,y = os.pullEvent()\\\
- if event == \\\"mouse_click\\\" then\\\
- for key,val in pairs(Objects[\\\"buttons\\\"]) do\\\
- if x>=Objects[\\\"buttons\\\"][key][\\\"x1\\\"] and x<=Objects[\\\"buttons\\\"][key][\\\"x2\\\"] and y==Objects[\\\"buttons\\\"][key][\\\"y1\\\"] then\\\
- drawButton(Objects[\\\"buttons\\\"][key][\\\"x1\\\"],Objects[\\\"buttons\\\"][key][\\\"y1\\\"],key,colors.white,colors.blue)\\\
- sleep(0.2)\\\
- return key\\\
- end\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------------\\\
- \\\
- function aboutFile(x,y,xWindowSize,path)\\\
- os.loadAPI(\\\"System/API/image\\\")\\\
- \\\
- local name = fs.getName(path)\\\
- local limitOfText = xWindowSize - 2\\\
- local yWindowSize = 16\\\
- \\\
- --СОЗДАНпЕ ОБЪЕКТОВ\\\
- local Objects = {}\\\
- local function newObj(class,name,x1,y1,width,height)\\\
- Objects[class] = Objects[class] or {}\\\
- Objects[class][name] = {}\\\
- Objects[class][name][\\\"x1\\\"]=x1\\\
- Objects[class][name][\\\"y1\\\"]=y1\\\
- Objects[class][name][\\\"x2\\\"]=x1+width-1\\\
- Objects[class][name][\\\"y2\\\"]=y1+height-1\\\
- end\\\
- \\\
- --РпСОВАНпЕ КНОПКп\\\
- local function drawButton(x,y,name,textColor,backColor)\\\
- local sizeOfButton = 2+#name+2\\\
- square(x,y,sizeOfButton,1,backColor)\\\
- colorText(x+2,y,name,textColor)\\\
- newObj(\\\"buttons\\\",name,x,y,sizeOfButton,1)\\\
- end\\\
- \\\
- ---------------НЕНУЖНОЕ ГОВНО, ЛОСОСНп\\\
- \\\
- local info = {}\\\
- \\\
- info[\\\"fileFormat\\\"] = getFileFormat(path)\\\
- \\\
- info[\\\"fileType\\\"] = getFileType(path)\\\
- \\\
- info[\\\"fileSize\\\"] = math.ceil(getFileSize(path)/1024)..\\\"KB\\\"\\\
- \\\
- info[\\\"readOnly\\\"] = tostring(fs.isReadOnly(path))\\\
- ---------------НУЖНОЕ ГОВНО\\\
- \\\
- --КОРРЕКЦпЯ КООРДпНАТЫ GOVNA, ЧТОБ ЗА КРАЯ ЭКРАНА НЕ ЗАЛЕЗАЛО\\\
- if y+yWindowSize - 1 >= ySize then y = y - (y+yWindowSize - 1 - ySize) - 1 end\\\
- if x+xWindowSize - 1 >= xSize then x = x - (x+xWindowSize - 1 - xSize) - 1 end\\\
- \\\
- --РпСУЕМ ОКНО\\\
- emptyWindow(x,y,xWindowSize,yWindowSize,\\\"Properties\\\")\\\
- \\\
- --пКОНОЧКп, БпЧ\\\
- drawOSIcon(x+1,y+2,path,name,info[\\\"fileFormat\\\"])\\\
- \\\
- --ПОЛОСОЧКА ПОД пКОНКОЙ\\\
- square(x,y+7,xWindowSize,1,colors.lightGray)\\\
- colorText(x+1,y+7,\\\"Info\\\",colors.white)\\\
- \\\
- --ТЕКСТ СПРАВА ОТ пКОНКп\\\
- term.setBackgroundColor(colors.white)\\\
- colorText(x+8,y+3,stringLimit(\\\"start\\\",name,xWindowSize-9),colors.gray)\\\
- colorText(x+8,y+4,info[\\\"fileSize\\\"],colors.lightGray)\\\
- \\\
- --ТЕКСТ ПОД пКОНКОЙ\\\
- local textStart = y+9\\\
- colorText(x+1,textStart,\\\"Type:\\\",colors.gray)\\\
- usualText(x+1,textStart+1,\\\"Size:\\\",colors.gray)\\\
- usualText(x+1,textStart+2,\\\"Path:\\\",colors.gray)\\\
- usualText(x+1,textStart+3,\\\"Read only:\\\",colors.gray)\\\
- \\\
- colorText(x+7,textStart,info[\\\"fileType\\\"],colors.lightGray)\\\
- usualText(x+7,textStart+1,info[\\\"fileSize\\\"])\\\
- usualText(x+7,textStart+2,stringLimit(\\\"start\\\",path,xWindowSize-8))\\\
- usualText(x+12,textStart+3,info[\\\"readOnly\\\"])\\\
- \\\
- --КНОПКА\\\
- drawButton(x+xWindowSize-11,y+yWindowSize-2,\\\"Close\\\",colors.black,colors.lightBlue)\\\
- \\\
- --ОТСЛЕЖпВАНпЕ НАЖАТпЯ НА КНОПКУ\\\
- while true do\\\
- local event,side,x,y = os.pullEvent()\\\
- if event == \\\"mouse_click\\\" then\\\
- for key,val in pairs(Objects[\\\"buttons\\\"]) do\\\
- if x>=Objects[\\\"buttons\\\"][key][\\\"x1\\\"] and x<=Objects[\\\"buttons\\\"][key][\\\"x2\\\"] and y==Objects[\\\"buttons\\\"][key][\\\"y1\\\"] then\\\
- drawButton(Objects[\\\"buttons\\\"][key][\\\"x1\\\"],Objects[\\\"buttons\\\"][key][\\\"y1\\\"],key,colors.white,colors.blue)\\\
- sleep(0.2)\\\
- return key\\\
- end\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------------\\\
- \\\
- function progressBar(xStart,yStart,xWindowSize,title,text,speed)\\\
- --СКОРРЕКТпРОВАТЬ ШпРпНУ ОКНА\\\
- if xWindowSize < 4+#text then\\\
- xWindowSize = 4+#text\\\
- end\\\
- \\\
- local yWindowSize = 6\\\
- local sizeOfProgressBar = xWindowSize - 4\\\
- \\\
- --СКОРРЕКТпРОВАТЬ КООРДЫ\\\
- xStart,yStart = correctStartCoords(xStart,yStart,xWindowSize,yWindowSize)\\\
- \\\
- --САМО ОКНО\\\
- emptyWindow(xStart,yStart,xWindowSize,yWindowSize,title)\\\
- \\\
- --ТЕКСТ ОКНА\\\
- term.setBackgroundColor(colors.white)\\\
- colorText(math.floor(xStart+(xWindowSize/2-#text/2)),yStart+2,text,colors.gray)\\\
- \\\
- --РпСОВАНпЕ ПРОГРЕСС БАРА\\\
- local xProgressBarPos = xStart+2\\\
- local yProgressBarPos = yStart+4\\\
- drawProgressBar(xProgressBarPos,yProgressBarPos,sizeOfProgressBar,1,colors.lightBlue,colors.lightGray,0)\\\
- sleep(0)\\\
- for i=1,100,speed do\\\
- drawProgressBar(xProgressBarPos,yProgressBarPos,sizeOfProgressBar,1,colors.lightBlue,colors.lightGray,i)\\\
- sleep(0)\\\
- end\\\
- drawProgressBar(xProgressBarPos,yProgressBarPos,sizeOfProgressBar,1,colors.lightBlue,colors.lightGray,100)\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------------\\\
- \\\
- function search(xStart,yStart,xWindowSize,limitOfElements,searchText)\\\
- \\\
- os.loadAPI(\\\"System/API/image\\\")\\\
- \\\
- local searchList = {}\\\
- \\\
- local sizeOfOneElement = 5\\\
- local yWindowSize = 4 + sizeOfOneElement*limitOfElements\\\
- local sizeOfSearchBar = xWindowSize - #searchText - 3\\\
- local xStartOfSearchBar = xStart + 2 + #searchText\\\
- local yStartOfSearchBar = yStart + 1\\\
- local limitOfAllText = xWindowSize - 10\\\
- local xWindowEnd = xStart + xWindowSize - 1\\\
- local yWindowEnd = yStart + yWindowSize - 1\\\
- \\\
- local fromElement = 1\\\
- local searchInput = \\\"\\\"\\\
- \\\
- --СОЗДАНпЕ ОБЪЕКТОВ\\\
- local Objects = {}\\\
- local function newObj(class,name,x1,y1,width,height,fileType,fileSize,path,fileName,fileFormat)\\\
- Objects[class] = Objects[class] or {}\\\
- Objects[class][name] = {}\\\
- Objects[class][name][\\\"x1\\\"]=x1\\\
- Objects[class][name][\\\"y1\\\"]=y1\\\
- Objects[class][name][\\\"x2\\\"]=x1+width-1\\\
- Objects[class][name][\\\"y2\\\"]=y1+height-1\\\
- Objects[class][name][\\\"fileType\\\"]=fileType\\\
- Objects[class][name][\\\"fileSize\\\"]=fileSize\\\
- Objects[class][name][\\\"path\\\"]=path\\\
- Objects[class][name][\\\"fileName\\\"]=fileName\\\
- Objects[class][name][\\\"fileFormat\\\"]=fileFormat\\\
- end\\\
- \\\
- local function drawConcretnoIcon(xStart,yStart,path,name,fileType,fileSize,backColor,fileFormat)\\\
- drawOSIcon(xStart,yStart,path,name,fileFormat)\\\
- term.setBackgroundColor(backColor)\\\
- colorText(xStart+8,yStart,stringLimit(\\\"end\\\",name,limitOfAllText),colors.gray)\\\
- colorText(xStart+8,yStart+1,stringLimit(\\\"start\\\",path,limitOfAllText),colors.lightGray)\\\
- colorText(xStart+8,yStart+2,stringLimit(\\\"start\\\",\\\"Type: \\\"..fileType,limitOfAllText),colors.lightGray)\\\
- colorText(xStart+8,yStart+3,stringLimit(\\\"start\\\",\\\"Size: \\\"..math.ceil(fileSize/1024)..\\\"KB\\\",limitOfAllText),colors.lightGray)\\\
- \\\
- newObj(\\\"icon\\\",path..\\\"/\\\"..name,xStart,yStart,xWindowSize,4,fileType,fileSize,path,name,fileFormat)\\\
- end\\\
- \\\
- local function drawSearches(fromElement)\\\
- --ОБНУЛЕНпЕ ОБЪЕКТОВ\\\
- Objects = {}\\\
- newObj(\\\"icon\\\",\\\"cykaBlyad\\\",-5,-5,1,1,\\\"hehe\\\",5) \\\
- \\\
- --ОЧпСТКА ЭКРАНА ПОКАЗА\\\
- square(xStart,yStart+3,xWindowSize-1,yWindowSize-3,colors.white)\\\
- \\\
- if #searchList == 0 then\\\
- colorText(xStart+1,yStart+4,\\\"No mathes found.\\\",colors.lightGray)\\\
- else\\\
- local iconCounter = 1\\\
- for i=fromElement,#searchList do\\\
- local yIconPos = yStart+4 + iconCounter*sizeOfOneElement - sizeOfOneElement\\\
- \\\
- drawConcretnoIcon(xStart+1,yIconPos,searchList[i][\\\"path\\\"],searchList[i][\\\"name\\\"],searchList[i][\\\"fileType\\\"],searchList[i][\\\"fileSize\\\"],colors.white,searchList[i][\\\"fileFormat\\\"])\\\
- \\\
- iconCounter = iconCounter + 1\\\
- if iconCounter > limitOfElements then break end\\\
- end\\\
- end\\\
- \\\
- scrollBar(xWindowEnd,yStart+3,yWindowSize-3,#searchList,fromElement,colors.lightGray,colors.lightBlue)\\\
- end\\\
- \\\
- local function textOnSearchBar()\\\
- term.setBackgroundColor(colors.white)\\\
- usualText(xStartOfSearchBar,yStartOfSearchBar,string.rep(\\\" \\\",sizeOfSearchBar))\\\
- colorText(xStartOfSearchBar,yStartOfSearchBar,stringLimit(\\\"start\\\",searchInput,sizeOfSearchBar),colors.black)\\\
- end\\\
- \\\
- --ОКНО\\\
- sampleWindow(xStart,yStart,xWindowSize,yWindowSize)\\\
- --ГОЛУБАЯ ШТУЧКА\\\
- square(xStart,yStart,xWindowSize,3,colors.blue)\\\
- colorText(xStart+1,yStart+1,searchText,colors.white)\\\
- square(xStartOfSearchBar,yStartOfSearchBar,sizeOfSearchBar,1,colors.white)\\\
- \\\
- drawSearches(fromElement)\\\
- \\\
- while true do\\\
- textOnSearchBar(searchInput)\\\
- if #searchInput > sizeOfSearchBar then\\\
- term.setCursorPos(xStartOfSearchBar+sizeOfSearchBar-1,yStartOfSearchBar)\\\
- else\\\
- term.setCursorPos(xStartOfSearchBar+#searchInput,yStartOfSearchBar)\\\
- end\\\
- \\\
- term.setCursorBlink(true)\\\
- \\\
- local event,side,x,y = os.pullEvent()\\\
- if event == \\\"mouse_scroll\\\" then\\\
- term.setCursorBlink(false)\\\
- if side == 1 then\\\
- fromElement = fromElement + 1\\\
- if fromElement > #searchList then\\\
- fromElement = #searchList\\\
- else\\\
- drawSearches(fromElement)\\\
- end\\\
- else\\\
- fromElement = fromElement - 1\\\
- if fromElement < 1 then\\\
- fromElement = 1\\\
- else\\\
- drawSearches(fromElement)\\\
- end\\\
- end\\\
- elseif event == \\\"mouse_click\\\" then\\\
- for key,val in pairs(Objects[\\\"icon\\\"]) do\\\
- 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\\\
- square(Objects[\\\"icon\\\"][key][\\\"x1\\\"]-1,Objects[\\\"icon\\\"][key][\\\"y1\\\"],xWindowSize-1,4,colors.blue)\\\
- 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\\\"])\\\
- sleep(0.3)\\\
- term.setCursorBlink(false)\\\
- return string.sub(key,2,-1)\\\
- end\\\
- end\\\
- term.setCursorBlink(false)\\\
- return nil\\\
- \\\
- elseif event == \\\"char\\\" then\\\
- fromElement = 1\\\
- searchInput = searchInput..side\\\
- searchList = searchInAllFiles(\\\"/\\\",searchInput)\\\
- drawSearches(fromElement)\\\
- elseif event == \\\"key\\\" then\\\
- if side == 14 then\\\
- fromElement = 1\\\
- searchInput = string.sub(searchInput,1,-2)\\\
- searchList = searchInAllFiles(\\\"/\\\",searchInput)\\\
- drawSearches(fromElement)\\\
- end\\\
- end\\\
- end\\\
- end\\\
- \\\
- --print(\\\"You selected: \\\"..search(2,2,28,2,\\\"Search\\\"))\\\
- \\\
- \\\
- ---------------------------------------------------------------------------------------------------------------------\\\
- \\\
- function info(xStart,yStart,title,text)\\\
- local sizeOfText = #text\\\
- local xWindowSize = 4+sizeOfText\\\
- local yWindowSize = 4\\\
- local xStart,yStart = correctStartCoords(xStart,yStart,xWindowSize,yWindowSize)\\\
- \\\
- emptyWindow(xStart,yStart,xWindowSize,yWindowSize,title)\\\
- \\\
- term.setBackgroundColor(colors.white)\\\
- colorText(xStart+2,yStart+2,text,colors.gray)\\\
- end\\\
- \\\
- ---------------------------------------------------------------------------------------------------------------------\\\
- \\\
- --[[function fileManager(mode,workPath)\\\
- if workPath == nil then workPath = \\\"\\\" end\\\
- \\\
- local xSize,ySize = term.getSize()\\\
- \\\
- local managerX = xSize-3\\\
- local managerY = ySize-3\\\
- \\\
- local xStart = 2\\\
- local yStart = 2\\\
- \\\
- local main = window.create(term.native(),xStart,yStart,managerX+1,managerY+1)\\\
- term.redirect(main)\\\
- \\\
- local function getFoldersList(workPath)\\\
- \\\
- end\\\
- \\\
- local function drawManager()\\\
- local currentPath = fs.getName(workPath)\\\
- emptyWindow(1,1,managerX,managerY,currentPath)\\\
- colorTextWithBack(1,1,\\\"x\\\",colors.black,colors.red);colorTextWithBack(2,1,\\\"-\\\",colors.black,colors.orange);colorTextWithBack(3,1,\\\"+\\\",colors.black,colors.lime)\\\
- end\\\
- \\\
- local function clickedAtArea(x,y,sx,sy,ex,ey)\\\
- if (x >= sx) and (x <= ex) and (y >= sy) and (y <= ey) then return true end \\\
- return false\\\
- end\\\
- \\\
- drawManager()\\\
- \\\
- term.redirect(term.native())\\\
- end]]\",\
- path = \"/rootfs/system/api/windows\",\
- },\
- {\
- text = \"function parseargs(s)\\\
- local arg = {}\\\
- string.gsub(s, \\\"([%-%w]+)=([\\\\\\\"'])(.-)%2\\\", function (w, _, a)\\\
- arg[w] = a\\\
- end)\\\
- return arg\\\
- end\\\
- \\\
- function collect(s)\\\
- local stack = {}\\\
- local top = {}\\\
- table.insert(stack, top)\\\
- local ni,c,label,xarg, empty\\\
- local i, j = 1, 1\\\
- while true do\\\
- ni,j,c,label,xarg, empty = string.find(s, \\\"<(%/?)([%w:]+)(.-)(%/?)>\\\", i)\\\
- if not ni then break end\\\
- local text = string.sub(s, i, ni-1)\\\
- if not string.find(text, \\\"^%s*$\\\") then\\\
- table.insert(top, text)\\\
- end\\\
- if empty == \\\"/\\\" then -- empty element tag\\\
- table.insert(top, {label=label, xarg=parseargs(xarg), empty=1})\\\
- elseif c == \\\"\\\" then -- start tag\\\
- top = {label=label, xarg=parseargs(xarg)}\\\
- table.insert(stack, top) -- new level\\\
- else -- end tag\\\
- local toclose = table.remove(stack) -- remove top\\\
- top = stack[#stack]\\\
- if #stack < 1 then\\\
- error(\\\"nothing to close with \\\"..label)\\\
- end\\\
- if toclose.label ~= label then\\\
- error(\\\"trying to close \\\"..toclose.label..\\\" with \\\"..label)\\\
- end\\\
- table.insert(top, toclose)\\\
- end\\\
- i = j+1\\\
- end\\\
- local text = string.sub(s, i)\\\
- if not string.find(text, \\\"^%s*$\\\") then\\\
- table.insert(stack[#stack], text)\\\
- end\\\
- if #stack > 1 then\\\
- error(\\\"unclosed \\\"..stack[#stack].label)\\\
- end\\\
- return stack[1]\\\
- end\",\
- path = \"/rootfs/system/api/xml\",\
- },\
- {\
- text = \"function archive(chto,vochto)\\\
- local Massiv2 = {}\\\
- local function FileList(path)\\\
- local Massiv = fs.list(path)\\\
- if #Massiv==0 then\\\
- local Massiv2Id = #Massiv2 + 1\\\
- Massiv2[Massiv2Id] = {}\\\
- Massiv2[Massiv2Id][\\\"path\\\"] = path\\\
- Massiv2[Massiv2Id][\\\"text\\\"] = \\\"@empty@empty\\\"\\\
- else\\\
- for i=1,#Massiv do\\\
- if fs.isDir(path..\\\"/\\\"..Massiv[i]) and Massiv[i] ~= \\\"/rom\\\" and Massiv[i] ~= \\\"rom\\\" then\\\
- FileList(path..\\\"/\\\"..Massiv[i])\\\
- elseif not fs.isDir(path..\\\"/\\\"..Massiv[i]) and Massiv[i] ~= \\\"/rom\\\" and Massiv[i] ~= \\\"rom\\\" then\\\
- local Massiv2Id = #Massiv2 + 1\\\
- Massiv2[Massiv2Id] = {}\\\
- Massiv2[Massiv2Id][\\\"path\\\"] = path..\\\"/\\\"..Massiv[i]\\\
- local file = fs.open(path..\\\"/\\\"..Massiv[i],\\\"r\\\")\\\
- Massiv2[Massiv2Id][\\\"text\\\"] = file.readAll()\\\
- file.close()\\\
- end\\\
- end\\\
- end\\\
- end\\\
- FileList(chto)\\\
- file=fs.open(vochto..\\\".zip\\\",\\\"w\\\")\\\
- file.write(textutils.serialise(Massiv2))\\\
- file.close()\\\
- return Massiv2\\\
- end\\\
- \\\
- function unarchive(chto,kuda)\\\
- local file = fs.open(chto,\\\"r\\\")\\\
- Massiv = textutils.unserialise(file.readAll())\\\
- file.close()\\\
- for i=1,#Massiv do\\\
- if Massiv[i][\\\"text\\\"] == \\\"@empty@empty\\\" then\\\
- fs.makeDir(kuda..\\\"/\\\"..Massiv[i][\\\"path\\\"])\\\
- else\\\
- local file = fs.open(kuda..\\\"/\\\"..Massiv[i][\\\"path\\\"],\\\"w\\\")\\\
- file.write(Massiv[i][\\\"text\\\"])\\\
- file.close()\\\
- end\\\
- end\\\
- end\",\
- path = \"/rootfs/system/api/zip\",\
- },\
- {\
- text = \"local xSize, ySize = term.getSize()\\\
- \\\
- local fileImage = 0\\\
- local fileDocument = 0\\\
- local fileOther = 0\\\
- local computerLabel = os.getComputerLabel()\\\
- if computerLabel == nil then computerLabel = \\\"not set\\\" end\\\
- \\\
- --------------------MODEM FIND----------------------------\\\
- function findModem()\\\
- local PeriList = peripheral.getNames()\\\
- for i=1,#PeriList do\\\
- if peripheral.getType(PeriList[i]) == \\\"modem\\\" then\\\
- return PeriList[i]\\\
- end\\\
- end\\\
- end\\\
- \\\
- local computerModem = findModem()\\\
- if computerModem == nil then computerModem = \\\"not found\\\" end\\\
- \\\
- local function clearScreen(color)\\\
- term.setBackgroundColor(color)\\\
- term.clear()\\\
- end\\\
- \\\
- local function fadeIn(time)\\\
- clearScreen(colors.gray)\\\
- sleep(time)\\\
- clearScreen(colors.lightGray)\\\
- sleep(time)\\\
- clearScreen(colors.white)\\\
- sleep(time)\\\
- end\\\
- \\\
- local function fadeOut(time)\\\
- clearScreen(colors.lightGray)\\\
- sleep(time)\\\
- clearScreen(colors.gray)\\\
- sleep(time)\\\
- clearScreen(colors.black)\\\
- sleep(time)\\\
- term.setCursorPos(1,1)\\\
- term.setTextColor(colors.white)\\\
- end\\\
- \\\
- local function getSizeOfAll()\\\
- local sizeOfAll1 = 0\\\
- local function files(path)\\\
- local massiv = fs.list(path)\\\
- for i=1,#massiv do\\\
- if fs.isDir(massiv[i]) then\\\
- files(path..\\\"/\\\"..massiv[i])\\\
- else\\\
- sizeOfAll1 = sizeOfAll1 + fs.getSize(path..\\\"/\\\"..massiv[i])\\\
- end\\\
- end\\\
- end\\\
- files(\\\"\\\")\\\
- return sizeOfAll1\\\
- end\\\
- \\\
- local function getFileFormat(file)\\\
- local start,ending = string.find(file,\\\"%.%w*$\\\")\\\
- if start == nil then\\\
- return nil\\\
- else\\\
- return string.sub(file,start,ending)\\\
- end\\\
- end\\\
- \\\
- local function getSizeOfFormat()\\\
- local sizeOfAll1 = 0\\\
- local function files(path)\\\
- local massiv = fs.list(path)\\\
- for i=1,#massiv do\\\
- if fs.isDir(massiv[i]) then\\\
- files(path..\\\"/\\\"..massiv[i])\\\
- else\\\
- local f = getFileFormat(path..\\\"/\\\"..massiv[i])\\\
- local s = fs.getSize(path..\\\"/\\\"..massiv[i])\\\
- if f == \\\".png\\\" then\\\
- fileImage = fileImage + s\\\
- elseif f == \\\".cfg\\\" or f == \\\".log\\\" then\\\
- fileDocument = fileDocument + s\\\
- elseif f == nil then\\\
- fileOther = fileOther + s\\\
- end\\\
- end\\\
- end\\\
- end\\\
- files(\\\"\\\")\\\
- return sizeOfAll1\\\
- end\\\
- \\\
- local function writeText(text,x,y)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- local function infoText(key,keyColor,value,x,y)\\\
- term.setCursorPos(x,y)\\\
- term.setTextColor(keyColor)\\\
- term.write(key..\\\": \\\")\\\
- term.setTextColor(colors.lightGray)\\\
- term.write(value)\\\
- end\\\
- \\\
- getSizeOfFormat()\\\
- \\\
- local sizeOfAll = getSizeOfAll()\\\
- local freeSpace = fs.getFreeSpace(\\\"\\\")\\\
- local totalSpace = freeSpace + sizeOfAll\\\
- local lengthOfPolosa = xSize-6\\\
- local lengthOfAll = math.floor(lengthOfPolosa*(math.ceil(sizeOfAll/totalSpace*100))/100)\\\
- local lengthOfDocuments = math.floor(lengthOfPolosa*math.ceil(fileDocument/sizeOfAll*100)/100)\\\
- local lengthOfImages = math.floor(lengthOfPolosa*math.ceil(fileImage/sizeOfAll*100)/100)\\\
- \\\
- -------------------------------------------------------------\\\
- fadeIn(0.05)\\\
- \\\
- local xStart = math.floor(xSize/2-lengthOfPolosa/2)\\\
- local yStart = ySize-3\\\
- \\\
- \\\
- local function displayBar(time)\\\
- while true do\\\
- for y=yStart,(yStart+1) do\\\
- for x=(xStart+1),(xStart+lengthOfPolosa) do\\\
- paintutils.drawPixel(x,y,colors.gray)\\\
- end\\\
- end\\\
- for y=yStart,(yStart+1) do\\\
- for x=(xStart+1),(xStart+lengthOfAll) do\\\
- paintutils.drawPixel(x,y,colors.black)\\\
- end\\\
- end\\\
- \\\
- ------------------------------\\\
- sleep(2)\\\
- ------------------------------\\\
- \\\
- for y=yStart,(yStart+1) do\\\
- for x=(xStart+1),(xStart+lengthOfPolosa) do\\\
- paintutils.drawPixel(x,y,colors.lime)\\\
- end\\\
- end\\\
- for y=yStart,(yStart+1) do\\\
- for x=(xStart+1),(xStart+lengthOfDocuments) do\\\
- paintutils.drawPixel(x,y,colors.red)\\\
- end\\\
- end\\\
- for y=yStart,(yStart+1) do\\\
- for x=(xStart+1+lengthOfDocuments),(xStart+lengthOfDocuments+lengthOfImages) do\\\
- paintutils.drawPixel(x,y,colors.yellow)\\\
- end\\\
- end\\\
- ------------------------------\\\
- sleep(2)\\\
- ------------------------------\\\
- end\\\
- end\\\
- \\\
- \\\
- \\\
- for i=1,xSize do\\\
- paintutils.drawPixel(i,1,colors.gray)\\\
- end\\\
- term.setTextColor(colors.lightGray)\\\
- writeText(\\\"About\\\",math.floor(xSize/2-string.len(\\\"About\\\")/2),1)\\\
- \\\
- term.setBackgroundColor(colors.white)\\\
- infoText(\\\"Computer label\\\",colors.gray,computerLabel,2,3)\\\
- infoText(\\\"Computer ID\\\",colors.gray,tostring(os.getComputerID()),2,4)\\\
- infoText(\\\"Connected modem\\\",colors.gray,computerModem,2,5)\\\
- infoText(\\\"Aviable space\\\",colors.gray,math.ceil(totalSpace/1024)..\\\" KB\\\",2,6)\\\
- infoText(\\\"Used space\\\",colors.black,math.ceil(sizeOfAll/1024)..\\\" KB\\\",2,8)\\\
- infoText(\\\"Free space\\\",colors.gray,math.ceil(freeSpace/1024)..\\\" KB\\\",2,9)\\\
- infoText(\\\"Documents\\\",colors.red,math.ceil(fileDocument/1024)..\\\" KB\\\",2,10)\\\
- infoText(\\\"Images\\\",colors.yellow,math.ceil(fileImage/1024)..\\\" KB\\\",2,11)\\\
- infoText(\\\"Other\\\",colors.lime,math.ceil(fileOther/1024)..\\\" KB\\\",2,12)\\\
- \\\
- local function touch()\\\
- while true do\\\
- event = os.pullEvent()\\\
- if event == \\\"key\\\" or event == \\\"mouse_click\\\" then break end\\\
- end\\\
- end\\\
- \\\
- parallel.waitForAny(displayBar,touch)\\\
- \\\
- fadeOut(0.05)\",\
- path = \"/rootfs/system/os/apps/about\",\
- },\
- {\
- text = \"-- Project LinOS AccountSettings (made by nikov2002)\\\
- \\\
- \\\
- os.loadAPI(\\\"system/api/windows\\\")\\\
- os.loadAPI(\\\"system/api/image\\\")\\\
- standartErrorFunction = windows.error\\\
- \\\
- term.setBackgroundColor(colors.white)\\\
- term.clear()\\\
- \\\
- local function textWrite(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- local function square(x1,y1,width,height,color)\\\
- local string = string.rep(\\\" \\\",width)\\\
- term.setBackgroundColor(color)\\\
- for y=y1,(y1+height-1) do\\\
- textWrite(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- function FuckingXbutton()\\\
- paintutils.drawPixel(1,1,colors.red)\\\
- term.setCursorPos(1,1)\\\
- print (\\\"X\\\")\\\
- end\\\
- \\\
- \\\
- function YNW()\\\
- term.setTextColor(colors.gray)\\\
- square(1,2,51,1,colors.white)\\\
- textWrite(1,2,\\\" Please, enter your old password, then your new\\\")\\\
- textWrite(7,3,\\\"To exit, leave old password as a blank\\\")\\\
- textWrite(18,6,\\\"Old password\\\")\\\
- square(15,8,18,1,colors.lightGray)\\\
- square(15,10,18,1,colors.white)\\\
- textWrite(18,10,\\\"New password\\\")\\\
- square(15,12,18,1,colors.lightGray)\\\
- end\\\
- \\\
- function pwdc()\\\
- term.setCursorPos(15,8)\\\
- local old = read()\\\
- local file = fs.open(\\\"system/config/pwd.cfg\\\",\\\"r\\\")\\\
- local oldacc = file.readLine()\\\
- file.close()\\\
- if old ~= oldacc then\\\
- windows.error(\\\"Password is incorrect\\\")\\\
- shell.run(\\\"system/os/apps/desktop\\\")\\\
- else\\\
- term.setCursorPos(15,12)\\\
- local new = read()\\\
- local file1 = fs.open(\\\"system/config/pwd.cfg\\\",\\\"w\\\")\\\
- file1.write(new)\\\
- file1.close()\\\
- windows.attention({\\\"Password\\\"},{\\\"Successfully changed!\\\"})\\\
- shell.run(\\\"system/os/apps/desktop\\\")\\\
- end\\\
- end\\\
- \\\
- YNW()\\\
- pwdc()\",\
- path = \"/rootfs/system/os/apps/acc\",\
- },\
- {\
- text = \"-- Project LinOS Customisation (made by nikov2002)\\\
- \\\
- \\\
- os.loadAPI(\\\"System/api/image\\\")\\\
- os.loadAPI(\\\"System/api/xml\\\")\\\
- os.loadAPI(\\\"system/api/windows\\\")\\\
- os.loadAPI(\\\"system/api/filemanager\\\")\\\
- \\\
- \\\
- local function textWrite(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- local function square(x1,y1,width,height,color)\\\
- local string = string.rep(\\\" \\\",width)\\\
- term.setBackgroundColor(color)\\\
- for y=y1,(y1+height-1) do\\\
- textWrite(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- local function setWallpaper(path)\\\
- fs.delete(\\\"system/os/wallpaper.png\\\")\\\
- fs.copy(path,\\\"system/os/wallpaper.png\\\")\\\
- end\\\
- \\\
- function Tab()\\\
- textWrite(2,1,\\\" Customisation settings\\\")\\\
- term.setBackgroundColor(colors.white)\\\
- term.setTextColor(colors.gray)\\\
- textWrite(2,3,\\\"Background Color:\\\")\\\
- square(2,5,2,2,colors.lightBlue)\\\
- square(5,5,2,2,colors.red)\\\
- square(5,5,2,2,colors.red)\\\
- square(8,5,2,2,colors.green)\\\
- square(11,5,2,2,colors.orange)\\\
- square(14,5,2,2,colors.gray)\\\
- square(17,5,2,2,colors.lightGray)\\\
- square(26,3,12,1,colors.white)\\\
- textWrite(26,3,\\\" Wallpaper: \\\")\\\
- square(27,5,7,1,colors.lightBlue)\\\
- textWrite(28,5,\\\"Set it \\\")\\\
- square(2,13,1,40,colors.white)\\\
- textWrite(2,13,\\\"Set Computer label\\\")\\\
- square(2,15,20,1,colors.lightGray)\\\
- square(24,13,1,20,colors.white)\\\
- textWrite(24,13,\\\"Full Wipe (can't be undone)\\\")\\\
- square(26,15,5,1,colors.lightBlue)\\\
- textWrite(27,15,\\\"Wipe It \\\")\\\
- square(2,8,2,2,colors.brown)\\\
- square(5,8,2,2,colors.yellow)\\\
- square(8,8,2,2,colors.purple)\\\
- square(11,8,2,2,colors.pink)\\\
- square(14,8,2,2,colors.cyan)\\\
- term.setBackgroundColor(colors.white)\\\
- term.setTextColor(colors.lightGray)\\\
- textWrite(17,8,\\\"##\\\")\\\
- textWrite(17,9,\\\"##\\\")\\\
- end\\\
- \\\
- function FuckingXbutton()\\\
- paintutils.drawPixel(1,1,colors.red)\\\
- term.setCursorPos(1,1)\\\
- print (\\\"X\\\")\\\
- end\\\
- \\\
- function drawWindow()\\\
- square(1,1,51,19,colors.white)\\\
- square(1,1,51,1,colors.gray)\\\
- end\\\
- \\\
- function DRAWIT()\\\
- drawWindow()\\\
- Tab()\\\
- FuckingXbutton()\\\
- end\\\
- \\\
- DRAWIT()\\\
- \\\
- while true do\\\
- local event, button, X, Y = os.pullEventRaw()\\\
- if event == \\\"mouse_click\\\" then\\\
- if X==1 and Y==1 then\\\
- shell.run(\\\"system/os/apps/desktop\\\")\\\
- elseif X >= 2 and X <= 3 and Y >= 5 and Y <= 6 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"8\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=5 and X <= 6 and Y >= 5 and Y <= 6 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"16384\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=2 and X <= 3 and Y >= 8 and Y <= 9 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"4096\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=5 and X <= 6 and Y >= 8 and Y <= 9 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"16\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=8 and X <= 9 and Y >= 8 and Y <= 9 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"1024\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=11 and X <= 12 and Y >= 8 and Y <= 9 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"64\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=14 and X <= 15 and Y >= 8 and Y <= 9 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"512\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=17 and X <= 18 and Y >= 8 and Y <= 9 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"1\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=8 and X <= 9 and Y >= 5 and Y <= 6 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"8192\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=11 and X <= 12 and Y >= 5 and Y <= 6 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"2\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=14 and X <= 15 and Y >= 5 and Y <= 6 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"128\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >=17 and X <= 18 and Y >= 5 and Y <= 6 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"256\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- DRAWIT()\\\
- elseif X >= 2 and X <= 20 and Y == 15 then\\\
- square(2,15,20,1,colors.lightGray)\\\
- term.setCursorPos(2,15)\\\
- labelocc = read()\\\
- os.setComputerLabel(labelocc)\\\
- square(2,15,20,1,colors.lightGray)\\\
- elseif X >= 26 and X <= 34 and Y == 15 then\\\
- shell.run(\\\"pastebin get b1KkmQE5 /wiper\\\")\\\
- shell.run(\\\"wiper\\\")\\\
- elseif X >= 27 and X <= 34 and Y == 5 then\\\
- local pathToOpen = filemanager.open(\\\"\\\")\\\
- if pathToOpen == nil then\\\
- DRAWIT()\\\
- elseif windows.getFileFormat(pathToOpen) ~= \\\".png\\\" then\\\
- windows.attention({\\\"Can't open file\\\"},{\\\"This file format\\\",\\\"is not supported.\\\"})\\\
- DRAWIT()\\\
- else\\\
- fs.copy(pathToOpen,\\\"system/os/wallpaper.png\\\")\\\
- DRAWIT()\\\
- end\\\
- end\\\
- end\\\
- end\",\
- path = \"/rootfs/system/os/apps/cs\",\
- },\
- {\
- text = \"-- Project LinOS (made by nikov2002) APIS and \\\"Photoshop\\\" by EliteClubSessions (Igor_Pavlov)\\\
- \\\
- \\\
- os.loadAPI(\\\"system/api/windows\\\")\\\
- os.loadAPI(\\\"system/api/image\\\")\\\
- os.loadAPI(\\\"system/api/context\\\")\\\
- os.loadAPI(\\\"system/api/config\\\")\\\
- \\\
- \\\
- local standartErrorFunction = windows.error\\\
- \\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"r\\\")\\\
- \\\
- if not term.isColor() then error(\\\"This program will work only on advanced computer.\\\") end\\\
- colbg = tonumber(file.readLine())\\\
- colt = 32768\\\
- tbc = 1\\\
- term.setBackgroundColor(colbg)\\\
- term.setTextColor(colt)\\\
- topBar = 128\\\
- \\\
- local xSize, ySize = term.getSize()\\\
- \\\
- function appsbuddon()\\\
- image.draw(1,18,\\\"/system/os/Icons/apps.png\\\")\\\
- end\\\
- \\\
- function textWrite(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- function timetop()\\\
- term.setBackgroundColor(topBar)\\\
- term.setTextColor(tbc)\\\
- term.setCursorPos(46,1)\\\
- local time = textutils.formatTime(os.time(),true)\\\
- term.setBackgroundColor(topBar)\\\
- print(\\\" \\\",time,\\\" \\\")\\\
- end\\\
- \\\
- function searchFromFiles()\\\
- term.setCursorPos(1,1)\\\
- term.setBackgroundColor(topBar)\\\
- term.setTextColor(tbc)\\\
- term.setCursorPos(22,1)\\\
- print(\\\" Search \\\")\\\
- end\\\
- \\\
- function titleBar()\\\
- term.setCursorPos(1,1) \\\
- term.setBackgroundColor(topBar)\\\
- term.setTextColor(tbc)\\\
- term.setCursorPos(1,1)\\\
- print(\\\" LinOS Settings \\\")\\\
- timetop()\\\
- searchFromFiles()\\\
- end\\\
- \\\
- function drawDesktop()\\\
- term.clear()\\\
- term.setBackgroundColor(colbg)\\\
- term.setTextColor(colt)\\\
- if fs.exists(\\\"system/os/wallpaper.png\\\") then\\\
- image.draw(1,1,\\\"system/os/wallpaper.png\\\")\\\
- end\\\
- titleBar()\\\
- appsbuddon()\\\
- end\\\
- \\\
- function CM1()\\\
- local contextAction1 = context.menu(10,2,{\\\"Password Management\\\"},{\\\"Customise\\\"},{\\\"Updater (BUGGY)\\\"})\\\
- if contextAction1 == \\\"Password Management\\\" then\\\
- shell.run(\\\"/system/os/apps/acc\\\")\\\
- elseif contextAction1 == \\\"Customise\\\" then\\\
- shell.run(\\\"/system/os/apps/cs\\\")\\\
- elseif contextAction1 == \\\"Updater (BUGGY)\\\" then\\\
- shell.run(\\\"/system/update/updater\\\")\\\
- else\\\
- term.setBackgroundColor(colbg)\\\
- drawDesktop()\\\
- term.setBackgroundColor(colbg)\\\
- end\\\
- end\\\
- \\\
- function ContextMenu()\\\
- local contextAction = context.menu(1,2,{\\\"Reboot\\\"},{\\\"Shutdown\\\"},{\\\"AboutCC\\\"},\\\"-\\\",{\\\"By nikov2002\\\",true})\\\
- if contextAction == \\\"Reboot\\\" then\\\
- os.reboot()\\\
- elseif contextAction == \\\"Shutdown\\\" then\\\
- os.shutdown()\\\
- elseif contextAction == \\\"AboutCC\\\" then\\\
- shell.run(\\\"/system/os/apps/about\\\")\\\
- end\\\
- end\\\
- \\\
- function ContextMenu1()\\\
- local contextAction1 = context.menu(10,2,{\\\"Not ready yet\\\",true})\\\
- end\\\
- \\\
- drawDesktop()\\\
- \\\
- while true do\\\
- local event, button, X, Y = os.pullEventRaw()\\\
- if event == \\\"mouse_click\\\" then\\\
- if X >=1 and X <=7 and Y==1 and button ==1 then\\\
- term.setBackgroundColor(colbg)\\\
- ContextMenu()\\\
- elseif X >=1 and X <=3 and Y >=18 and Y <=19 and button ==1 then\\\
- term.setBackgroundColor(colbg)\\\
- shell.run (\\\"system/os/apps/drawer\\\")\\\
- elseif X >=22 and X <=30 and Y==1 and button==1 then\\\
- windows.search(14,2,25,2,\\\"Search\\\")\\\
- elseif X >=10 and X <=20 and Y==1 and button==1 then\\\
- term.setBackgroundColor(colbg)\\\
- CM1()\\\
- drawDesktop()\\\
- else\\\
- term.setBackgroundColor(colbg)\\\
- drawDesktop()\\\
- end\\\
- end\\\
- end\",\
- path = \"/rootfs/system/os/apps/desktop\",\
- },\
- {\
- text = \"-- Project LinOS Appdrawer (made by nikov2002)\\\
- \\\
- local Args = {...}\\\
- os.loadAPI(\\\"system/api/windows\\\")\\\
- os.loadAPI(\\\"system/api/image\\\")\\\
- if not term.isColor() then error(\\\"This program will work only on advanced computer.\\\") end\\\
- \\\
- --[[local standartErrorFunction = error\\\
- error = windows.error]]\\\
- \\\
- local xSize, ySize = term.getSize()\\\
- local centerX = math.floor(xSize/2)\\\
- local centerY = math.floor(ySize/2)\\\
- local appWidth = 10\\\
- local appHeight = 6\\\
- \\\
- local countOfAppsByX = math.floor((xSize-2)/(appWidth+2))\\\
- local countOfAppsByY = math.floor((ySize-5)/(appHeight+1))\\\
- local countOfAppsOnDesktop = countOfAppsByX*countOfAppsByY\\\
- \\\
- local countOfDesktops = nil\\\
- \\\
- local startDisplayAllAppsFromX = centerX - math.floor((countOfAppsByX*(appWidth+2)-2)/2) + 1\\\
- local startDisplayAllAppsFromY = centerY - math.floor((countOfAppsByY*(appHeight+1)-1)/2) + 1\\\
- \\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"r\\\")\\\
- local currentDesktop = 1\\\
- local currentBackground = tonumber(file.readLine())\\\
- \\\
- local Obj = {}\\\
- local ObjBottom = {}\\\
- local ObjApp = {}\\\
- \\\
- local clipboardName = nil\\\
- \\\
- local workPath = \\\"/apps\\\"\\\
- local workPathHistory = {}\\\
- \\\
- local function newObjApp(name,x1,y1,width,height,id,fileFormat)\\\
- ObjApp[name]={}\\\
- ObjApp[name][\\\"x1\\\"]=x1\\\
- ObjApp[name][\\\"y1\\\"]=y1\\\
- ObjApp[name][\\\"x2\\\"]=x1+width-1\\\
- ObjApp[name][\\\"y2\\\"]=y1+height-1\\\
- ObjApp[name][\\\"id\\\"]=id\\\
- ObjApp[name][\\\"fileFormat\\\"]=fileFormat\\\
- end\\\
- \\\
- local function newObj(name,x1,y1,width,height)\\\
- Obj[name]={}\\\
- Obj[name][\\\"x1\\\"]=x1\\\
- Obj[name][\\\"y1\\\"]=y1\\\
- Obj[name][\\\"x2\\\"]=x1+width-1\\\
- Obj[name][\\\"y2\\\"]=y1+height-1\\\
- end\\\
- \\\
- local function newObjBottom(name,x1,y1,width,height)\\\
- ObjBottom[name]={}\\\
- ObjBottom[name][\\\"x1\\\"]=x1\\\
- ObjBottom[name][\\\"y1\\\"]=y1\\\
- ObjBottom[name][\\\"x2\\\"]=x1+width-1\\\
- ObjBottom[name][\\\"y2\\\"]=y1+height-1\\\
- end\\\
- \\\
- local function stringLimit(text,size)\\\
- if string.len(text)<=size then return text end\\\
- return string.sub(text,1,size-3)..\\\"...\\\"\\\
- end\\\
- \\\
- local function stringLimitFromStart(text,size)\\\
- if string.len(text)<=size then return text end\\\
- return \\\"...\\\"..string.sub(text,string.len(text)-size+4,string.len(text))\\\
- end\\\
- \\\
- local function usualText(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- function appsbuddon()\\\
- image.draw(1,18,\\\"/system/os/Icons/apps.png\\\")\\\
- end\\\
- \\\
- local function square(x1,y1,width,height,color)\\\
- local string = string.rep(\\\" \\\",width)\\\
- term.setBackgroundColor(color)\\\
- for y=y1,(y1+height-1) do\\\
- usualText(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- local function clearScreen(color)\\\
- term.setBackgroundColor(color)\\\
- term.clear()\\\
- end\\\
- \\\
- local function prepareToExit()\\\
- clearScreen(colors.black)\\\
- term.setTextColor(colors.white)\\\
- term.setCursorPos(1,1)\\\
- end\\\
- \\\
- local function programFinished()\\\
- local xCusor,yCursor = term.getCursorPos()\\\
- term.setBackgroundColor(colors.black)\\\
- term.setTextColor(colors.white)\\\
- usualText(1,yCursor+1,\\\"Press any key to quit.\\\")\\\
- \\\
- while true do\\\
- local event = os.pullEvent()\\\
- if event == \\\"monitor_touch\\\" or event == \\\"mouse_click\\\" or event == \\\"key\\\" then break end\\\
- end\\\
- end\\\
- \\\
- \\\
- \\\
- local function drawKonkretnoApp(x,y,name,background,id)\\\
- \\\
- newObjApp(name,x,y,appWidth,appHeight,id,windows.getFileFormat(name))\\\
- \\\
- windows.drawOSIcon(x+2,y,workPath,name,ObjApp[name][\\\"fileFormat\\\"],showSystemFolders)\\\
- \\\
- term.setBackgroundColor(background)\\\
- if fs.isReadOnly(workPath..\\\"/\\\"..name) then\\\
- term.setTextColor(colors.red)\\\
- else\\\
- term.setTextColor(colors.black)\\\
- end\\\
- if windows.isFileHidden(name) then\\\
- term.setTextColor(colors.gray)\\\
- end\\\
- if hideFileFormat then\\\
- name = windows.hideFileFormat(name)\\\
- end\\\
- name = stringLimit(name,10)\\\
- usualText(math.floor(x+5-#name/2),y+5,name)\\\
- \\\
- end\\\
- \\\
- local function displayApps(workPath,currentDesktop,background)\\\
- \\\
- ObjApp = {}\\\
- ObjBottom = {}\\\
- \\\
- --clearScreen(background)\\\
- square(0,0,52,20,background)\\\
- \\\
- local files = fs.list(workPath)\\\
- \\\
- files = windows.reorganizeFilesAndFolders(workPath,files,showHiddenFiles,showSystemFolders)\\\
- \\\
- local countOfFiles = #files\\\
- countOfDesktops = math.ceil(countOfFiles/(countOfAppsByY*countOfAppsByX))\\\
- \\\
- local bottomButtonsStartX = nil\\\
- if #workPathHistory == 0 then\\\
- bottomButtonsStartX = centerX - math.floor((countOfDesktops*2+1)/2)\\\
- else\\\
- bottomButtonsStartX = centerX - math.floor((countOfDesktops*2-1)/2)\\\
- end\\\
- local bottomY = ySize-1\\\
- for i=1,countOfDesktops do\\\
- local bottomX = bottomButtonsStartX + i * 2\\\
- if currentDesktop == i then\\\
- paintutils.drawPixel(bottomX,bottomY,colors.white)\\\
- else\\\
- paintutils.drawPixel(bottomX,bottomY,colors.lightGray)\\\
- end\\\
- newObjBottom(i,bottomX,bottomY,1,1)\\\
- end\\\
- if #workPathHistory>0 then\\\
- paintutils.drawPixel(bottomButtonsStartX,bottomY,colors.white)\\\
- term.setTextColor(colors.black)\\\
- usualText(bottomButtonsStartX,bottomY,\\\"<\\\")\\\
- newObj(\\\"<\\\",bottomButtonsStartX,bottomY,1,1)\\\
- end\\\
- \\\
- \\\
- local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX\\\
- for y = 1,countOfAppsByY do\\\
- for x = 1,countOfAppsByX do\\\
- if files[appCounter] ~= nil then\\\
- drawKonkretnoApp(startDisplayAllAppsFromX+x*(appWidth+2)-(appWidth+2),startDisplayAllAppsFromY+y*(appHeight+1)-(appHeight+1),files[appCounter],background,appCounter)\\\
- appCounter = appCounter + 1\\\
- else\\\
- break\\\
- end\\\
- end\\\
- end\\\
- appsbuddon()\\\
- end\\\
- local function launchFile(path,fileFormat,arguments)\\\
- if fileFormat == nil then\\\
- local success,err = loadfile(path)\\\
- if success ~= nil then\\\
- prepareToExit()\\\
- if arguments == nil then\\\
- shell.run(path)\\\
- else\\\
- shell.run(path..\\\" \\\"..arguments)\\\
- end\\\
- programFinished()\\\
- else\\\
- windows.error(err)\\\
- end\\\
- elseif fileFormat == \\\".app\\\" then\\\
- path = path..\\\"/main\\\"\\\
- local success,err = loadfile(path)\\\
- if success ~= nil then\\\
- prepareToExit()\\\
- if arguments == nil then\\\
- shell.run(path)\\\
- else\\\
- shell.run(path..\\\" \\\"..arguments)\\\
- end\\\
- --programFinished()\\\
- else\\\
- windows.error(err)\\\
- end\\\
- end\\\
- end\\\
- \\\
- \\\
- local function gotoDirectory(path)\\\
- workPathHistory[#workPathHistory+1] = workPath\\\
- workPath = path\\\
- currentDesktop = 1\\\
- end\\\
- \\\
- displayApps(workPath,currentDesktop,currentBackground)\\\
- \\\
- local exitFromProgram = false\\\
- while true do\\\
- if exitFromProgram then break end\\\
- \\\
- local appCounter = 1 + currentDesktop * countOfAppsByY * countOfAppsByX - countOfAppsByY * countOfAppsByX\\\
- \\\
- local event,side,x,y = os.pullEvent()\\\
- \\\
- if event == \\\"monitor_touch\\\" then side = 1 end\\\
- if event == \\\"mouse_click\\\" or event == \\\"monitor_touch\\\" then\\\
- \\\
- if side == 1 then\\\
- \\\
- local exit1 = false\\\
- \\\
- if #workPathHistory > 0 then\\\
- if x==Obj[\\\"<\\\"][\\\"x1\\\"] and y==Obj[\\\"<\\\"][\\\"y1\\\"] and #workPathHistory > 0 then\\\
- \\\
- term.setBackgroundColor(colors.blue)\\\
- term.setTextColor(colors.white)\\\
- usualText(Obj[\\\"<\\\"][\\\"x1\\\"],Obj[\\\"<\\\"][\\\"y1\\\"],\\\"<\\\")\\\
- sleep(0.2)\\\
- \\\
- workPath = workPathHistory[#workPathHistory]\\\
- workPathHistory[#workPathHistory] = nil\\\
- currentDesktop = 1\\\
- displayApps(workPath,currentDesktop,currentBackground)\\\
- exit1 = true\\\
- end\\\
- end\\\
- \\\
- for i=1,#ObjBottom do\\\
- if exit1 then break end\\\
- if x==ObjBottom[i][\\\"x1\\\"] and y==ObjBottom[i][\\\"y1\\\"] then\\\
- currentDesktop = i\\\
- displayApps(workPath,currentDesktop,currentBackground)\\\
- exit1=true\\\
- end\\\
- end\\\
- \\\
- for key,val in pairs(ObjApp) do\\\
- if exit1 then break end\\\
- for i=appCounter,(appCounter+countOfAppsOnDesktop-1) do\\\
- if exit1 then break end\\\
- if ObjApp[key][\\\"id\\\"] == i then\\\
- if x>=ObjApp[key][\\\"x1\\\"] and x<=ObjApp[key][\\\"x2\\\"] and y>=ObjApp[key][\\\"y1\\\"] and y<=ObjApp[key][\\\"y2\\\"] then\\\
- square(ObjApp[key][\\\"x1\\\"],ObjApp[key][\\\"y1\\\"],appWidth,appHeight,colors.blue)\\\
- drawKonkretnoApp(ObjApp[key][\\\"x1\\\"],ObjApp[key][\\\"y1\\\"],key,colors.blue,ObjApp[key][\\\"id\\\"])\\\
- sleep(0.2)\\\
- \\\
- local fileFormat = ObjApp[key][\\\"fileFormat\\\"]\\\
- \\\
- if not fs.isDir(workPath..\\\"/\\\"..key) then\\\
- \\\
- if key ~= \\\"OS\\\" and key ~= \\\"os\\\" and fileFormat == nil then\\\
- launchFile(workPath..\\\"/\\\"..key,fileFormat)\\\
- else\\\
- windows.attention({\\\"Can't open this\\\"},{\\\"Unknown file extension\\\"})\\\
- end\\\
- \\\
- exit1 = true\\\
- displayApps(workPath,currentDesktop,currentBackground)\\\
- else\\\
- if fileFormat == \\\".app\\\" then\\\
- launchFile(workPath..\\\"/\\\"..key,fileFormat)\\\
- displayApps(workPath,currentDesktop,currentBackground)\\\
- else\\\
- gotoDirectory(workPath..\\\"/\\\"..key)\\\
- appCounter = 1\\\
- displayApps(workPath,currentDesktop,currentBackground) \\\
- end\\\
- \\\
- exit1 = true\\\
- end\\\
- end\\\
- end\\\
- end\\\
- end\\\
- term.setCursorBlink(false)\\\
- \\\
- elseif event == \\\"mouse_scroll\\\" then\\\
- if side == -1 then\\\
- currentDesktop = currentDesktop + 1\\\
- if currentDesktop > countOfDesktops then\\\
- currentDesktop = countOfDesktops\\\
- else\\\
- displayApps(workPath,currentDesktop,currentBackground)\\\
- end\\\
- end\\\
- end\\\
- end\\\
- if x>=1 and x<=3 and y>=18 and y<=19 then\\\
- shell.run (\\\"/system/os/apps/Desktop\\\")\\\
- else\\\
- end\\\
- end\\\
- prepareToExit()\\\
- --windows.tv(0)\",\
- path = \"/rootfs/system/os/apps/drawer\",\
- },\
- {\
- text = \"os.loadAPI(\\\"system/api/image\\\")\\\
- os.loadAPI(\\\"system/api/windows\\\")\\\
- --if fs.exists(\\\"system/config/pwd.cfg/\\\") then\\\
- --shell.run(\\\"system/apps/desktop\\\")\\\
- --else\\\
- --\\\
- --end\\\
- \\\
- local function textWrite(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- local function square(x1,y1,width,height,color)\\\
- local string = string.rep(\\\" \\\",width)\\\
- term.setBackgroundColor(color)\\\
- for y=y1,(y1+height-1) do\\\
- textWrite(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- local function clearScreen(color)\\\
- term.setBackgroundColor(color)\\\
- term.clear()\\\
- end\\\
- \\\
- local function fadeIn(time)\\\
- clearScreen(colors.gray)\\\
- sleep(time)\\\
- clearScreen(colors.lightGray)\\\
- sleep(time)\\\
- clearScreen(colors.white)\\\
- sleep(time)\\\
- end\\\
- \\\
- function pwd()\\\
- term.clear()\\\
- square(1,1,51,19,colors.white)\\\
- image.draw(13,3,\\\"/system/os/hello.png\\\")\\\
- sleep(1)\\\
- term.setCursorPos(12,10)\\\
- square(12,10,1,20,colors.white)\\\
- term.setTextColor(colors.black)\\\
- textWrite(5,10,\\\"Let we setup your password (type it there)\\\")\\\
- square(14,12,23,1,colors.lightGray)\\\
- term.setCursorPos(14,12)\\\
- local newpwd = read()\\\
- local file = fs.open(\\\"system/config/pwd.cfg\\\",\\\"w\\\")\\\
- file.write(newpwd)\\\
- file.close()\\\
- end\\\
- \\\
- \\\
- function final()\\\
- term.clear()\\\
- square(1,1,51,19,colors.white)\\\
- image.draw(13,3,\\\"/system/os/hello.png\\\")\\\
- sleep(1)\\\
- square(12,10,1,20,colors.white)\\\
- term.setTextColor(colors.black)\\\
- textWrite(12,10,\\\" Let we do few more things\\\")\\\
- sleep(2)\\\
- square(1,1,51,19,colors.white)\\\
- textWrite(20,10,\\\"Here we go\\\")\\\
- sleep(0.5)\\\
- fadeIn(0.05)\\\
- shell.run(\\\"/system/os/apps/desktop\\\")\\\
- end\\\
- \\\
- \\\
- function bg()\\\
- term.clear()\\\
- square(1,1,51,19,colors.white)\\\
- image.draw(13,3,\\\"/system/os/hello.png\\\")\\\
- sleep(1)\\\
- term.setBackgroundColor(colors.white)\\\
- term.setTextColor(colors.black)\\\
- textWrite(11,10,\\\"Let we setup your background\\\")\\\
- square(17,13,2,2,colors.lightBlue)\\\
- square(20,13,2,2,colors.red)\\\
- square(23,13,2,2,colors.green)\\\
- square(26,13,2,2,colors.orange)\\\
- square(29,13,2,2,colors.gray)\\\
- square(32,13,2,2,colors.lightGray)\\\
- square(17,16,2,2,colors.brown)\\\
- square(20,16,2,2,colors.yellow)\\\
- square(23,16,2,2,colors.purple)\\\
- square(26,16,2,2,colors.pink)\\\
- square(29,16,2,2,colors.cyan)\\\
- term.setBackgroundColor(colors.white)\\\
- term.setTextColor(colors.lightGray)\\\
- textWrite(32,16,\\\"##\\\")\\\
- textWrite(32,17,\\\"##\\\")\\\
- while true do\\\
- local event, button, X, Y = os.pullEventRaw()\\\
- if event == \\\"mouse_click\\\" then\\\
- if X==1 and Y==1 then\\\
- shell.run(\\\"System/apps/desktop\\\")\\\
- elseif X >= 17 and X <= 18 and Y >= 13 and Y <=14 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"8\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=20 and X <= 21 and Y >= 13 and Y <= 14 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"16384\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=23 and X <= 24 and Y >= 13 and Y <= 14 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"8192\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=26 and X <= 27 and Y >= 13 and Y <= 14 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"2\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=29 and X <= 30 and Y >= 13 and Y <= 14 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"128\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=32 and X <= 33 and Y >= 13 and Y <= 14 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"256\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=17 and X <= 18 and Y >= 16 and Y <= 17 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"4096\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=20 and X <= 21 and Y >= 16 and Y <= 17 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"16\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=23 and X <= 24 and Y >= 16 and Y <= 17 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"1024\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=26 and X <= 27 and Y >= 16 and Y <= 17 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"64\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=29 and X <= 30 and Y >= 16 and Y <= 17 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"512\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- elseif X >=32 and X <= 33 and Y >= 16 and Y <= 17 then\\\
- local file = fs.open(\\\"system/config/bg.cfg\\\",\\\"w\\\")\\\
- file.write(\\\"1\\\")\\\
- file.close()\\\
- windows.attention({\\\"Background\\\"},{\\\"Successfully changed!\\\"})\\\
- final()\\\
- end\\\
- end\\\
- end\\\
- end\\\
- function all()\\\
- pwd()\\\
- bg()\\\
- end\\\
- \\\
- all()\",\
- path = \"/rootfs/system/os/apps/firstsetup\",\
- },\
- {\
- text = \"-- Project LinOS Bootstrap (made by nikov2002)\\\
- \\\
- \\\
- os.loadAPI(\\\"System/api/windows\\\")\\\
- os.loadAPI(\\\"System/api/image\\\")\\\
- standartErrorFunction = windows.error\\\
- \\\
- \\\
- local function textWrite(x,y,text)\\\
- term.setCursorPos(x,y)\\\
- term.write(text)\\\
- end\\\
- \\\
- local function square(x1,y1,width,height,color)\\\
- local string = string.rep(\\\" \\\",width)\\\
- term.setBackgroundColor(color)\\\
- for y=y1,(y1+height-1) do\\\
- textWrite(x1,y,string)\\\
- end\\\
- end\\\
- \\\
- function access()\\\
- term.clear()\\\
- term.setBackgroundColor(colors.white)\\\
- square(1,1,51,19,colors.white)\\\
- term.setTextColor(colors.black)\\\
- term.setCursorPos(12,9)\\\
- print(\\\"Please, enter your password\\\")\\\
- square(12,11,27,1,colors.lightGray)\\\
- term.setCursorPos(12,11)\\\
- local pwd = read()\\\
- local file = fs.open(\\\"system/config/pwd.cfg\\\",\\\"r\\\")\\\
- local pwdacc = file.readLine()\\\
- file.close()\\\
- if pwd ~= pwdacc then\\\
- windows.error(\\\"Your password is incorrect\\\")\\\
- access()\\\
- else\\\
- shell.run (\\\"/system/os/apps/desktop\\\")\\\
- end\\\
- end\\\
- access()\",\
- path = \"/rootfs/system/os/apps/login\",\
- },\
- {\
- 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\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 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\",\
- path = \"/rootfs/system/os/bootscr/111.png\",\
- },\
- {\
- 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\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 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\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\\\
- 00 00 00 00 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\",\
- path = \"/rootfs/system/os/bootscr/boot.png\",\
- },\
- {\
- text = \" 07######### 07### 07 07 07 07### 07############ 07############ 07 07 07###\\\
- 07######### 07### 07############ 07############ 07######### 07######### 07\\\
- 07 07 07 07 07### 07 07 07 07### 07############ 07######### 07######### 07\\\
- 07######### 07### 07############ 07############ 07######### 07######### 07\\\
- 07######### 07### 07 07 07 07### 07 07 07 07### 07 07 07 07### 07 07 07###\",\
- path = \"/rootfs/system/os/hello.png\",\
- },\
- {\
- text = \".07.07.07\\\
- .07.07.07\",\
- path = \"/rootfs/system/os/Icons/apps.png\",\
- },\
- {\
- text = \"###-80-80-80-80###\\\
- ###-80-80-80-80###\\\
- ###-80-80-80-80###\\\
- ###.e0ce0fe0ge0###\",\
- path = \"/rootfs/system/os/Icons/config.png\",\
- },\
- {\
- text = \" 0f 0f 0f 0f 0f 0f\\\
- 0f>4f_0f 0f 0f 0f\\\
- 0f 0f 0f 0f 0f 0f\\\
- 0f 0f 0f 0f 0f 0f\",\
- path = \"/rootfs/system/os/Icons/default.png\",\
- },\
- {\
- text = \" 07 07 07 07 07 07\\\
- 07 5f 5f 5f 5f 07\\\
- 08 f8 08 f8.e8.58\\\
- 08d78i78s78k78 08\",\
- path = \"/rootfs/system/os/Icons/disk.png\",\
- },\
- {\
- text = \" 04 04############\\\
- -04-04-04-04-04-04\\\
- 04 04 04 04 04 04\\\
- ff4of4lf4df4ef4rf4\",\
- path = \"/rootfs/system/os/Icons/folder.png\",\
- },\
- {\
- text = \" 30 3b 3b 3b 3b 30\\\
- 30 0bP0bS0b 0b 30\\\
- 30 fb fb fb fb 30\\\
- 30.f0pf0nf0gf0 30\",\
- path = \"/rootfs/system/os/Icons/image.png\",\
- },\
- {\
- text = \" 80 80 80 80 80 80\\\
- 80 80O70S70 80 80\\\
- 80 80 80 80 80 80\\\
- 80v80380.80080 80\",\
- path = \"/rootfs/system/os/Icons/os.png\",\
- },\
- {\
- text = \",70-70-70-70,70###\\\
- |70 70 70 00|70###\\\
- z07i07p07 70|70###\\\
- |70_70_70_70|70###\",\
- path = \"/rootfs/system/os/Icons/zip.png\",\
- },\
- {\
- text = \"-- Project LinOS Updater (made by nikov2002)\\\
- \\\
- os.loadAPI(\\\"System/api/filemanager\\\")\\\
- os.loadAPI(\\\"system/api/zip\\\")\\\
- os.loadAPI(\\\"System/api/image\\\")\\\
- os.loadAPI(\\\"system/api/windows\\\")\\\
- function bs()\\\
- image.draw(1,1,\\\"/system/os/bootscr/boot.png\\\")\\\
- term.setCursorPos(13,6)\\\
- term.setTextColor(colors.red)\\\
- term.setCursorPos(14,6)\\\
- print(\\\"Downloading update.zip...\\\")\\\
- \\\
- shell.run(\\\"pastebin get isBCrzsx /temp/update.zip\\\")\\\
- sleep(1)\\\
- end\\\
- \\\
- function fileopen()\\\
- local yyy = windows.select({\\\"Updater\\\"},{\\\"Proceed?\\\"},{\\\"No\\\",colors.lightGray,colors.black},{\\\"Yes\\\",colors.lightBlue,colors.black})\\\
- if yyy == \\\"Yes\\\" then\\\
- image.draw(1,1,\\\"/system/os/bootscr/boot.png\\\")\\\
- term.setTextColor(colors.red)\\\
- term.setCursorPos(20,6)\\\
- print(\\\" Updating\\\")\\\
- sleep(1)\\\
- zip.unarchive(\\\"/temp/update.zip\\\",\\\"/temp\\\")\\\
- fs.delete(\\\"/system/os\\\")\\\
- fs.delete(\\\"/startup\\\")\\\
- fs.move(\\\"/temp/rootfs/system/os\\\",\\\"/system/os\\\")\\\
- fs.move(\\\"/temp/rootfs/startup\\\",\\\"/startup\\\")\\\
- os.reboot()\\\
- else\\\
- shell.run(\\\"/system/os/apps/desktop\\\")\\\
- end\\\
- end\\\
- \\\
- function drawall()\\\
- bs()\\\
- fileopen()\\\
- end\\\
- \\\
- drawall()\",\
- path = \"/rootfs/system/update/updater\",\
- },\
- }",
- image = "function draw(startX,startY,image)\
- local Colors = {\
- [\"0\"] = 1,\
- [\"1\"] = 2,\
- [\"2\"] = 4,\
- [\"3\"] = 8,\
- [\"4\"] = 16,\
- [\"5\"] = 32,\
- [\"6\"] = 64,\
- [\"7\"] = 128,\
- [\"8\"] = 256,\
- [\"9\"] = 512,\
- [\"a\"] = 1024,\
- [\"b\"] = 2048,\
- [\"c\"] = 4096,\
- [\"d\"] = 8192,\
- [\"e\"] = 16384,\
- [\"f\"] = 32768\
- }\
- local Pixels = {}\
- \
- local function convert(mode,color)\
- if mode == \"from cc\" then\
- for key,value in pairs(Colors) do\
- if color == value then\
- return key\
- end\
- end\
- else\
- if color == \"#\" then\
- return \"0\"\
- else\
- return Colors[color]\
- end\
- end\
- end\
- \
- local function load(path)\
- local file = fs.open(path,\"r\")\
- local lineCounter = 1\
- while true do\
- local line = file.readLine()\
- Pixels[lineCounter]={}\
- if line ~= nil then\
- for i=1,#line,3 do\
- Pixels[lineCounter][(i+2)/3]={}\
- Pixels[lineCounter][(i+2)/3][\"symbol\"] = string.sub(line,i,i)\
- Pixels[lineCounter][(i+2)/3][\"textColor\"] = convert(\"to cc\",string.sub(line,i+1,i+1))\
- Pixels[lineCounter][(i+2)/3][\"backColor\"] = convert(\"to cc\",string.sub(line,i+2,i+2))\
- end\
- lineCounter = lineCounter + 1\
- else\
- break\
- end\
- end\
- file.close()\
- end\
- \
- load(image)\
- \
- for y=1,#Pixels do\
- for x=1,#Pixels[y] do\
- if Pixels[y][x][\"symbol\"] ~= \"#\" then\
- term.setTextColor(Pixels[y][x][\"textColor\"])\
- term.setBackgroundColor(Pixels[y][x][\"backColor\"])\
- term.setCursorPos(startX+x-1,startY+y-1)\
- term.write(Pixels[y][x][\"symbol\"])\
- end\
- end\
- end\
- \
- end",
- zip = "function archive(chto,vochto)\
- local Massiv2 = {}\
- local function FileList(path)\
- local Massiv = fs.list(path)\
- if #Massiv==0 then\
- local Massiv2Id = #Massiv2 + 1\
- Massiv2[Massiv2Id] = {}\
- Massiv2[Massiv2Id][\"path\"] = path\
- Massiv2[Massiv2Id][\"text\"] = \"@empty@empty\"\
- else\
- for i=1,#Massiv do\
- if fs.isDir(path..\"/\"..Massiv[i]) and Massiv[i] ~= \"/rom\" and Massiv[i] ~= \"rom\" then\
- FileList(path..\"/\"..Massiv[i])\
- elseif not fs.isDir(path..\"/\"..Massiv[i]) and Massiv[i] ~= \"/rom\" and Massiv[i] ~= \"rom\" then\
- local Massiv2Id = #Massiv2 + 1\
- Massiv2[Massiv2Id] = {}\
- Massiv2[Massiv2Id][\"path\"] = path..\"/\"..Massiv[i]\
- local file = fs.open(path..\"/\"..Massiv[i],\"r\")\
- Massiv2[Massiv2Id][\"text\"] = file.readAll()\
- file.close()\
- end\
- end\
- end\
- end\
- FileList(chto)\
- file=fs.open(vochto..\".zip\",\"w\")\
- file.write(textutils.serialise(Massiv2))\
- file.close()\
- return Massiv2\
- end\
- \
- function unarchive(chto,kuda)\
- local file = fs.open(chto,\"r\")\
- Massiv = textutils.unserialise(file.readAll())\
- file.close()\
- for i=1,#Massiv do\
- if Massiv[i][\"text\"] == \"@empty@empty\" then\
- fs.makeDir(kuda..\"/\"..Massiv[i][\"path\"])\
- else\
- local file = fs.open(kuda..\"/\"..Massiv[i][\"path\"],\"w\")\
- file.write(Massiv[i][\"text\"])\
- file.close()\
- end\
- end\
- end",
- [ "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\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
- 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\
- 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\
- 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\
- 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\
- 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\
- 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\
- 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\
- 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\
- 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\
- 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\
- 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\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
- 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00\
- 00 00 00 00 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",
- },
- startup = "os.loadAPI(\"instfiles/zip\")\
- os.loadAPI(\"instfiles/image\")\
- image.draw(1,1,\"instfiles/111.png\")\
- zip.unarchive(\"instfiles/rootfs.zip\",\"/temp\")\
- paintutils.drawPixel(14, 13, colors.lightBlue)\
- paintutils.drawPixel(14, 14, colors.lightBlue)\
- paintutils.drawPixel(15, 13, colors.lightBlue)\
- paintutils.drawPixel(15, 14, colors.lightBlue)\
- paintutils.drawPixel(16, 13, colors.lightBlue)\
- paintutils.drawPixel(16, 14, colors.lightBlue)\
- paintutils.drawPixel(17, 13, colors.lightBlue)\
- paintutils.drawPixel(17, 14, colors.lightBlue)\
- sleep(0.2)\
- paintutils.drawPixel(18, 13, colors.lightBlue)\
- paintutils.drawPixel(18, 14, colors.lightBlue)\
- paintutils.drawPixel(19, 13, colors.lightBlue)\
- paintutils.drawPixel(19, 14, colors.lightBlue)\
- paintutils.drawPixel(20, 13, colors.lightBlue)\
- paintutils.drawPixel(20, 14, colors.lightBlue)\
- paintutils.drawPixel(21, 13, colors.lightBlue)\
- paintutils.drawPixel(21, 14, colors.lightBlue)\
- paintutils.drawPixel(22, 13, colors.lightBlue)\
- paintutils.drawPixel(22, 14, colors.lightBlue)\
- paintutils.drawPixel(23, 13, colors.lightBlue)\
- paintutils.drawPixel(23, 14, colors.lightBlue)\
- paintutils.drawPixel(24, 13, colors.lightBlue)\
- paintutils.drawPixel(24, 14, colors.lightBlue)\
- sleep(1.5)\
- paintutils.drawPixel(25, 13, colors.lightBlue)\
- paintutils.drawPixel(25, 14, colors.lightBlue)\
- paintutils.drawPixel(26, 13, colors.lightBlue)\
- paintutils.drawPixel(26, 14, colors.lightBlue)\
- paintutils.drawPixel(27, 13, colors.lightBlue)\
- paintutils.drawPixel(27, 14, colors.lightBlue)\
- paintutils.drawPixel(28, 13, colors.lightBlue)\
- paintutils.drawPixel(28, 14, colors.lightBlue)\
- paintutils.drawPixel(29, 13, colors.lightBlue)\
- paintutils.drawPixel(29, 14, colors.lightBlue)\
- fs.copy(\"/temp/rootfs/system\",\"/system\")\
- fs.copy(\"/temp/rootfs/apps\",\"/apps\")\
- fs.copy(\"/temp/rootfs/startup\",\"/startup\")\
- paintutils.drawPixel(30, 13, colors.lightBlue)\
- paintutils.drawPixel(30, 14, colors.lightBlue)\
- paintutils.drawPixel(31, 13, colors.lightBlue)\
- paintutils.drawPixel(31, 14, colors.lightBlue)\
- paintutils.drawPixel(32, 13, colors.lightBlue)\
- paintutils.drawPixel(32, 14, colors.lightBlue)\
- paintutils.drawPixel(33, 13, colors.lightBlue)\
- paintutils.drawPixel(33, 14, colors.lightBlue)\
- term.setBackgroundColor(colors.white)\
- term.setTextColor(colors.lightGray)\
- term.clear()\
- term.setCursorPos(14,13)\
- print(\"Rebooting your system\")\
- os.reboot()",
- }
- local function run(tArgs)
- local fnFile, err = loadstring(files['startup'], 'startup')
- if err then
- error(err)
- end
- local function split(str, pat)
- local t = {}
- local fpat = "(.-)" .. pat
- local last_end = 1
- local s, e, cap = str:find(fpat, 1)
- while s do
- if s ~= 1 or cap ~= "" then
- table.insert(t,cap)
- end
- last_end = e+1
- s, e, cap = str:find(fpat, last_end)
- end
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t
- end
- local function resolveTreeForPath(path, single)
- local _files = files
- local parts = split(path, '/')
- if parts then
- for i, v in ipairs(parts) do
- if #v > 0 then
- if _files[v] then
- _files = _files[v]
- else
- _files = nil
- break
- end
- end
- end
- elseif #path > 0 and path ~= '/' then
- _files = _files[path]
- end
- if not single or type(_files) == 'string' then
- return _files
- end
- end
- local oldFs = fs
- local env
- env = {
- fs = {
- list = function(path)
- local list = {}
- if fs.exists(path) then
- list = fs.list(path)
- end
- for k, v in pairs(resolveTreeForPath(path)) do
- if not fs.exists(path .. '/' ..k) then
- table.insert(list, k)
- end
- end
- return list
- end,
- exists = function(path)
- if fs.exists(path) then
- return true
- elseif resolveTreeForPath(path) then
- return true
- else
- return false
- end
- end,
- isDir = function(path)
- if fs.isDir(path) then
- return true
- else
- local tree = resolveTreeForPath(path)
- if tree and type(tree) == 'table' then
- return true
- else
- return false
- end
- end
- end,
- isReadOnly = function(path)
- if not fs.isReadOnly(path) then
- return false
- else
- return true
- end
- end,
- getName = fs.getName,
- getSize = fs.getSize,
- getFreespace = fs.getFreespace,
- makeDir = fs.makeDir,
- move = fs.move,
- copy = fs.copy,
- delete = fs.delete,
- combine = fs.combine,
- open = function(path, mode)
- if fs.exists(path) then
- return fs.open(path, mode)
- elseif type(resolveTreeForPath(path)) == 'string' then
- local handle = {close = function()end}
- if mode == 'r' then
- local content = resolveTreeForPath(path)
- handle.readAll = function()
- return content
- end
- local line = 1
- local lines = split(content, '\n')
- handle.readLine = function()
- if line > #lines then
- return nil
- else
- return lines[line]
- end
- line = line + 1
- end
- return handle
- else
- error('Cannot write to read-only file (compilr archived).')
- end
- else
- return fs.open(path, mode)
- end
- end
- },
- io = {
- input = io.input,
- output = io.output,
- type = io.type,
- close = io.close,
- write = io.write,
- flush = io.flush,
- lines = io.lines,
- read = io.read,
- open = function(path, mode)
- if fs.exists(path) then
- return io.open(path, mode)
- elseif type(resolveTreeForPath(path)) == 'string' then
- local content = resolveTreeForPath(path)
- local f = fs.open(path, 'w')
- f.write(content)
- f.close()
- if mode == 'r' then
- return io.open(path, mode)
- else
- error('Cannot write to read-only file (compilr archived).')
- end
- else
- return io.open(path, mode)
- end
- end
- },
- loadfile = function( _sFile )
- local file = env.fs.open( _sFile, "r" )
- if file then
- local func, err = loadstring( file.readAll(), fs.getName( _sFile ) )
- file.close()
- return func, err
- end
- return nil, "File not found: ".._sFile
- end,
- dofile = function( _sFile )
- local fnFile, e = env.loadfile( _sFile )
- if fnFile then
- setfenv( fnFile, getfenv(2) )
- return fnFile()
- else
- error( e, 2 )
- end
- end
- }
- setmetatable( env, { __index = _G } )
- local tAPIsLoading = {}
- env.os.loadAPI = function( _sPath )
- local sName = fs.getName( _sPath )
- if tAPIsLoading[sName] == true then
- printError( "API "..sName.." is already being loaded" )
- return false
- end
- tAPIsLoading[sName] = true
- local tEnv = {}
- setmetatable( tEnv, { __index = env } )
- local fnAPI, err = env.loadfile( _sPath )
- if fnAPI then
- setfenv( fnAPI, tEnv )
- fnAPI()
- else
- printError( err )
- tAPIsLoading[sName] = nil
- return false
- end
- local tAPI = {}
- for k,v in pairs( tEnv ) do
- tAPI[k] = v
- end
- env[sName] = tAPI
- tAPIsLoading[sName] = nil
- return true
- end
- env.shell = shell
- setfenv( fnFile, env )
- fnFile(unpack(tArgs))
- end
- local function extract()
- local function node(path, tree)
- if type(tree) == 'table' then
- fs.makeDir(path)
- for k, v in pairs(tree) do
- node(path .. '/' .. k, v)
- end
- else
- local f = fs.open(path, 'w')
- if f then
- f.write(tree)
- f.close()
- end
- end
- end
- node('', files)
- end
- extract()
- fs.move("startup","installer")
- shell.run("installer")
Add Comment
Please, Sign In to add comment