Skip to content

Commit

Permalink
feat(cmdline): use cmdline prompt as title. Noice is now great for vi…
Browse files Browse the repository at this point in the history
…m.ui.input out of the box
  • Loading branch information
folke committed Jun 12, 2024
1 parent ba79352 commit 4c1efad
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions lua/noice/message/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 5 additions & 2 deletions lua/noice/ui/cmdline.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions lua/noice/view/nui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 4c1efad

Please sign in to comment.