Skip to content

Commit

Permalink
feat(api): new function, tasks_left()
Browse files Browse the repository at this point in the history
  • Loading branch information
Hashino committed Jan 7, 2025
1 parent 99afc60 commit 7e7dfab
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 11 deletions.
9 changes: 7 additions & 2 deletions lua/doing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ local edit = require("doing.edit")

local Doing = {}

---@brief setup doing.nvim
--- setup doing.nvim
---@param opts? DoingOptions
function Doing.setup(opts)
config.options = vim.tbl_deep_extend("force", config.default_opts, opts or {})
Expand All @@ -29,7 +29,7 @@ function Doing.setup(opts)
end
end

---@brief add a task to the list
--- add a task to the list
---@param task? string task to add
---@param to_front? boolean whether to add task to front of list
function Doing.add(task, to_front)
Expand Down Expand Up @@ -116,4 +116,9 @@ function Doing.toggle()
utils.task_modified()
end

---@return integer number of tasks left
function Doing.tasks_left()
return state.tasks:count()
end

return Doing
4 changes: 4 additions & 0 deletions lua/doing/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ local Config = {}
---@field winbar.enabled boolean if plugin should manage the winbar
---@field store.file_name string name of the task file
---@field store.auto_delete_file boolean auto delete tasks file
---@field show_messages boolean show messages in status string
---@field show_remaining boolean show "+n more" when there are more than 1 tasks
---@field edit_win_config vim.api.keyset.win_config window configs of the floating editor

Expand All @@ -22,6 +23,9 @@ Config.default_opts = {
-- if should append "+n more" to the status when there's tasks remaining
show_remaining = true,

-- if should show messages on the status string
show_messages = true,

winbar = {
enabled = true, -- if plugin should manage the winbar
},
Expand Down
2 changes: 1 addition & 1 deletion lua/doing/edit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ local Edit = {
buf = nil,
}

---@brief open floating window to edit tasks
--- open floating window to edit tasks
---@param state table current state of doing.nvim
function Edit.open_edit(state)
if not Edit.buf then
Expand Down
2 changes: 1 addition & 1 deletion lua/doing/state.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ State.message = nil
State.view_enabled = true
State.auGroupID = nil

---@brief initialzes the tasklist state
--- initialzes the tasklist state
---@param file_name string name of the file to store tasks
---@return table instance instantiated state
function State.init(file_name)
Expand Down
18 changes: 11 additions & 7 deletions lua/doing/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,21 @@ function Utils.task_modified()
})
end

---@brief show a message for the duration of `options.message_timeout` or timeout
--- show a message for the duration of `options.message_timeout` or timeout
---@param str string message to show
---@param timeout? number time in ms to show message
function Utils.show_message(str, timeout)
require("doing.state").message = str
Utils.task_modified()
if config.options.show_messages then
require("doing.state").message = str
Utils.task_modified()

vim.defer_fn(function()
require("doing.state").message = nil
vim.defer_fn(function()
require("doing.state").message = nil
Utils.task_modified()
end, timeout or config.options.message_timeout)
else
Utils.task_modified()
end, timeout or config.options.message_timeout)
end
end

function Utils.get_path_separator()
Expand All @@ -87,7 +91,7 @@ function Utils.get_path_separator()
return dir_separator
end

---@brief calls vim.notify with a title and icon
--- calls vim.notify with a title and icon
---@param msg string the message to show
---@param log_level? integer the log level to show
function Utils.notify(msg, log_level)
Expand Down

0 comments on commit 7e7dfab

Please sign in to comment.