Simpletask embeds a Lua scripting engine that can be used for configuration and callbacks. The configuration is read whenever you restart the app or when you change it in the Lua Config screen. The callbacks are executed when certain events occur (such as filtering). Both the configuration and callbacks will call specific Lua functions, see below for the details of the supported callbacks.
All code (config and callbacks) will be executed in the same Lua interpreter. This way you can define helper functions in the config and use them in callbacks.
NB: The filtering callback has been changed from pre 8.0 versions (See below).
To change existing (app and widget) filters to the 8.0 format do the following.
Add function onFilter(t,f,e)
before and end
after the existing script. Prefix all fields with f.
i.e. due
-> f.due
. Example:
if due~=nil then
return os.time() >= due;
end
--- tasks with no due date are not overdue.
return false;
becomes
function onFilter(t,f,e)
if f.due~=nil then
return os.time() >= f.due;
end
--- tasks with no due date are not overdue.
return false;
end
Shows string
as an Android toast. Useful for debugging scripts.
Logs string
to the Android logcat logging with info level and tag LuaInterp
.
Don't use toasts inside functions. This is a good way to make Simpletask hang.
Most functions get passed the same collection of parameters:
task
: The task as a string.fields
: Parts of the task converted to different types (such as a timestamp forcreatedate
)completed
: Boolean indicating if the task is completed.completiondate
: The completion date in seconds of the task ornil
if not set.createdate
: The created date in seconds of the task ornil
if not set.due
: The due date in seconds ornil
if not set.lists
: A table with the lists of the task as keys.fields.lists
itself will never benil
priority
: The priority of the task as string.recurrence
: The recurrence pattern of the task as string ornil
if not set.tags
: A table with the tags of the task as keys.fields.tags
itself will never benil
task
: The full task as string.threshold
: The threshold date in seconds ornil
if not set.text
: The text entered when the task was created.
extensions
: A table with the Todo.txt extensions (key:val
)of the task as key value pairs. There is only one entry for every key, this is to make use easier. If you need multiplekey:val
pairs with the same key, you can parse the task in Lua.
Called for every task as part of filtering the todo list.
true
if the task should be shownfalse
if the task should not be shown
- If there is a Lua error in the callback, it behaves as if it had returned
true
- Considering this function is called a lot (for every task in the list) it should be fast. If it is too slow Simpletask might give ANRs.
- You should define the
onFilter
function in the filter (not in the configuration). Defining it in the main configuration will not work, if the Filter script is empty, theonFilter
function will be undefined.
Called for every task as part of filtering the todo list.
- The group this task belongs to.
- If there is a Lua error in the callback, it behaves as if it had returned
""
- Considering this function is called a lot (for every task in the list) it should be fast. If it is too slow Simpletask might give ANRs.
- You should define the
onGroup
function in the filter (not in the configuration). Defining it in the main configuration will not work, if the Filter script is empty, theonGroup
function will be undefined.
Called for every task as part of sorting the todo list. This function should return a string for every task. This string is then used to sort the tasks.
- The string to use for task sorting.
- If there is a Lua error in the callback, it behaves as if it had returned
""
- Considering this function is called a lot (for every task in the list) it should be fast. If it is too slow Simpletask might give ANRs.
- You should define the
onSort
function in the filter (not in the configuration). Defining it in the main configuration will not work, if the Filter script is empty, theonGroup
function will be undefined.
Called for every task before it is displayed.
- A string which is displayed.
- If there is a Lua error in the callback, it behaves as if it had returned
""
- Considering this function is called a lot (for every task in the list) it should be fast. If it is too slow Simpletask might give ANRs.
- You should define the
onDisplay
function in the filter (not in the configuration). Defining it in the main configuration will not work, if the Filter script is empty, theonDisplay
function will be undefined.
Called for every task before it is added.
- A string which will be the actual task that is added.
- If there is a Lua error in the callback, the original task text is saved.
- You should define the
onAdd
callback in the main Lua configuration as it is not filter specific. Defining it in a filter will not work.
Called for every task as when searching for text.
taskText
: The task text as it appears in thetodo.txt
filesearchText
: Text being searched forcaseSensitive
:true
if case sensitive searching is configured in the settings.
true
if the task should be shownfalse
if the task should not be shown
- If there is a Lua error in the callback, it behaves as if it had returned
true
- Considering this function is called a lot (for every task in the list) it should be fast. If it is too slow Simpletask might give ANRs.
Configuration is read on app start and whenever it is changed or ran from the Lua Config screen. Configuration from Lua will always override the value from the settings (Lua wins).
None
"dark"
for the Material dark theme"black"
for the black theme (works well on Amoled devices)."light_darkactionbar"
for the Material light theme
- Requires an application restart to take effect (more accurately it needs to recreate the activity)
None
The font size of the main task list in SP as a float.
- Requires an application restart to take effect (more accurately it needs to recreate the activity)
- The default size in Android at the moment is
14sp
The following code will show only overdue tasks where tasks without a due date, will never be overdue.
function onFilter(t,f,e)
if f.due~=nil then
return os.time() > f.due;
end
--- tasks with no due date are not overdue.
return false;
end
Show tasks without tags or lists (the GTD Inbox):
function onFilter(t,f,e)
return next(f.tags)==nil and next(f.lists)==nil
end
Show all tasks on the @errands
list:
function onFilter(t,f,e)
return f.lists["errands"]
end
Change the font size of the main task list to 16sp
:
function tasklistTextSize()
return 16.0
end
The 8.0.0 fuzzy search in Lua:
function onTextSearch(text, search, case)
pat = string.gsub(search, ".", "%0.*")
res = string.match(text, pat)
return res~=nil
end
A group callback to group by list with custom empty header:
function onGroup(t,f,e)
if not next(f.lists) then
return "Inbox"
else
return next(f.lists)
end
end
Don't group at all and don't show any headers (regardless of sort order)
function onGroup()
return ""
end
A callback to modify the display of a task:
function onDisplay(t,f,e)
if f.due~=nil and os.time() > f.due then
--- Display overdue tasks in uppercase. (Prefixing with '=' replaces entire task.)
return "="..string.upper(f.tasktext)
end
return f.tasktext
end
Googling should turn up plenty of good resources. Programming in Lua should cover almost everything.