Skip to content

Commit

Permalink
refactor: highlighting when using snacks.nvim
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisgrieser committed Nov 12, 2024
1 parent cef9c56 commit 984c43f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
10 changes: 3 additions & 7 deletions lua/tinygit/commands/commit-and-amend.lua
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,7 @@ local function insertIssueNumber(mode)
setupNotificationHighlights(highlight.issueText)
local msg = string.format("#%d %s by %s", issue.number, issue.title, issue.user.login)
M.state.issueNotif = u.notify(msg, "info", "Referenced Issue", {
-- `ft`, `keep` and `id` are for `snacks.nvim`
ft = "text",
-- `keep` and `id` are for `snacks.nvim`
id = "tinygit.issue-notification",
keep = function() return true end,
-- `replace`, and `timeout` are for `nvim-notify`
Expand Down Expand Up @@ -274,9 +273,7 @@ local function postCommitNotif(title, stagedAllChanges, commitMsg, extraInfo)
if extraInfo then vim.fn.matchadd("Comment", extraInfo) end
end)

u.notify(text, "info", title, {
ft = "text", -- `ft` only for `snacks.nvim`
})
u.notify(text, "info", title)
end

local function showCommitPreview()
Expand Down Expand Up @@ -353,8 +350,7 @@ local function showCommitPreview()
end)

u.notify(changes, "info", title, {
-- `ft`, `keep` and `id` only for `snacks.nvim`
ft = "text",
-- `keep` and `id` only for `snacks.nvim`
id = "tinygit.commit-preview",
keep = function() return true end,
-- `animate`, `timeout` only for `nvim-notify`
Expand Down
5 changes: 3 additions & 2 deletions lua/tinygit/commands/push-pull.lua
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ local function pushCmd(opts)
local numOfPushedCommits = u.syncShellCmd { "git", "rev-list", "--count", commitRange }
if numOfPushedCommits ~= "" then
local plural = numOfPushedCommits ~= "1" and "s" or ""
out = out .. ("\n(%s commit%s)"):format(numOfPushedCommits, plural)
-- `[]` together with `ft=markdown` -> simple highlighting for `snacks.nvim`
out = out .. ("\n[%s commit%s]"):format(numOfPushedCommits, plural)
end
end
u.notify(out, result.code == 0 and "info" or "error", "Push")
u.notify(out, result.code == 0 and "info" or "error", "Push", { ft = "markdown" })

-- sound
if config.confirmationSound and jit.os == "OSX" then
Expand Down
5 changes: 4 additions & 1 deletion lua/tinygit/shared/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ function M.notify(body, level, title, extraOpts)
local notifyTitle = title and pluginName .. ": " .. title or pluginName
local notifyLevel = level and vim.log.levels[level:upper()] or vim.log.levels.INFO

local baseOpts = { title = notifyTitle }
local baseOpts = {
title = notifyTitle,
ft = "text", -- `ft` only for `snacks.nvim`
}
local opts = vim.tbl_extend("force", baseOpts, extraOpts or {})
return vim.notify(vim.trim(body), notifyLevel, opts)
end
Expand Down

0 comments on commit 984c43f

Please sign in to comment.