From 857a4c7872d97699c61dd52fb1e7f561d9335599 Mon Sep 17 00:00:00 2001 From: Igor Timofeev Date: Sat, 26 Mar 2016 12:29:33 +0300 Subject: [PATCH] =?UTF-8?q?=D0=A3=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD?= =?UTF-8?q?=D0=B8=D0=B5=20=D1=84=D0=BE=D1=82=D0=BE=D1=88=D0=BE=D0=BF=D0=B0?= =?UTF-8?q?,=20=D1=83=D0=BB=D1=83=D1=87=D1=88=D0=B5=D0=BD=D0=B8=D0=B5=20?= =?UTF-8?q?=D0=BB=D0=B8=D0=B1=D1=8B=20=D0=BF=D0=BE=D0=B4=D1=81=D0=B2=D0=B5?= =?UTF-8?q?=D1=82=D0=BA=D0=B8=20=D1=81=D0=B8=D0=BD=D1=82=D0=B0=D0=BA=D1=81?= =?UTF-8?q?=D0=B8=D1=81=D0=B0,=20=D1=82=D0=B5=D1=81=D1=82=D0=BE=D0=B2?= =?UTF-8?q?=D0=B0=D1=8F=20=D0=B2=D0=B5=D1=80=D1=81=D0=B8=D1=8F=20=D0=9C?= =?UTF-8?q?=D0=B0=D0=B9=D0=BD=D0=9A=D0=BE=D0=B4=D0=B0=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=BC=D0=B5=D0=BD=D1=83=20=D0=A5=D0=B0=D0=B9=D0=BB?= =?UTF-8?q?=D0=B0=D0=B9=D1=82=D1=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Applications.txt | 19 +- Applications/Highlight/Highlight.lua | 5 +- Applications/MineCode/English.lang | 8 - Applications/MineCode/Icon.pic | Bin 270 -> 305 bytes Applications/MineCode/Icon.png | 4 - Applications/MineCode/MineCode.lua | 1182 ++++++-------------------- Applications/MineCode/Russian.lang | 8 - Applications/Photoshop/Photoshop.lua | 12 +- lib/doubleBuffering.lua | 15 +- lib/filemanager.lua | 96 +++ lib/syntax.lua | 34 +- 11 files changed, 384 insertions(+), 999 deletions(-) delete mode 100644 Applications/MineCode/English.lang delete mode 100644 Applications/MineCode/Icon.png delete mode 100644 Applications/MineCode/Russian.lang create mode 100644 lib/filemanager.lua diff --git a/Applications.txt b/Applications.txt index 372fd171..65e94c58 100644 --- a/Applications.txt +++ b/Applications.txt @@ -251,6 +251,12 @@ ----------------------------------------------------- Библиотеки -------------------------------------------------------------------------- + { + ["name"]="lib/filemanager.lua", + ["url"]="IgorTimofeev/OpenComputers/master/lib/filemanager.lua", + ["type"]="Library", + ["version"]=1.0, + }, { ["name"]="lib/modemConnection.lua", ["url"]="IgorTimofeev/OpenComputers/master/lib/modemConnection.lua", @@ -752,18 +758,11 @@ }, }, { - ["name"]="MineOS/Applications/Highlight", - ["url"]="IgorTimofeev/OpenComputers/master/Applications/Highlight/Highlight.lua", - ["type"]="Application", - ["icon"]="IgorTimofeev/OpenComputers/master/Applications/Highlight/Icon.pic", + ["name"]="MineOS/Applications/MineCode", + ["url"]="IgorTimofeev/OpenComputers/master/Applications/MineCode/MineCode.lua", + ["icon"]="IgorTimofeev/OpenComputers/master/Applications/MineCode/Icon.pic", ["createShortcut"] = "desktop", ["version"]=1.0, - ["resources"]={ - { - ["name"]="TestFile.txt", - ["url"]="IgorTimofeev/OpenComputers/master/Applications/Highlight/TestFile.txt", - }, - }, }, { ["name"]="MineOS/Applications/HoloEdit", diff --git a/Applications/Highlight/Highlight.lua b/Applications/Highlight/Highlight.lua index bf8d139f..6130aa84 100644 --- a/Applications/Highlight/Highlight.lua +++ b/Applications/Highlight/Highlight.lua @@ -3,10 +3,11 @@ ecs.prepareToExit() local data = ecs.universalWindow("auto", "auto", 40, 0xeeeeee, true, {"EmptyLine"}, {"CenterText", 0x262626, "Enter path to file"}, {"EmptyLine"}, {"Input", 0x262626, 0x880000, "MineOS/Applications/Highlight.app/Resources/TestFile.txt"}, {"EmptyLine"}, {"Button", {0x33db80, 0xffffff, "GO!"}}) local path = data[1] -local strings = syntax.convertFileToStrings(path) +local strings, maxStringWidth = syntax.convertFileToStrings(path) local xSize, ySize = gpu.getResolution() buffer.square(1, 1, xSize, ySize, ecs.colors.green, 0xFFFFFF, " ") buffer.draw(true) -syntax.viewCode(2, 2, 70, 20, strings, 1, 1, true, {from = {x = 6, y = 2}, to = {x = 3, y = 8}}) +syntax.viewCode(2, 2, 70, 20, strings, maxStringWidth, 1, 1, true, {from = {x = 6, y = 2}, to = {x = 10, y = 4}}) +buffer.draw() ecs.waitForTouchOrClick() diff --git a/Applications/MineCode/English.lang b/Applications/MineCode/English.lang deleted file mode 100644 index 4c748a01..00000000 --- a/Applications/MineCode/English.lang +++ /dev/null @@ -1,8 +0,0 @@ -topMenuFile = File -topMenuEdit = Edit -topMenuFind = Find -topMenuView = View -topMenuGoto = Goto -infoPanelNewProject = New project -infoPanelString = String -infoPanelStringOf = of diff --git a/Applications/MineCode/Icon.pic b/Applications/MineCode/Icon.pic index d0964e2b4e0d1676d612484a16888f965171be3f..084ac3a6b00b391d168b22a2287bdda00e517cf5 100644 GIT binary patch literal 305 zcmYL^F$w}P5JmGRvnI7CuwB7IJ%K9(1i@mkNNFJ`h=?e*p2915BzsR`BRKA|JLTg| z{?A{{7l|X!(077s!n1NHGpG>U5gpO#a$o>b zDD;K-P=SjLP{xIQFveyWV*}I>BcK4tF*#5=A4(@f=|nVn1t>ogs^1vOhl#`J0;qTq LOg)s&gVH4c{D*pq diff --git a/Applications/MineCode/Icon.png b/Applications/MineCode/Icon.png deleted file mode 100644 index 5166514d..00000000 --- a/Applications/MineCode/Icon.png +++ /dev/null @@ -1,4 +0,0 @@ -c3c3c3 ffffff c3c3c3 ffffff ffffff c3c3c3 ffffff 0f0f0f ffffff 0f0f0f ffffff 0f0f0f c3c3c3 ffffff c3c3c3 ffffff -5a5a5a c3c3c3 1 2d2d2d 339240 - 2d2d2d 339240 - 2d2d2d 339240 П 2d2d2d 339240 р 2d2d2d 339240 о 2d2d2d 339240 г 2d2d2d 339240 а -5a5a5a c3c3c3 2 2d2d2d ffffff l 2d2d2d ffffff o 2d2d2d ffffff c 2d2d2d ffffff a 2d2d2d ffffff l 2d2d2d ffffff 2d2d2d ffffff i -5a5a5a c3c3c3 3 2d2d2d ffffff 2d2d2d ffffff 2d2d2d ffffff p 2d2d2d ffffff r 2d2d2d ffffff i 2d2d2d ffffff n 2d2d2d ffffff t diff --git a/Applications/MineCode/MineCode.lua b/Applications/MineCode/MineCode.lua index 564974f8..6343cfc0 100644 --- a/Applications/MineCode/MineCode.lua +++ b/Applications/MineCode/MineCode.lua @@ -1,1008 +1,300 @@ ---local component = require("component") -local event = require("event") -local term = require("term") -local unicode = require("unicode") ---local ecs = require("ECSAPI") ---local fs = require("filesystem") -local context = require("context") ---local colorlib = require("colorlib") ---local palette = require("palette") -local computer = require("computer") -local seri = require("serialization") -local keyboard = require("keyboard") -local shell = require("shell") -local config = require("config") -local lang = config.readAll("MineCode.app/Resources/".._OSLANGUAGE..".lang") -local gpu = component.gpu +_G.syntax = nil +_G.filemanager = nil +_G.doubleBuffering = nil +package.loaded.doubleBuffering = nil +package.loaded.syntax = nil +package.loaded.filemanager = nil --------------------------------------ПЕРЕМЕННЫЕ------------------------------------------------------ +-- Адаптивная загрузка необходимых библиотек и компонентов +local libraries = { + ecs = "ECSAPI", + fs = "fs", + syntax = "syntax", + buffer = "buffer", + unicode = "unicode", + context = "context", + event = "event", + component = "component", + filemanager = "filemanager", +} +local components = { + gpu = "gpu", +} -local args = {...} +for library in pairs(libraries) do if not _G[library] then _G[library] = require(libraries[library]) end end +for comp in pairs(components) do if not _G[comp] then _G[comp] = _G.component[components[comp]] end end +libraries, components = nil, nil -local xSize, ySize = gpu.getResolution() +--------------------------------------------------- Константы ------------------------------------------------------------------ -local projectPath = "/test.lua" -local leftToolbarPath = projectPath +local pathToFile = "OS.lua" +local fileSize = 0 +local indentationWidth = 4 -local strings = {} +local strings +local maximumStringWidth +local fromString = 1 +local fromSymbol = 1 +local scrollSpeed = 8 +local showLuaSyntax = true +local showFilemanager = true ---local topButtons = {"Файл", "Правка", "Поиск", "Вид", "Переход"} -local topButtons = {lang.topMenuFile, lang.topMenuEdit, lang.topMenuFind, lang.topMenuView, lang.topMenuGoto} +local xCursor, yCursor = 1, 1 +local textFieldPosition -local toolbarsToShow = {top = true, left = true, bottom = true} +local selection = { + from = { x = 18, y = 6 }, + to = { x = 4, y = 8 } +} -local stringToDisplayFrom = 1 -local symbolToDisplayFrom = 1 --- -local yStartOfTopBar = 2 -local heightOfTopBar = 3 --- -local yStartOfText = yStartOfTopBar + heightOfTopBar -local xStartOfText = 0 -local textWidth = 0 -local textHeight = ySize - 1 - heightOfTopBar - 1 --- -local lineNumbersHeight = ySize - yStartOfText -local lineNumbersWidth = 0 -local xStartOfLineNumbers = 1 --- -local infoPanelWidth = math.floor(xSize / 3) -local xInfoPanel = math.floor(xSize / 2 - infoPanelWidth / 2) --- -local leftBarWidth = 17 -local leftBarLimit = ySize - yStartOfText - 3 -local leftBarHeight = leftBarLimit + 2 --- -local indentationWidth = 2 --- -local scaleMultiplier = math.ceil(xSize / gpu.maxResolution() * 100) -local oldScale = scaleMultiplier / 100 --- -local leftToolbarFileList = {} -local drawFilesOnLeftToolBarFrom = 1 -local drawFilesOnLeftToolBarTo = 0 -local leftToolbarHeight = ySize - heightOfTopBar - 1 --- -local xCursorPos, yCursorPos = 1, 1 -local canCursorBeBlinked = true --- -local useAnimations = true --- -local bottomToolbarHeight = 3 -local yStartOfBottomToolbar = ySize - bottomToolbarHeight + 1 -local xStartOfBottomToolbar = xStartOfLineNumbers -local bottomToolbarWidth = 0 +local highlightedStrings = { + { number = 31, color = 0xFF4444 }, + { number = 32, color = 0xFF4444 }, + { number = 34, color = 0x66FF66 }, +} +local colors = { + infoPanel = 0xCCCCCC, + infoPanelText = 0x262626, + topBar = 0xDDDDDD, + topBarButton = 0xCCCCCC, + topBarButtonText = 0x262626, + topMenu = 0xFFFFFF, + topMenuText = 0x262626, +} -------------------------------------------------------------- +local topButtonsSymbols = { + launch = "‣", + toggleSyntax = "*", +} -local topBarColor = 0xcccccc -local topBarButtonColor = 0xbbbbbb -local topBarButtonPressedColor = 0x3d3d3d -local topBarButtonTextColor = 0x3d3d3d -local topBarButtonPressedTextColor = 0xffffff -local topMenuColor = 0xeeeeee -local topMenuTextColor = 0x444444 -local lineNumbersColor = 0x3d3d3d -local lineNumbersTextColor = 0xcccccc -local textAreaColor = 0x262626 -local textAreaTextColor = 0xffffff -local scrollBarColor = 0x222222 -local scrollBarActiveColor = ecs.colors.lightBlue -local shadowColor = 0x1d1d1d -local infoPanelColor = 0xe8e8e8 -local infoPanelTextColor = 0x444444 -local usualTextColor = 0xffffff -local backSelectionColor = 0xaaaaff -local textSelectionColor = 0xffffff -local backHighlightColor = 0xff9200 -local textHighlightColor = 0xffffff -local textCommentColor = 0x339933 -local indentationColor = 0x3d3d3d -local leftToolbarColor = 0xdddddd -local leftToolbarFileColor = 0x3d3d3d -local leftToolbarFolderColor = 0x00aa00 -local leftToolbarFieldColor = 0x000000------------------ -local errorColor = 0xcc0000 -local errorTextColor = 0xffffff -local successColor = 0x55ff55 -local successTextColor = 0xffffff -local bottomToolbarColor = 0x555555 -local bottomToolbarButtonColor = 0x383838 -local bottomToolbarTextColor = 0xffffff +local sizes = { + yTopBar = 2, + topBarHeight = 3, + filemanagerWidth = math.floor(buffer.screen.width * 0.16), +} ---------------------------------------ФУНКЦИИ------------------------------------------------------ +--------------------------------------------------- Функции ------------------------------------------------------------------ +local function recalculateSizes() + sizes.yCode = sizes.yTopBar + sizes.topBarHeight + sizes.codeHeight = buffer.screen.height - 1 - sizes.topBarHeight + if showFilemanager then + sizes.codeWidth = buffer.screen.width - sizes.filemanagerWidth + sizes.xCode = sizes.filemanagerWidth + 1 + else + sizes.codeWidth = buffer.screen.width + sizes.xCode = 1 + end +end + +--Объекты для тача local obj = {} local function newObj(class, name, ...) obj[class] = obj[class] or {} obj[class][name] = {...} end -local function convertCoordsToCursorPoses(x, y, reverse) - if reverse then - --FALSE - return (x + xStartOfText - 1), (y + yStartOfText - 1) - else - --TRUE - return (x - xStartOfText + 1), (y - yStartOfText + 1) - end -end - -local function setCursor(blink) - term.setCursorBlink(false) - local x, y = convertCoordsToCursorPoses(xCursorPos, yCursorPos, true) - local pixel = {gpu.get(x, y)} - gpu.setBackground(pixel[3]) - gpu.setForeground(textAreaTextColor) - term.setCursor(x, y) - term.setCursorBlink(canCursorBeBlinked or blink or false) -end - -local function calculateLineNumbersWidth() - lineNumbersWidth = #tostring(#strings) + 2 - --ЭТО ШОБ ТЕКСТ НЕ ВЫЛЕЗАЛ В ПИЗДУ КАРОЧ, ВОООТ - textWidth = xSize - (xStartOfLineNumbers + lineNumbersWidth) - 3 - --А ЭТО КАРОЧ ТОЧКА, ОТКУДОВА ТЕКСТ БУДЕТ РИСОВАТЬСЯ, ВООООТ - xStartOfText = xStartOfLineNumbers + lineNumbersWidth + 1 -end - -local function recalculateTo4toNuzhno() - - textHeight = ySize - 2 - bottomToolbarWidth = xSize - - if toolbarsToShow.top then - yStartOfText = yStartOfTopBar + heightOfTopBar - textHeight = textHeight - heightOfTopBar - leftToolbarHeight = ySize - heightOfTopBar - 1 - else - yStartOfText = 2 - leftToolbarHeight = ySize - 1 - end - - if toolbarsToShow.left then - xStartOfLineNumbers = leftBarWidth + 1 - bottomToolbarWidth = bottomToolbarWidth - leftBarWidth - else xStartOfLineNumbers = 1 - xStartOfLineNumbers = 1 - end - - if toolbarsToShow.bottom then - bottomToolbarHeight = 3 - yStartOfBottomToolbar = ySize - bottomToolbarHeight + 1 - xStartOfBottomToolbar = xStartOfLineNumbers - textHeight = textHeight - bottomToolbarHeight - else - bottomToolbarHeight = 0 - end - - textWidth = xSize - (xStartOfLineNumbers + lineNumbersWidth) - 3 - lineNumbersHeight = ySize - yStartOfText - infoPanelWidth = math.floor(xSize / 3) - xInfoPanel = math.floor(xSize / 2 - infoPanelWidth / 2) - - leftBarLimit = ySize - yStartOfText - 1 - leftBarHeight = leftBarLimit + 2 - - calculateLineNumbersWidth() - - setCursor(true) - - --ecs.error("xStartOfText="..xStartOfText..", xCursorPos="..xCursorPos) - - newObj("zones", "textArea", xStartOfText, yStartOfText, xStartOfText + textWidth - 1, yStartOfText + textHeight - 1) - newObj("zones", "leftBar", 1, yStartOfText, leftBarWidth, yStartOfText + leftBarHeight - 1) - newObj("zones", "topBar", 1, yStartOfTopBar, xSize, yStartOfTopBar + heightOfTopBar - 1) - newObj("zones", "bottomBar", xStartOfBottomToolbar, yStartOfBottomToolbar, bottomToolbarWidth, bottomToolbarHeight) -end - - -local function drawTopButtons() - ecs.square(1,1,xSize,1,topMenuColor) - - local posX = 3 - local spaceBetween = 2 - gpu.setForeground(topMenuTextColor) - for i=1,#topButtons do - gpu.set(posX,1,topButtons[i]) - local length = unicode.len(topButtons[i]) - - posX = posX + length + spaceBetween - end -end - -local function getInfoAboutRAM() - local free = computer.freeMemory() - local total = computer.totalMemory() - local used = total - free - return math.ceil(used / 1024), math.floor(total / 1024) -end - -local function drawInfoPanel(massivSudaPihay, zad, pered) - - local used, total = getInfoAboutRAM() - - local text = massivSudaPihay or { - [1] = fs.name(projectPath) or lang.infoPanelNewProject, - [2] = lang.infoPanelString .." "..stringToDisplayFrom .. " "..lang.infoPanelStringOf.." " .. #strings, - [3] = tostring(used) .. "/" .. tostring(total) .. " KB RAM" - } - local backColor = zad or infoPanelColor - local frontColor = pered or infoPanelTextColor - - ---------------------------------------------------------------------- - - --КАРОЧ ФОН ВОТ ЭТОЙ БЕЛОЙ ШНЯГИ - ecs.square(xInfoPanel, yStartOfTopBar, infoPanelWidth, heightOfTopBar, backColor) - - --ОБРЕЗАНИЕ И РИСОВАНИЕ ТЕКСТА - gpu.setForeground(frontColor) - for i = 1, #text do - text[i] = ecs.stringLimit("start", text[i], infoPanelWidth) - - local xPos = xInfoPanel + infoPanelWidth / 2 - unicode.len(text[i]) / 2 - gpu.set(xPos, yStartOfTopBar + i - 1, text[i]) - end -end - -local function drawTopToolbar() - ecs.square(1, yStartOfTopBar, xSize, heightOfTopBar, topBarColor) - - --ЭТО КРОПОЧКИ - local xPos = 3 - local spaceBetween = 2 - xPos = {ecs.drawAdaptiveButton(xPos, yStartOfTopBar, 2, 1, "►", topBarButtonColor, topBarButtonTextColor)} - newObj("topButtons", "►", xPos[1], xPos[2], xPos[3], xPos[4]) - xPos = xPos[3] + spaceBetween + 1 - ecs.drawAdaptiveButton(xPos, yStartOfTopBar, 2, 1, "☼", topBarButtonColor, topBarButtonTextColor) - - - - --А ЭТО Я ВООБЩЕ РОТ ЕТОГО ЕБАЛ - --ГОВНОКОД, НО РАБОТАЕТ - local hernya = { - { - "╓───┐", - "║ │", - "╙───┘" - }, - { - "╒═══╕", - "│ │", - "└───┘" - }, - { - "┌───╖", - "│ ║", - "└───╜" - }, - } - - xPos = xInfoPanel + infoPanelWidth + 2 - gpu.setBackground(topBarColor) - for i = 1, 3 do - local color = topBarButtonTextColor - if i == 1 and not toolbarsToShow.left then color = topBarButtonColor end - if i == 2 and not toolbarsToShow.top then color = topBarButtonColor end - if i == 3 and not toolbarsToShow.bottom then color = topBarButtonColor end - - gpu.setForeground(color) - for j = 1, 3 do - gpu.set(xPos, yStartOfTopBar + j - 1, hernya[i][j]) +local function readFile(path) + if fs.exists(path) then + maximumStringWidth = 0 + strings = {} + fileSize = math.floor(fs.size(path) / 1024) + local file = io.open(path, "r") + for line in file:lines() do + line = string.gsub(line, " ", string.rep(" ", indentationWidth)) + maximumStringWidth = math.max(maximumStringWidth, unicode.len(line)) + table.insert(strings, line) end - - xPos = xPos + 6 - - - color = nil + file:close() + else + ecs.error("Файл \"" .. path .. "\" не существует") end - - --ecs.drawAdaptiveButton(xPos, yStartOfTopBar, 2, 1, "☼", topBarColor, topBarButtonTextColor) - - - xPos, spaceBetween = nil, nil - - if toolbarsToShow.top then drawInfoPanel() end end -local function drawBottomScrollBar() - local yPos = yStartOfText + textHeight +local function drawInfoPanel() + local width = math.floor(buffer.screen.width * 0.3) + local x, y = math.floor(buffer.screen.width / 2 - width / 2), 2 - local width = 0 - if toolbarsToShow.left then width = xSize - leftBarWidth - 2 else width = xSize - 2 end - ecs.square(xStartOfText - 1, yPos, width, 1, scrollBarColor) - ecs.square(xStartOfText - 1, yPos, 8, 1, scrollBarActiveColor) - - width, yPos = nil, nil -end - -local function drawRightSrollBar() - local rightScrollBarHeight = textHeight - local countOfAllElements = #strings - local sizeOfScrollBar = math.ceil(1 / countOfAllElements * rightScrollBarHeight) - local displayBarFrom = math.floor(yStartOfText + rightScrollBarHeight * ((stringToDisplayFrom - 1) / countOfAllElements)) - - ecs.square(xSize - 1, yStartOfText, 2, rightScrollBarHeight, scrollBarColor) - ecs.square(xSize - 1, displayBarFrom, 2, sizeOfScrollBar, scrollBarActiveColor) - - sizeOfScrollBar, displayBarFrom, rightScrollBarHeight, countOfAllElements = nil, nil, nil, nil -end - -local function isStringCommented(stro4ka) - local starting, ending = string.find(stro4ka, "^%-%-") - if not starting then - starting, ending = string.find(stro4ka, "^%s*%-%-") - end - if not starting then return false end - - return starting, ending -end - -local function analyseStrings(from, to) - for i = from, to do - - --УБИРАЕМ ТАБСЫ НА ХЕР, ЗАМЕНЯЕМ ИХ ПРОБЕЛАМИ - strings[i][1] = string.gsub(strings[i][1], " ", string.rep(" ", indentationWidth)) - - --ВСЯКИЕ ТАМ КОММЕНТАРИИ И ПРОЧЕЕ - local isCommentet = false - local starting = isStringCommented(strings[i][1]) - if starting then isCommentet = true end - - strings[i][2] = isCommentet - strings[i][3] = false - strings[i][4] = false - - isCommentet = nil - end - - calculateLineNumbersWidth() -end - -local function drawString(i) - - local yPos = yStartOfText + i - stringToDisplayFrom - --ecs.error("yPos="..yPos..", yStartOfText="..yStartOfText..", stringToDisplayFrom="..stringToDisplayFrom..", i="..i) - local xPos = xStartOfText - - --ВСЯКАЯ ПОЕБИСТИКА С ЦВЕТАМИ - local textColor = textAreaTextColor - local backColor = textAreaColor - - if strings[i][4] then - backColor = backSelectionColor - textColor = textSelectionColor - if strings[i][3] then backColor = backSelectionColor + backHighlightColor end - elseif strings[i][3] then - backColor = backHighlightColor - textColor = textHighlightColor - end - - if strings[i][2] then - textColor = textCommentColor - end - - --if strings[i][3] or strings[i][4] then ecs.square(xPos + 1, yPos, textWidth - 1, 1, backColor) end - - --САМА ПЕЧАТЬ ТЕКСТА - - gpu.setBackground(backColor) - - local symbolToDisplayFromEnd = symbolToDisplayFrom + textWidth - 1 - local widthOfCoverSpaces = textWidth - unicode.len(unicode.sub(strings[i][1], symbolToDisplayFrom, symbolToDisplayFromEnd)) - local text = unicode.sub(strings[i][1], symbolToDisplayFrom, symbolToDisplayFromEnd) - - ecs.colorText(xStartOfText, yPos, textColor, text .. string.rep(" ", widthOfCoverSpaces)) - - -- ОТСТУПЫ, ТАБУЛЯЦИЯ - -- local starting, ending = string.find(text, "^%s*[^%s]") - -- if starting then - -- local count = math.floor(ending / indentationWidth) - -- ecs.colorText(xStartOfText - math.ceil((ending - 1) % indentationWidth), yPos, indentationColor, string.rep("│" .. string.rep(" ", indentationWidth - 1), count)) - -- end - - --А ЭТО КАРОЧ ВАЩЕ АХУЕННАЯ ИДЕЙКА, ЩА ПОТЕСТИМ, БУДЕТ ЛИ РАБОТАТЬ - --В ОБЩЕМ, ЭТО ОТРИСОВОЧКА ЛИНЕНУМБЕРСОВ ВАШЕ ВСЕХ!!! ПРЯМ ВСЕХ - --ВАЩЕЕЕЕ, СУКА, ВСЕХ! - gpu.setBackground(lineNumbersColor) - gpu.setForeground(lineNumbersTextColor) - local text = string.rep(" ", lineNumbersWidth - 1 - #tostring(i)) .. i .. " " - gpu.set(xStartOfLineNumbers, yPos, text) - text = nil + buffer.square(x, y, width, 3, colors.infoPanel, 0x000000, " ") - symbolToDisplayFromEnd, text, widthOfCoverSpaces, textColor, count, starting, ending = nil, nil, nil, nil, nil, nil, nil + local textArray = { + "Файл: " .. pathToFile .. ", " .. fileSize .. "KB", + "Позиция курсора: " .. xCursor .. "x" .. yCursor, + } - return yPos, xPos -end - -local function drawText() - local yPos = 0 - for i = stringToDisplayFrom, (stringToDisplayFrom + textHeight - 1) do - if strings[i] then - --ТУТ МЫ КАРОЧ ПОЛУЧАЕМ СТРОЧКУ - НОМЕР ЕЕ, НУ И РИСУЕМ ЗАОДНО - yPos = drawString(i) - --А ЭТО КАРОЧ ОЧИСТКА ВСЕГО ЛИШНЕГО ГОВНА, КОТОРОЕ ПРИ СКРОЛЛИНГЕ ОСТАЕТСЯ - if i >= #strings then - if yPos < (yStartOfText + textHeight -1) then - gpu.setBackground(textAreaColor) - gpu.set(xStartOfText, yPos + 1, string.rep(" ", textWidth)) - --ЭТО СЕРАЯ ХУЙНЯ ДОНИЗУ - ecs.square(xStartOfLineNumbers, yPos + 1, lineNumbersWidth, ySize - yPos - bottomToolbarHeight , lineNumbersColor) - end - end - else - break - end + for i = 1, #textArray do + textArray[i] = ecs.stringLimit("end", textArray[i], width) + x = math.floor(buffer.screen.width / 2 - unicode.len(textArray[i]) / 2) + + buffer.text(x, y, colors.infoPanelText, textArray[i]) + + y = y + 1 end - - yPos = nil - - -- ОЧИСТКА ВЕРТИКАЛЬНОЙ ХУЕТЫ ОКОЛО ЛИНЕНУМБЕРСА - ecs.square(xStartOfLineNumbers + lineNumbersWidth, yStartOfText, 1, textHeight, textAreaColor) end -local function moveText(direction) +local function drawTopBar() + obj["TopBarButtons"] = {} + + local x, y = 1, sizes.yTopBar + local buttonWidth = 7 + buffer.square(x, y, buffer.screen.width, sizes.topBarHeight, colors.topBar, 0x000000, " ") + + local buttonNames = { + topButtonsSymbols.launch, + topButtonsSymbols.toggleSyntax, + } + + for i = 1, #buttonNames do + newObj("TopBarButtons", buttonNames[i], buffer.button(x, y, buttonWidth, 3, colors.topBarButton, colors.topBarButtonText, buttonNames[i])) + x = x + buttonWidth + 1 + end +end + +local function drawTopMenu() + local x, y = 1, 1 + + buffer.square(x, y, buffer.screen.width, 1, colors.topMenu, 0x000000, " ") + + local buttonNames = { + "Файл", + "Правка", + "Вид", + "О программе" + } + + for i = 1, #buttonNames do + local length = unicode.len(buttonNames[i]) + 2 + buffer.button(x, y, length, 1, colors.topMenu, colors.topMenuText, buttonNames[i]) + x = x + length + end +end + +local function drawCode() + textFieldPosition = syntax.viewCode(sizes.xCode, sizes.yCode, sizes.codeWidth, sizes.codeHeight, strings, maximumStringWidth,fromSymbol, fromString, showLuaSyntax, selection, highlightedStrings) +end + +local function launch() + local callback, reason = loadfile(pathToFile) + if callback then + ecs.prepareToExit() + local success, reason = pcall(callback) + if success then + ecs.prepareToExit() + print("Программа успешно выполнена!") + else + ecs.error("Ошибка при выполнении программы: " .. reason) + end + else + ecs.error("Ошибка при запуске программы: " .. reason) + end +end + +-- local function convertCoordsToCursor(x, y) + +-- end + +local function drawFileManager() + filemanager.draw(1, sizes.yCode, sizes.filemanagerWidth, buffer.screen.height - 4, fs.path(pathToFile), 1) +end + +local function drawAll(force) + drawTopBar() + drawInfoPanel() + drawTopMenu() + if showFilemanager then drawFileManager() end + drawCode() + buffer.draw(force) +end + +local function scroll(direction, count) if direction == "up" then - if stringToDisplayFrom > 1 then - stringToDisplayFrom = stringToDisplayFrom - 1 - drawText() - drawRightSrollBar() + if fromString > count then + fromString = fromString - count + drawInfoPanel(); drawCode(); buffer.draw() end elseif direction == "down" then - if stringToDisplayFrom < #strings then - stringToDisplayFrom = stringToDisplayFrom + 1 - drawText() - drawRightSrollBar() + if fromString < (#strings - count) then + fromString = fromString + count + drawInfoPanel(); drawCode(); buffer.draw() end elseif direction == "left" then - if symbolToDisplayFrom > 1 then - symbolToDisplayFrom = symbolToDisplayFrom - 1 - drawText() + if fromSymbol > count then + fromSymbol = fromSymbol - count + drawInfoPanel(); drawCode(); buffer.draw() end elseif direction == "right" then - if symbolToDisplayFrom < 100 then - symbolToDisplayFrom = symbolToDisplayFrom + 1 - drawText() - end - end - if toolbarsToShow.top then drawInfoPanel() end -end - -local function convertCoordToString(coord) - return stringToDisplayFrom + (coord - yStartOfText) -end - -local function convertStringToCoord(string) - -end - -local selectedStrings = {} -local function selectString(coord) - local number = convertCoordToString(coord) - if strings[number] and number >= stringToDisplayFrom and number <= (stringToDisplayFrom + textHeight) then - - if not strings[number][4] then - strings[number][4] = true - drawString(number) - - table.insert(selectedStrings, number) - end - end - number = nil -end - -local function deselectStrings() - for i = 1, #selectedStrings do - strings[selectedStrings[i]][4] = false - end - - selectedStrings = {} -end - -local function selectAll() - selectedStrings = {} - for i = 1, #strings do - strings[i][4] = true - selectedStrings[i] = i - end -end - -local function deselectAll() - selectedStrings = {} - for i = 1, #strings do - strings[i][4] = false - end -end - -local function indent() - for i = 1, #selectedStrings do - local number = selectedStrings[i] - strings[number][1] = string.rep(" ", indentationWidth) .. strings[number][1] - end -end - -local function unIndent() - for i = 1, #selectedStrings do - local number = selectedStrings[i] - local starting, ending = string.find(strings[number][1], "^"..string.rep("%s", indentationWidth)) - if starting then - strings[number][1] = unicode.sub(strings[number][1], ending + 1, -1) - end - end -end - -local function toggleComment() - local countOfCommentedStrings = 0 - - for i = 1, #selectedStrings do - local number = selectedStrings[i] - - local starting, ending = isStringCommented(strings[number][1]) - - if starting then countOfCommentedStrings = countOfCommentedStrings + 1 end - - number, starting, ending = nil, nil, nil - end - - if countOfCommentedStrings >= #selectedStrings then - for i = 1, #selectedStrings do - local number = selectedStrings[i] - local starting, ending = isStringCommented(strings[number][1]) - if starting then - strings[number][2] = false - strings[number][1] = unicode.sub(strings[number][1], 1, starting - 1) .. unicode.sub(strings[number][1], ending + 1, -1) - end - end - else - for i = 1, #selectedStrings do - local number = selectedStrings[i] - strings[number][2] = true - strings[number][1] = "--"..strings[number][1] + if fromSymbol < (maximumStringWidth - count) then + fromSymbol = fromSymbol + count + drawInfoPanel(); drawCode(); buffer.draw() end end end -local clipBoard = {} -local function copy() - clipBoard = {} +--------------------------------------------------- Начало работы скрипта ------------------------------------------------------------------ - --КОПИРУЕМ В БУФЕР ОБМЕНА ВОТ ТАКИМ ВОТ ХИТРОЗАДЫМ МЕТОДОМ - for i = 1, #selectedStrings do - local position = #clipBoard + 1 - clipBoard[position] = {} - - for j = 1, 4 do - clipBoard[position][j] = strings[selectedStrings[i]][j] - end - - clipBoard[position][3], clipBoard[position][4] = false, false - end - - --ecs.error("#selectedStrings = "..#selectedStrings..", #clipBoard = "..#clipBoard..", #strings = "..#strings) +local args = { ... } +if args[1] == "open" then + pathToFile = args[2] end -local function paste(yPos) - deselectStrings() - local massiv - local counter = 1 - for i = 1, #clipBoard do - massiv = {} - for j = 1, 4 do - massiv[j] = clipBoard[i][j] - end - table.insert(strings, yPos + counter, massiv) - counter = counter + 1 - end +buffer.square(1, 1, buffer.screen.width, buffer.screen.height, ecs.colors.red, 0xFFFFFF, " ") +buffer.draw(true) -end - -local function highlightString(number) - strings[number][3] = true -end - ---ОТРИСОВКА ПОЛОСЫ ПРОКРУТКИ -local function newScrollBar(x,y,height,countOfAllElements,displayingFrom,displayingTo,backColor,frontColor) - local diapason = displayingTo - displayingFrom + 1 - local percent = diapason / countOfAllElements - local sizeOfScrollBar = math.ceil(percent * height) - local displayBarFrom = math.floor(y + height*(displayingFrom-1)/countOfAllElements) - - ecs.square(x,y,1,height,backColor) - ecs.square(x, displayBarFrom, 1, sizeOfScrollBar, frontColor) -end - -local function calculateEndFile() - local size = #leftToolbarFileList - if size < leftBarLimit then drawFilesOnLeftToolBarTo = drawFilesOnLeftToolBarFrom + size - 1 else drawFilesOnLeftToolBarTo = drawFilesOnLeftToolBarFrom + leftBarLimit - 1 end -end - -local function drawFileListOnLeftToolbar(path) - calculateEndFile() - local from, to = drawFilesOnLeftToolBarFrom, drawFilesOnLeftToolBarTo - local yPos = yStartOfText + 1 - local xPos = 2 - local textLimit = leftBarWidth - 3 - - --СКРОЛЛБАР - newScrollBar(leftBarWidth, yStartOfText + 1, leftBarLimit, #leftToolbarFileList, from, to, scrollBarColor, scrollBarActiveColor) - - --САМ ТЕКСТ - gpu.setBackground(leftToolbarColor) - - for i = from, to do - if leftToolbarFileList[i] then - local color = leftToolbarFileColor - local cyka = path..leftToolbarFileList[i] - if fs.isDirectory(cyka) then - color = leftToolbarFolderColor - end - if ecs.isFileHidden(cyka) then - color = leftToolbarFileColor - 0x999999 - end - --ecs.error(cyka.." "..projectPath) - if cyka == projectPath then - color = 0xffffff - ecs.square(1, yPos, leftBarWidth - 1, 1, ecs.colors.blue) - end - local text = ecs.stringLimit("start", leftToolbarFileList[i], textLimit) - ecs.colorText(2, yPos, color, text) - gpu.setBackground(leftToolbarColor) - - - newObj("leftBarFiles", cyka, 1, yPos, leftBarWidth - 1, yPos, text) - --ecs.error("path = ".. cyka) - - yPos = yPos + 1 - color, cyka, text = nil, nil, nil - else - break - end - end - - countOfAllElements, sizeOfScrollBar, displayBarFrom, xPos, yPos = nil, nil, nil, nil, nil -end - -local leftToolbarHistory = {} -local function drawLeftToolBar() - local path = leftToolbarPath - - --ЭТО КАРОЧ ВЕРХНЯЯ ПОЛОСОЧКА И ЗАЛИВКА ВООБЩЕ ВСЯ - ecs.square(1, yStartOfText, leftBarWidth, 1, 0xffffff) - ecs.colorText(1, yStartOfText, 0x000000, ecs.stringLimit("start", path, leftBarWidth)) - ecs.square(1, yStartOfText + 1, leftBarWidth - 1, leftToolbarHeight, leftToolbarColor) - ecs.square(1, ySize, leftBarWidth, 1, leftToolbarFieldColor) - - --ОТРИСОВКА КНОПОЧЕК СНИЗУ КАРОЧ - local buttons = {"◄", "Home", "Root"} - local xPos = 2 - for i = 1, #buttons do - newObj("leftBarButtons", buttons[i], ecs.drawAdaptiveButton(xPos, ySize, 0, 0, buttons[i], leftToolbarFieldColor, topBarButtonTextColor)) - xPos = xPos + unicode.len(buttons[i]) + 2 - end - --ecs.colorText(2, yStartOfText + textHeight, topBarButtonTextColor, "◄ Home Root") - - obj["leftBarFiles"] = {} - local fileList = ecs.getFileList(path) - if #fileList > 0 then - leftToolbarFileList = ecs.sortFiles(path, fileList, "name", false) - drawFileListOnLeftToolbar(path) - end - - - -end - -local function drawBottomToolbar() - --СЕРАЯ ПОДЛОЖКА - ecs.square(xStartOfBottomToolbar, yStartOfBottomToolbar, bottomToolbarWidth, bottomToolbarHeight, bottomToolbarColor ) - --КНОПЫ - local xPos = xStartOfBottomToolbar + 2 - local yPos = yStartOfBottomToolbar + 1 - local buttonCase = {ecs.drawAdaptiveButton(xPos, yPos, 1, 0, "Aa", bottomToolbarButtonColor, bottomToolbarTextColor)}; xPos = xPos + 5 - local buttonInSelection = {ecs.drawAdaptiveButton(xPos, yPos, 1, 0, "¬", bottomToolbarButtonColor, bottomToolbarTextColor)}; xPos = xPos + 4 - - --БЕЛАЯ СТРОКА ПОИСКА - local inputWidth = bottomToolbarWidth - 36 - ecs.inputText(xPos, yPos, inputWidth, "local function", 0xffffff, 0x000000, true) - - --ОПЯТЬ КНОПЫ - xPos = xStartOfBottomToolbar + bottomToolbarWidth - 24 - local buttonFind = {ecs.drawAdaptiveButton(xPos, yPos, 2, 0, "Find", bottomToolbarButtonColor, bottomToolbarTextColor)}; xPos = xPos + 9 - local buttonFindNext = {ecs.drawAdaptiveButton(xPos, yPos, 2, 0, "Find Prev", bottomToolbarButtonColor, bottomToolbarTextColor)} - - --ОБЖЕКТЫ - newObj("bottomElements", "Aa") -end - -local function drawAll() - ecs.square(xStartOfLineNumbers, yStartOfText, xStartOfLineNumbers + lineNumbersWidth + textWidth, textHeight, textAreaColor) - drawTopButtons() - --ВОТ ТУТ РИСУЕМ ТУ МЕЛКУЮ ХУЙНЮ ПОД НОМЕРАМИ СТРОК - ecs.square(xStartOfLineNumbers, yStartOfText + textHeight, lineNumbersWidth, 1, lineNumbersColor) - drawText() - drawBottomScrollBar() - drawRightSrollBar() - if toolbarsToShow.top then drawTopToolbar() end - if toolbarsToShow.left then drawLeftToolBar() end - if toolbarsToShow.bottom then drawBottomToolbar() end - - setCursor(true) -end - -local function changeScale(plus) - if plus then - scaleMultiplier = scaleMultiplier + 10 - else - scaleMultiplier = scaleMultiplier - 10 - end - - local width, height = gpu.maxResolution() - local proportion = width / height - local newWidth = math.ceil(width * (scaleMultiplier / 100)) - local newHeight = math.ceil(newWidth / proportion) - gpu.setResolution(newWidth,newHeight) - xSize, ySize = newWidth, newHeight - - width, height, proportion, newHeight, newWidth = nil, nil, nil, nil, nil - - recalculateTo4toNuzhno() - drawAll() -end - -local function open(path) - local f = io.open(path,"r") - local lines = {} - while true do - local line = f:read("*l") - if not line then break else table.insert(lines, line) end - line = nil - end - f:close() - - strings = {} - for i = 1, #lines do - table.insert(strings, {lines[i]}) - end - - stringToDisplayFrom = 1 - selectedStrings = {} -end - - -local function compile() - local success, reason = shell.execute(projectPath) - drawAll() - if not success then - --ecs.error("reason = "..reason) - if toolbarsToShow.top then drawInfoPanel({" ", "Ошибка!", " "}, errorColor, errorTextColor) end - --drawErrorMessage(yStartOfText, reason, xSize - 20) - --ecs.error(reason) - ecs.displayCompileMessage(yStartOfText, reason, true) - else - if toolbarsToShow.top then drawInfoPanel({" ", "Программа выполнена!", " "}, successColor, successTextColor) end - end -end - ----------------------------------------ПРОГА------------------------------------------------------ - -if args[1] == "-o" or args[1] == "open" then - projectPath = "/"..args[2] - leftToolbarPath = fs.path(projectPath) - open(projectPath) -else - projectPath = "/" - leftToolbarPath = projectPath - strings = {{"Hello world!"}, {"This is insane lags"}, {"while true do"}, {"forever end ahahahha for i = 1, 10 do"}, {"end"}} -end - -leftToolbarHistory = {""} - -recalculateTo4toNuzhno() -analyseStrings(1, #strings) +recalculateSizes() +readFile(pathToFile) drawAll() -ecs.error("MineCode вообще в стадии разработки. Так что не думай, что тут что-то можно делать. Можно только файлики открывать.") - - while true do - local e = {event.pull()} - if e[1] == "drag" then - if ecs.clickedAtArea(e[3], e[4], obj["zones"]["textArea"][1], obj["zones"]["textArea"][2], obj["zones"]["textArea"][3], obj["zones"]["textArea"][4]) then - - selectString(e[4]) + local e = { event.pull() } + if e[1] == "touch" then + for key in pairs(obj.TopBarButtons) do + if ecs.clickedAtArea(e[3], e[4], obj.TopBarButtons[key][1], obj.TopBarButtons[key][2], obj.TopBarButtons[key][3], obj.TopBarButtons[key][4]) then + buffer.button(obj.TopBarButtons[key][1], obj.TopBarButtons[key][2], 7, 3, ecs.colors.blue, ecs.colors.white, key) + buffer.draw() + os.sleep(0.2) + buffer.button(obj.TopBarButtons[key][1], obj.TopBarButtons[key][2], 7, 3, colors.topBarButton, colors.topBarButtonText, key) + buffer.draw() - end - - elseif e[1] == "touch" then - - --КЛИК В ТЕКСТОВУЮ ЗОНУ - if ecs.clickedAtArea(e[3], e[4], obj["zones"]["textArea"][1], obj["zones"]["textArea"][2], obj["zones"]["textArea"][3], obj["zones"]["textArea"][4]) then - - if e[5] == 0 then - if #selectedStrings > 0 and not keyboard.isControlDown() then - deselectStrings() - drawText() + if key == topButtonsSymbols.launch then + launch() + drawAll() + elseif key == topButtonsSymbols.toggleSyntax then + showLuaSyntax = not showLuaSyntax + drawAll() end - xCursorPos, yCursorPos = convertCoordsToCursorPoses(e[3], e[4]) - - setCursor(true) - else - local action = context.menu(e[3], e[4], {"Вырезать", false, "^X"}, {"Копировать", false, "^C"}, {"Вставить", not (#clipBoard > 0), "^V"}, "-", {"Подсветить",false,"^L"}, {"Закомментировать",false,"^⌂C"}, "-", {"Выбрать все",false,"^A"}) - if action == "Вставить" and #clipBoard > 0 then - paste(yCursorPos) - calculateLineNumbersWidth() - drawText() - elseif action == "Копировать" and #selectedStrings > 0 then - copy() - deselectStrings() - drawText() - elseif action == "Закомментировать" and #selectedStrings > 0 then - toggleComment() - drawText() - elseif action == "Выбрать все" then - selectAll() - drawText() - elseif action == "Подсветить" and #selectedStrings > 0 then - for i = 1, #selectedStrings do - highlightString(selectedStrings[i]) - end - drawText() - end - end - - --ЕСЛИ КЛИКНУЛИ НА ТОП ТУЛБАР - elseif toolbarsToShow.top and ecs.clickedAtArea(e[3], e[4], obj["zones"]["topBar"][1], obj["zones"]["topBar"][2], obj["zones"]["topBar"][3], obj["zones"]["topBar"][4]) then - - for key, val in pairs(obj["topButtons"]) do - if ecs.clickedAtArea(e[3], e[4], obj["topButtons"][key][1], obj["topButtons"][key][2], obj["topButtons"][key][3], obj["topButtons"][key][4]) then - ecs.drawAdaptiveButton(obj["topButtons"][key][1], obj["topButtons"][key][2], 2, 1, key, topBarButtonTextColor, 0xffffff - topBarButtonTextColor) - os.sleep(0.2) - compile() - - break - end - end - - --КЛИК НА ЛЕВЫЙ ТУЛБАР - elseif toolbarsToShow.left and ecs.clickedAtArea(e[3], e[4], obj["zones"]["leftBar"][1], obj["zones"]["leftBar"][2], obj["zones"]["leftBar"][3], obj["zones"]["leftBar"][4]) then - for key, val in pairs(obj["leftBarFiles"]) do - if ecs.clickedAtArea(e[3], e[4], obj["leftBarFiles"][key][1], obj["leftBarFiles"][key][2], obj["leftBarFiles"][key][3], obj["leftBarFiles"][key][4]) then - - - - if fs.isDirectory(key) then - - ecs.square(1, obj["leftBarFiles"][key][2], obj["leftBarFiles"][key][3], 1, ecs.colors.blue) - ecs.colorText(2, obj["leftBarFiles"][key][2], 0xffffff, obj["leftBarFiles"][key][5]) - os.sleep(0.2) - table.insert(leftToolbarHistory, key) - leftToolbarPath = key - drawLeftToolBar() - else - projectPath = key - open(projectPath) - analyseStrings(1, #strings) - recalculateTo4toNuzhno() - drawAll() - end - break - - end - end - - --КЛИК НА КНПОЧКИ ЛЕВОГО ТУЛБАРА - for key, val in pairs(obj["leftBarButtons"]) do - if ecs.clickedAtArea(e[3], e[4], obj["leftBarButtons"][key][1], obj["leftBarButtons"][key][2], obj["leftBarButtons"][key][3], obj["leftBarButtons"][key][4]) then - - ecs.drawAdaptiveButton(obj["leftBarButtons"][key][1] - 1, obj["leftBarButtons"][key][2], 1, 0, key, topBarButtonTextColor, topBarColor) - os.sleep(0.3) - - if key == "◄" and #leftToolbarHistory > 1 then - leftToolbarHistory[#leftToolbarHistory] = nil - leftToolbarPath = leftToolbarHistory[#leftToolbarHistory] - elseif key == "Home" then - leftToolbarHistory = {"/"} - leftToolbarPath = fs.path(projectPath) - elseif key == "Root" then - leftToolbarHistory = {"/"} - leftToolbarPath = "/" - end - - drawLeftToolBar() - - break - end + break end end - elseif e[1] == "key_down" then if e[4] == 200 then - moveText("up") + scroll("up", 1) elseif e[4] == 208 then - moveText("down") + scroll("down", 1) elseif e[4] == 203 then - moveText("left") + scroll("left", 1) elseif e[4] == 205 then - moveText("right") - -- CTRL + C - elseif e[4] == 46 then - if keyboard.isControlDown() and not keyboard.isShiftDown() and #selectedStrings > 0 then - copy() - ecs.error("Скопировалось") - deselectStrings() - drawText() - elseif keyboard.isControlDown() and keyboard.isShiftDown() and #selectedStrings > 0 then - --ecs.error("Закомментировалось") - toggleComment() - drawText() - end - -- CTRL + V - --КЛАВИШИ - И + - elseif e[4] == 12 then - if keyboard.isControlDown() and scaleMultiplier < 100 then changeScale(true) end - elseif e[4] == 13 then - if keyboard.isControlDown() and scaleMultiplier > 50 then changeScale(false) end - --КЛАВИША Q - elseif e[4] == 16 then - if keyboard.isControlDown() then - ecs.setScale(oldScale) - ecs.prepareToExit(0x262626) - return 0 - end - --КЛАВИША 0 - elseif e[4] == 11 then - if toolbarsToShow.top then toolbarsToShow.top = false else toolbarsToShow.top = true end - recalculateTo4toNuzhno() - drawAll() - --КЛАВИША 9 - elseif e[4] == 10 then - if toolbarsToShow.left then toolbarsToShow.left = false else toolbarsToShow.left = true end - recalculateTo4toNuzhno() - drawAll() - --КЛАВИША 8 - elseif e[4] == 9 then - toolbarsToShow.bottom = not toolbarsToShow.bottom - recalculateTo4toNuzhno() - drawAll() - -- ENTER - elseif e[4] == 28 then - if keyboard.isControlDown() then compile() end - elseif e[4] == 47 then - if keyboard.isControlDown() and #clipBoard > 0 then - - paste(yCursorPos) - --ecs.error("Вставилось") - calculateLineNumbersWidth() - - drawText() - end - -- CTRL + A - elseif e[4] == 30 then - if keyboard.isControlDown() then - - selectAll() - - drawText() - end - -- CTRL + D - elseif e[4] == 32 then - if keyboard.isControlDown() then - deselectAll() - drawText() - end - -- TAB - elseif e[4] == 15 and #selectedStrings > 0 then - if keyboard.isShiftDown() then - unIndent() - else - indent() - end - drawText() + scroll("right", 1) + end + elseif e[1] == "scroll" then + if e[5] == 1 then + scroll("up", scrollSpeed) + else + scroll("down", scrollSpeed) end end end + + + + + + + + + + diff --git a/Applications/MineCode/Russian.lang b/Applications/MineCode/Russian.lang deleted file mode 100644 index 19ef99d8..00000000 --- a/Applications/MineCode/Russian.lang +++ /dev/null @@ -1,8 +0,0 @@ -topMenuFile = Файл -topMenuEdit = Правка -topMenuFind = Поиск -topMenuView = Вид -topMenuGoto = Переход -infoPanelNewProject = Новый проект -infoPanelString = Строка -infoPanelStringOf = из diff --git a/Applications/Photoshop/Photoshop.lua b/Applications/Photoshop/Photoshop.lua index 97380e61..99bf58be 100644 --- a/Applications/Photoshop/Photoshop.lua +++ b/Applications/Photoshop/Photoshop.lua @@ -387,12 +387,16 @@ local function inputText(x, y, limit) elseif e[4] == 28 then break elseif e[4] == 200 then - text = "▀" - inputPos = 1 + text = text .. "▀" + if unicode.len(text) < limit then + inputPos = inputPos + 1 + end drawThisShit() elseif e[4] == 208 then - text = "▄" - inputPos = 1 + text = text .. "▄" + if unicode.len(text) < limit then + inputPos = inputPos + 1 + end drawThisShit() else local symbol = ecs.convertCodeToSymbol(e[3]) diff --git a/lib/doubleBuffering.lua b/lib/doubleBuffering.lua index a43d2c90..a5aa7da5 100644 --- a/lib/doubleBuffering.lua +++ b/lib/doubleBuffering.lua @@ -108,7 +108,7 @@ function buffer.square(x, y, width, height, background, foreground, symbol, tran local index, indexPlus1, indexPlus2 if transparency then transparency = transparency * 2.55 end if not foreground then foreground = 0x000000 end - if symbol == " " then foreground = 0x000000 elseif not symbol then symbol = " " end + -- if symbol == " " then foreground = 0x000000 elseif not symbol then symbol = " " end for j = y, (y + height - 1) do for i = x, (x + width - 1) do @@ -323,7 +323,8 @@ function buffer.image(x, y, picture) end --Если символ равен пробелу, то сбрасываем цвет текста на ноль - buffer.screen.new[indexPlus1] = picture[imageIndexPlus3] == " " and 0x000000 or picture[imageIndexPlus1] + -- buffer.screen.new[indexPlus1] = picture[imageIndexPlus3] == " " and 0x000000 or picture[imageIndexPlus1] + buffer.screen.new[indexPlus1] = picture[imageIndexPlus1] buffer.screen.new[indexPlus2] = picture[imageIndexPlus3] end end @@ -353,7 +354,7 @@ end -- Вертикальный скролл-бар function buffer.scrollBar(x, y, width, height, countOfAllElements, currentElement, backColor, frontColor) - local sizeOfScrollBar = math.ceil(1 / countOfAllElements * height) + local sizeOfScrollBar = math.ceil(height / countOfAllElements) local displayBarFrom = math.floor(y + height * ((currentElement - 1) / countOfAllElements)) buffer.square(x, y, width, height, backColor, 0xFFFFFF, " ") @@ -362,6 +363,14 @@ function buffer.scrollBar(x, y, width, height, countOfAllElements, currentElemen sizeOfScrollBar, displayBarFrom = nil, nil end +function buffer.horizontalScrollBar(x, y, width, countOfAllElements, currentElement, background, foreground) + local pipeSize = math.ceil(width / countOfAllElements) + local displayBarFrom = math.floor(x + width * ((currentElement - 1) / countOfAllElements)) + + buffer.text(x, y, background, string.rep("▄", width)) + buffer.text(displayBarFrom, y, foreground, string.rep("▄", pipeSize)) +end + -- Отрисовка любого изображения в виде трехмерного массива. Неоптимизированно, зато просто. function buffer.customImage(x, y, pixels) x = x - 1 diff --git a/lib/filemanager.lua b/lib/filemanager.lua new file mode 100644 index 00000000..9fea99b8 --- /dev/null +++ b/lib/filemanager.lua @@ -0,0 +1,96 @@ + +_G.fs = require("filesystem") +_G.buffer = require("doubleBuffering") + +local filemanager = {} + +local massiv = { + { + name = "Root", + showContent = true, + content = { + { + name = "File1", + }, + { + name = "File2", + }, + { + name = "Folder1", + showContent = true, + content = { + { + name = "FileInFolder1", + }, + { + name = "FileInFolder2", + }, + { + name = "FolderInFolder1", + showContent = true, + content = { + { + name = "FileInFolderInFolder1", + }, + }, + }, + }, + }, + { + name = "File3", + }, + { + name = "File4", + }, + }, + }, +} + +filemanager.colors = { + background = 0xcccccc, + text = 0x262626, + scrollBar = 0x444444, + scrollBarPipe = 0x24c0ff, +} + +local function recursiveDraw(x, y, array) + for i = 1, #array do + + if array[i].content then + if array[i].showContent then + buffer.text(x, y, filemanager.colors.text, "∨ ▄ " .. array[i].name) + y = y + 1 + _, y = recursiveDraw(x + 2, y, array[i].content) + else + buffer.text(x, y, filemanager.colors.text, "> ▄ " .. array[i].name) + y = y + 1 + end + else + buffer.text(x, y, filemanager.colors.text, " • " .. array[i].name) + y = y + 1 + end + end + + return x, y +end + +function filemanager.draw(x, y, width, height, path, fromElement) + buffer.square(x, y, width, height, filemanager.colors.background, 0xFFFFFF, " ") + + buffer.setDrawLimit(x, y, width - 2, height) + recursiveDraw(x + 1, y, massiv) + buffer.resetDrawLimit() + + buffer.scrollBar(x + width - 1, y, 1, height, #massiv, 1, filemanager.colors.scrollBar, filemanager.colors.scrollBarPipe) +end + +return filemanager + + + + + + + + + diff --git a/lib/syntax.lua b/lib/syntax.lua index 4b95458d..fa282abb 100644 --- a/lib/syntax.lua +++ b/lib/syntax.lua @@ -1,6 +1,6 @@ -local gpu = require("component").gpu -local buffer = require("doubleBuffering") -local unicode = require("unicode") +_G.buffer = require("doubleBuffering") +_G.unicode = require("unicode") + local syntax = {} ---------------------------------------------------------------------------------------------------------------------------------------- @@ -179,36 +179,41 @@ end function syntax.convertFileToStrings(path) local array = {} + local maximumStringWidth = 0 local file = io.open(path, "r") for line in file:lines() do line = string.gsub(line, " ", string.rep(" ", 4)) + maximumStringWidth = math.max(maximumStringWidth, unicode.len(line)) table.insert(array, line) end file:close() - return array + return array, maximumStringWidth end -- Открыть окно-просмотрщик кода -function syntax.viewCode(x, y, width, height, strings, fromSymbol, fromString, highlightLuaSyntax, selection, highlightedStrings) +function syntax.viewCode(x, y, width, height, strings, maximumStringWidth, fromSymbol, fromString, highlightLuaSyntax, selection, highlightedStrings) --Рассчитываем максимальное количество строк, которое мы будем отображать local maximumNumberOfAvailableStrings, yPos if strings[fromString + height - 1] then - maximumNumberOfAvailableStrings = fromString + height - 1 + maximumNumberOfAvailableStrings = fromString + height - 2 else - maximumNumberOfAvailableStrings = #strings + maximumNumberOfAvailableStrings = #strings - 1 end --Рассчитываем ширину полоски с номерами строк local widthOfStringCounter = unicode.len(maximumNumberOfAvailableStrings) + 2 --Рассчитываем стратовую позицию текстового поля local textFieldPosition = x + widthOfStringCounter local widthOfText = width - widthOfStringCounter - 3 + local xEnd, yEnd = x + width - 1, y + height - 1 --Рисуем подложку под текст - buffer.square(textFieldPosition, y, width - widthOfStringCounter - 1, height, currentColorScheme.background, 0xFFFFFF, " ") - --Рисуем скроллбар - buffer.scrollBar(x + width - 1, y, 1, height, #strings, fromString, currentColorScheme.scrollBar, currentColorScheme.scrollBarPipe) - --Рисуем номера строк + buffer.square(x, y, width, height, currentColorScheme.background, 0xFFFFFF, " ") + --Рисуем подложку под номера строк buffer.square(x, y, widthOfStringCounter, height, currentColorScheme.lineNumbers, 0xFFFFFF, " ") + --Рисуем вертикальный скроллбар + buffer.scrollBar(xEnd, y, 1, height, #strings, fromString, currentColorScheme.scrollBar, currentColorScheme.scrollBarPipe) + --Рисуем горизонтальный скроллбар + buffer.horizontalScrollBar(x + widthOfStringCounter, yEnd, width - widthOfStringCounter - 1, maximumStringWidth, fromSymbol, currentColorScheme.scrollBar, currentColorScheme.scrollBarPipe) --Подсвечиваем некоторые строки, если указано if highlightedStrings then @@ -220,6 +225,7 @@ function syntax.viewCode(x, y, width, height, strings, fromSymbol, fromString, h end end + --Рисуем номера строк yPos = y for i = fromString, maximumNumberOfAvailableStrings do buffer.text(x + widthOfStringCounter - unicode.len(i) - 1, yPos, currentColorScheme.text, tostring(i)) @@ -276,8 +282,6 @@ function syntax.viewCode(x, y, width, height, strings, fromSymbol, fromString, h yPos = yPos + 1 end - --Рисуем изменения из буфера - buffer.draw() --Убираем ограничение отрисовки buffer.resetDrawLimit() @@ -290,7 +294,7 @@ end syntax.setColorScheme(syntax.colorSchemes.midnight) -- -- Епты бля! --- local strings = syntax.convertFileToStrings("MineOS/Applications/Highlight.app/Resources/TestFile.txt") +-- local strings, maximumStringWidth = syntax.convertFileToStrings("MineOS/Applications/Highlight.app/Resources/TestFile.txt") -- local strings = syntax.convertFileToStrings("OS.lua") -- local xSize, ySize = gpu.getResolution() @@ -307,7 +311,7 @@ syntax.setColorScheme(syntax.colorSchemes.midnight) -- {number = 32, color = 0xFF4444}, -- } --- syntax.viewCode(20, 5, 100, 40, strings, 1, 20, true, selection, highlightedStrings) +-- syntax.viewCode(20, 5, 100, 40, strings, maximumStringWidth, 1, 20, true, selection, highlightedStrings) ----------------------------------------------------------------------------------------------------------------