Fixes with paths to avoid crashes and now the partition folders are shown in suggestions

This commit is contained in:
George Sokianos 2022-09-26 14:21:51 +01:00
parent b15bcbd397
commit 98711e1cb5
1 changed files with 8 additions and 14 deletions

View File

@ -1,7 +1,5 @@
local common = {} local common = {}
local mos = PLATFORM == "MORPHOS"
function common.is_utf8_cont(s, offset) function common.is_utf8_cont(s, offset)
local byte = s:byte(offset or 1) local byte = s:byte(offset or 1)
return byte >= 0x80 and byte < 0xc0 return byte >= 0x80 and byte < 0xc0
@ -59,14 +57,7 @@ function common.color(str)
r = (f() or 0) r = (f() or 0)
g = (f() or 0) g = (f() or 0)
b = (f() or 0) b = (f() or 0)
if mos then
a = (f() or "1.0"):gsub("%.", ",") * 0xff -- This is necessary for Lua 5.2 on MOS
-- having issues with float numbers having
-- a dot instead of comma
else
a = (f() or 1) * 0xff a = (f() or 1) * 0xff
end
else else
error(string.format("bad color string '%s'", str)) error(string.format("bad color string '%s'", str))
end end
@ -141,7 +132,7 @@ end
function common.path_suggest(text) function common.path_suggest(text)
local path, name = text:match("^(.-)([^/\\]*)$") local path, name = text:match("^(.-)([^:/\\]*)$")
local files = system.list_dir(path == "" and "." or path) or {} local files = system.list_dir(path == "" and "." or path) or {}
local res = {} local res = {}
for _, file in ipairs(files) do for _, file in ipairs(files) do
@ -161,7 +152,7 @@ end
function common.dir_path_suggest(text) function common.dir_path_suggest(text)
local path, name = text:match("^(.-)([^/\\]*)$") local path, name = text:match("^(.-)([^:/\\]*)$")
local files = system.list_dir(path == "" and "." or path) or {} local files = system.list_dir(path == "" and "." or path) or {}
local res = {} local res = {}
for _, file in ipairs(files) do for _, file in ipairs(files) do
@ -176,7 +167,7 @@ end
function common.dir_list_suggest(text, dir_list) function common.dir_list_suggest(text, dir_list)
local path, name = text:match("^(.-)([^/\\]*)$") local path, name = text:match("^(.-)([^:/\\]*)$")
local res = {} local res = {}
for _, dir_path in ipairs(dir_list) do for _, dir_path in ipairs(dir_list) do
if dir_path:lower():find(text:lower(), nil, true) == 1 then if dir_path:lower():find(text:lower(), nil, true) == 1 then
@ -245,7 +236,7 @@ end
-- can return nil if there is no directory part in the path -- can return nil if there is no directory part in the path
function common.dirname(path) function common.dirname(path)
return path:match("(.+)[\\/][^\\/]+$") return path:match("(.+)[:\\/][^\\/]+$")
end end
@ -272,6 +263,9 @@ end
function common.home_expand(text) function common.home_expand(text)
if text == nil then
return HOME
end
return HOME and text:gsub("^~", HOME) or text return HOME and text:gsub("^~", HOME) or text
end end