mirror of
https://github.com/ctruLua/ctruLua.git
synced 2025-10-27 16:39:29 +00:00
Updated apps that rely on file selection
The editor doesn't use openfile.lua anymore, the main shell is updated to use filepicker.filePicker's new format. Also, updated the editor to use resources/VeraMono.ttf instead of its own copy, which was deleted.
This commit is contained in:
parent
4669a68402
commit
05c9adc2a0
3 changed files with 28 additions and 17 deletions
Binary file not shown.
|
|
@ -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()
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue