Skip to content

Commit

Permalink
feat: add Terminal.find function
Browse files Browse the repository at this point in the history
  • Loading branch information
willothy committed Sep 6, 2023
1 parent 12cba0a commit c160dee
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions lua/toggleterm/terminal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -536,6 +536,23 @@ function M.get(id, include_hidden)
return (term and (include_hidden == true or not term.hidden)) and term or nil
end

---Get the first terminal that matches a predicate
---@param predicate fun(term: Terminal): boolean
---@return Terminal?
function M.find(predicate)
if type(predicate) ~= "function" then
vim.notify_once(
"[toggleterm.nvim] terminal.find predicate expects a function, got " .. type(predicate),
vim.log.levels.ERROR
)
return
end
for _, term in pairs(terminals) do
if predicate(term) then return term end
end
return nil
end

---Return the potentially non contiguous map of terminals as a sorted array
---@param include_hidden boolean? whether or nor to filter out hidden
---@return Terminal[]
Expand Down

0 comments on commit c160dee

Please sign in to comment.