Add an option to show timestamps in chat copy

"Show Timestamps In Chat Copy" (chat text settings, on by default) is read
each time chat copy opens. With it off, chat copy takes each line through
pfUI.chat.StripTimestamp, which removes the exact timestamp AddMessage
prepends: the configured color and brackets, so other bracketed text
stays.

Whispers are now recolored before the timestamp goes on, not after. The
recolor turned the stamp's closing "|r " into "|r" plus the whisper color,
so whisper lines did not match. The shown text and the saved history come
out the same.
This commit is contained in:
Brues
2026-10-30 01:25:36 -05:00
parent 7928db33bf
commit 393b37b8c3
4 changed files with 27 additions and 6 deletions
+1
View File
@@ -825,6 +825,7 @@ function pfUI:LoadConfig()
pfUI:UpdateConfig("chat", "text", "timeformat", "%H:%M:%S")
pfUI:UpdateConfig("chat", "text", "timebracket", "[]")
pfUI:UpdateConfig("chat", "text", "timecolor", ".8,.8,.8,1")
pfUI:UpdateConfig("chat", "text", "copytime", "1")
pfUI:UpdateConfig("chat", "text", "tintunknown", "1")
pfUI:UpdateConfig("chat", "text", "unknowncolor", ".7,.7,.7,1")
pfUI:UpdateConfig("chat", "text", "channelnumonly", "1")
+21 -6
View File
@@ -779,6 +779,20 @@ pfUI:RegisterModule("chat", function ()
local r,g,b,a = GetStringColor(C.chat.text.timecolor)
local timecolorhex = rgbhex(r,g,b,a)
-- AddMessage puts the time between these at the start of each line
local timestampStart = timecolorhex .. tleft
local timestampEnd = tright .. "|r "
-- [ StripTimestamp ]
-- Returns a chat line without the timestamp AddMessage put before it.
function pfUI.chat.StripTimestamp(text)
if C.chat.text.time ~= "1" or text:sub(1, #timestampStart) ~= timestampStart then
return text
end
local _, last = text:find(timestampEnd, #timestampStart + 1, true)
return last and text:sub(last + 1) or text
end
local r,g,b = GetStringColor(C.chat.text.unknowncolor)
local unknowncolorhex = rgbhex(r,g,b)
@@ -879,9 +893,15 @@ pfUI:RegisterModule("chat", function ()
-- pushes the whisper colour code off position 1 and the find below fails
local isWhisper = C.chat.global.whispermod == "1" and string.find(text, wcol, 1) == 1
if isWhisper then
-- patch incoming whisper string to match the colors, before the
-- timestamp so it keeps the form StripTimestamp looks for
text = string.gsub(text, "|r", "|r" .. wcol)
end
-- show timestamp in chat
if C.chat.text.time == "1" then
text = timecolorhex .. tleft .. date(C.chat.text.timeformat) .. tright .. "|r " .. text
text = timestampStart .. date(C.chat.text.timeformat) .. timestampEnd .. text
end
-- save chat history
@@ -891,11 +911,6 @@ pfUI:RegisterModule("chat", function ()
SaveChatHistory(frame:GetID(), text, a1, a2, a3)
end
if isWhisper then
-- patch incoming whisper string to match the colors
text = string.gsub(text, "|r", "|r" .. wcol)
end
frame:HookAddMessage(text, a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15, a16, a17)
end
+3
View File
@@ -75,6 +75,9 @@ pfUI:RegisterModule("chatcopy", function ()
local lines = {}
for index=1, frame:GetNumMessages() do
local text, r, g, b = frame:GetMessageInfo(index)
if C.chat.text.copytime == "0" then
text = pfUI.chat.StripTimestamp(text)
end
local color = rgbhex(r, g, b)
table.insert(lines, color .. text:gsub("|r", color))
end
+2
View File
@@ -2892,6 +2892,8 @@ pfUI:RegisterModule("gui", function ()
CreateConfig(nil, T["Timestamp Format"], C.chat.text, "timeformat", nil, nil, nil, nil, "STRING")
CreateConfig(nil, T["Timestamp Brackets"], C.chat.text, "timebracket", nil, nil, nil, nil, "STRING")
CreateConfig(nil, T["Timestamp Color"], C.chat.text, "timecolor", "color")
-- read each time chat copy opens, so no reload
CreateConfig(function() end, T["Show Timestamps In Chat Copy"], C.chat.text, "copytime", "checkbox")
CreateConfig(nil, T["Hide Channel Names"], C.chat.text, "channelnumonly", "checkbox")
CreateConfig(nil, T["Generate Playerlinks"], C.chat.text, "playerlinks", "checkbox")
CreateConfig(nil, T["Enable URL Detection"], C.chat.text, "detecturl", "checkbox")