Skip to content

Commit

Permalink
feat: provide right header
Browse files Browse the repository at this point in the history
Closes #14
  • Loading branch information
rcarriga committed Sep 1, 2021
1 parent 280a08c commit 1350ba9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -33,7 +33,7 @@ There are a number of custom options that can be supplied in a table as the thir
- `timeout`: Number of milliseconds to show the window (default 5000)
- `on_open`: A function to call with the window ID as an argument after opening
- `on_close`: A function to call with the window ID as an argument after closing
- `title`: Title string for the header
- `title`: Title string or tuple of strings for the header. If tuple, the right header is set to the second element.
- `icon`: Icon to use for the header
- `keep`: Function that returns whether or not to keep the window open instead of using a timeout

Expand Down
4 changes: 2 additions & 2 deletions lua/notify/service/buffer/init.lua
Expand Up @@ -72,15 +72,15 @@ function NotificationBuf:render()

api.nvim_buf_set_option(buf, "modifiable", true)

local right_title = vim.fn.strftime("%H:%M", notif.time)
local left_icon = notif.icon .. " "
local max_width = math.max(
math.max(unpack(vim.tbl_map(function(line)
return vim.fn.strchars(line)
end, notif.message))),
50
)
local left_title = (notif.title or "") .. string.rep(" ", max_width)
local left_title = notif.title[1] .. string.rep(" ", max_width)
local right_title = notif.title[2]
api.nvim_buf_set_lines(buf, 0, 1, false, { "", "" })
api.nvim_buf_set_extmark(buf, namespace, 0, 0, {
virt_text = {
Expand Down
11 changes: 8 additions & 3 deletions lua/notify/service/notification.lua
Expand Up @@ -4,7 +4,7 @@ local config = require("notify.config")
---@field level string
---@field message string
---@field timeout number | nil
---@field title string
---@field title string[]
---@field icon string
---@field time number
---@field width number
Expand All @@ -21,11 +21,16 @@ function Notification:new(message, level, opts)
message = vim.split(message, "\n")
end
level = vim.fn.toupper(level or "info")
local time = vim.fn.localtime()
local title = opts.title or ""
if type(title) == "string" then
title = { title, vim.fn.strftime("%H:%M", time) }
end
local notif = {
message = message,
title = opts.title or "",
title = title,
icon = opts.icon or config.icons()[level] or config.icons().INFO,
time = vim.fn.localtime(),
time = time,
timeout = opts.timeout,
level = level,
keep = opts.keep,
Expand Down

0 comments on commit 1350ba9

Please sign in to comment.