1
0
mirror of https://github.com/SquidDev-CC/CC-Tweaked synced 2024-06-25 22:53:22 +00:00

Make errors messages in edit more obvious

See #1222.
This commit is contained in:
Jonathan Coates 2023-01-17 21:43:26 +00:00
parent 67244b17af
commit 8cfbfe7ceb
No known key found for this signature in database
GPG Key ID: B9E431FF07C98D06

View File

@ -30,7 +30,7 @@ local tLines = {}
local bRunning = true local bRunning = true
-- Colours -- Colours
local highlightColour, keywordColour, commentColour, textColour, bgColour, stringColour local highlightColour, keywordColour, commentColour, textColour, bgColour, stringColour, errorColour
if term.isColour() then if term.isColour() then
bgColour = colours.black bgColour = colours.black
textColour = colours.white textColour = colours.white
@ -38,6 +38,7 @@ if term.isColour() then
keywordColour = colours.yellow keywordColour = colours.yellow
commentColour = colours.green commentColour = colours.green
stringColour = colours.red stringColour = colours.red
errorColour = colours.red
else else
bgColour = colours.black bgColour = colours.black
textColour = colours.white textColour = colours.white
@ -45,6 +46,7 @@ else
keywordColour = colours.white keywordColour = colours.white
commentColour = colours.white commentColour = colours.white
stringColour = colours.white stringColour = colours.white
errorColour = colours.white
end end
local runHandler = [[multishell.setTitle(multishell.getCurrent(), %q) local runHandler = [[multishell.setTitle(multishell.getCurrent(), %q)
@ -89,14 +91,27 @@ if peripheral.find("printer") then
end end
table.insert(tMenuItems, "Exit") table.insert(tMenuItems, "Exit")
local sStatus local status_ok, status_text
if term.isColour() then local function set_status(text, ok)
sStatus = "Press Ctrl or click here to access menu" status_ok = ok ~= false
else status_text = text
sStatus = "Press Ctrl to access menu"
end end
if #sStatus > w - 5 then
sStatus = "Press Ctrl for menu" if not bReadOnly and fs.getFreeSpace(sPath) < 1024 then
set_status("Disk is low on space", false)
else
local message
if term.isColour() then
message = "Press Ctrl or click here to access menu"
else
message = "Press Ctrl to access menu"
end
if #message > w - 5 then
message = "Press Ctrl for menu"
end
set_status(message)
end end
local function load(_sPath) local function load(_sPath)
@ -306,8 +321,8 @@ local function redrawMenu()
end end
else else
-- Draw status -- Draw status
term.setTextColour(highlightColour) term.setTextColour(status_ok and highlightColour or errorColour)
term.write(sStatus) term.write(status_text)
term.setTextColour(textColour) term.setTextColour(textColour)
end end
@ -318,7 +333,7 @@ end
local tMenuFuncs = { local tMenuFuncs = {
Save = function() Save = function()
if bReadOnly then if bReadOnly then
sStatus = "Access denied" set_status("Access denied", false)
else else
local ok, _, fileerr = save(sPath, function(file) local ok, _, fileerr = save(sPath, function(file)
for _, sLine in ipairs(tLines) do for _, sLine in ipairs(tLines) do
@ -326,12 +341,12 @@ local tMenuFuncs = {
end end
end) end)
if ok then if ok then
sStatus = "Saved to " .. sPath set_status("Saved to " .. sPath)
else else
if fileerr then if fileerr then
sStatus = "Error saving to " .. fileerr set_status("Error saving: " .. fileerr, false)
else else
sStatus = "Error saving to " .. sPath set_status("Error saving to " .. sPath, false)
end end
end end
end end
@ -340,17 +355,17 @@ local tMenuFuncs = {
Print = function() Print = function()
local printer = peripheral.find("printer") local printer = peripheral.find("printer")
if not printer then if not printer then
sStatus = "No printer attached" set_status("No printer attached", false)
return return
end end
local nPage = 0 local nPage = 0
local sName = fs.getName(sPath) local sName = fs.getName(sPath)
if printer.getInkLevel() < 1 then if printer.getInkLevel() < 1 then
sStatus = "Printer out of ink" set_status("Printer out of ink", false)
return return
elseif printer.getPaperLevel() < 1 then elseif printer.getPaperLevel() < 1 then
sStatus = "Printer out of paper" set_status("Printer out of paper", false)
return return
end end
@ -368,11 +383,11 @@ local tMenuFuncs = {
while not printer.newPage() do while not printer.newPage() do
if printer.getInkLevel() < 1 then if printer.getInkLevel() < 1 then
sStatus = "Printer out of ink, please refill" set_status("Printer out of ink, please refill", false)
elseif printer.getPaperLevel() < 1 then elseif printer.getPaperLevel() < 1 then
sStatus = "Printer out of paper, please refill" set_status("Printer out of paper, please refill", false)
else else
sStatus = "Printer output tray full, please empty" set_status("Printer output tray full, please empty", false)
end end
term.redirect(screenTerminal) term.redirect(screenTerminal)
@ -404,16 +419,16 @@ local tMenuFuncs = {
end end
while not printer.endPage() do while not printer.endPage() do
sStatus = "Printer output tray full, please empty" set_status("Printer output tray full, please empty")
redrawMenu() redrawMenu()
sleep(0.5) sleep(0.5)
end end
bMenu = true bMenu = true
if nPage > 1 then if nPage > 1 then
sStatus = "Printed " .. nPage .. " Pages" set_status("Printed " .. nPage .. " Pages")
else else
sStatus = "Printed 1 Page" set_status("Printed 1 Page")
end end
redrawMenu() redrawMenu()
end, end,
@ -427,7 +442,7 @@ local tMenuFuncs = {
end end
local sTempPath = bReadOnly and ".temp." .. sTitle or fs.combine(fs.getDir(sPath), ".temp." .. sTitle) local sTempPath = bReadOnly and ".temp." .. sTitle or fs.combine(fs.getDir(sPath), ".temp." .. sTitle)
if fs.exists(sTempPath) then if fs.exists(sTempPath) then
sStatus = "Error saving to " .. sTempPath set_status("Error saving to " .. sTempPath, false)
return return
end end
local ok = save(sTempPath, function(file) local ok = save(sTempPath, function(file)
@ -438,11 +453,11 @@ local tMenuFuncs = {
if nTask then if nTask then
shell.switchTab(nTask) shell.switchTab(nTask)
else else
sStatus = "Error starting Task" set_status("Error starting Task", false)
end end
fs.delete(sTempPath) fs.delete(sTempPath)
else else
sStatus = "Error saving to " .. sTempPath set_status("Error saving to " .. sTempPath, false)
end end
redrawMenu() redrawMenu()
end, end,