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.
This commit is contained in:
Barrett Ruth 2026-02-24 15:08:59 -05:00
parent be31f95551
commit 116e3c5b25

42
lua/todo/config.lua Normal file
View file

@ -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