From 4d7e15c295cc63d1b2b44d84ff23c955209ed02b Mon Sep 17 00:00:00 2001 From: rxi Date: Sun, 13 Apr 2014 10:25:46 +0100 Subject: [PATCH] Changed .lines to store metadata; Added repeated-line counter * The lovebird.lines table now stores metadata for the printed line: the time it was printed and the number of consecutive repetitions of that line to occur. * Consecutive duplicate lines now get a little repeat count marker instead of having the line print out multiple times. --- lovebird.lua | 49 ++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 40 insertions(+), 9 deletions(-) diff --git a/lovebird.lua b/lovebird.lua index ece67f6..2784599 100644 --- a/lovebird.lua +++ b/lovebird.lua @@ -53,6 +53,19 @@ end color: #909090; padding-right: 4px; } + .repeatcount { + color: #F0F0F0; + background: #505050; + font-size: 11px; + font-weight: bold; + text-align: center; + padding-left: 4px; + padding-right: 4px; + padding-top: 1px; + padding-bottom: 1px; + border-radius: 6px; + display: inline-block; + } .greybordered { margin: 12px; background: #F0F0F0; @@ -411,17 +424,35 @@ end function lovebird.print(...) local str = table.concat(map({...}, tostring), " ") - if not lovebird.allowhtml then - str = lovebird.htmlescape(str) + local last = lovebird.lines[#lovebird.lines] + if last and str == last.str then + -- Update last line if this line is a duplicate of it + last.time = os.time() + last.count = last.count + 1 + else + -- Create new line + local line = { str = str, time = os.time(), count = 1 } + table.insert(lovebird.lines, line) + if #lovebird.lines > lovebird.maxlines then + table.remove(lovebird.lines, 1) + end end - if lovebird.timestamp then - str = os.date('%H:%M:%S ') .. str + -- Build string buffer from lines + local function doline(line) + local str = line.str + if not lovebird.allowhtml then + str = lovebird.htmlescape(line.str) + end + if line.count > 1 then + str = '' .. line.count .. ' ' .. str + end + if lovebird.timestamp then + str = os.date('%H:%M:%S ', line.time) .. + str + end + return str end - table.insert(lovebird.lines, str) - if #lovebird.lines > lovebird.maxlines then - table.remove(lovebird.lines, 1) - end - lovebird.buffer = table.concat(lovebird.lines, "
") + lovebird.buffer = table.concat(map(lovebird.lines, doline), "
") end