From 4708d5e010f8e787a06d2ec3361d70756d03d75f Mon Sep 17 00:00:00 2001 From: Autumn Date: Sun, 23 Aug 2026 11:44:35 +0100 Subject: [bunnytask] added config file support --- main.ha | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'main.ha') diff --git a/main.ha b/main.ha index 995d5d4..7833db8 100644 --- a/main.ha +++ b/main.ha @@ -1,17 +1,29 @@ use fmt; +use fs; +use lib; use strings; use todo; -use fs; - -def TODO_FILE = "todo.txt"; export fn main() void = { - const todos = match(todo::open(TODO_FILE)) { + + // load config + const config = match (lib::config_read()) { + case let config: *lib::config => yield config; + case let err: fs::error => fmt::fatalf("Error opening config: {}", fs::strerror(err)); + }; + defer lib::config_free(config); + + // TODO handle multiple todo files + const todo_file = config.files[0]; + + // load todos + const todos = match (todo::open(todo_file)) { case let todos: []str => yield todos; - case let err: fs::error => fmt::fatalf("Error opening {}: {}", TODO_FILE, fs::strerror(err)); + case let err: fs::error => fmt::fatalf("Error opening {}: {}", todo_file, fs::strerror(err)); }; defer strings::freeall(todos); + // print todos fmt::println("To-dos:")!; for (let item .. todos) { -- cgit v1.3