Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
gadefox opened this issue May 25, 2023 · 4 comments
Open

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

gadefox opened this issue May 25, 2023 · 4 comments

Comments

@gadefox
Copy link

gadefox commented May 25, 2023

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 added a commit that referenced this issue Jun 5, 2023
@rcarriga
Copy link
Owner

rcarriga commented Jun 5, 2023

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
Copy link
Author

gadefox commented Jun 5, 2023

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
Copy link
Author

gadefox commented Jun 5, 2023

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
Copy link
Author

gadefox commented Jun 6, 2023

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants