nvim-notify icon indicating copy to clipboard operation
nvim-notify copied to clipboard

Is it possible to show the title in the border?

Open gadefox opened this issue 1 year ago • 4 comments

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??

gadefox avatar May 25 '23 19:05 gadefox

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,
  })

rcarriga avatar Jun 05 '23 15:06 rcarriga

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 avatar Jun 05 '23 19:06 gadefox

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 avatar Jun 05 '23 19:06 gadefox

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

gadefox avatar Jun 06 '23 07:06 gadefox