rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
3.09k stars 83 forks source link

Change format depending on whether the title is supplied #55

Closed VrIgHtEr closed 2 years ago

VrIgHtEr commented 2 years ago

I have set this plugin as the default notify function in nvim.

When writing my own code, I always supply the title in the opts table (3rd parameter), as I know I will be using this plugin. However not every plugin might be aware of this possible functionality. As a result notifications are a bit ugly in that they still have the title line, but it's blank.

Is it possible to maybe add an option to switch the theme for a particular notification based on whether the title is available or not? For example to use the default theme if a title is supplied, but use the minimal theme if no title was supplied?

rcarriga commented 2 years ago

You can do this by just using a simple wrapper render function in the setup

  local notify_renderers = require("notify.render")

  require("notify").setup({ 
  ...
  render = function (bufnr, notif, highlights) 
    if notif.title[1] == "" then
      return notify_renderers.minimal(bufnr, notif, highlights)
    else
      return notify_renderers.default(bufnr, notif, highlights)
    end
  end
VrIgHtEr commented 2 years ago

Thanks a lot!