C and Python API + Smarter account-based wait times
This commit is contained in:
1 parent
35c568333d
commit
10badb282c
18 files changed
+2204
-429
No files matched your search
@@ -0,0 +1,65 @@
|
||||
/* Minimal use of the lls C API: add accounts and tasks, set a wait, print the panels. */
|
||||
#include <stdio.h>
|
||||
|
||||
#include "lls_api.h"
|
||||
|
||||
static int check(lls_db* db, int code, const char* what) {
|
||||
if (code != LLS_OK) {
|
||||
fprintf(stderr, "%s failed (%d): %s\n", what, code, lls_last_error(db));
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
int main(int argc, char** argv) {
|
||||
const char* path = (argc > 1) ? argv[1] : "example.db";
|
||||
|
||||
lls_db* db = NULL;
|
||||
if (lls_open(path, &db) != LLS_OK) {
|
||||
fprintf(stderr, "open failed: %s\n", lls_last_error(NULL));
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Ignore "already exists" so the example can be run twice. */
|
||||
lls_account_add(db, "Acrux");
|
||||
lls_account_add(db, "Beta");
|
||||
lls_task_add(db, "Breeze A", "Acrux", "testing");
|
||||
lls_task_add(db, "Breeze B", "Acrux", NULL); /* NULL = prompt */
|
||||
lls_task_add(db, "Breeze C", "Beta", "done");
|
||||
|
||||
/* The wait belongs to the account: Acrux's Prompt / Testing tasks now show Wait. */
|
||||
if (!check(db, lls_account_set_wait(db, "Acrux", "11:59pm"), "set_wait")) {
|
||||
lls_close(db);
|
||||
return 1;
|
||||
}
|
||||
printf("%s\n\n", lls_last_messages(db));
|
||||
|
||||
lls_task_list* tasks = NULL;
|
||||
if (check(db, lls_tasks(db, &tasks), "tasks")) {
|
||||
printf("%-10s %-8s %-12s %s\n", "TASK", "ACCOUNT", "STATUS", "NOTES");
|
||||
for (int i = 0; i < lls_task_list_count(tasks); ++i) {
|
||||
const lls_task_info* t = lls_task_list_get(tasks, i);
|
||||
printf("%-10s %-8s %-12s %d lines\n", t->name, t->account ? t->account : "-", t->status_label,
|
||||
t->notes_lines);
|
||||
}
|
||||
lls_task_list_free(tasks);
|
||||
}
|
||||
|
||||
lls_account_list* accounts = NULL;
|
||||
if (check(db, lls_accounts(db, &accounts), "accounts")) {
|
||||
printf("\n%-8s %-6s %s\n", "ACCOUNT", "LEVEL", "TASKS");
|
||||
for (int i = 0; i < lls_account_list_count(accounts); ++i) {
|
||||
const lls_account_info* a = lls_account_list_get(accounts, i);
|
||||
printf("%-8s %-6s", a->name, a->level_label);
|
||||
for (int k = 0; k < a->task_count; ++k) {
|
||||
printf(" %s", a->tasks[k]);
|
||||
}
|
||||
printf("\n");
|
||||
}
|
||||
lls_account_list_free(accounts);
|
||||
}
|
||||
|
||||
check(db, lls_save(db), "save"); /* nothing is saved automatically */
|
||||
lls_close(db);
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user