rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
2.88k stars 72 forks source link

[Feature Request] add a bell to the notification #246

Closed fent closed 4 months ago

fent commented 5 months ago

Sometimes I look away from my terminal and look at other apps. During that time, a notification could have happened. It would be convenient to know when that happens in case it needs my attention, such as when a test/build is finished.

The shell bell can be a nice way to achieve this. By having nvim-notify run tput bel, we can get that effect

rcarriga commented 4 months ago

You can do this by using the on_open in your setup

    on_open = function()
      vim.loop.spawn("tput", { args = { "bel" } })
    end,
fent commented 2 months ago

Not sure why the above didn't work, but the following did

on_open = function()
  if vim.fn.executable("tput") == 0 then
    return
  end
  local dummy_bufnr = vim.api.nvim_create_buf(false, true)
  vim.api.nvim_buf_call(dummy_bufnr, function()
    vim.cmd.edit("term://tput bel")
    vim.defer_fn(function()
      vim.api.nvim_buf_delete(dummy_bufnr, { force = true })
    end, 500)
  end)
end,

It starts a terminal with the tput bel command, then closes it in 500ms. There may be a better lua way to start the terminal than calling :edit