mirror of
https://github.com/TangentFoxy/lovebird.git
synced 2025-07-28 11:02:19 +00:00
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.
This commit is contained in:
47
lovebird.lua
47
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)
|
||||
end
|
||||
if lovebird.timestamp then
|
||||
str = os.date('<span class="timestamp">%H:%M:%S</span> ') .. str
|
||||
end
|
||||
table.insert(lovebird.lines, 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
|
||||
lovebird.buffer = table.concat(lovebird.lines, "<br>")
|
||||
end
|
||||
-- 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 = '<span class="repeatcount">' .. line.count .. '</span> ' .. str
|
||||
end
|
||||
if lovebird.timestamp then
|
||||
str = os.date('<span class="timestamp">%H:%M:%S</span> ', line.time) ..
|
||||
str
|
||||
end
|
||||
return str
|
||||
end
|
||||
lovebird.buffer = table.concat(map(lovebird.lines, doline), "<br>")
|
||||
end
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user