Quantcast

Adjust buffer sizes and add an option

James Whitehead II [01-13-11 - 17:27]
Adjust buffer sizes and add an option
Filename
CaptainsLog.lua
diff --git a/CaptainsLog.lua b/CaptainsLog.lua
index 5cd4835..637f4e9 100644
--- a/CaptainsLog.lua
+++ b/CaptainsLog.lua
@@ -7,8 +7,6 @@ local L = addon.L

 addon.ldb = LibStub("LibDataBroker-1.1")

-local BUFFER_SIZE = 10
-
 local C = {
     whisper = WHISPER,
     party = PARTY,
@@ -27,6 +25,9 @@ function addon:Initialize()
         profile = {
             timestamp = true,
             timestamp_format = "%H:%M ",
+            buffersize = {
+                ["*"] = 10,
+            },
             showinfeed = {
                 whisper = true,
                 party = true,
@@ -78,10 +79,19 @@ function addon:Initialize()
     end
 end

+function addon:PruneMessages()
+    for mtype, list in pairs(self.messages) do
+        while #list > addon.db.profile.buffersize[mtype] do
+            table.remove(list, 1)
+        end
+    end
+end
+
 function addon:Log(mtype, sender, msg)
     table.insert(self.messages[mtype], {time(), sender, msg})

-    while #self.messages[mtype] > BUFFER_SIZE do
+    local bufsize = addon.db.profile.buffersize[mtype]
+    while #self.messages[mtype] > bufsize do
         table.remove(self.messages[mtype], 1)
     end