-- Small shared pieces of the IDE's own screens. local M = {} --- A read-only page in a centred floating window; q or closes it. Returns the buffer. function M.page(title, lines) local buf = vim.api.nvim_create_buf(false, true) vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines) vim.bo[buf].modifiable = false vim.bo[buf].bufhidden = "wipe" vim.bo[buf].filetype = "llembas-ide-page" local width = 20 for _, l in ipairs(lines) do width = math.max(width, vim.fn.strdisplaywidth(l)) end width = math.min(width + 2, math.max(20, vim.o.columns - 4)) local height = math.min(#lines, math.max(3, vim.o.lines - 6)) local win = vim.api.nvim_open_win(buf, true, { relative = "editor", style = "minimal", border = "rounded", title = " " .. title .. " ", title_pos = "center", width = width, height = height, row = math.max(0, math.floor((vim.o.lines - height) / 2) - 1), col = math.max(0, math.floor((vim.o.columns - width) / 2)), }) vim.wo[win].wrap = false vim.wo[win].cursorline = false for _, key in ipairs({ "q", "" }) do vim.keymap.set("n", key, function() pcall(vim.api.nvim_win_close, win, true) end, { buffer = buf, nowait = true }) end return buf, win end return M