Skip to content

Commit

Permalink
feat(summary): tweak help format
Browse files Browse the repository at this point in the history
  • Loading branch information
rcarriga committed Mar 18, 2024
1 parent d38d38b commit 65f6922
Showing 1 changed file with 30 additions and 23 deletions.
53 changes: 30 additions & 23 deletions lua/neotest/consumers/summary/component.lua
Original file line number Diff line number Diff line change
Expand Up @@ -233,30 +233,37 @@ function SummaryComponent:_render(canvas, tree, expanded, focused, indent)
neotest.summary.clear_marked({ adapter = self.adapter_id })
end)

canvas:add_mapping("help", async_func(function()
local help_text = {
"SUMMARY MAPPINGS",
"================",
}
for name, mapping in pairs(config.summary.mappings) do
local mappings = type(mapping) == "table" and table.concat(mapping, ", ") or mapping
local line = "(" .. name .. "): " .. mappings
table.insert(help_text, line)
end
canvas:add_mapping(
"help",
async_func(function()
local help_text = {}
local width = 0
for name, mapping in pairs(config.summary.mappings) do
local mappings = type(mapping) == "table" and table.concat(mapping, ", ") or mapping
local line = "(" .. name .. "): " .. mappings
width = math.max(width, #line)
table.insert(help_text, line)
end

local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, help_text)
vim.api.nvim_buf_set_option(buf, "modifiable", false)
local float = lib.ui.float.open({
width = 80,
height = 60,
buffer = buf,
auto_close = true,
})
local win = float.win_id
vim.api.nvim_win_set_buf(win, buf)
vim.api.nvim_set_current_win(win)
end))
table.insert(help_text, 1, "Mappings")
width = math.max(width, #help_text[1])
table.insert(help_text, 2, string.rep("=", width))

local buf = vim.api.nvim_create_buf(false, true)
vim.api.nvim_buf_set_lines(buf, 0, -1, false, help_text)
vim.api.nvim_buf_set_option(buf, "modifiable", false)
local float = lib.ui.float.open({
width = width,
height = #help_text,
buffer = buf,
auto_close = true,
})
local win = float.win_id
vim.api.nvim_win_set_buf(win, buf)
vim.api.nvim_set_current_win(win)
vim.api.nvim_buf_set_keymap(buf, "n", "q", "<cmd>q<CR>", { noremap = true, silent = true })
end)
)

local status = self:_get_status(position)
has_running = has_running or status == "running"
Expand Down

0 comments on commit 65f6922

Please sign in to comment.