added color to logfile display for easier reading

This commit is contained in:
Sokomine 2022-09-11 19:32:39 +02:00
parent 258e990d7a
commit 0b2c8ac5ce

View File

@ -86,28 +86,50 @@ end
-- helper function for get_fs_show_log
-- text: list of string
yl_speak_up.show_log_add_line = function(text, last_day, last_who, last_line, same_lines)
yl_speak_up.show_log_add_line = function(text, last_day, last_who, last_line, same_lines, entry_type)
local line = {}
-- split the line up so that it can actually be read
local line_parts = minetest.wrap_text(last_line, 75, true)
for i, p in ipairs(line_parts) do
local multiline = minetest.wrap_text(last_line, 75, true)
for i, p in ipairs(multiline) do
if(i == 1) then
table.insert(text, '#AAAAAA')
table.insert(text, minetest.formspec_escape(last_day))
table.insert(text, '#FFFF00')
table.insert(text, minetest.formspec_escape(last_who))
table.insert(text, '#AAAAAA')
table.insert(line, '#AAAAAA')
table.insert(line, minetest.formspec_escape(last_day))
table.insert(line, '#FFFF00')
table.insert(line, minetest.formspec_escape(last_who))
table.insert(line, '#AAAAAA')
if(same_lines > 1) then
table.insert(text, tostring(same_lines).."x")
table.insert(line, tostring(same_lines).."x")
else
table.insert(text, "")
table.insert(line, "")
end
else
-- do not repeat all the other entries - we just continue text
table.insert(text, '#AAAAAA,,#FFFF00,,#AAAAAA,')
table.insert(line, '#AAAAAA,,#FFFF00,,#AAAAAA,')
end
table.insert(text, '#FFFFFF')
table.insert(text, minetest.formspec_escape(p))
if(entry_type and entry_type == "bought") then
--table.insert(line, '#FF0000') -- red
--table.insert(line, '#00FF00') -- green
--table.insert(line, '#0000FF') -- blue
--table.insert(line, '#FFFF00') -- yellow
--table.insert(line, '#00FFFF') -- cyan
--table.insert(line, '#FF00FF') -- magenta
table.insert(line, '#00FF00') -- green
elseif(entry_type and entry_type == "takes") then
table.insert(line, '#FF6600') -- orange
elseif(entry_type and entry_type == "adds") then
table.insert(line, '#FFCC00') -- orange
elseif(entry_type and (entry_type == "buy_if_less" or entry_type == "sell_if_more")) then
table.insert(line, '#00FFFF') -- cyan
elseif(entry_type and entry_type == "Trade:") then
table.insert(line, '#00BBFF') -- darker cyan
elseif(entry_type and entry_type == "error:") then
table.insert(line, '#FF4444') -- bright red
else
table.insert(line, '#FFFFFF')
end
table.insert(line, minetest.formspec_escape(p))
end
table.insert(text, table.concat(line, ','))
end
@ -134,7 +156,7 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
'color;text,align=right;'.. -- how many times the entry was repeated
'color;text,align=left]'.. -- actual log file entry
'table[0.1,1.0;17.8,9.8;show_log_of_npc;'..
'#FFFFFF,Date,#FFFFFF,Player,#FFFFFF,,#FFFFFF,Log entry,',
'#FFFFFF,Date,#FFFFFF,Player,#FFFFFF,,#FFFFFF,',
}
-- without the time information, some entries (in particular when someone buys from a shpo)
-- may be the same. Those entries are combined into one when viewing the log.
@ -148,6 +170,7 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
-- we don't want to get too much into detail here for players
return "size[5,1]label[0,0;Error reading NPC logfile.]"
else
local last_entry_type = ""
for line in file:lines() do
local parts = string.split(line, " ")
-- suppress the time information as that would be too detailled;
@ -158,25 +181,33 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
-- just count the line
same_lines = same_lines + 1
else
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines)
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines,
last_entry_type)
-- store information about the next line
same_lines = 0
last_line = this_line
last_day = parts[1]
last_who = parts[3]
last_entry_type = parts[4]
end
count = count + 1
end
-- cover the last line
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines)
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines, last_entry_type)
file:close()
table.insert(formspec, table.concat(text, ','))
-- reverse the order so that new entries are on top (newer entries are more intresting)
local reverse_text = {}
for part = #text, 1, -1 do
table.insert(reverse_text, text[part])
end
table.insert(formspec, minetest.formspec_escape('Log entry, newest first, '..
tostring(#text)..' entries:')..",")
table.insert(formspec, table.concat(reverse_text, ','))
end
-- selected row
table.insert(formspec, ";1]")
-- TODO: show lines read? (count)
return table.concat(formspec, '')
end