rcarriga / nvim-notify

A fancy, configurable, notification manager for NeoVim
MIT License
2.91k stars 74 forks source link

Is it possible to show the title in the border? #200

Open gadefox opened 1 year ago

gadefox commented 1 year ago

I'm trying to change the renderer according to this. I know how to change the colors, I can change the message buffer renderer and I'd like to display the title in the border. Any idea??

rcarriga commented 1 year ago

on_open now receives the notification record so you can use it for setting the title like so

  notify.setup({
    on_open = function(win, record)
      vim.api.nvim_win_set_config(win, { title = record.title[1], title_pos = "center" })
    end,
  })
gadefox commented 1 year ago
set_hl {
  NotifyINFOBody = { bg = palette.surface0 },
  NotifyINFOBorder = { bg = palette.surface0, fg = palette.surface0 },
  NotifyINFOIcon = { bg = palette.surface0, fg = palette.green },
  NotifyINFOTitle = { bg = palette.green, fg = palette.mantle },
  NotifyWARNBody = { bg = palette.surface0 },
  NotifyWARNBorder = { bg = palette.surface0, fg = palette.surface0 },
  NotifyWARNIcon = { bg = palette.surface0, fg = palette.peach },
  NotifyWARNTitle = { bg = palette.peach, fg = palette.mantle },
  NotifyERRORBody = { bg = palette.surface0 },
  NotifyERRORBorder = { bg = palette.surface0, fg = palette.surface0 },
  NotifyERRORIcon = { bg = palette.surface0, fg = palette.red },
  NotifyERRORTitle = { bg = palette.red, fg = palette.mantle }
}

local renderbase = require("notify.render.base")

require("notify").setup {
  on_open = function(win, record)
    vim.api.nvim_win_set_config(win, {
      border = "solid",
      title = {
        {
          " " .. record.title[1] .. " ",
          "Notify" .. record.level .. "Title"
        }
      },
      title_pos = "center"
    })
  end,
  render = function(bufnr, notif, highlights)
    local namespace = renderbase.namespace()
    local length = string.len(notif.icon)

    notif.message[1] = string.format("%s %s", notif.icon, notif.message[1])
    vim.api.nvim_buf_set_lines(bufnr, 0, -1, false, notif.message)

    vim.api.nvim_buf_set_extmark(bufnr, namespace, 0, 0, {
      hl_group = highlights.icon,
      end_col = length,
      priority = 50
    })
    vim.api.nvim_buf_set_extmark(bufnr, namespace, 0, length, {
      hl_group = highlights.body,
      end_line = #notif.message,
      priority = 50
    })
  end
}
gadefox commented 1 year ago

theme


@rcarriga Any idea why the message type (record.level) is wrong here?

  1. open new nvim
  2. exec :PackerUpdate
  3. try to save the file (:w)
gadefox commented 1 year ago

@rcarriga https://pasteboard.co/RFDUpBusMntk.png