Skip to content

Commit 01a84bc

Browse files
authored
feat: add Terminal.find function (#486)
1 parent f2c7207 commit 01a84bc

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

lua/toggleterm/terminal.lua

+14
Original file line numberDiff line numberDiff line change
@@ -536,6 +536,20 @@ function M.get(id, include_hidden)
536536
return (term and (include_hidden == true or not term.hidden)) and term or nil
537537
end
538538

539+
---Get the first terminal that matches a predicate
540+
---@param predicate fun(term: Terminal): boolean
541+
---@return Terminal?
542+
function M.find(predicate)
543+
if type(predicate) ~= "function" then
544+
utils.notify("terminal.find expects a function, got " .. type(predicate), "error")
545+
return
546+
end
547+
for _, term in pairs(terminals) do
548+
if predicate(term) then return term end
549+
end
550+
return nil
551+
end
552+
539553
---Return the potentially non contiguous map of terminals as a sorted array
540554
---@param include_hidden boolean? whether or nor to filter out hidden
541555
---@return Terminal[]

0 commit comments

Comments
 (0)