make longer lines in logfile readable

This commit is contained in:
Sokomine 2022-09-11 18:34:30 +02:00
parent 97c6741a4e
commit 258e990d7a

View File

@ -84,6 +84,33 @@ yl_speak_up.input_show_log = function(player, formname, fields)
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)
-- 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
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')
if(same_lines > 1) then
table.insert(text, tostring(same_lines).."x")
else
table.insert(text, "")
end
else
-- do not repeat all the other entries - we just continue text
table.insert(text, '#AAAAAA,,#FFFF00,,#AAAAAA,')
end
table.insert(text, '#FFFFFF')
table.insert(text, minetest.formspec_escape(p))
end
end
-- TODO: make use of log_type and toggle between trade entries and full log?
yl_speak_up.get_fs_show_log = function(player, log_type)
local pname = player:get_player_name()
@ -131,18 +158,7 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
-- just count the line
same_lines = same_lines + 1
else
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')
if(same_lines > 1) then
table.insert(text, tostring(same_lines).."x")
else
table.insert(text, "")
end
table.insert(text, '#FFFFFF')
table.insert(text, minetest.formspec_escape(last_line))
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines)
-- store information about the next line
same_lines = 0
last_line = this_line
@ -152,18 +168,7 @@ yl_speak_up.get_fs_show_log = function(player, log_type)
count = count + 1
end
-- cover the last line
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')
if(same_lines > 1) then
table.insert(text, tostring(same_lines).."x")
else
table.insert(text, "")
end
table.insert(text, '#FFFFFF')
table.insert(text, minetest.formspec_escape(last_line))
yl_speak_up.show_log_add_line(text, last_day, last_who, last_line, same_lines)
file:close()
table.insert(formspec, table.concat(text, ','))