Skip to content
Permalink
Browse files

Add functions to strip color information. (#5472)

  • Loading branch information...
kaeza authored and nerzhul committed Mar 28, 2017
1 parent 1b299b4 commit 81c3dc32a8e48aee076e4b28cae0037a4ae254d9
Showing with 26 additions and 1 deletion.
  1. +14 −1 builtin/common/misc_helpers.lua
  2. +6 −0 doc/client_lua_api.md
  3. +6 −0 doc/lua_api.txt
@@ -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
@@ -818,6 +818,12 @@ The following functions provide escape sequences:
* `color` is a ColorString
* The escape sequence sets the background of the whole text element to
`color`. Only defined for item descriptions and tooltips.
* `color.strip_foreground_colors(str)`
* Removes foreground colors added by `get_color_escape_sequence`.
* `color.strip_background_colors(str)`
* Removes background colors added by `get_background_escape_sequence`.
* `color.strip_colors(str)`
* Removes all color escape sequences.

`ColorString`
-------------
@@ -1872,6 +1872,12 @@ The following functions provide escape sequences:
* `color` is a ColorString
* The escape sequence sets the background of the whole text element to
`color`. Only defined for item descriptions and tooltips.
* `color.strip_foreground_colors(str)`
* Removes foreground colors added by `get_color_escape_sequence`.
* `color.strip_background_colors(str)`
* Removes background colors added by `get_background_escape_sequence`.
* `color.strip_colors(str)`
* Removes all color escape sequences.

Spatial Vectors
---------------

0 comments on commit 81c3dc3

Please sign in to comment.
You can’t perform that action at this time.