From 4c1efadccc5d4568e3abf0afdd3ee0c5c27b4be9 Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Wed, 12 Jun 2024 10:42:37 +0200 Subject: [PATCH] feat(cmdline): use cmdline prompt as title. Noice is now great for vim.ui.input out of the box --- lua/noice/message/init.lua | 1 + lua/noice/ui/cmdline.lua | 7 +++++-- lua/noice/view/nui.lua | 12 ++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lua/noice/message/init.lua b/lua/noice/message/init.lua index 1bb9746a..d76476ec 100644 --- a/lua/noice/message/init.lua +++ b/lua/noice/message/init.lua @@ -9,6 +9,7 @@ local _id = 0 ---@field super NoiceBlock ---@field id number ---@field event NoiceEvent +---@field title? string ---@field ctime number ---@field mtime number ---@field tick number diff --git a/lua/noice/ui/cmdline.lua b/lua/noice/ui/cmdline.lua index 7e1f2f69..2f77b7c4 100644 --- a/lua/noice/ui/cmdline.lua +++ b/lua/noice/ui/cmdline.lua @@ -124,9 +124,12 @@ function Cmdline:format(message, text_only) message.kind = format.name end - -- FIXME: prompt if self.state.prompt ~= "" then - message:append(self.state.prompt, "NoiceCmdlinePrompt") + if format.view == "cmdline_input" then + message.title = " " .. self.state.prompt:gsub("%s*:%s*$", "") .. " " + else + message:append(self.state.prompt, "NoiceCmdlinePrompt") + end end if not format.conceal then diff --git a/lua/noice/view/nui.lua b/lua/noice/view/nui.lua index 17f9eeff..243cd957 100644 --- a/lua/noice/view/nui.lua +++ b/lua/noice/view/nui.lua @@ -48,7 +48,19 @@ function NuiView:update_options() }, }, self._opts, self:get_layout()) + local title = {} ---@type string[] + for _, m in ipairs(self._messages) do + if m.title then + title[#title + 1] = m.title + end + end + self._opts = Util.nui.normalize(self._opts) + if #title > 0 then + self._opts.border = self._opts.border or {} + self._opts.border.text = self._opts.border.text or {} + self._opts.border.text.top = table.concat(title, " | ") + end if self._opts.anchor == "auto" then if self._opts.type == "popup" and self._opts.size then local width = self._opts.size.width