Skip to content

Commit

Permalink
🥨 work in progress Mon Oct 21 19:55:41 2024
Browse files Browse the repository at this point in the history
  • Loading branch information
mosheavni committed Oct 21, 2024
1 parent ab17e0e commit 9f3093a
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 0 deletions.
15 changes: 15 additions & 0 deletions lua/kubectl/mappings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,23 @@ function M.register()
local current_view, _ = view.view_and_definition(string.lower(vim.trim(buf_name)))

local name, ns = current_view.getCurrentSelection()
local resource_idx = 0
for i, row in ipairs(state.instance.processedData) do
if row.name == name and (ns and row.ns == ns or true) then
resource_idx = i
break
end
end
local resource = state.instance.processedData[resource_idx]
local line_number = vim.api.nvim_win_get_cursor(0)[1]

if resource.selected then
resource.selected = false
else
resource.selected = true
end
vim.print("resource selected: " .. vim.inspect(resource))

if state.selections.selected["line" .. line_number] then
state.selections.selected["line" .. line_number] = nil
else
Expand Down
1 change: 1 addition & 0 deletions lua/kubectl/resourcebuilder.lua
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,7 @@ function ResourceBuilder:view(definition, cancellationToken, opts)
end)

state.instance = self
state.selections.selected = {}
return self
end

Expand Down
16 changes: 16 additions & 0 deletions lua/kubectl/utils/tables.lua
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,8 @@ function M.pretty_print(data, headers, sort_by)
current_col_position = current_col_position + #display_value
end
table.insert(tbl, table.concat(row_line, ""))

-- selections
end

return tbl, extmarks
Expand Down Expand Up @@ -525,6 +527,20 @@ function M.find_resource(data, name, namespace)
return nil
end

function M.find_processed_resource(data, name, namespace)
if data.items then
return vim.iter(data.items):find(function(row)
return row.metadata.name == name and (namespace and row.metadata.namespace == namespace or true)
end)
end
if data.rows then
return vim.iter(data.rows):find(function(row)
return row.object.metadata.name == name and (namespace and row.object.metadata.namespace == namespace or true)
end).object
end
return nil
end

--- Check if a table is empty
---@param table table
---@return boolean
Expand Down

0 comments on commit 9f3093a

Please sign in to comment.