feat(nvim): add "tasks remaining" from orgmode in statusline
All checks were successful
Check Formatting of Files / Check-Formatting (push) Successful in 1m11s

This commit is contained in:
Price Hiller 2024-09-05 06:56:54 -05:00
parent 23cdc71938
commit 34a78e941d
Signed by: Price
GPG Key ID: C3FADDE7A8534BEB

View File

@ -618,20 +618,25 @@ return {
} }
vim.opt.showcmdloc = "statusline" vim.opt.showcmdloc = "statusline"
local timer = vim.uv.new_timer()
timer:start(
1000,
500,
vim.schedule_wrap(function()
vim.api.nvim_exec_autocmds("User", { pattern = "HeirlineOrgUpdate" })
end)
)
local org = require("orgmode") local org = require("orgmode")
local OrgDate = require("orgmode.objects.date")
local Orgmode = { local Orgmode = {
condition = function() condition = function()
return org.initialized and org.clock.clocked_headline and org.clock.clocked_headline:is_clocked_in() return org.initialized
end,
update = function(self)
local time = os.time()
self.last_updated = self.last_updated or time
if time - self.last_updated >= 1 then
self.last_updated = time
return true
end
end, end,
update = {
"User",
pattern = "HeirlineOrgUpdate",
},
margin(1), margin(1),
{ {
provider = seps.full.left, provider = seps.full.left,
@ -660,6 +665,7 @@ return {
bg = colors.sumiInk4, bg = colors.sumiInk4,
}, },
provider = function() provider = function()
local clocked_in_task = function()
local headline = org.clock.clocked_headline local headline = org.clock.clocked_headline
if not headline then if not headline then
return return
@ -682,6 +688,25 @@ return {
message = message:sub(1, 65) .. "" message = message:sub(1, 65) .. ""
end end
return message return message
end
local remaining_tasks_today = function()
local remaining_tasks_today = 0
local today = OrgDate:today()
for _, orgfile in pairs(org.files.files) do
---@type OrgFile
orgfile = orgfile
for _, headline in ipairs(orgfile:get_opened_unfinished_headlines()) do
for _, date in ipairs(headline:get_deadline_and_scheduled_dates()) do
if date:is_same_or_before(today, "day") then
remaining_tasks_today = remaining_tasks_today + 1
break
end
end
end
end
return ("Tasks Remaining: %d"):format(remaining_tasks_today)
end
return clocked_in_task() or remaining_tasks_today()
end, end,
}, },
{ {