aboutsummaryrefslogtreecommitdiff
path: root/lua/cmake-explorer/build_list.lua
diff options
context:
space:
mode:
authorDaniil Rozanov <daniilrozzanov@gmail.com>2024-03-18 01:49:23 +0300
committerDaniil Rozanov <daniilrozzanov@gmail.com>2024-03-18 01:49:23 +0300
commit6184ca819279c7e44f470a731fcca3d469f40a01 (patch)
tree4f51162ca534935c2cbbf404c08ea1c51359340b /lua/cmake-explorer/build_list.lua
parentd36594025727d32b6580f188a4c0476aaeecfd77 (diff)
feat: new CMakeConfigureLast and CMakeConfigureDir commands. CMakeConfigure and CMakeConfigureDir now have vim.ui.* interface to edit
Diffstat (limited to 'lua/cmake-explorer/build_list.lua')
-rw-r--r--lua/cmake-explorer/build_list.lua57
1 files changed, 57 insertions, 0 deletions
diff --git a/lua/cmake-explorer/build_list.lua b/lua/cmake-explorer/build_list.lua
new file mode 100644
index 0000000..7abaddc
--- /dev/null
+++ b/lua/cmake-explorer/build_list.lua
@@ -0,0 +1,57 @@
+local Build = require("cmake-explorer.build")
+
+local BuildFilter = {}
+
+BuildFilter.__call = function(self, build)
+ for k, v in pairs(self) do
+ if type(k) == "string" then
+ if v ~= build[k] then
+ return false
+ end
+ end
+ end
+ return true
+end
+
+local BuildList = {
+ __newindex = function(t, k, v)
+ for _, value in ipairs(t) do
+ if value == v then
+ return
+ end
+ end
+ rawset(t, k, v)
+ end,
+}
+
+function BuildList:new()
+ local obj = {
+ current = nil,
+ }
+ setmetatable(obj, BuildList)
+ return obj
+end
+
+function BuildList:insert(o)
+ local build = Build:new(o)
+ table.insert(self, build)
+ self.current = build
+end
+
+function BuildList:filter(pred)
+ pred = pred or {}
+ local i, n = 0, #self
+ if type(pred) == "table" then
+ setmetatable(pred, BuildFilter)
+ end
+ return function()
+ repeat
+ i = i + 1
+ if pred(self[i]) then
+ return self[i]
+ end
+ until i ~= n
+ end
+end
+
+return BuildList