summaryrefslogtreecommitdiff
path: root/builtin/common/misc_helpers.lua
diff options
context:
space:
mode:
authorDiego Martínez <kaeza@users.noreply.github.com>2017-03-28 16:55:39 -0300
committerLoïc Blot <nerzhul@users.noreply.github.com>2017-03-28 21:55:39 +0200
commit81c3dc32a8e48aee076e4b28cae0037a4ae254d9 (patch)
treedd81cf0d1a7d2de99528175d1aae4c141d13b14e /builtin/common/misc_helpers.lua
parent1b299b40391b4ea0fe058b63aad14e3360e917d9 (diff)
downloadminetest-81c3dc32a8e48aee076e4b28cae0037a4ae254d9.tar.gz
minetest-81c3dc32a8e48aee076e4b28cae0037a4ae254d9.tar.bz2
minetest-81c3dc32a8e48aee076e4b28cae0037a4ae254d9.zip
Add functions to strip color information. (#5472)
Diffstat (limited to 'builtin/common/misc_helpers.lua')
-rw-r--r--builtin/common/misc_helpers.lua15
1 files changed, 14 insertions, 1 deletions
diff --git a/builtin/common/misc_helpers.lua b/builtin/common/misc_helpers.lua
index cf76fbde9..f7111680c 100644
--- a/builtin/common/misc_helpers.lua
+++ b/builtin/common/misc_helpers.lua
@@ -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