Alpha 3.13

New sPhone.menu GUI
This commit is contained in:
Ale32bit 2016-11-15 23:20:04 +01:00 committed by GitHub
parent e3b570c0d8
commit 8e811ddab7

View file

@ -1,6 +1,6 @@
local function kernel(...) local function kernel(...)
_G.sPhone = { _G.sPhone = {
version = "Alpha 3.12", version = "Alpha 3.13",
user = "Guest", user = "Guest",
devMode = false, devMode = false,
mainTerm = term.current(), mainTerm = term.current(),
@ -9,7 +9,7 @@ local function kernel(...)
if safemode then if safemode then
sPhone.safeMode = true sPhone.safeMode = true
_G.safemode = nil safemode = nil
end end
sPhone.defaultApps = { sPhone.defaultApps = {
@ -69,7 +69,7 @@ local function kernel(...)
elseif string.lower(k) == "n" then elseif string.lower(k) == "n" then
print("Cannot delete config without user authorization") print("Cannot delete config without user authorization")
print("Delete aborted") print("Delete aborted")
print("Shuttind down...") print("Shutting down...")
error("Config corrupted",0) error("Config corrupted",0)
end end
end end
@ -136,7 +136,7 @@ local function kernel(...)
sPhone.crash = crash sPhone.crash = crash
end end
_G.crash = nil crash = nil
function os.version() function os.version()
return "sPhone "..sPhone.version return "sPhone "..sPhone.version
@ -241,6 +241,8 @@ local function kernel(...)
opt.fg3 = opt.fg3 or sPhone.getTheme("headerText") opt.fg3 = opt.fg3 or sPhone.getTheme("headerText")
opt.output = opt.output or true opt.output = opt.output or true
opt.list = opt.list or false opt.list = opt.list or false
opt.pairs = opt.pairs or false
opt.title = opt.title or false
if not path then if not path then
path = "" path = ""
end end
@ -249,6 +251,7 @@ local function kernel(...)
end end
local scroll = 0 local scroll = 0
local items local items
local cho = {}
local w, h local w, h
local function rebuild() local function rebuild()
local files, dirs = {}, {} local files, dirs = {}, {}
@ -259,7 +262,15 @@ local function kernel(...)
else else
flist = opt.list flist = opt.list
end end
for i, v in ipairs(flist) do
local function pair(tab)
if opt.pairs then
return pairs(tab)
end
return ipairs(tab)
end
for i, v in pair(flist) do
if fs.isDir(fs.combine(path, v)) then if fs.isDir(fs.combine(path, v)) then
table.insert(dirs, v) table.insert(dirs, v)
else else
@ -268,12 +279,18 @@ local function kernel(...)
end end
table.sort(files) table.sort(files)
table.sort(dirs) table.sort(dirs)
for i, v in ipairs(dirs) do for i, v in pair(dirs) do
table.insert(items, v) table.insert(items, v)
end end
for i, v in ipairs(files) do for i, v in pair(files) do
table.insert(items, v) table.insert(items, v)
end end
if opt.pairs then
for k, v in pairs(flist) do
cho[v] = k
end
end
scroll = 0 scroll = 0
end end
rebuild() rebuild()
@ -308,6 +325,9 @@ local function kernel(...)
if #_path > w - 2 then if #_path > w - 2 then
_path = ".." .. _path:sub(-w + 4) _path = ".." .. _path:sub(-w + 4)
end end
if opt.title then
_path = opt.title
end
term.write(_path) term.write(_path)
term.setBackgroundColor(opt.bg3) term.setBackgroundColor(opt.bg3)
term.setTextColor(opt.fg3) term.setTextColor(opt.fg3)
@ -350,6 +370,9 @@ local function kernel(...)
rebuild() rebuild()
else else
if opt.output then if opt.output then
if opt.pairs then
return cho[fullPath], fullPath
end
return fullPath return fullPath
end end
end end
@ -728,7 +751,7 @@ local function kernel(...)
end end
local termWidth, termHeight = term.getSize() local termWidth, termHeight = term.getSize()
local drawSize = termHeight - 6 local drawSize = termHeight - 2
local function maxPages() local function maxPages()
local itemCount = #items local itemCount = #items
@ -775,16 +798,15 @@ local function kernel(...)
term.setTextColor(sPhone.theme["text"]) term.setTextColor(sPhone.theme["text"])
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
sPhone.header("",closeButton)
term.setCursorPos(1,3)
if not title then if not title then
title = " sPhone" title = ""
end end
cprint(" "..title) sPhone.header(title,closeButton)
term.setCursorPos(1,3)
if moreTitle then if moreTitle then
head = moreTitle head = moreTitle
else else
head = {"\n",} head = {}
if not allowNil or allowNil == true then if not allowNil or allowNil == true then
--head[3] = 'Terminate to cancel.' --head[3] = 'Terminate to cancel.'
end end
@ -835,9 +857,9 @@ local function kernel(...)
if eventData[1] == 'mouse_click' then if eventData[1] == 'mouse_click' then
if eventData[4] == 1 and eventData[3] == termWidth then if eventData[4] == 1 and eventData[3] == termWidth then
return false, 0 return false, 0
elseif eventData[4] > 3 then elseif eventData[4] > 2 then
clear() clear()
selected = (eventData[4]-6+((page-1)*drawSize))+1 selected = (eventData[4]-3+((page-1)*drawSize))+1
if selected then if selected then
return items[selected], selected return items[selected], selected
end end
@ -1117,6 +1139,10 @@ end
return (_config.version or nil) return (_config.version or nil)
end, end,
getType = function()
return (_config.type or nil)
end,
open = function(file, mode) open = function(file, mode)
return fs.open("/.sPhone/apps/spk/".._config.id.."/data/"..file,mode) return fs.open("/.sPhone/apps/spk/".._config.id.."/data/"..file,mode)
end, end,
@ -1135,21 +1161,24 @@ end
local function home() local function home()
sPhone.inHome = true sPhone.inHome = true
while true do while true do
local homeSPKs = {
"sphone.home",
}
os.pullEvent = os.oldPullEvent os.pullEvent = os.oldPullEvent
term.setBackgroundColor(colors.black) term.setBackgroundColor(colors.black)
term.setTextColor(colors.white) term.setTextColor(colors.white)
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
local homePath = sPhone.getDefaultApp("home") local homeID = sPhone.getDefaultApp("home")
if not sPhone.safeMode then if not sPhone.safeMode then
if not fs.exists(homePath) then if not config.list("/.sPhone/config/spklist")[homeID] then
homePath = "/.sPhone/apps/home" homeID = "sphone.home"
end end
else else
homePath = "/.sPhone/apps/home" homeID = "sphone.home"
end end
temp.set("homePID",task.add(function() shell.run(homePath) end)) temp.set("homePID",task.add(function() sPhone.launch(homeID) end))
task.run() task.run()
end end
@ -1171,7 +1200,7 @@ end
} }
while true do while true do
local w,h = term.getSize() local w,h = term.getSize()
local clockS = textutils.formatTime(os.time(),true) local clockS = textutils.formatTime(os.time(), not config.read("/.sPhone/config/sPhone","format12time"))
term.setBackgroundColor(sPhone.theme["lock.background"]) term.setBackgroundColor(sPhone.theme["lock.background"])
term.clear() term.clear()
term.setCursorPos(1,1) term.setCursorPos(1,1)
@ -1181,7 +1210,7 @@ end
term.setCursorPos(6,4) term.setCursorPos(6,4)
bigfont.bigPrint(clockS) bigfont.bigPrint(clockS)
visum.align("center"," Slide to unlock",false,h) visum.align("center"," Slide to unlock",false,h)
local clockUpdate = os.startTimer(0.3) local clockUpdate = os.startTimer(1)
local e = {os.pullEvent()} local e = {os.pullEvent()}
if fEvents[e[1]] then if fEvents[e[1]] then
os.pullEvent = old os.pullEvent = old
@ -1234,6 +1263,9 @@ end
local w, h = term.getSize() local w, h = term.getSize()
local skipped = false local skipped = false
sPhone.firstBoot = true sPhone.firstBoot = true
sPhone.install("/.sPhone/apps/home.spk")
while not skipped do while not skipped do
term.setBackgroundColor(sPhone.theme["lock.background"]) term.setBackgroundColor(sPhone.theme["lock.background"])