123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- return function(BOXUI)
- local utils = BOXUI.utils
- local List = BOXUI.list
- local M = utils.newclass("logger", List)
- M.init = function(self, x, y, width, height)
- List.init(self, x, y, width, height)
- self.count = 0
- self.maxlog = 50
- self.icons = nil
- end
- M.format = function(i, text, count)
- if count then return ("%.3i:\t%s (x %i)"):format(i, text, count) end
- return ("%.3i:\t%s"):format(i, text)
- end
- M.add = function(self, text, level)
- local logitems = self.list.items
- local entry = {raw = text, icon = self.icons[level or "ok"]}
- if not logitems then
- self.count = self.count + 1
- entry.text = self.format(self.count, text)
- self:setItems({entry}, true)
- return
- end
- local len = #logitems
- if logitems[len].raw == text then
- entry = logitems[len]
- entry.count = (entry.count or 1) + 1
- entry.text = self.format(self.count, text, entry.count)
- table.remove(logitems)
- else
- self.count = self.count + 1
- entry.text = self.format(self.count, text)
- end
-
- if len >= self.maxlog then table.remove(logitems, 1) end
- table.insert(logitems, entry)
- self:setItems(logitems, true)
- end
- BOXUI.add(M)
- end
|