diff --git a/sdcard/3ds/ctruLua/editor/VeraMono.ttf b/sdcard/3ds/ctruLua/editor/VeraMono.ttf deleted file mode 100644 index 139f0b4..0000000 Binary files a/sdcard/3ds/ctruLua/editor/VeraMono.ttf and /dev/null differ diff --git a/sdcard/3ds/ctruLua/editor/main.lua b/sdcard/3ds/ctruLua/editor/main.lua index 64c9145..1831568 100644 --- a/sdcard/3ds/ctruLua/editor/main.lua +++ b/sdcard/3ds/ctruLua/editor/main.lua @@ -4,19 +4,23 @@ local gfx = require("ctr.gfx") -- Open libs local keyboard = require("keyboard") -local openfile = require("openfile") +local filepicker = require("filepicker") local color = dofile("color.lua") local syntax = dofile("syntax.lua") -- Load data -local font = gfx.font.load("VeraMono.ttf") +local font = gfx.font.load(ctr.root .. "resources/VeraMono.ttf") -- Open file -local path, status = openfile("Choose a file to edit", nil, nil, "any") -if not path then return end +local path, binding, mode, key = filepicker(nil, {__default = { + a = {filepicker.openFile, "Open"}, + y = {filepicker.newFile, "New File"} + } +}) +if not mode then return end local lineEnding local lines = {} -if status == "exist" then +if mode == "open" then for line in io.lines(path, "L") do if not lineEnding then lineEnding = line:match("([\n\r]+)$") end table.insert(lines, line:match("^(.-)[\n\r]*$")) @@ -110,7 +114,7 @@ while ctr.run() do -- Keyboard input local input = keyboard.read() if input then - if input == "BACK" then + if input == "\b" then if cursorX > utf8.len(lines[cursorY])+1 then cursorX = utf8.len(lines[cursorY])+1 end if cursorX > 1 then lines[cursorY] = lines[cursorY]:sub(1, utf8.offset(lines[cursorY], cursorX-1)-1).. @@ -173,7 +177,7 @@ while ctr.run() do gfx.text(3, 3, "FPS: "..math.ceil(gfx.getFPS())) - keyboard.draw(5, 115) + keyboard.draw(4, 115) gfx.stop() diff --git a/sdcard/3ds/ctruLua/main.lua b/sdcard/3ds/ctruLua/main.lua index 44c840e..bea7791 100644 --- a/sdcard/3ds/ctruLua/main.lua +++ b/sdcard/3ds/ctruLua/main.lua @@ -5,21 +5,24 @@ local gfx = require("ctr.gfx") -- Set up path local ldir = ctr.root.."libs/" package.path = package.path..";".. ldir.."?.lua;".. ldir.."?/init.lua" +local filepicker = require("filepicker") -- Erroring -local function displayError(err) +local function displayError(err, trace) gfx.set3D(false) gfx.color.setBackground(0xFF0000B3) gfx.color.setDefault(0xFFFDFDFD) + gfx.setTextSize(12) gfx.font.setDefault(gfx.font.load(ctr.root .. "resources/VeraMono.ttf")) while ctr.run() do - gfx.start(gfx.TOP) - gfx.text(1, 1, "An error has occured.", 12) - gfx.wrappedText(1, 30, err, gfx.TOP_WIDTH-2, 12) - gfx.text(1, gfx.TOP_HEIGHT-15, "Press Start to continue.", 12) - gfx.stop() gfx.start(gfx.BOTTOM) + gfx.text(1, 1, "An error has occured.") + gfx.wrappedText(1, 30, err, gfx.BOTTOM_WIDTH-2) + gfx.text(1, gfx.BOTTOM_HEIGHT-15, "Press Start to continue.") + gfx.stop() + gfx.start(gfx.TOP) + gfx.wrappedText(2, 6, trace, gfx.TOP_WIDTH - 2) gfx.stop() gfx.render() @@ -34,11 +37,15 @@ while ctr.run() do gfx.font.setDefault() gfx.color.setDefault(0xFFFDFDFD) gfx.color.setBackground(0xFF333333) - local file, ext, mode = require("filepicker")({{name="Lua Script", ext=".lua", a="Execute"}}) - if file and mode == "A" then + local file, ext, mode, key = filepicker(ctr.root, { + ["%.lua$"] = { + a = {filepicker.openFile, "Run"}, + __name = "Lua Script" + } + }) + if mode then fs.setDirectory(file:match("^(.-)[^/]*$")) - local ok, err = pcall(dofile, file) - if not ok then displayError(err) end + xpcall(dofile, function(err) displayError(err, debug.traceback()) end, file) else break end