Make edit display errors/results of execution and handle require. (#723)
This commit is contained in:
parent
8f3ea60c74
commit
1f70ed6985
|
@ -47,6 +47,30 @@ else
|
||||||
stringColour = colours.white
|
stringColour = colours.white
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local runHandler = [[multishell.setTitle(multishell.getCurrent(), %q)
|
||||||
|
local current = term.current()
|
||||||
|
local ok, err = load(%q, %q, nil, _ENV)
|
||||||
|
if ok then ok, err = pcall(ok, ...) end
|
||||||
|
term.redirect(current)
|
||||||
|
term.setTextColor(term.isColour() and colours.yellow or colours.white)
|
||||||
|
term.setBackgroundColor(colours.black)
|
||||||
|
term.setCursorBlink(false)
|
||||||
|
local _, y = term.getCursorPos()
|
||||||
|
local _, h = term.getSize()
|
||||||
|
if not ok then
|
||||||
|
printError(err)
|
||||||
|
end
|
||||||
|
if ok and y >= h then
|
||||||
|
term.scroll(1)
|
||||||
|
end
|
||||||
|
term.setCursorPos(1, h)
|
||||||
|
if ok then
|
||||||
|
write("Program finished. ")
|
||||||
|
end
|
||||||
|
write("Press any key to continue")
|
||||||
|
os.pullEvent('key')
|
||||||
|
]]
|
||||||
|
|
||||||
-- Menus
|
-- Menus
|
||||||
local bMenu = false
|
local bMenu = false
|
||||||
local nMenuItem = 1
|
local nMenuItem = 1
|
||||||
|
@ -89,7 +113,7 @@ local function load(_sPath)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function save(_sPath)
|
local function save(_sPath, fWrite)
|
||||||
-- Create intervening folder
|
-- Create intervening folder
|
||||||
local sDir = _sPath:sub(1, _sPath:len() - fs.getName(_sPath):len())
|
local sDir = _sPath:sub(1, _sPath:len() - fs.getName(_sPath):len())
|
||||||
if not fs.exists(sDir) then
|
if not fs.exists(sDir) then
|
||||||
|
@ -101,8 +125,8 @@ local function save(_sPath)
|
||||||
local function innerSave()
|
local function innerSave()
|
||||||
file, fileerr = fs.open(_sPath, "w")
|
file, fileerr = fs.open(_sPath, "w")
|
||||||
if file then
|
if file then
|
||||||
for _, sLine in ipairs(tLines) do
|
if file then
|
||||||
file.write(sLine .. "\n")
|
fWrite(file)
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
error("Failed to open " .. _sPath)
|
error("Failed to open " .. _sPath)
|
||||||
|
@ -293,7 +317,11 @@ local tMenuFuncs = {
|
||||||
if bReadOnly then
|
if bReadOnly then
|
||||||
sStatus = "Access denied"
|
sStatus = "Access denied"
|
||||||
else
|
else
|
||||||
local ok, _, fileerr = save(sPath)
|
local ok, _, fileerr = save(sPath, function(file)
|
||||||
|
for _, sLine in ipairs(tLines) do
|
||||||
|
file.write(sLine .. "\n")
|
||||||
|
end
|
||||||
|
end)
|
||||||
if ok then
|
if ok then
|
||||||
sStatus = "Saved to " .. sPath
|
sStatus = "Saved to " .. sPath
|
||||||
else
|
else
|
||||||
|
@ -390,8 +418,18 @@ local tMenuFuncs = {
|
||||||
bRunning = false
|
bRunning = false
|
||||||
end,
|
end,
|
||||||
Run = function()
|
Run = function()
|
||||||
local sTempPath = "/.temp"
|
local sTitle = fs.getName(sPath)
|
||||||
local ok = save(sTempPath)
|
if sTitle:sub(-4) == ".lua" then
|
||||||
|
sTitle = sTitle:sub(1, -5)
|
||||||
|
end
|
||||||
|
local sTempPath = bReadOnly and ".temp." .. sTitle or fs.combine(fs.getDir(sPath), ".temp." .. sTitle)
|
||||||
|
if fs.exists(sTempPath) then
|
||||||
|
sStatus = "Error saving to " .. sTempPath
|
||||||
|
return
|
||||||
|
end
|
||||||
|
local ok = save(sTempPath, function(file)
|
||||||
|
file.write(runHandler:format(sTitle, table.concat(tLines, "\n"), "@" .. fs.getName(sPath)))
|
||||||
|
end)
|
||||||
if ok then
|
if ok then
|
||||||
local nTask = shell.openTab(sTempPath)
|
local nTask = shell.openTab(sTempPath)
|
||||||
if nTask then
|
if nTask then
|
||||||
|
|
Loading…
Reference in New Issue