update viewlog

This commit is contained in:
Squishy (C6H12O6+NaCl+H2O)
2024-01-07 11:23:54 +07:00
parent 6594b4a238
commit d09f5b0176

View File

@@ -1,85 +1,122 @@
local fullLog,currentLog local fullLog,currentLogID
local logTimeList={}
local currentLogText={}
local gc=love.graphics local gc=love.graphics
local scene={} local scene={}
local textBox=WIDGET.newTextBox{name='texts',x=30,y=45,w=1000,h=540,font=20,fix=true}
local textBox=WIDGET.newTextBox {x= 30,y= 45,w=1000,h=540,font=25,fix=true}
local logList=WIDGET.newSelector{x=305,y=640,w= 550,name='list',color='O',fText='Crash log',list={''},disp=function() return '' end,code=function() end}
local function updateText()
currentLogText=fullLog[currentLogID]:split('\n')
do
local _,wt=getFont(25):getWrap(fullLog[currentLogID],975)
textBox:setTexts(wt)
end
logList:reset()
end
function scene.enter() function scene.enter()
fullLog=(FILE.load('/conf/error.log','-string -canskip') or '/conf/error.log not found'):split('\n\n') fullLog=(FILE.load('/conf/error.log','-string -canskip') or '/conf/error.log not found'):split('\n\n')
TABLE.reverse(fullLog) TABLE.reverse(fullLog)
currentLog=1 currentLogID=1
textBox:setTexts(fullLog[1]:split('\n')) updateText()
if fullLog[1]=='/conf/error.log not found' then if fullLog[1]=='/conf/error.log not found' then
local _w=scene.widgetList local _w=scene.widgetList
_w.del .hide=true _w.home.hide=true;_w.list.hide=true
_w.delA.hide=true _w.endd.hide=true;_w.del .hide=true
_w.next.hide=true _w.copy.hide=true;_w.delA.hide=true
_w.prev.hide=true
_w.home.hide=true
_w.endd.hide=true
_w.copy.hide=true
textBox.font=25 textBox.font=25
textBox:reset() textBox:reset()
logList.list={''}
logList.select=false
logList.disp=function() return '' end
logList.code=function() end
logList:reset()
else else
local _w=scene.widgetList local _w=scene.widgetList
_w.del .hide=false _w.home.hide=false;_w.list.hide=false
_w.delA.hide=false _w.endd.hide=false;_w.del .hide=false
_w.next.hide=false _w.copy.hide=false;_w.delA.hide=false
_w.prev.hide=false
_w.home.hide=false
_w.endd.hide=false
_w.copy.hide=false
textBox.font=15 textBox.font=15
textBox:reset() textBox:reset()
for i,d in pairs(fullLog) do logTimeList[i]=d:split('\n')[1] end
logList.list=logTimeList
logList.select=false
logList.disp=function() return currentLogText[1] end
logList.code=function() currentLogID=logList.select updateText() end
logList:reset()
end end
end end
local deleteOld,deleteAll
local sureTime=-1e99 do
local function deleteAllExcludeLast10() local sureTime=-1e99
local function task_redButton() function deleteOld()
scene.widgetList.del.color=COLOR.R local function task_redButton()
for _=1,120 do coroutine.yield() end scene.widgetList.del.color=COLOR.R
scene.widgetList.del.color=COLOR.Z for _=1,120 do coroutine.yield() end
end scene.widgetList.del.color=COLOR.Z
end
if TIME()-sureTime<1 then
sureTime=-1e99 if TIME()-sureTime<1 then
scene.widgetList.del.color=COLOR.Z sureTime=-1e99
do scene.widgetList.del.color=COLOR.Z
local temp=TABLE.sub(TABLE.copy(fullLog),1,10) do
fullLog=TABLE.copy(temp) local temp=TABLE.sub(TABLE.copy(fullLog),1,25)
temp=table.concat(temp,'\n\n')..'\n\n' fullLog=TABLE.copy(temp)
FILE.save(temp,'/conf/error.log','-string') temp=table.concat(temp,'\n\n')..'\n\n'
scene.keyDown('home') TASK.removeTask_code(task_redButton)
TASK.removeTask_code(task_redButton)
logTimeList=TABLE.sub(logTimeList,1,25)
logList.list=logTimeList
logList.select=25
scene.keyDown('end')
FILE.save(temp,'/conf/error.log','-string')
end
else
sureTime=TIME()
MES.new('warn',text.sureDelete)
TASK.removeTask_code(task_redButton)
TASK.new(task_redButton)
end end
else
sureTime=TIME()
MES.new('warn',text.sureDelete)
TASK.removeTask_code(task_redButton)
TASK.new(task_redButton)
end end
end end
local function deleteAll() do
local function task_redButton() local sureTime=-1e99
scene.widgetList.delA.color=COLOR.R function deleteAll()
for _=1,120 do coroutine.yield() end local function task_redButton()
scene.widgetList.delA.color=COLOR.Z scene.widgetList.delA.color=COLOR.R
end for _=1,120 do coroutine.yield() end
scene.widgetList.delA.color=COLOR.Z
end
if TIME()-sureTime<1 then if TIME()-sureTime<1 then
sureTime=-1e99 sureTime=-1e99
scene.widgetList.delA.color=COLOR.Z scene.widgetList.delA.color=COLOR.Z
love.filesystem.remove('/conf/error.log') love.filesystem.remove('/conf/error.log')
TASK.removeTask_code(task_redButton) TASK.removeTask_code(task_redButton)
SCN.swapTo('viewLog','none')
else logList.list={''}
sureTime=TIME() logList.select=false
MES.new('warn',text.sureDelete) logList.disp=function() return '' end
TASK.removeTask_code(task_redButton) logList.code=function() end
TASK.new(task_redButton) logList:reset()
SCN.swapTo('viewLog','none')
else
sureTime=TIME()
MES.new('warn',text.sureDelete)
TASK.removeTask_code(task_redButton)
TASK.new(task_redButton)
end
end end
end end
@@ -89,17 +126,17 @@ end
function scene.keyDown(key) function scene.keyDown(key)
if key=='left' then if key=='left' then
currentLog=math.max(1,currentLog-1) currentLogID=math.max(1,currentLogID-1)
textBox:setTexts(fullLog[currentLog]:split('\n')) updateText()
elseif key=='right' then elseif key=='right' then
currentLog=math.min(currentLog+1,#fullLog) currentLogID=math.min(currentLogID+1,#fullLog)
textBox:setTexts(fullLog[currentLog]:split('\n')) updateText()
elseif key=='home' then elseif key=='home' then
currentLog=1 currentLogID=1
textBox:setTexts(fullLog[1]:split('\n')) updateText()
elseif key=='end' then elseif key=='end' then
currentLog=#fullLog currentLogID=#fullLog
textBox:setTexts(fullLog[#fullLog]:split('\n')) updateText()
elseif key=='up' then elseif key=='up' then
textBox:scroll(-5) textBox:scroll(-5)
elseif key=='down' then elseif key=='down' then
@@ -115,21 +152,21 @@ end
function scene.draw() function scene.draw()
setFont(40) setFont(40)
gc.print(currentLog..' / '..#fullLog,1000,800) gc.print(currentLogID..' / '..#fullLog,1000,800)
end end
scene.widgetList={ scene.widgetList={
textBox, textBox,
WIDGET.newButton{name='prev',x=1140,y= 90,w=170,h=80,sound='click',font=60,fText=CHAR.key.left ,code=pressKey('left')}, WIDGET.newButton {name='home',x=1140,y= 90,w=170,h=80,sound='click',font=60,fText=CHAR.key.macHome,code=pressKey('home')},
WIDGET.newButton{name='next',x=1140,y=190,w=170,h=80,sound='click',font=60,fText=CHAR.key.right ,code=pressKey('right')}, WIDGET.newButton {name='endd',x=1140,y=190,w=170,h=80,sound='click',font=60,fText=CHAR.key.macEnd ,code=pressKey('end')},
WIDGET.newButton{name='home',x=1140,y=290,w=170,h=80,sound='click',font=60,fText=CHAR.key.macHome,code=pressKey('home')}, WIDGET.newButton {name='copy',x=1140,y=290,w=170,h=80,sound='click',font=60,fText=CHAR.icon.copy ,code=function()love.system.setClipboardText(table.concat(textBox.texts,'\n'))end},
WIDGET.newButton{name='endd',x=1140,y=390,w=170,h=80,sound='click',font=60,fText=CHAR.key.macEnd ,code=pressKey('end')},
WIDGET.newButton{name='copy',x=1140,y=490,w=170,h=80,sound='click',font=60,fText=CHAR.icon.copy ,code=function() love.system.setClipboardText(table.concat(textBox.texts,'\n')) end},
WIDGET.newKey {name='del' ,x= 260,y=640,w=450,h=80,sound=false, font=30,fText='Delete all log exclude last 10',color='Z',code=deleteAllExcludeLast10}, logList,
WIDGET.newKey {name='delA',x= 620,y=640,w=250,h=80,sound=false, font=30,fText='DELETE ALL!',color='Z',code=deleteAll},
WIDGET.newButton{name='back',x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene}, WIDGET.newKey {name='del' ,x= 710,y=640,w=200,h=80,sound=false, font=30,fText='Clear old' ,color='Z',code=deleteOld},
WIDGET.newKey {name='delA',x= 930,y=640,w=200,h=80,sound=false, font=30,fText='DELETE ALL!',color='Z',code=deleteAll},
WIDGET.newButton {name='back',x=1140,y=640,w=170,h=80,sound='back',font=60,fText=CHAR.icon.back,code=backScene},
} }
return scene return scene