Skip to content

Commit

Permalink
feat: add toggleable_timestamps_in_logs (#284)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ramilito committed Aug 29, 2024
1 parent a076125 commit b637e87
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
16 changes: 16 additions & 0 deletions ftplugin/k8s_pod_logs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local str = require("kubectl.utils.string")
mappings.map_if_plug_not_set("n", "f", "<Plug>(kubectl.follow)")
mappings.map_if_plug_not_set("n", "gw", "<Plug>(kubectl.wrap)")
mappings.map_if_plug_not_set("n", "gp", "<Plug>(kubectl.prefix)")
mappings.map_if_plug_not_set("n", "gt", "<Plug>(kubectl.timestamps)")
mappings.map_if_plug_not_set("n", "<CR>", "<Plug>(kubectl.select)")

--- Set key mappings for the buffer
Expand All @@ -27,6 +28,21 @@ local function set_keymaps(bufnr)
end,
})

vim.api.nvim_buf_set_keymap(bufnr, "n", "<Plug>(kubectl.timestamps)", "", {
noremap = true,
silent = true,
desc = "Toggle timestamps",
callback = function()
if pod_view.show_timestamps == "true" then
pod_view.show_timestamps = "false"
else
pod_view.show_timestamps = "true"
end
vim.cmd.close()
pod_view.Logs()
end,
})

vim.api.nvim_buf_set_keymap(bufnr, "n", "<Plug>(kubectl.prefix)", "", {
noremap = true,
silent = true,
Expand Down
7 changes: 5 additions & 2 deletions lua/kubectl/views/pods/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@ local M = {
selection = {},
pfs = {},
tail_handle = nil,
-- TODO: should propably be configurable
show_log_prefix = "true",
show_timestamps = "true",
}

function M.View(cancellationToken)
Expand Down Expand Up @@ -41,7 +43,7 @@ function M.TailLogs(pod, ns, container)
else
table.insert(args, "--all-containers=true")
table.insert(args, "--prefix=" .. M.show_log_prefix)
table.insert(args, "--timestamps=true")
table.insert(args, "--timestamps=" .. M.show_timestamps)
end
local buf = vim.api.nvim_get_current_buf()
local logs_win = vim.api.nvim_get_current_win()
Expand Down Expand Up @@ -95,7 +97,7 @@ function M.Logs()
"logs",
"--all-containers=true",
"--prefix=" .. M.show_log_prefix,
"--timestamps=true",
"--timestamps=" .. M.show_timestamps,
M.selection.pod,
"-n",
M.selection.ns,
Expand All @@ -105,6 +107,7 @@ function M.Logs()
{ key = "<Plug>(kubectl.follow)", desc = "Follow" },
{ key = "<Plug>(kubectl.wrap)", desc = "Wrap" },
{ key = "<Plug>(kubectl.prefix)", desc = "Prefix" },
{ key = "<Plug>(kubectl.timestamps)", desc = "Timestamps" },
},
}, { cmd = "kubectl" })
end
Expand Down

0 comments on commit b637e87

Please sign in to comment.