Update sPhone.lua
This commit is contained in:
parent
a7e9bf66d3
commit
e09a479e1d
1 changed files with 196 additions and 59 deletions
249
src/sPhone.lua
249
src/sPhone.lua
|
@ -120,13 +120,174 @@ local function kernel()
|
||||||
sPhone.forceReboot()
|
sPhone.forceReboot()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function sPhone.header(butt)
|
||||||
|
|
||||||
|
if not sPhone then
|
||||||
|
sPhone = {
|
||||||
|
user = "Unknown",
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
|
local w, h = term.getSize()
|
||||||
|
|
||||||
|
paintutils.drawLine(1,1,w,1, colors.blue)
|
||||||
|
term.setTextColor(colors.white)
|
||||||
|
term.setCursorPos(1,1)
|
||||||
|
write(" "..sPhone.user)
|
||||||
|
term.setCursorPos(w,1)
|
||||||
|
write("X")
|
||||||
|
term.setBackgroundColor(colors.white)
|
||||||
|
term.setTextColor(colors.black)
|
||||||
|
term.setCursorPos(1,3)
|
||||||
|
end
|
||||||
|
|
||||||
|
function sPhone.menu(items, title, closeButton)
|
||||||
|
local function cprint(text)
|
||||||
|
if type(text) ~= 'table' then
|
||||||
|
text = {text}
|
||||||
|
end
|
||||||
|
|
||||||
|
local w, h = term.getSize()
|
||||||
|
|
||||||
|
for i=1,#text do
|
||||||
|
local x, y = term.getCursorPos()
|
||||||
|
term.setCursorPos(math.floor(w/2)-math.floor(text[i]:len()/2), y)
|
||||||
|
print(text[i])
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local function clear()
|
||||||
|
term.clear()
|
||||||
|
term.setCursorPos(1, 1)
|
||||||
|
end
|
||||||
|
|
||||||
|
local termWidth, termHeight = term.getSize()
|
||||||
|
local drawSize = termHeight - 6
|
||||||
|
|
||||||
|
local function maxPages()
|
||||||
|
local itemCount = #items
|
||||||
|
local pageCount = 0
|
||||||
|
while itemCount > 0 do
|
||||||
|
itemCount = itemCount - drawSize
|
||||||
|
pageCount = pageCount + 1
|
||||||
|
end
|
||||||
|
return pageCount
|
||||||
|
end
|
||||||
|
|
||||||
|
local function iif(cond, trueval, falseval)
|
||||||
|
if cond then
|
||||||
|
return trueval
|
||||||
|
else
|
||||||
|
return falseval
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function pagedItems()
|
||||||
|
local ret = {}
|
||||||
|
for i = 1, maxPages() do
|
||||||
|
local tmp = {}
|
||||||
|
local nElements = 0
|
||||||
|
for j = drawSize*(i-1)+1, iif(drawSize*(i+1) > #items, #items, drawSize*(i+1)) do
|
||||||
|
if nElements < drawSize then
|
||||||
|
table.insert(tmp, items[j])
|
||||||
|
nElements = nElements + 1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
table.insert(ret, tmp)
|
||||||
|
end
|
||||||
|
return ret
|
||||||
|
end
|
||||||
|
|
||||||
|
local selected = 1
|
||||||
|
if start then
|
||||||
|
selected = start
|
||||||
|
end
|
||||||
|
local page = 1
|
||||||
|
|
||||||
|
local function redraw()
|
||||||
|
term.setBackgroundColor(colors.white)
|
||||||
|
term.setTextColor(colors.black)
|
||||||
|
term.clear()
|
||||||
|
term.setCursorPos(1,1)
|
||||||
|
sPhone.header(closeButton)
|
||||||
|
term.setCursorPos(1,3)
|
||||||
|
if not title then
|
||||||
|
title = "sPhone"
|
||||||
|
end
|
||||||
|
cprint(" "..title)
|
||||||
|
if moreTitle then
|
||||||
|
head = moreTitle
|
||||||
|
else
|
||||||
|
head = {"\n",}
|
||||||
|
if not allowNil or allowNil == true then
|
||||||
|
--head[3] = 'Terminate to cancel.'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
for i=1,#head do
|
||||||
|
print(head[i])
|
||||||
|
end
|
||||||
|
if maxPages() > 1 then
|
||||||
|
pages = "<- (page "..page.." of "..maxPages()..") ->"
|
||||||
|
print(pages)
|
||||||
|
end
|
||||||
|
for i = 1, #pagedItems()[page] do
|
||||||
|
if selected == drawSize*(page-1)+i then
|
||||||
|
term.setBackgroundColor(colors.white)
|
||||||
|
term.setTextColor(colors.black)
|
||||||
|
else
|
||||||
|
term.setBackgroundColor(colors.white)
|
||||||
|
term.setTextColor(colors.black)
|
||||||
|
end
|
||||||
|
term.clearLine()
|
||||||
|
cprint(iif(selected == drawSize*(page-1)+i,"","").." "..pagedItems()[page][i])
|
||||||
|
term.setBackgroundColor(colors.white)
|
||||||
|
term.setTextColor(colors.black)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function changePage(pW)
|
||||||
|
if pW == 1 and page < maxPages() then
|
||||||
|
page = page + 1
|
||||||
|
if selected + drawSize > #items then
|
||||||
|
selected = #items
|
||||||
|
else
|
||||||
|
selected = selected + drawSize
|
||||||
|
end
|
||||||
|
elseif pW == -1 and page > 1 then
|
||||||
|
page = page - 1
|
||||||
|
if selected - drawSize < 1 then
|
||||||
|
selected = 1
|
||||||
|
else
|
||||||
|
selected = selected - drawSize
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
while true do
|
||||||
|
redraw()
|
||||||
|
local eventData = {os.pullEventRaw()}
|
||||||
|
if eventData[1] == 'mouse_click' then
|
||||||
|
if eventData[4] == 1 and eventData[3] == 26 then
|
||||||
|
return false, 0
|
||||||
|
end
|
||||||
|
if eventData[4] > 3 then
|
||||||
|
clear()
|
||||||
|
selected = (eventData[4]-6+((page-1)*drawSize))+1
|
||||||
|
if selected then
|
||||||
|
return items[selected], selected
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
sleep(0)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function sPhone.yesNo(title, desc, hideUser)
|
function sPhone.yesNo(title, desc, hideUser)
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
paintutils.drawLine(1,1,w,1, colors.gray)
|
paintutils.drawLine(1,1,w,1, colors.blue)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
if not hideUser then
|
if not hideUser then
|
||||||
|
@ -170,7 +331,7 @@ local function kernel()
|
||||||
smessage = ""
|
smessage = ""
|
||||||
end
|
end
|
||||||
if not bg then
|
if not bg then
|
||||||
bg = colors.gray
|
bg = colors.lightBlue
|
||||||
end
|
end
|
||||||
if not text then
|
if not text then
|
||||||
text = colors.white
|
text = colors.white
|
||||||
|
@ -179,7 +340,7 @@ local function kernel()
|
||||||
button = colors.lightGray
|
button = colors.lightGray
|
||||||
end
|
end
|
||||||
if not side then
|
if not side then
|
||||||
side = colors.lightGray
|
side = colors.blue
|
||||||
end
|
end
|
||||||
if #fmessage >= #smessage then
|
if #fmessage >= #smessage then
|
||||||
local w, h = term.getSize
|
local w, h = term.getSize
|
||||||
|
@ -226,7 +387,7 @@ local function kernel()
|
||||||
local function lChat()
|
local function lChat()
|
||||||
clear()
|
clear()
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
paintutils.drawLine(1,1,w,1,colors.gray)
|
paintutils.drawLine(1,1,w,1,colors.blue)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
sertextext.center(1," Chat")
|
sertextext.center(1," Chat")
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
|
@ -255,7 +416,7 @@ local function kernel()
|
||||||
end
|
end
|
||||||
clear()
|
clear()
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
paintutils.drawLine(1,1,w,1, colors.gray)
|
paintutils.drawLine(1,1,w,1, colors.blue)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
sertextext.right(1,"vvv")
|
sertextext.right(1,"vvv")
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
|
@ -278,9 +439,9 @@ local function kernel()
|
||||||
sPhone.isFooterMenuOpen = true
|
sPhone.isFooterMenuOpen = true
|
||||||
function redraw()
|
function redraw()
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
graphics.box(1,2,w,4,colors.gray)
|
graphics.box(1,2,w,4,colors.blue)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setBackgroundColor(colors.gray)
|
term.setBackgroundColor(colors.blue)
|
||||||
sertextext.right(1,"^^^")
|
sertextext.right(1,"^^^")
|
||||||
sertextext.right(3, "Reboot")
|
sertextext.right(3, "Reboot")
|
||||||
term.setCursorPos(11,3)
|
term.setCursorPos(11,3)
|
||||||
|
@ -355,7 +516,7 @@ local function kernel()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
|
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
|
||||||
term.setTextColor(colors.white)
|
term.setTextColor(colors.white)
|
||||||
term.setBackgroundColor(colors.gray)
|
term.setBackgroundColor(colors.blue)
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
write(" "..sPhone.user)
|
write(" "..sPhone.user)
|
||||||
if sPhone.wrongPassword then
|
if sPhone.wrongPassword then
|
||||||
|
@ -366,22 +527,14 @@ local function kernel()
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
sertextext.center(7," Insert Password")
|
sertextext.center(7," Insert Password")
|
||||||
|
local loginTerm = window.create(term.native(), 8,10,12,1, true)
|
||||||
|
term.redirect(loginTerm)
|
||||||
|
term.setBackgroundColor(colors.white)
|
||||||
|
term.clear()
|
||||||
|
term.setCursorPos(1,1)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.setCursorBlink(true)
|
local passwordLogin = read("*")
|
||||||
term.setCursorPos(9,10)
|
term.redirect(sPhone.mainTerm)
|
||||||
local _, k1 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(12,10)
|
|
||||||
local _, k2 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(15,10)
|
|
||||||
local _, k3 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(18,10)
|
|
||||||
local _, k4 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorBlink(false)
|
|
||||||
local passwordLogin = k1..k2..k3..k4
|
|
||||||
local fpw = fs.open("/.sPhone/.password","r")
|
local fpw = fs.open("/.sPhone/.password","r")
|
||||||
if sha256.sha256(passwordLogin) == fpw.readLine() then
|
if sha256.sha256(passwordLogin) == fpw.readLine() then
|
||||||
sPhone.wrongPassword = false
|
sPhone.wrongPassword = false
|
||||||
|
@ -407,22 +560,14 @@ local function kernel()
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
sertextext.center(3," Setup")
|
sertextext.center(3," Setup")
|
||||||
sertextext.center(7," Insert Password")
|
sertextext.center(7," Insert Password")
|
||||||
|
local loginTerm = window.create(term.native(), 8,10,12,1, true)
|
||||||
|
term.redirect(loginTerm)
|
||||||
|
term.setBackgroundColor(colors.white)
|
||||||
|
term.clear()
|
||||||
|
term.setCursorPos(1,1)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.setCursorBlink(true)
|
local password1 = read("*")
|
||||||
term.setCursorPos(9,10)
|
term.redirect(sPhone.mainTerm)
|
||||||
local _, k1 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(12,10)
|
|
||||||
local _, k2 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(15,10)
|
|
||||||
local _, k3 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(18,10)
|
|
||||||
local _, k4 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorBlink(false)
|
|
||||||
local password1 = k1..k2..k3..k4
|
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
|
paintutils.drawImage(paintutils.loadImage("/.sPhone/interfaces/login"),1,1)
|
||||||
|
@ -430,22 +575,14 @@ local function kernel()
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
sertextext.center(3," Setup")
|
sertextext.center(3," Setup")
|
||||||
sertextext.center(7," Repeat")
|
sertextext.center(7," Repeat")
|
||||||
|
local loginTerm = window.create(term.native(), 8,10,12,1, true)
|
||||||
|
term.redirect(loginTerm)
|
||||||
|
term.setBackgroundColor(colors.white)
|
||||||
|
term.clear()
|
||||||
|
term.setCursorPos(1,1)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.setCursorBlink(true)
|
local password2 = read("*")
|
||||||
term.setCursorPos(9,10)
|
term.redirect(sPhone.mainTerm)
|
||||||
local _, v1 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(12,10)
|
|
||||||
local _, v2 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(15,10)
|
|
||||||
local _, v3 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorPos(18,10)
|
|
||||||
local _, v4 = os.pullEvent("char")
|
|
||||||
write("*")
|
|
||||||
term.setCursorBlink(false)
|
|
||||||
local password2 = v1..v2..v3..v4
|
|
||||||
if password1 == password2 then
|
if password1 == password2 then
|
||||||
local f = fs.open("/.sPhone/.password", "w")
|
local f = fs.open("/.sPhone/.password", "w")
|
||||||
f.write(sha256.sha256(password1))
|
f.write(sha256.sha256(password1))
|
||||||
|
@ -463,7 +600,7 @@ local function kernel()
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
paintutils.drawLine(1,1,w,1,colors.gray)
|
paintutils.drawLine(1,1,w,1,colors.blue)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
sertextext.center(3," Setup Sertex ID")
|
sertextext.center(3," Setup Sertex ID")
|
||||||
|
@ -481,7 +618,7 @@ local function kernel()
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
paintutils.drawLine(1,1,w,1,colors.gray)
|
paintutils.drawLine(1,1,w,1,colors.blue)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
sertextext.center(3," Setup Sertex ID")
|
sertextext.center(3," Setup Sertex ID")
|
||||||
|
@ -522,7 +659,7 @@ local function kernel()
|
||||||
term.clear()
|
term.clear()
|
||||||
term.setCursorPos(1,1)
|
term.setCursorPos(1,1)
|
||||||
local w, h = term.getSize()
|
local w, h = term.getSize()
|
||||||
paintutils.drawLine(1,1,w,1,colors.gray)
|
paintutils.drawLine(1,1,w,1,colors.blue)
|
||||||
term.setTextColor(colors.black)
|
term.setTextColor(colors.black)
|
||||||
term.setBackgroundColor(colors.white)
|
term.setBackgroundColor(colors.white)
|
||||||
sertextext.center(3," Setup Sertex ID")
|
sertextext.center(3," Setup Sertex ID")
|
||||||
|
|
Loading…
Reference in a new issue