dotfiles/nvim/lua/config/compose.lua

42 lines
803 B
Lua
Raw Normal View History

2024-01-23 22:23:58 +01:00
---Tags used for filtering certain features
---@alias ComposerTag
--- | 'standalone' # True if running as a standalone application
--- | 'linux' # True if running on Linux
2024-01-22 23:14:16 +01:00
2024-01-23 22:23:58 +01:00
---@type table<ComposerTag, boolean>
2024-01-22 23:14:16 +01:00
local env = {
2024-06-13 21:48:16 +02:00
standalone = not vim.g.vscode,
linux = jit.os == 'Linux',
2024-01-22 23:14:16 +01:00
}
2024-01-23 22:23:58 +01:00
---@param tags ComposerTag | ComposerTag[]
---@return boolean
2024-01-22 23:14:16 +01:00
local function is(tags)
2024-06-13 21:48:16 +02:00
if type(tags) == 'string' then
return env[tags] or false
end
2024-01-22 23:14:16 +01:00
2024-06-13 21:48:16 +02:00
for _, tag in ipairs(tags) do
if not env[tag] then
return false
end
end
2024-01-23 22:23:58 +01:00
2024-06-13 21:48:16 +02:00
return true
2024-01-22 23:14:16 +01:00
end
2024-01-23 22:23:58 +01:00
---@param tags ComposerTag | ComposerTag[]
2024-01-22 23:14:16 +01:00
local function when(tags)
2024-06-13 21:48:16 +02:00
local match = is(tags)
---@generic T
---@param value `T`
---@return T | nil
return function(value)
return match and value or nil
end
2024-01-22 23:14:16 +01:00
end
return function()
2024-06-13 21:48:16 +02:00
return is, when
2024-01-22 23:14:16 +01:00
end