Skip to content

Commit c25174a

Browse files
committed
chore: add nice formatting to AstroNvim notifications
1 parent 02c2f50 commit c25174a

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

init.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ end
1414
if astronvim.default_colorscheme then
1515
if not pcall(vim.cmd.colorscheme, astronvim.default_colorscheme) then
1616
require("astronvim.utils").notify(
17-
"Error setting up colorscheme: " .. astronvim.default_colorscheme,
17+
("Error setting up colorscheme: `%s`"):format(astronvim.default_colorscheme),
1818
vim.log.levels.ERROR
1919
)
2020
end

lua/astronvim/lazy.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ if not vim.loop.fs_stat(lazypath) then
2222
vim.cmd.bw()
2323
vim.opt.cmdheight = oldcmdheight
2424
vim.tbl_map(function(module) pcall(require, module) end, { "nvim-treesitter", "mason" })
25-
require("astronvim.utils").notify "Mason is installing packages if configured, check status with :Mason"
25+
require("astronvim.utils").notify "Mason is installing packages if configured, check status with `:Mason`"
2626
end,
2727
})
2828
end

lua/astronvim/utils/mason.lua

+16-16
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
local M = {}
1313

1414
local utils = require "astronvim.utils"
15-
local notify = utils.notify
1615
local astroevent = utils.event
16+
local function mason_notify(msg, type) utils.notify(msg, type, { title = "Mason" }) end
1717

1818
--- Update specified mason packages, or just update the registries if no packages are listed
1919
---@param pkg_names? string|string[] The package names as defined in Mason (Not mason-lspconfig or mason-null-ls) if the value is nil then it will just update the registries
@@ -32,34 +32,34 @@ function M.update(pkg_names, auto_install)
3232
if success then
3333
local count = #updated_registries
3434
if vim.tbl_count(pkg_names) == 0 then
35-
notify(("Successfully updated %d %s."):format(count, count == 1 and "registry" or "registries"))
35+
mason_notify(("Successfully updated %d %s."):format(count, count == 1 and "registry" or "registries"))
3636
end
3737
for _, pkg_name in ipairs(pkg_names) do
3838
local pkg_avail, pkg = pcall(registry.get_package, pkg_name)
3939
if not pkg_avail then
40-
notify(("Mason: %s is not available"):format(pkg_name), vim.log.levels.ERROR)
40+
mason_notify(("`%s` is not available"):format(pkg_name), vim.log.levels.ERROR)
4141
else
4242
if not pkg:is_installed() then
4343
if auto_install then
44-
notify(("Mason: Installing %s"):format(pkg.name))
44+
mason_notify(("Installing `%s`"):format(pkg.name))
4545
pkg:install()
4646
else
47-
notify(("Mason: %s not installed"):format(pkg.name), vim.log.levels.WARN)
47+
mason_notify(("`%s` not installed"):format(pkg.name), vim.log.levels.WARN)
4848
end
4949
else
5050
pkg:check_new_version(function(update_available, version)
5151
if update_available then
52-
notify(("Mason: Updating %s to %s"):format(pkg.name, version.latest_version))
53-
pkg:install():on("closed", function() notify(("Mason: Updated %s"):format(pkg.name)) end)
52+
mason_notify(("Updating `%s` to %s"):format(pkg.name, version.latest_version))
53+
pkg:install():on("closed", function() mason_notify(("Updated %s"):format(pkg.name)) end)
5454
else
55-
notify(("Mason: No updates available for %s"):format(pkg.name))
55+
mason_notify(("No updates available for `%s`"):format(pkg.name))
5656
end
5757
end)
5858
end
5959
end
6060
end
6161
else
62-
notify(("Failed to update registries: %s"):format(updated_registries), vim.log.levels.ERROR)
62+
mason_notify(("Failed to update registries: %s"):format(updated_registries), vim.log.levels.ERROR)
6363
end
6464
end))
6565
end
@@ -72,37 +72,37 @@ function M.update_all()
7272
return
7373
end
7474

75-
notify "Mason: Checking for package updates..."
75+
mason_notify "Checking for package updates..."
7676
registry.update(vim.schedule_wrap(function(success, updated_registries)
7777
if success then
7878
local installed_pkgs = registry.get_installed_packages()
7979
local running = #installed_pkgs
8080
local no_pkgs = running == 0
8181

8282
if no_pkgs then
83-
notify "Mason: No updates available"
83+
mason_notify "No updates available"
8484
astroevent "MasonUpdateCompleted"
8585
else
8686
local updated = false
8787
for _, pkg in ipairs(installed_pkgs) do
8888
pkg:check_new_version(function(update_available, version)
8989
if update_available then
9090
updated = true
91-
notify(("Mason: Updating %s to %s"):format(pkg.name, version.latest_version))
91+
mason_notify(("Updating `%s` to %s"):format(pkg.name, version.latest_version))
9292
pkg:install():on("closed", function()
9393
running = running - 1
9494
if running == 0 then
95-
notify "Mason: Update Complete"
95+
mason_notify "Update Complete"
9696
astroevent "MasonUpdateCompleted"
9797
end
9898
end)
9999
else
100100
running = running - 1
101101
if running == 0 then
102102
if updated then
103-
notify "Mason: Update Complete"
103+
mason_notify "Update Complete"
104104
else
105-
notify "Mason: No updates available"
105+
mason_notify "No updates available"
106106
end
107107
astroevent "MasonUpdateCompleted"
108108
end
@@ -111,7 +111,7 @@ function M.update_all()
111111
end
112112
end
113113
else
114-
notify(("Failed to update registries: %s"):format(updated_registries), vim.log.levels.ERROR)
114+
mason_notify(("Failed to update registries: %s"):format(updated_registries), vim.log.levels.ERROR)
115115
end
116116
end))
117117
end

lua/astronvim/utils/updater.lua

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ end
7575
function M.version(quiet)
7676
local version = astronvim.install.version or git.current_version(false) or "unknown"
7777
if astronvim.updater.options.channel ~= "stable" then version = ("nightly (%s)"):format(version) end
78-
if version and not quiet then notify("Version: " .. version) end
78+
if version and not quiet then notify(("Version: *%s*"):format(version)) end
7979
return version
8080
end
8181

@@ -147,7 +147,7 @@ function M.update_available(opts)
147147
-- if the git command is not available, then throw an error
148148
if not git.available() then
149149
notify(
150-
"git command is not available, please verify it is accessible in a command line. This may be an issue with your PATH",
150+
"`git` command is not available, please verify it is accessible in a command line. This may be an issue with your `PATH`",
151151
vim.log.levels.ERROR
152152
)
153153
return

lua/plugins/neo-tree.lua

+1-1
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ return {
9797
vim.api.nvim_echo(messages, false, {})
9898
local result = results[vim.fn.getcharstr()]
9999
if result and result.val and result.val ~= "" then
100-
vim.notify("Copied: " .. result.val)
100+
utils.notify(("Copied: `%s`"):format(result.val))
101101
vim.fn.setreg("+", result.val)
102102
end
103103
end,

0 commit comments

Comments
 (0)