From a07db1a72334bf6550683d5f9132d806febed1cd Mon Sep 17 00:00:00 2001 From: Folke Lemaitre Date: Mon, 18 Nov 2024 23:32:49 +0100 Subject: [PATCH] feat(snacks): use `snacks.dashboard` as the default dashboard. moved `dashboard-nvim` to extras (#4832) ## Description Snacks has a new dashboard plugin that will be LazyVim's default. Check the docs at https://github.com/folke/snacks.nvim/blob/main/docs/dashboard.md ## Related Issue(s) ## Screenshots ## Checklist - [x] I've read the [CONTRIBUTING](https://github.com/LazyVim/LazyVim/blob/main/CONTRIBUTING.md) guidelines. --- NEWS.md | 7 ++ lua/lazyvim/plugins/extras/ui/alpha.lua | 3 +- .../plugins/extras/ui/dashboard-nvim.lua | 68 +++++++++++++++ .../plugins/extras/ui/mini-starter.lua | 3 +- lua/lazyvim/plugins/init.lua | 6 +- lua/lazyvim/plugins/ui.lua | 85 ++++++------------- 6 files changed, 104 insertions(+), 68 deletions(-) create mode 100644 lua/lazyvim/plugins/extras/ui/dashboard-nvim.lua diff --git a/NEWS.md b/NEWS.md index b2bb693b..1b9c1593 100644 --- a/NEWS.md +++ b/NEWS.md @@ -2,6 +2,13 @@ ## 13.x +- **LazyVim** now uses `Snacks.dashboard` as the default dashboard. + Check the [docs](https://github.com/folke/snacks.nvim/blob/main/docs/dashboard.md), + for more information and examples. + +- A new [dashboard-nvim](https://github.com/nvimdev/dashboard-nvim) extra + is available for those who prefer the old dashboard. + - Big new release with a lot of changes and improvements! - The biggest change is the move of a bunch of core features to diff --git a/lua/lazyvim/plugins/extras/ui/alpha.lua b/lua/lazyvim/plugins/extras/ui/alpha.lua index 33f79ba9..2a25a3e7 100644 --- a/lua/lazyvim/plugins/extras/ui/alpha.lua +++ b/lua/lazyvim/plugins/extras/ui/alpha.lua @@ -1,7 +1,6 @@ return { - { "nvimdev/dashboard-nvim", enabled = false }, - { "echasnovski/mini.starter", enabled = false }, + { "folke/snacks.nvim", opts = { dashboard = { enabled = false } } }, -- Dashboard. This runs when neovim starts, and is what displays -- the "LAZYVIM" banner. { diff --git a/lua/lazyvim/plugins/extras/ui/dashboard-nvim.lua b/lua/lazyvim/plugins/extras/ui/dashboard-nvim.lua new file mode 100644 index 00000000..4bda3fe5 --- /dev/null +++ b/lua/lazyvim/plugins/extras/ui/dashboard-nvim.lua @@ -0,0 +1,68 @@ +return { + { "folke/snacks.nvim", opts = { dashboard = { enabled = false } } }, + { + "nvimdev/dashboard-nvim", + lazy = false, -- As https://github.com/nvimdev/dashboard-nvim/pull/450, dashboard-nvim shouldn't be lazy-loaded to properly handle stdin. + opts = function() + local logo = [[ + ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z + ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z + ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z + ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z + ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ + ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ + ]] + + logo = string.rep("\n", 8) .. logo .. "\n\n" + + local opts = { + theme = "doom", + hide = { + -- this is taken care of by lualine + -- enabling this messes up the actual laststatus setting after loading a file + statusline = false, + }, + config = { + header = vim.split(logo, "\n"), + -- stylua: ignore + center = { + { action = 'lua LazyVim.pick()()', desc = " Find File", icon = " ", key = "f" }, + { action = "ene | startinsert", desc = " New File", icon = " ", key = "n" }, + { action = 'lua LazyVim.pick("oldfiles")()', desc = " Recent Files", icon = " ", key = "r" }, + { action = 'lua LazyVim.pick("live_grep")()', desc = " Find Text", icon = " ", key = "g" }, + { action = 'lua LazyVim.pick.config_files()()', desc = " Config", icon = " ", key = "c" }, + { action = 'lua require("persistence").load()', desc = " Restore Session", icon = " ", key = "s" }, + { action = "LazyExtras", desc = " Lazy Extras", icon = " ", key = "x" }, + { action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" }, + { action = function() vim.api.nvim_input("qa") end, desc = " Quit", icon = " ", key = "q" }, + }, + footer = function() + local stats = require("lazy").stats() + local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100) + return { "⚡ Neovim loaded " .. stats.loaded .. "/" .. stats.count .. " plugins in " .. ms .. "ms" } + end, + }, + } + + for _, button in ipairs(opts.config.center) do + button.desc = button.desc .. string.rep(" ", 43 - #button.desc) + button.key_format = " %s" + end + + -- open dashboard after closing lazy + if vim.o.filetype == "lazy" then + vim.api.nvim_create_autocmd("WinClosed", { + pattern = tostring(vim.api.nvim_get_current_win()), + once = true, + callback = function() + vim.schedule(function() + vim.api.nvim_exec_autocmds("UIEnter", { group = "dashboard" }) + end) + end, + }) + end + + return opts + end, + }, +} diff --git a/lua/lazyvim/plugins/extras/ui/mini-starter.lua b/lua/lazyvim/plugins/extras/ui/mini-starter.lua index 6407345c..c1bd7bc1 100644 --- a/lua/lazyvim/plugins/extras/ui/mini-starter.lua +++ b/lua/lazyvim/plugins/extras/ui/mini-starter.lua @@ -1,8 +1,7 @@ -- start screen return { -- disable alpha - { "goolord/alpha-nvim", enabled = false }, - { "nvimdev/dashboard-nvim", enabled = false }, + { "folke/snacks.nvim", opts = { dashboard = { enabled = false } } }, -- enable mini.starter { diff --git a/lua/lazyvim/plugins/init.lua b/lua/lazyvim/plugins/init.lua index 34d67963..cf587454 100644 --- a/lua/lazyvim/plugins/init.lua +++ b/lua/lazyvim/plugins/init.lua @@ -30,11 +30,9 @@ return { opts = function() ---@type snacks.Config return { + bigfile = { enabled = true }, notifier = { enabled = true }, quickfile = { enabled = true }, - bigfile = { enabled = true }, - words = { enabled = true }, - toggle = { map = LazyVim.safe_keymap_set }, statuscolumn = { enabled = false }, -- we set this in options.lua terminal = { win = { @@ -46,6 +44,8 @@ return { }, }, }, + toggle = { map = LazyVim.safe_keymap_set }, + words = { enabled = true }, } end, keys = { diff --git a/lua/lazyvim/plugins/ui.lua b/lua/lazyvim/plugins/ui.lua index c5d8b043..d52c6741 100644 --- a/lua/lazyvim/plugins/ui.lua +++ b/lua/lazyvim/plugins/ui.lua @@ -307,68 +307,31 @@ return { { "MunifTanjim/nui.nvim", lazy = true }, { - "nvimdev/dashboard-nvim", - lazy = false, -- As https://github.com/nvimdev/dashboard-nvim/pull/450, dashboard-nvim shouldn't be lazy-loaded to properly handle stdin. - opts = function() - local logo = [[ - ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z - ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z - ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z - ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z - ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ - ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ - ]] - - logo = string.rep("\n", 8) .. logo .. "\n\n" - - local opts = { - theme = "doom", - hide = { - -- this is taken care of by lualine - -- enabling this messes up the actual laststatus setting after loading a file - statusline = false, - }, - config = { - header = vim.split(logo, "\n"), - -- stylua: ignore - center = { - { action = 'lua LazyVim.pick()()', desc = " Find File", icon = " ", key = "f" }, - { action = "ene | startinsert", desc = " New File", icon = " ", key = "n" }, - { action = 'lua LazyVim.pick("oldfiles")()', desc = " Recent Files", icon = " ", key = "r" }, - { action = 'lua LazyVim.pick("live_grep")()', desc = " Find Text", icon = " ", key = "g" }, - { action = 'lua LazyVim.pick.config_files()()', desc = " Config", icon = " ", key = "c" }, - { action = 'lua require("persistence").load()', desc = " Restore Session", icon = " ", key = "s" }, - { action = "LazyExtras", desc = " Lazy Extras", icon = " ", key = "x" }, - { action = "Lazy", desc = " Lazy", icon = "󰒲 ", key = "l" }, - { action = function() vim.api.nvim_input("qa") end, desc = " Quit", icon = " ", key = "q" }, - }, - footer = function() - local stats = require("lazy").stats() - local ms = (math.floor(stats.startuptime * 100 + 0.5) / 100) - return { "⚡ Neovim loaded " .. stats.loaded .. "/" .. stats.count .. " plugins in " .. ms .. "ms" } + "folke/snacks.nvim", + opts = { + dashboard = { + preset = { + header = [[ + ██╗ █████╗ ███████╗██╗ ██╗██╗ ██╗██╗███╗ ███╗ Z + ██║ ██╔══██╗╚══███╔╝╚██╗ ██╔╝██║ ██║██║████╗ ████║ Z + ██║ ███████║ ███╔╝ ╚████╔╝ ██║ ██║██║██╔████╔██║ z + ██║ ██╔══██║ ███╔╝ ╚██╔╝ ╚██╗ ██╔╝██║██║╚██╔╝██║ z + ███████╗██║ ██║███████╗ ██║ ╚████╔╝ ██║██║ ╚═╝ ██║ + ╚══════╝╚═╝ ╚═╝╚══════╝ ╚═╝ ╚═══╝ ╚═╝╚═╝ ╚═╝ + ]], + ---@param keys snacks.dashboard.Item[] + keys = function(keys) + -- add LazyExtra before Lazy + for k, key in ipairs(keys) do + if key.action == ":Lazy" then + key.key = "l" -- we don't have multiple panes, so `l` is free + table.insert(keys, k, { icon = " ", desc = "Lazy Extras", action = ":LazyExtras", key = "x" }) + break + end + end end, }, - } - - for _, button in ipairs(opts.config.center) do - button.desc = button.desc .. string.rep(" ", 43 - #button.desc) - button.key_format = " %s" - end - - -- open dashboard after closing lazy - if vim.o.filetype == "lazy" then - vim.api.nvim_create_autocmd("WinClosed", { - pattern = tostring(vim.api.nvim_get_current_win()), - once = true, - callback = function() - vim.schedule(function() - vim.api.nvim_exec_autocmds("UIEnter", { group = "dashboard" }) - end) - end, - }) - end - - return opts - end, + }, + }, }, }