Skip to content

Commit

Permalink
feat: noice presets
Browse files Browse the repository at this point in the history
  • Loading branch information
folke committed Oct 27, 2022
1 parent 498a8b3 commit c43d82b
Show file tree
Hide file tree
Showing 2 changed files with 110 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lua/noice/config/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,13 @@ M.defaults = {
-- add any filetypes here, that shouldn't trigger smart move.
excluded_filetypes = { "cmp_menu", "cmp_docs", "notify" },
},
---@type NoicePresets
presets = {
-- you can enable a preset by setting it to true, or a table that will override the preset config
bottom_search = false, -- use a classic bottom cmdline for search
command_palette = false, -- position the cmdline and popupmenu together
long_message_to_split = false, -- long messages will be sent to a split
},
throttle = 1000 / 30, -- how frequently does Noice need to check for ui updates? This has no effect when in blocking mode.
---@type NoiceConfigViews
views = {}, ---@see section on views
Expand Down Expand Up @@ -181,13 +188,15 @@ function M.setup(options)
},
}, options)

require("noice.config.preset").setup()

if M.options.popupmenu.kind_icons == false then
M.options.popupmenu.kind_icons = {}
end

require("noice.config.cmdline").setup()

M.options.routes = Routes.get(options.routes)
M.options.routes = Routes.get(M.options.routes)

require("noice.config.highlights").setup()
vim.api.nvim_create_autocmd("ColorScheme", {
Expand Down
100 changes: 100 additions & 0 deletions lua/noice/config/preset.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
local require = require("noice.util.lazy")

local Util = require("noice.util")
local Config = require("noice.config")

---@class NoicePreset: NoiceConfig
---@field enabled? boolean

local M = {}

function M.setup()
for name, preset in pairs(Config.options.presets) do
if preset ~= false then
M.load(name, preset)
end
end
end

---@param name string
---@param preset NoiceConfig|boolean
function M.load(name, preset)
if preset == true and not M.presets[name] then
return Util.panic("Unknown preset " .. name)
end

preset = vim.tbl_deep_extend("force", {}, M.presets[name], type(preset) == "table" and preset or {})
---@cast preset NoicePreset

if preset.enabled == false then
return
end

local routes = preset.routes
preset.routes = nil
Config.options = vim.tbl_deep_extend("force", Config.options, preset)
if routes then
vim.list_extend(Config.options.routes, routes)
end
end

---@class NoicePresets: table<string, NoicePreset|boolean>
M.presets = {
bottom_search = {
cmdline = {
format = {
search_down = {
view = "cmdline",
},
search_up = {
view = "cmdline",
},
},
},
},
command_palette = {
views = {
cmdline_popup = {
position = {
row = 3,
col = "50%",
},
size = {
min_width = 60,
width = "auto",
height = "auto",
},
},
popupmenu = {
relative = "editor",
position = {
row = 6,
col = "50%",
},
size = {
width = 60,
height = "auto",
max_height = 15,
},
border = {
style = "rounded",
padding = { 0, 1 },
},
win_options = {
winhighlight = { Normal = "Normal", FloatBorder = "NoiceCmdlinePopupBorder" },
},
},
},
},
long_message_to_split = {
routes = {
{
filter = { event = "msg_show", min_height = 20 },
view = "split",
opts = { enter = true },
},
},
},
}

return M

0 comments on commit c43d82b

Please sign in to comment.