Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = {...}
- local w, h = term.getSize()
- local lChanged = false
- local pChanged = true
- local numlength = 1
- local type = 1
- local tabNum = 0
- local mode = "edit"
- local clickStart, clickEnd, prevline, currentLine, currentPos
- local cTables = {}
- cComTab = {}
- local program = {}
- local colTab = {}
- if mode == "edit" then
- colTab[1] = colors.lightGray
- colTab[2] = colors.green
- colTab[3] = colors.red
- colTab[4] = colors.orange
- colTab[5] = colors.lightBlue
- colTab[6] = colors.white
- elseif mode == "read" then
- colTab[1] = colors.white
- colTab[2] = colors.white
- colTab[3] = colors.white
- colTab[4] = colors.white
- colTab[5] = colors.white
- colTab[6] = colors.white
- end
- local location = {
- ["x"] = 1,
- ["y"] = 1
- }
- local position = {
- ["x"] = 1,
- ["y"] = 1
- }
- local conditionals = {
- ["if"] = {"end", colors.red, colors.pink},
- ["while"] = {"end", colors.red, colors.pink},
- ["for"] = {"end", colors.red, colors.pink},
- ["function"] = {"end", colors.red, colors.pink}
- }
- local keywords = {
- ["if"] = colors.yellow,
- ["then"] = colors.yellow,
- ["else"] = colors.yellow,
- ["elseif"] = colors.yellow,
- ["end"] = colors.yellow,
- ["function"] = colors.yellow,
- ["while"] = colors.yellow,
- ["for"] = colors.yellow,
- ["in"] = colors.yellow,
- ["do"] = colors.yellow,
- ["local"] = colors.yellow,
- ["repeat"] = colors.yellow,
- ["until"] = colors.yellow,
- ["next"] = colors.yellow,
- ["and"] = colors.orange,
- ["or"] = colors.orange,
- ["not"] = colors.orange,
- ["true"] = colors.orange,
- ["false"] = colors.orange,
- ["nil"] = colors.gray,
- ["break"] = colors.purple,
- ["return"] = colors.purple,
- ["print"] = colors.pink,
- ["write"] = colors.pink,
- ["pairs"] = colors.pink,
- ["ipairs"] = colors.pink,
- ["type"] = colors.blue,
- ["tostring"] = colors.blue,
- ["tonumber"] = colors.blue,
- ["assert"] = colors.blue,
- ["setmetatable"] = colors.blue
- }
- if tArgs[1] and fs.exists(tArgs[1]) then
- for line in io.lines(tArgs[1]) do
- program[#program + 1] = tostring(line)
- program[#program] = program[#program]:gsub(" ", "$___")
- end
- if #program == 0 then
- program[1] = ""
- end
- elseif tArgs[1] then
- program[1] = ""
- end
- local function draw(string, xPos, yPos, txtcol, bakcol)
- local string = string or ""
- local txtcol = txtcol or colors.white
- local bakcol = bakcol or colors.black
- term.setCursorPos(xPos, yPos)
- term.setBackgroundColor(bakcol)
- term.setTextColor(txtcol)
- term.write(string)
- end
- local function codeDraw(string, xPos, yPos)
- local string = string or ""
- local xPos = xPos - location["x"] + 1
- local sStart, sEnd = 1, 1 + w - numlength
- local tabDraw = true
- local multiComment = false
- while #string > 0 and xPos <= sEnd do
- for i in pairs(cComTab) do
- if mode == "edit" then --and yPos >= cComTab[i][1][2] and yPos <= cComTab[i][2][2] then
- if not multiComment and (yPos-1 == cComTab[i][1][2]-location["y"] + 1 and xPos-3 >= cComTab[i][1][1]-location["x"] + 1) or (yPos-1 == cComTab[i][2][2]-location["y"]+1 and xPos-2 <= cComTab[i][2][1]-location["x"]+1) or (yPos-1 > cComTab[i][1][2]-location["y"]+1 and yPos-1 < cComTab[i][2][2]-location["y"]+1) then
- colTab[1] = colors.green
- colTab[2] = colors.green
- colTab[3] = colors.green
- colTab[4] = colors.green
- colTab[5] = colors.green
- colTab[6] = colors.green
- multiComment = true
- break
- elseif multiComment then
- colTab[1] = colors.lightGray
- colTab[2] = colors.green
- colTab[3] = colors.red
- colTab[4] = colors.orange
- colTab[5] = colors.lightBlue
- colTab[6] = colors.white
- multiComment = false
- end
- end
- end
- if string:find("^%$___") then
- local _, en = string:find("^%$___")
- if en >= sStart and xPos <= sEnd then
- if tabDraw and not multiComment then
- draw(" |", xPos, yPos, colTab[1], colors.black)
- else
- draw(" ", xPos, yPos, colTab[1], colors.black)
- end
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^%-%-.*") then
- tabDraw = false
- local _, en = string:find("^%-%-.*")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[2], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^\".-[^\\]\"") then
- tabDraw = false
- local _, en = string:find("^\".-[^\\]\"")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[3], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^\'.-[^\\]\'") then
- tabDraw = false
- local _, en = string:find("^\'.-[^\\]\'")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[3], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^\"\"") then
- tabDraw = false
- local _, en = string:find("^\"\"")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[3], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^\'\'") then
- tabDraw = false
- local _, en = string:find("^\'\'")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[3], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^%[%[.-%]%]") then
- tabDraw = false
- local _, en = string:find("^%[%[.-%]%]")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[3], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^%d+") then
- tabDraw = false
- local _, en = string:find("^%d+")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[4], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^%p") then
- tabDraw = false
- local _, en = string:find("^%p")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[5], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^[%a_]+") then
- tabDraw = false
- local _, en = string:find("^[%a_]+")
- local test = string:sub(1, en)
- local color = colors.white
- if keywords[test] and mode == "edit" then
- color = keywords[test]
- end
- if multiComment then
- color = colors.green
- end
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, color, colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- elseif string:find("^[^%w_]") then
- tabDraw = false
- local _, en = string:find("^[^%w_]")
- if en >= sStart and xPos <= sEnd then
- draw(string:sub(1, en), xPos, yPos, colTab[6], colors.black)
- end
- string = string:sub(en + 1)
- xPos = xPos + en
- end
- end
- end
- local function printMenu()
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- draw("Press CTRL for menu...", 1, 1, colors.gray, colors.lightGray)
- end
- local function saveFile(codeTable, filename)
- local tempFile = {}
- for i, v in ipairs(codeTable) do
- tempFile[i] = v:gsub("$___", " ")
- end
- local sFile = fs.open(filename, "w")
- for _, v in ipairs(tempFile) do
- sFile.writeLine(v)
- end
- sFile.close()
- end
- local function showProgram()
- multiComment = false
- numlength = #tostring(#program - location["y"] + 1 >= h and location["y"] + h - 1 or #program)
- for y = location["y"], #program - location["y"] + 1 >= h - 1 and location["y"] + h - 2 or #program do
- codeDraw(program[y], 1 + numlength, y - location["y"] + 2)
- end
- end
- local function showProgramLine(line)
- numlength = #tostring(#program - location["y"] + 1 >= h and location["y"] + h - 1 or #program)
- codeDraw(program[line], 1 + numlength, line - location["y"] + 2)
- end
- local function showNumbers()
- local activeLoops = {}
- local up, down
- for _, v in pairs(cTables) do
- if currentLine >= v[1] and currentLine <= v[2] then
- activeLoops[#activeLoops + 1] = {v[1], v[2]}
- end
- end
- if #activeLoops > 0 then
- local key, mini = 0, #program
- for i, v in pairs(activeLoops) do
- if v[2] - v[1] < mini then
- key, mini = i, v[2] - v[1]
- end
- end
- if key > 0 then
- up, down = activeLoops[key][1], activeLoops[key][2]
- end
- end
- for y = location["y"], #program - location["y"] + 1 >= h - 1 and location["y"] + h - 2 or #program do
- local text, back = colors.gray, colors.lightGray
- if up and down and y > up and y < down then
- text, back = colors.red, colors.pink
- elseif up and down and (y == up or y == down) then
- text, back = colors.pink, colors.red
- end
- draw(tostring(y), 1, y - location["y"] + 2, text, back)
- if #tostring(y) < numlength then
- write(" ")
- end
- end
- end
- local function checkParenthises()
- local posChar = program[position["y"] + location["y"] - 1]:sub(position["x"] + location["x"] - 1, position["x"] + location["x"] - 1)
- local str = program[position["y"] + location["y"] - 1]
- local strlen = #str
- local startPos = position["x"] + location["x"] - 1
- local endPos, endChar
- if posChar == "(" or posChar == "[" or posChar == "{" then
- str = str:sub(startPos)
- if str:find("^%b()") then
- _, endPos = str:find("^%b()")
- endChar = ")"
- elseif str:find("^%b[]") then
- _, endPos = str:find("^%b[]")
- endChar = "]"
- elseif str:find("^%b{}") then
- _, endPos = str:find("^%b{}")
- endChar = "}"
- end
- if endPos then
- draw(posChar, position["x"] + numlength, position["y"] + 1, colors.blue, colors.lightBlue)
- if startPos + endPos + numlength - location["x"] <= w - numlength then
- draw(endChar, startPos + endPos + numlength - location["x"], position["y"] + 1, colors.blue, colors.lightBlue)
- end
- end
- return position["y"] + location["y"] - 1
- elseif posChar == ")" or posChar == "]" or posChar == "}" then
- str = str:reverse()
- startPos = #str - startPos + 1
- str = str:sub(startPos)
- if str:find("^%b)(") then
- _, endPos = str:find("^%b)(")
- endChar = "("
- elseif str:find("^%b][") then
- _, endPos = str:find("^%b][")
- endChar = "["
- elseif str:find("^%b}{") then
- _, endPos = str:find("^%b}{")
- endChar = "{"
- end
- if endPos then
- endPos = strlen - endPos + 1
- draw(posChar, position["x"] + numlength, position["y"] + 1, colors.blue, colors.lightBlue)
- if startPos + endPos + numlength - location["x"] <= w - numlength then
- draw(endChar, endPos - startPos + numlength - location["x"] + 2, position["y"] + 1, colors.blue, colors.lightBlue)
- end
- end
- return position["y"] + location["y"] - 1
- end
- return nil
- end
- local function checkConditionals()
- local cWords = {}
- local active = false
- local cancelNum = 0
- local cConditional = {}
- for y = 1, #program do
- for i in pairs(conditionals) do
- local test = program[y]:gsub(" ", "")
- local st = test:find(i)
- local _, en = program[y]:find(i)
- if st and en then
- if st == 1 and (en == #program[y] or program[y]:sub(en + 1, en + 1) == " ") then
- cWords[#cWords + 1] = {}
- cWords[#cWords][1] = y
- cancelNum = cancelNum + 1
- cConditional[cancelNum] = #cWords
- active = true
- end
- end
- end
- if active and program[y]:find("end") then
- cWords[cConditional[cancelNum]][2] = y
- cancelNum = cancelNum - 1
- if cancelNum == 0 then
- active = false
- if y > location["y"] + h - 2 then
- break
- end
- end
- end
- end
- local rem = {}
- for i = 1, #cWords do
- if not (cWords[i][1] and cWords[i][2]) then
- rem[#rem + 1] = i
- end
- end
- for i, v in pairs(rem) do
- table.remove(cWords, v - i + 1)
- end
- return cWords
- end
- function checkMultiComments()
- local cComments = {}
- local active = false
- local cancelNum = 0
- local cConditional = {}
- for y = 1, #program do
- if program[y]:find("%-%-%[%[") and not active then
- active = true
- local st = program[y]:find("%-%-%[%[")
- cComments[#cComments + 1] = {}
- cComments[#cComments][1]= {st, y}
- elseif program[y]:find("%]%]") and active then
- active = false
- local _, en = program[y]:find("%]%]")
- cComments[#cComments][2] = {en, y}
- end
- end
- local rem = {}
- for i = 1, #cComments do
- if #cComments[i] < 2 then
- rem[#rem + 1] = i
- end
- end
- for i, v in pairs(rem) do
- table.remove(cComments, v - i + 1)
- end
- return cComments
- end
- local function addLetter(char, str, pos)
- return str:sub(0, pos - 1) .. tostring(char) .. str:sub(pos)
- end
- local function removeLetter(str, pos)
- return str:sub(0, pos) .. str:sub(pos + 2)
- end
- term.setCursorBlink(true)
- while true do
- currentLine = location["y"] + position["y"] - 1
- currentPos = position["x"] + location["x"] - 1
- local dollarNum
- if program[currentLine]:sub(currentPos, currentPos) == "_" then
- for i = 1, 3 do
- if program[currentLine]:sub(currentPos - i, currentPos - i) ~= "_" then
- if program[currentLine]:sub(currentPos - i, currentPos - i) == "$" then
- dollarNum = i
- break
- end
- break
- end
- end
- if dollarNum and dollarNum < 3 then
- for i = 1, 3 - dollarNum do
- if program[currentLine]:sub(currentPos + i, currentPos + i) ~= "_" then
- dollarNum = nil
- break
- end
- end
- end
- if dollarNum then
- position["x"] = position["x"] - numlength - dollarNum + 1
- if position["x"] < 1 then
- location["x"] = location["x"] + position["x"] - 1
- position["x"] = 1
- pChanged = true
- end
- end
- end
- if mode == "edit" then
- numlength = #tostring(#program - location["y"] + 1 >= h and location["y"] + h - 1 or #program)
- elseif mode == "read" then
- numlength = 0
- end
- if mode == "read" and location["x"] < 3 then
- location["x"] = 3
- elseif mode == "edit" and location["x"] < 1 then
- location["x"] = 1
- end
- currentLine = location["y"] + position["y"] - 1
- currentPos = position["x"] + location["x"] - 1
- cComTab = checkMultiComments()
- if pChanged or program[currentLine]:sub(currentPos - 2, currentPos - 1) == "]]" then
- cTables = checkConditionals()
- term.setBackgroundColor(colors.black)
- term.clear()
- showProgram()
- pChanged = false
- lChanged = false
- elseif lChanged then
- cTables = checkConditionals()
- term.setBackgroundColor(colors.black)
- term.clearLine()
- showProgramLine(currentLine)
- lChanged = false
- end
- if mode == "edit" then
- showNumbers()
- end
- printMenu()
- if prevline then
- showProgramLine(prevline)
- end
- if mode == "edit" then
- prevline = checkParenthises()
- end
- term.setTextColor(colors.white)
- term.setCursorPos(position["x"] + numlength, position["y"] + 1)
- local events = {os.pullEvent()}
- if events[1] == "char" and mode == "edit" then
- lChanged = true
- program[currentLine] = addLetter(events[2], program[currentLine], position["x"] + location["x"] - 1)
- if position["x"] < w - #tostring(currentLine) then
- position["x"] = position["x"] + 1
- elseif position["x"] == w - #tostring(currentLine) then
- pChanged = true
- location["x"] = location["x"] + 1
- position["x"] = w - #tostring(currentLine)
- end
- elseif events[1] == "key" then
- if events[2] == keys.up then
- if position["y"] > 1 then
- position["y"] = position["y"] - 1
- elseif location["y"] > 1 and position["y"] == 1 then
- pChanged = true
- location["y"] = location["y"] - 1
- position["y"] = 1
- end
- if currentLine > 1 then
- local temp = location["x"]
- location["x"] = location["x"] > #program[currentLine - 1] and #program[currentLine - 1] + 1 or location["x"]
- position["x"] = math.min(#program[currentLine - 1] + 1, position["x"] + location["x"] - 1) - location["x"] + 1
- if temp ~= location["x"] then
- pChanged = true
- end
- end
- elseif events[2] == keys.right then
- if (position["x"] + location["x"] - 1) % 4 == 1 and position["x"] + location["x"] - 1 < #program[currentLine] and program[currentLine]:sub(position["x"] + location["x"] - 1, position["x"] + location["x"] + 2) == "$___" then
- position["x"] = position["x"] + 4
- if position["x"] > w - numlength then
- location["x"] = location["x"] + position["x"] - (w - numlength)
- position["x"] = 1
- pChanged = true
- end
- elseif location["x"] + position["x"] - 1 <= #program[currentLine] and position["x"] < w - numlength then
- position["x"] = position["x"] + 1
- elseif location["x"] + position["x"] - 1 <= #program[currentLine] and position["x"] == w - numlength then
- pChanged = true
- location["x"] = location["x"] + 1
- elseif location["x"] + position["x"] - 1 > #program[currentLine] and currentLine < #program then
- if location["x"] ~= 1 then
- location["x"] = 1
- pChanged = true
- end
- position["x"] = 1
- if position["y"] < h - 1 then
- position["y"] = position["y"] + 1
- elseif position["y"] == h - 1 then
- pChanged = true
- location["y"] = location["y"] + 1
- position["y"] = h - 1
- end
- end
- elseif events[2] == keys.down then
- if currentLine < #program and position["y"] < h - 1 then
- position["y"] = position["y"] + 1
- elseif currentLine < #program and position["y"] == h - 1 then
- pChanged = true
- location["y"] = location["y"] + 1
- position["y"] = h - 1
- end
- if currentLine + 1 <= #program then
- local temp = location["x"]
- location["x"] = location["x"] > #program[currentLine + 1] and #program[currentLine + 1] + 1 or location["x"]
- position["x"] = math.min(#program[currentLine + 1] + 1, position["x"] + location["x"] - 1) - location["x"] + 1
- if temp ~= location["x"] then
- pChanged = true
- end
- end
- elseif events[2] == keys.left then
- if (position["x"] + location["x"] - 1) % 4 == 1 and position["x"] + location["x"] - 1 > 4 and program[currentLine]:sub(position["x"] + location["x"] - 5, position["x"] + location["x"] - 2) == "$___" then
- position["x"] = position["x"] - 4
- if position["x"] < 1 then
- location["x"] = location["x"] + position["x"] - 1
- position["x"] = 1
- pChanged = true
- end
- elseif position["x"] > 1 then
- position["x"] = position["x"] - 1
- elseif location["x"] > 1 then
- pChanged = true
- location["x"] = location["x"] - 1
- elseif location["x"] + position["x"] - 1 == 1 and currentLine > 1 then
- if position["y"] > 1 then
- position["y"] = position["y"] - 1
- elseif location["y"] > 1 then
- location["y"] = location["y"] - 1
- position["y"] = 1
- pChanged = true
- end
- local temp = location["x"]
- location["x"] = location["x"] + w - numlength < #program[currentLine - 1] and #program[currentLine - 1] + numlength - w + 2 or location["x"]
- position["x"] = #program[currentLine - 1] - location["x"] + 2
- if temp ~= location["x"] then
- pChanged = true
- end
- end
- end
- if events[2] == keys.backspace and mode == "edit" then
- lChanged = true
- if (position["x"] + location["x"] - 1) % 4 == 1 and position["x"] + location["x"] - 1 > 4 and program[currentLine]:sub(position["x"] + location["x"] - 5, position["x"] + location["x"] - 2) == "$___" then
- for i = 1, 4 do
- program[currentLine] = removeLetter(program[currentLine], location["x"] + position["x"] - 6)
- end
- position["x"] = position["x"] - 4
- tabNum = tabNum - 1
- if position["x"] < 1 then
- location["x"] = location["x"] + position["x"] - 1
- position["x"] = 1
- pChanged = true
- end
- elseif position["x"] + location["x"] - 1 > 1 then
- program[currentLine] = removeLetter(program[currentLine], location["x"] + position["x"] - 3)
- if position["x"] > 1 then
- position["x"] = position["x"] - 1
- elseif location["x"] > 1 then
- pChanged = true
- location["x"] = location["x"] - 1
- end
- elseif currentLine > 1 then
- if position["y"] > 1 then
- position["y"] = position["y"] - 1
- elseif location["y"] > 1 and position["y"] == 1 then
- location["y"] = location["y"] - 1
- position["y"] = 1
- end
- location["x"] = (location["x"] > #program[currentLine - 1] or location["x"] + w - #tostring(currentLine - 1) < #program[currentLine - 1]) and #program[currentLine - 1] + 1 or location["x"]
- position["x"] = #program[currentLine - 1] - location["x"] + 2
- program[currentLine - 1] = program[currentLine - 1] .. (table.remove(program, currentLine))
- pChanged = true
- end
- end
- if events[2] == keys.enter and mode == "edit" then
- table.insert(program, currentLine + 1, program[currentLine]:sub(position["x"] + location["x"] - 1))
- program[currentLine] = program[currentLine]:sub(1, position["x"] + location["x"] - 2)
- program[currentLine + 1] = string.rep("$___", tabNum) .. program[currentLine + 1]
- if position["y"] < h - 1 then
- position["y"] = position["y"] + 1
- elseif position["y"] == h - 1 then
- location["y"] = location["y"] + 1
- position["y"] = h - 1
- end
- position["x"] = 1 + tabNum * 4
- location["x"] = position["x"] > w - numlength and location["x"] - (w - numlength) + 1 or 1
- pChanged = true
- end
- if events[2] == keys.tab and mode == "edit" then
- lChanged = true
- tabNum = tabNum + 1
- if (position["x"] + location["x"] - 1) % 4 == 1 then
- program[currentLine] = addLetter("$___", program[currentLine], position["x"] + location["x"] - 1)
- else
- local num = (position["x"] + location["x"] - 1) % 4 + 1
- if num == 4 then num = 2 end
- program[currentLine] = addLetter(string.rep(" ", num), program[currentLine], position["x"] + location["x"] - 1)
- end
- if position["x"] < w - #tostring(currentLine) - 3 - numlength then
- position["x"] = position["x"] + 4
- elseif position["x"] >= w - #tostring(currentLine) - 3 - numlength then
- pChanged = true
- location["x"] = location["x"] + 4
- position["x"] = w - #tostring(currentLine) - 3
- end
- end
- if events[2] == keys.leftCtrl then
- term.setCursorBlink(false)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- local broken = false
- while true do
- if type == 1 then
- draw("Save", 1, 1, colors.gray, colors.white)
- draw("Exit", 8, 1, colors.gray, colors.lightGray)
- draw("Funcs", 15, 1, colors.gray, colors.lightGray)
- elseif type == 2 then
- draw("Save", 1, 1, colors.gray, colors.lightGray)
- draw("Exit", 8, 1, colors.gray, colors.white)
- draw("Funcs", 15, 1, colors.gray, colors.lightGray)
- elseif type == 3 then
- draw("Save", 1, 1, colors.gray, colors.lightGray)
- draw("Exit", 8, 1, colors.gray, colors.lightGray)
- draw("Funcs", 15, 1, colors.gray, colors.white)
- end
- local events = {os.pullEvent()}
- if events[1] == "key" then
- if events[2] == keys.enter then
- if type == 1 then
- draw("Save", 1, 1, colors.gray, colors.yellow)
- saveFile(program, tArgs[1])
- sleep(.2)
- elseif type == 2 then
- draw("Exit", 8, 1, colors.gray, colors.yellow)
- broken = true
- sleep(.2)
- break
- elseif type == 3 then
- draw("Funcs", 15, 1, colors.gray, colors.yellow)
- sleep(.1)
- term.setCursorPos(1, 1)
- term.setBackgroundColor(colors.lightGray)
- term.clearLine()
- local choice = 1
- local brokenIn = false
- while true do
- if choice == 1 then
- draw("Move", 1, 1, colors.gray, colors.white)
- draw("Mode", 8, 1, colors.gray, colors.lightGray)
- elseif choice == 2 then
- draw("Move", 1, 1, colors.gray, colors.lightGray)
- draw("Mode", 8, 1, colors.gray, colors.white)
- end
- local events = {os.pullEvent()}
- if events[1] == "key" then
- if events[2] == keys.leftCtrl then
- break
- end
- if events[2] == keys.left then
- choice = choice - 1
- elseif events[2] == keys.right then
- choice = choice + 1
- end
- if choice == 3 then choice = 2 end
- if choice == 0 then choice = 1 end
- if events[2] == keys.enter then
- if choice == 1 then
- draw("Move", 1, 1, colors.gray, colors.yellow)
- draw(" ", 1, 2, colors.gray, colors.white)
- term.setCursorPos(1, 2)
- local line = read()
- if tonumber(line) and tonumber(line) > 0 then
- if tonumber(line) < #program - h + 2 then
- location["y"] = tonumber(line)
- else
- location["y"] = #program - h + 2
- end
- pChanged = true
- end
- brokenIn = true
- break
- elseif choice == 2 then
- pChanged = true
- draw("Mode", 8, 1, colors.gray, colors.yellow)
- local tempmode = mode
- while true do
- if mode == "edit" then
- draw("Edit", 8, 2, colors.white, colors.lime)
- draw("Read", 8, 3, colors.gray, colors.white)
- elseif mode == "read" then
- draw("Edit", 8, 2, colors.gray, colors.white)
- draw("Read", 8, 3, colors.white, colors.lime)
- end
- local events = {os.pullEvent()}
- if events[1] == "key" then
- if events[2] == keys.leftCtrl then
- break
- end
- if events[2] == keys.up then
- mode = "edit"
- elseif events[2] == keys.down then
- mode = "read"
- end
- if events[2] == keys.enter then
- if mode == "edit" and tempmode == "read" then
- location["x"] = 1
- end
- if mode == "edit" then
- colTab[1] = colors.lightGray
- colTab[2] = colors.green
- colTab[3] = colors.red
- colTab[4] = colors.orange
- colTab[5] = colors.lightBlue
- colTab[6] = colors.white
- elseif mode == "read" then
- colTab[1] = colors.white
- colTab[2] = colors.white
- colTab[3] = colors.white
- colTab[4] = colors.white
- colTab[5] = colors.white
- colTab[6] = colors.white
- end
- break
- end
- end
- end
- brokenIn = true
- break
- end
- end
- end
- end
- if brokenIn then break end
- end
- end
- if events[2] == keys.leftCtrl then
- break
- end
- if events[2] == keys.left then
- type = type - 1
- elseif events[2] == keys.right then
- type = type + 1
- end
- end
- if type == 4 then type = 3 end
- if type == 0 then type = 1 end
- end
- term.setCursorBlink(true)
- if broken then
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, 1)
- break
- end
- end
- end
- if events[1] == "mouse_click" and events[2] == 1 and #program >= events[4] + location["y"] - 2 and events[4] > 1 then
- local clickPosY, clickPosX = events[4] + location["y"] - 2, location["x"] + events[3] - numlength - 1
- local dollarNum
- if program[clickPosY]:sub(clickPosX, clickPosX) == "_" then
- for i = 1, 3 do
- if program[clickPosY]:sub(clickPosX - i, clickPosX - i) ~= "_" then
- if program[clickPosY]:sub(clickPosX - i, clickPosX - i) == "$" then
- dollarNum = i
- break
- end
- break
- end
- end
- if dollarNum and dollarNum < 3 then
- for i = 1, 3 - dollarNum do
- if program[clickPosY]:sub(clickPosX + i, clickPosX + i) ~= "_" then
- dollarNum = nil
- break
- end
- end
- end
- if dollarNum then
- position["y"] = events[4] - 1
- position["x"] = events[3] - numlength - dollarNum
- if position["x"] < 1 then
- location["x"] = location["x"] + position["x"] - 1
- position["x"] = 1
- pChanged = true
- end
- clickstart = {position["x"] + location["x"] - 1, position["y"] + location["y"] - 1}
- end
- else
- clickStart = {events[3] + location["x"] - 1, events[4] + location["y"] - 1}
- local temp = location["x"]
- position["y"] = events[4] - 1
- location["x"] = location["x"] - 1 > #program[events[4] + location["y"] - 2] and #program[events[4] + location["y"] - 2] + 1 or location["x"]
- position["x"] = math.min(#program[events[4] + location["y"] - 2] - location["x"] + 1, events[3] - numlength - 1) + 1
- if temp ~= location["x"] then
- pChanged = true
- end
- end
- elseif events[1] == "mouse_drag" and events[2] == 1 then
- clickEnd = {events[3] + location["x"] - 1, events[4] + location["y"] - 1}
- end
- if events[1] == "mouse_scroll" then
- if location["y"] >= 1 and location["y"] <= #program - h + 3 then
- location["y"] = location["y"] + events[2]
- pChanged = true
- end
- if location["y"] == 0 then location["y"] = 1 end
- if location["y"] == #program - h + 3 then location["y"] = #program - h + 2 end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement