Merge tag.add and tag.add_table

This commit is contained in:
Ottatop 2023-07-20 16:54:26 -05:00
parent 2d42f01b8a
commit afc0818805
3 changed files with 35 additions and 44 deletions

View file

@ -22,16 +22,11 @@ end
---Add tags to this output. See `tag.add`. ---Add tags to this output. See `tag.add`.
---@param ... string The names of the tags you want to add. ---@param ... string The names of the tags you want to add.
---@overload fun(self: self, tag_names: string[])
function op:add_tags(...) function op:add_tags(...)
require("tag").add(self, ...) require("tag").add(self, ...)
end end
---Add tags to this output as a table. See `tag.add_table`.
---@param names string[] The names of the tags you want to add, as a table.
function op:add_tags_table(names)
require("tag").add_table(self, names)
end
---Get this output's make. ---Get this output's make.
---@return string|nil ---@return string|nil
function op:make() function op:make()

View file

@ -83,13 +83,11 @@ end
----------------------------------------------------------- -----------------------------------------------------------
---Add tags. ---Add tags to the specified output.
--- ---
---If you need to add the names as a table, use `tag.add_table` instead. ---You can also do `output_object:add_tags(...)`.
--- ---
---You can also do `op:add_tags(...)`. ---### Examples
---
---### Example
--- ---
---```lua ---```lua
---local op = output.get_by_name("DP-1") ---local op = output.get_by_name("DP-1")
@ -97,40 +95,36 @@ end
--- tag.add(op, "1", "2", "3", "4", "5") -- Add tags with names 1-5 --- tag.add(op, "1", "2", "3", "4", "5") -- Add tags with names 1-5
---end ---end
---``` ---```
---@param output Output The output you want these tags to be added to. ---You can also pass in a table.
---@param ... string The names of the new tags you want to add.
function tag.add(output, ...)
local tag_names = table.pack(...)
tag_names["n"] = nil -- remove the length to make it a true array for serializing
SendMsg({
AddTags = {
output_name = output:name(),
tag_names = tag_names,
},
})
end
---Like `tag.add`, but with a table of strings instead.
---
---### Example
---
---```lua ---```lua
---local tags = { "Terminal", "Browser", "Mail", "Gaming", "Potato" } ---local tags = {"Terminal", "Browser", "Code", "Potato", "Email"}
---local output = output.get_by_name("DP-1") ---tag.add(op, tags) -- Add tags with those names
---if output ~= nil then
--- tag.add(output, tags) -- Add tags with the names above
---end
---``` ---```
---@param output Output The output you want these tags to be added to. ---@param output Output The output you want these tags to be added to.
---@param names string[] The names of the new tags you want to add, as a table. ---@param ... string The names of the new tags you want to add.
function tag.add_table(output, names) ---@overload fun(output: Output, tag_names: string[])
SendMsg({ function tag.add(output, ...)
AddTags = { local varargs = { ... }
output_name = output:name(), if type(varargs[1]) == "string" then
tag_names = names, local tag_names = varargs
}, tag_names["n"] = nil -- remove the length to make it a true array for serializing
})
SendMsg({
AddTags = {
output_name = output:name(),
tag_names = tag_names,
},
})
else
local tag_names = varargs[1] --[=[@as string[]]=]
SendMsg({
AddTags = {
output_name = output:name(),
tag_names = tag_names,
},
})
end
end end
---Toggle a tag on the specified output. If `output` isn't specified, toggle it on the currently focused output instead. ---Toggle a tag on the specified output. If `output` isn't specified, toggle it on the currently focused output instead.

View file

@ -138,9 +138,11 @@ require("pinnacle").setup(function(pinnacle)
-- Tags --------------------------------------------------------------------------- -- Tags ---------------------------------------------------------------------------
output.connect_for_all(function(op) output.connect_for_all(function(op)
op:add_tags("1", "2", "3", "4", "5") -- op:add_tags("1", "2", "3", "4", "5")
-- Same as tag.add(op, "1", "2", "3", "4", "5") -- Same as tag.add(op, "1", "2", "3", "4", "5")
tag.toggle("1", op)
local tags_table = { "Terminal", "Browser", "Code", "Email", "Potato" }
op:add_tags(tags_table)
end) end)
---@type Layout[] ---@type Layout[]