diff --git a/ftplugin/k8s_pod_logs.lua b/ftplugin/k8s_pod_logs.lua index 8b7bddb2..47373e39 100644 --- a/ftplugin/k8s_pod_logs.lua +++ b/ftplugin/k8s_pod_logs.lua @@ -5,6 +5,7 @@ local str = require("kubectl.utils.string") mappings.map_if_plug_not_set("n", "f", "(kubectl.follow)") mappings.map_if_plug_not_set("n", "gw", "(kubectl.wrap)") mappings.map_if_plug_not_set("n", "gp", "(kubectl.prefix)") +mappings.map_if_plug_not_set("n", "gt", "(kubectl.timestamps)") mappings.map_if_plug_not_set("n", "", "(kubectl.select)") --- Set key mappings for the buffer @@ -27,6 +28,21 @@ local function set_keymaps(bufnr) end, }) + vim.api.nvim_buf_set_keymap(bufnr, "n", "(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", "(kubectl.prefix)", "", { noremap = true, silent = true, diff --git a/lua/kubectl/views/pods/init.lua b/lua/kubectl/views/pods/init.lua index 58128bbb..cf94f8e4 100644 --- a/lua/kubectl/views/pods/init.lua +++ b/lua/kubectl/views/pods/init.lua @@ -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) @@ -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() @@ -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, @@ -105,6 +107,7 @@ function M.Logs() { key = "(kubectl.follow)", desc = "Follow" }, { key = "(kubectl.wrap)", desc = "Wrap" }, { key = "(kubectl.prefix)", desc = "Prefix" }, + { key = "(kubectl.timestamps)", desc = "Timestamps" }, }, }, { cmd = "kubectl" }) end