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.
42 lines
852 B
Lua
42 lines
852 B
Lua
---@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
|