From 116e3c5b258ce0b795983f93d74172acadbfdf8d Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Tue, 24 Feb 2026 15:08:59 -0500 Subject: [PATCH] feat(config): add configuration module Problem: need user-configurable settings with sensible defaults. Solution: add config module that merges vim.g.todo with defaults for data_path, default_view, default_category, date_format, and date_syntax. --- lua/todo/config.lua | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 lua/todo/config.lua diff --git a/lua/todo/config.lua b/lua/todo/config.lua new file mode 100644 index 0000000..622b96c --- /dev/null +++ b/lua/todo/config.lua @@ -0,0 +1,42 @@ +---@class todo.GcalConfig +---@field calendar? string +---@field credentials_path? string + +---@class todo.Config +---@field data_path string +---@field default_view 'category'|'priority' +---@field default_category string +---@field date_format string +---@field date_syntax string +---@field gcal? task.GcalConfig + +---@class todo.config +local M = {} + +---@type todo.Config +local defaults = { + data_path = vim.fn.stdpath('data') .. '/todo/tasks.json', + default_view = 'category', + default_category = 'Inbox', + date_format = '%b %d', + date_syntax = 'due', +} + +---@type todo.Config? +local _resolved = nil + +---@return todo.Config +function M.get() + if _resolved then + return _resolved + end + local user = vim.g.todo or {} + _resolved = vim.tbl_deep_extend('force', defaults, user) + return _resolved +end + +function M.reset() + _resolved = nil +end + +return M