aboutsummaryrefslogtreecommitdiff
path: root/hatask.ha
diff options
context:
space:
mode:
authorJulian Hurst <ark@mansus.space>2024-11-15 01:14:07 +0100
committerJulian Hurst <ark@mansus.space>2024-11-15 01:14:07 +0100
commit5fa7f3419bf5b2eb10cb2923ec47341075f84805 (patch)
treeb02c909bfffbc2a6107a0b267dc05b6184276929 /hatask.ha
downloadhatask-5fa7f3419bf5b2eb10cb2923ec47341075f84805.tar.gz
Initial commit
Diffstat (limited to 'hatask.ha')
-rw-r--r--hatask.ha62
1 files changed, 62 insertions, 0 deletions
diff --git a/hatask.ha b/hatask.ha
new file mode 100644
index 0000000..493c597
--- /dev/null
+++ b/hatask.ha
@@ -0,0 +1,62 @@
+use fmt;
+use dirs;
+use bufio;
+use os;
+use fs;
+use path;
+use io;
+use strings;
+use format::ini;
+
+type task = struct {
+ name: str,
+ context: (str | void),
+ tags: ([]str | void),
+ priority: uint,
+};
+
+def METADATASEP: str = "----";
+
+fn listtasks(root: str = "tasks", context: str = "*") ([]task | fs::error |
+ path::error) = {
+ const dirents = os::readdir(root)?;
+ defer fs::dirents_free(dirents);
+ let tasks: []task = [];
+ for (const dirent .. dirents) {
+ if (context == "*" || dirent.name == context) {
+ if (fs::isdir(dirent.ftype)) {
+ let buf = path::init()?;
+ const p = path::push(&buf, root, dirent.name)?;
+ listtasks(p)?;
+ } else {
+ fmt::println(dirent.name)!;
+ };
+ };
+ };
+ return tasks;
+};
+
+fn readtask(taskpath: str) (task | fs::error) = {
+ const f = os::open(taskpath)?;
+ defer io::close(f)!;
+ const sc = bufio::newscanner(f);
+ defer bufio::finish(&sc);
+ for (let line => bufio::scan_line(&sc)?) {
+ line = strings::trim(line);
+ if (line == METADATASEP) {
+ break;
+ };
+
+ };
+};
+
+export fn main() void = {
+ match (listtasks()) {
+ case let e: fs::error =>
+ fmt::fatal(fs::strerror(e));
+ case let e: path::error =>
+ fmt::fatal(path::strerror(e));
+ case =>
+ void;
+ };
+};