Edit.lua v1.2.2 - Fixed files with ANSI codes to show up formatted.

This commit is contained in:
Ponali
2025-07-16 10:07:08 +02:00
parent c6aa57983a
commit 2965d62655
2 changed files with 27 additions and 17 deletions
+1 -1
View File
@@ -84,7 +84,7 @@ local agcfg = {
}, },
["edit"] = { ["edit"] = {
["maindir"] = "", ["maindir"] = "",
["version"] = "1.2.1", ["version"] = "1.2.2",
["description"] = "The default text editor for Halyde.", ["description"] = "The default text editor for Halyde.",
["files"] = { ["files"] = {
"halyde/apps/edit.lua", "halyde/apps/edit.lua",
+26 -16
View File
@@ -64,16 +64,16 @@ local function render()
realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2) realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2)
end end
for i = scrollPosY, height + scrollPosY - 3 do for i = scrollPosY, height + scrollPosY - 3 do
rawset(1, i - scrollPosY + 1, (tmpdata[i] or ""):sub(scrollPosX)) gpu.set(1, i - scrollPosY + 1, (tmpdata[i] or ""):sub(scrollPosX))
end end
rawset(1, height - 1, "\27[107m\27[30m" .. filestring .. string.rep(" ", width)) rawset(1, height - 1, "\27[107m\27[30m" .. filestring .. string.rep(" ", width))
rawset(1, height, "\27[107m\27[30m^X\27[0m Exit \27[107m\27[30m^S\27[0m Save" .. string.rep(" ", width)) rawset(1, height, "\27[107m\27[30m^X\27[0m Exit \27[107m\27[30m^S\27[0m Save" .. string.rep(" ", width))
local char = gpu.get(realCursorX, cursorPosY) local char = gpu.get(realCursorX, cursorPosY)
if cursorWhite then if cursorWhite then
rawset(realCursorX, cursorPosY, "\27[107m\27[30m" .. char .. "\27[0m") gpu.setForeground(0)
else gpu.setBackground(0xFFFFFF)
rawset(realCursorX, cursorPosY, char)
end end
gpu.set(realCursorX, cursorPosY, char)
gpu.bitblt() gpu.bitblt()
gpu.setActiveBuffer(0) gpu.setActiveBuffer(0)
end end
@@ -210,7 +210,7 @@ local function processEvent(args)
scrollPosX = scrollPosX - 1 scrollPosX = scrollPosX - 1
renderFlag = true renderFlag = true
else else
rawset(1, cursorPosY, tmpdata[cursorPosY + scrollPosY - 1]:sub(scrollPosX) .. " ") gpu.set(1, cursorPosY, tmpdata[cursorPosY + scrollPosY - 1]:sub(scrollPosX) .. " ")
end end
end end
end end
@@ -225,7 +225,7 @@ local function processEvent(args)
cursorPosX = width cursorPosX = width
renderFlag = true renderFlag = true
else else
rawset(1, cursorPosY, tmpdata[cursorPosY + scrollPosY - 1]:sub(scrollPosX)) gpu.set(1, cursorPosY, tmpdata[cursorPosY + scrollPosY - 1]:sub(scrollPosX))
end end
end end
if args[3] >= 32 and args[3] <= 126 then if args[3] >= 32 and args[3] <= 126 then
@@ -240,7 +240,7 @@ local function processEvent(args)
scrollPosX = scrollPosX + 1 scrollPosX = scrollPosX + 1
renderFlag = true renderFlag = true
else else
rawset(1, cursorPosY, tmpdata[cursorPosY + scrollPosY - 1]:sub(scrollPosX)) gpu.set(1, cursorPosY, tmpdata[cursorPosY + scrollPosY - 1]:sub(scrollPosX))
end end
end end
elseif args[1] == "scroll" then elseif args[1] == "scroll" then
@@ -258,15 +258,21 @@ local function processEvent(args)
end end
local function save() local function save()
rawset(1, height - 1, "\27[107m\27[30m" .. string.rep(" ", width)) gpu.setBackground(0xFFFFFF)
gpu.setForeground(0)
gpu.set(1, height - 1, string.rep(" ", width))
termlib.cursorPosX = 1 termlib.cursorPosX = 1
termlib.cursorPosY = height - 1 termlib.cursorPosY = height - 1
local savepath = read(nil, "\27[107m\27[30mSave location: ", filepath) local savepath = read(nil, "\27[107m\27[30mSave location: ", filepath)
gpu.setBackground(0xFFFFFF)
gpu.setForeground(0)
if fs.exists(savepath) then if fs.exists(savepath) then
rawset(1, height - 1, "\27[107m\27[30m" .. string.rep(" ", width)) gpu.set(1, height - 1, string.rep(" ", width))
local answer = read(nil, "\27[107m\27[30mFile already exists. Overwrite it? [Y/n] ") local answer = read(nil, "\27[107m\27[30mFile already exists. Overwrite it? [Y/n] ")
if answer:lower() == "n" then if answer:lower() == "n" then
rawset(1, height - 1, "\27[107m\27[30m" .. filestring .. string.rep(" ", width)) gpu.setBackground(0xFFFFFF)
gpu.setForeground(0)
gpu.set(1, height - 1, filestring .. string.rep(" ", width))
return return
end end
end end
@@ -278,9 +284,9 @@ local function save()
handle:write(table.concat(tmpdata, "\n") .. "\n") -- add a newline at the end to follow POSIX standards handle:write(table.concat(tmpdata, "\n") .. "\n") -- add a newline at the end to follow POSIX standards
end end
handle:close() handle:close()
rawset(1, height - 1, "\27[107m\27[30m" .. filestring .. string.rep(" ", width)) gpu.set(1, height - 1, filestring .. string.rep(" ", width))
else else
rawset(1, height - 1, "\27[107m\27[30mERROR: " .. errorMessage:gsub("\n", "") .. string.rep(" ", width)) gpu.set(1, height - 1, "ERROR: " .. errorMessage:gsub("\n", "") .. string.rep(" ", width))
end end
changesMade = false changesMade = false
end end
@@ -321,7 +327,7 @@ while true do
end end
if cursorRenderFlag then if cursorRenderFlag then
local char = gpu.get(previousCursorX, previousCursorY) local char = gpu.get(previousCursorX, previousCursorY)
rawset(previousCursorX, previousCursorY, char) gpu.set(previousCursorX, previousCursorY, char)
local realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2) local realCursorX = math.min(cursorPosX, unicode.wlen(tmpdata[cursorPosY + scrollPosY - 1]) - scrollPosX + 2)
if realCursorX < 1 then if realCursorX < 1 then
scrollPosX = scrollPosX + realCursorX - 1 scrollPosX = scrollPosX + realCursorX - 1
@@ -330,9 +336,13 @@ while true do
end end
local char = gpu.get(realCursorX, cursorPosY) local char = gpu.get(realCursorX, cursorPosY)
if cursorWhite then if cursorWhite then
rawset(realCursorX, cursorPosY, "\27[107m\27[30m" .. char .. "\27[0m") gpu.setBackground(0xFFFFFF)
else gpu.setForeground(0)
rawset(realCursorX, cursorPosY, char) end
gpu.set(realCursorX, cursorPosY, char)
if cursorWhite then
gpu.setForeground(0xFFFFFF)
gpu.setBackground(0)
end end
end end
if renderFlag then if renderFlag then