Skip to content

Commit 4a0da37

Browse files
feat: allow custom time format (#214)
1 parent 5d33f5e commit 4a0da37

File tree

4 files changed

+16
-3
lines changed

4 files changed

+16
-3
lines changed

lua/notify/config/init.lua

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ local default_config = {
3030
minimum_width = 50,
3131
fps = 30,
3232
top_down = true,
33+
time_formats = {
34+
notification_history = "%FT%T",
35+
notification = "%T",
36+
},
3337
icons = {
3438
ERROR = "",
3539
WARN = "",
@@ -47,6 +51,7 @@ local default_config = {
4751
---@field stages string|function[] Animation stages
4852
---@field background_colour string For stages that change opacity this is treated as the highlight behind the window. Set this to either a highlight group, an RGB hex value e.g. "#000000" or a function returning an RGB code for dynamic values
4953
---@field icons table Icons for each level (upper case names)
54+
---@field time_formats table Time formats for different kind of notifications
5055
---@field on_open function Function called when a new window is opened, use for changing win settings/config
5156
---@field on_close function Function called when a window is closed
5257
---@field render function|string Function to render a notification buffer or a built-in renderer name
@@ -127,6 +132,10 @@ function Config.setup(custom_config)
127132
return tonumber(user_config.background_colour():gsub("#", "0x"), 16)
128133
end
129134

135+
function config.time_formats()
136+
return user_config.time_formats
137+
end
138+
130139
function config.icons()
131140
return user_config.icons
132141
end

lua/notify/init.lua

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ function notify._print_history()
159159
end
160160
for _, notif in ipairs(global_instance.history()) do
161161
vim.api.nvim_echo({
162-
{ vim.fn.strftime("%FT%T", notif.time), "NotifyLogTime" },
162+
{
163+
vim.fn.strftime(notify._config().time_formats().notification_history, notif.time),
164+
"NotifyLogTime",
165+
},
163166
{ " ", "MsgArea" },
164167
{ notif.title[1], "NotifyLogTitle" },
165168
{ #notif.title[1] > 0 and " " or "", "MsgArea" },

lua/notify/service/notification.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ function Notification:new(id, message, level, opts, config)
2929
local time = vim.fn.localtime()
3030
local title = opts.title or ""
3131
if type(title) == "string" then
32-
title = { title, vim.fn.strftime("%H:%M", time) }
32+
title = { title, vim.fn.strftime(config.time_formats().notification, time) }
3333
end
3434
vim.validate({
3535
message = { message, "table" },

lua/telescope/_extensions/notify.lua

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ local displayer = entry_display.create({
2727
})
2828

2929
local telescope_notifications = function(opts)
30+
local time_format = require("notify")._config().time_formats().notification
3031
local notifs = require("notify").history()
3132
local reversed = {}
3233
for i, notif in ipairs(notifs) do
@@ -43,7 +44,7 @@ local telescope_notifications = function(opts)
4344
value = notif,
4445
display = function(entry)
4546
return displayer({
46-
{ vim.fn.strftime("%T", entry.value.time), "NotifyLogTime" },
47+
{ vim.fn.strftime(time_format, entry.value.time), "NotifyLogTime" },
4748
{ entry.value.title[1], "NotifyLogTitle" },
4849
{ entry.value.icon, "Notify" .. entry.value.level .. "Title" },
4950
{ entry.value.level, "Notify" .. entry.value.level .. "Title" },

0 commit comments

Comments
 (0)