1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-02 16:38:41 +00:00

Add functions to strip color information. (#5472)

This commit is contained in:
Diego Martínez 2017-03-28 16:55:39 -03:00 committed by Loïc Blot
parent 1b299b4039
commit 81c3dc32a8
3 changed files with 26 additions and 1 deletions

View file

@ -640,6 +640,8 @@ if INIT == "client" or INIT == "mainmenu" then
end
end
local ESCAPE_CHAR = string.char(0x1b)
-- Client-sided mods don't have access to getbool
if core.setting_getbool and core.setting_getbool("disable_escape_sequences") then
@ -657,7 +659,6 @@ if core.setting_getbool and core.setting_getbool("disable_escape_sequences") the
else
local ESCAPE_CHAR = string.char(0x1b)
function core.get_color_escape_sequence(color)
return ESCAPE_CHAR .. "(c@" .. color .. ")"
end
@ -678,3 +679,15 @@ else
end
end
function core.strip_foreground_colors(str)
return (str:gsub(ESCAPE_CHAR .. "%(c@[^)]+%)", ""))
end
function core.strip_background_colors(str)
return (str:gsub(ESCAPE_CHAR .. "%(b@[^)]+%)", ""))
end
function core.strip_colors(str)
return (str:gsub(ESCAPE_CHAR .. "%([bc]@[^)]+%)", ""))
end