1) display list of task mark as priority (.) eg. 2012-04-03 (A) get some sleep.
2) display the first seven task chronological
3) display task age in year or month or day (date difference between now and date task was add)
4) able to archive task as completed by leftdoubleclick
5) use string.format ('%02d') to add leading zero for number below than 10
test.lua
Code: Select all
function Initialize()
sFileName = SELF:GetOption('FileName')
sKeyword = SKIN:GetVariable('Keyword')
sUserInput = SKIN:GetVariable('UserInput')
end -->Initialize
function Update()
tNum = {} ; tData = {} ; tDate = {}
tContext ={} ; tProject = {}
fLines={}
ntime = os.time()
local hFile = io.open(SKIN:MakePathAbsolute(sFileName),'a+')
if not hFile then
print('File error'); return 'File error';
else
for line in hFile:lines() do
table.insert(fLines,line)
end --for line
end -- if
if sUserInput ~="" then
hFile:write(os.date("%Y",os.time()),"-",os.date("%m",os.time()),"-",os.date("%d",os.time())," ",sUserInput,"\n") -- add task via userinput
SKIN:Bang('!Refresh')
print("userinput")
end --if
if sKeyword=="" then print ("keyword missing"); return 'file error' end
for i,v in ipairs(fLines) do
for taskage in string.gmatch(v,"%d+-%d+-%d+") do
strdate = string.gmatch(taskage,"%d+")
syear = strdate() ; smonth = strdate() ; sday = strdate()
ttime = os.time{year=syear, month=smonth, day=sday}
tdiff = os.difftime(ntime,ttime)
if calc(a) > 365 then
cyear=math.floor(calc(a)/365)
tage = " ["..cyear.." year]"
elseif calc(a) > 30 then
cmonth = math.floor(calc(a)/30)
tage = " ["..cmonth.." month]"
elseif calc(a) > 7 then
cweek = math.floor(calc(a)/7)
tage = " ["..cweek.." week]"
elseif calc(a) <= 0 then
tage = " [today]"
else
tage = " ["..calc(a).." day]"
end -- if
end --for
if sKeyword == "Today" or sKeyword =="Later" then
for sdue in string.gmatch(v,"due:%d+/%d+/%d+") do
strdate = string.gmatch(sdue,"%d+")
sday = strdate() ; smonth = strdate() ; syear = strdate()
ttime = os.time{year=syear, month=smonth, day=sday}
tdiff = os.difftime(ntime,ttime)
local sline3=string.sub(v,12) --> remove date position 1-11
if calc(a) >= 0 and sKeyword == "Today" then
table.insert(tData,sline3)
table.insert(tNum,string.format('%02d',i))--> insert padzero line number
table.insert(tDate,tage)
end -- if
if calc(a) <0 and calc(a) >-7 and sKeyword == "Later" then
table.insert(tData,sline3)
table.insert(tNum,string.format('%02d',i))
table.insert(tDate,tage)
end -- if
end--for sdue
elseif sKeyword == "Priority" then
for spriority in string.gmatch(v,"%d%s%(%a%)") do
local sline4=string.sub(v,12) --> remove date position 1-11
table.insert(tNum,string.format('%02d',i))
table.insert(tData,sline4)
table.insert(tDate,tage)
end -- for spriority
elseif sKeyword == "All" then
local sline4=string.sub(v,12) --> remove date position 1-11
table.insert(tNum,string.format('%02d',i))
table.insert(tData,sline4)
table.insert(tDate,tage)
elseif string.find(v,sKeyword) then
local sline2=string.sub(v,12) --> remove date position 1-11
table.insert(tNum,string.format('%02d',i))--> insert padzero line number
table.insert(tData,sline2)
table.insert(tDate,tage)
end --if
for context in string.gmatch(v,"@[%w]+") do --> context label
if not tContext[context] then
table.insert(tContext,context)
tContext[context] = true
end --if
end --for context
for project in string.gmatch(v,"\+[%w]+") do --> project label
if not tProject[project] then
table.insert(tProject,project)
tProject[project] = true
end--if
end--for project
end --for
fLines=nil
io.close(hFile)
NewNumber = #tData --> calc no of task containing context ToDotype
SKIN:Bang('!SetOption ToDoTypeTitle Text \"'..sKeyword..' · '..NewNumber..'\"')
print(NewNumber)
for i = 1, (#tData < 8) and #tData or 7 do
SKIN:Bang('!SetOption Num'..i..' Text \"'..tNum[i]..'\"')
SKIN:Bang('!SetOption Task'..i..' Text \"'..tData[i]..'\"')
SKIN:Bang('!SetOption Mark'..i..' Text \"'..tDate[i]..'\"')
SKIN:Bang('!SetOption Task'..i..' LeftMouseDoubleClickAction """!CommandMeasure "DoneScript" done(\"'..tNum[i]..'\")"""')
end
for i = 1, (#tContext < 11) and #tContext or 10 do
SKIN:Bang('!SetOption Context'..i..' Text \"'..tContext[i]..'\"')
SKIN:Bang('!SetOption Context'..i..' LeftMouseUpAction """!Execute [!WriteKeyValue Variables Keyword \"'..tContext[i]..'\"][!Refresh]"""')
end
for i = 1, (#tProject < 9) and #tProject or 8 do
SKIN:Bang('!SetOption Project'..i..' Text \"'..tProject[i]..'\"')
SKIN:Bang('!SetOption Project'..i..' LeftMouseUpAction """!Execute [!WriteKeyValue Variables Keyword \"'..tProject[i]..'\"][!Refresh]"""')
end
SKIN:Bang('!WriteKeyValue Variables UserInput ""') -- return userinput to nil
SKIN:Bang('!DisableMeasure MeasureScript')
end -->Update
function calc(a) -- calc day
local calc = math.floor(tdiff/86400)
return calc
end -- func calc
Code: Select all
--done.txt
function Initialize()
sFileName = SELF:GetOption('FileName')
sDonetxt = SELF:GetOption('Donetxt')
end -- Initialize
function done(n)
fLines={}
t=0
local hFile = io.open(sFileName,'r+')
if not hFile then
print('File error'); return 'File error';
else
for line in hFile:lines() do
table.insert(fLines,line)
t=t+1
end --for line
end--if
print(t)
io.close(hFile)
local aFile = io.open(sDonetxt,'a+')
local hFile = io.open(sFileName,'w+')
for line in hFile:lines() do
table.insert(fLines,line)
end --for line
print(n)
for i=1,t do
if i ~= n then
hFile:write(fLines[i],"\n")
else
--aFile:write(fLines[i],"\n")
aFile:write("x ",os.date("%Y",os.time()),"-",os.date("%m",os.time()),"-",os.date("%d",os.time())," ",fLines[i],"\n")
end -- if
end --for line
io.close(hFile)
io.close(aFile)
SKIN:Bang('!Refresh')
SKIN:Bang('!DisableMeasure DoneScript')
--return done()
end -- done
For now i create two script test.lua to display the parse task from todo.txt and done.lua to rewite todo.txt by removing completed task to done.txt.
skin.ini
Code: Select all
[MeasureScript]
Measure=Script
ScriptFile="#CURRENTPATH#test.lua"
FileName="D:\Dropbox\Rainmeter\1 - WHITE\todo.txt"
Disabled=0
[DoneScript]
Measure=Script
ScriptFile="#CURRENTPATH#done.lua"
FileName="D:\Dropbox\Rainmeter\1 - WHITE\todo.txt"
Donetxt="D:\Dropbox\Rainmeter\1 - WHITE\done.txt"
Disabled=0