aboutsummaryrefslogtreecommitdiff
path: root/builtin
diff options
context:
space:
mode:
authorEkdohibs <nathanael.courant@laposte.net>2016-05-31 17:30:11 +0200
committerEkdohibs <nathanael.courant@laposte.net>2016-05-31 17:34:29 +0200
commit14ef2b445adcec770defe1abf83af9d22ccf39d8 (patch)
treebe434ea35d6134f4e7b90a74283a21815ed079ee /builtin
parent1d40385d4aacf0cbea4b19ff06940e8c9bebaf47 (diff)
downloadminetest-14ef2b445adcec770defe1abf83af9d22ccf39d8.tar.gz
minetest-14ef2b445adcec770defe1abf83af9d22ccf39d8.tar.bz2
minetest-14ef2b445adcec770defe1abf83af9d22ccf39d8.zip
Add colored text (not only colored chat).
Add documentation, move files to a proper place and avoid memory leaks. Make it work with most kind of texts, and allow backgrounds too.
Diffstat (limited to 'builtin')
-rw-r--r--builtin/game/chatcommands.lua2
-rw-r--r--builtin/game/misc.lua43
-rw-r--r--builtin/settingtypes.txt5
3 files changed, 35 insertions, 15 deletions
diff --git a/builtin/game/chatcommands.lua b/builtin/game/chatcommands.lua
index 2627559a5..22755386b 100644
--- a/builtin/game/chatcommands.lua
+++ b/builtin/game/chatcommands.lua
@@ -102,7 +102,7 @@ core.register_chatcommand("help", {
description = "Get help for commands or list privileges",
func = function(name, param)
local function format_help_line(cmd, def)
- local msg = core.colorize("00ffff", "/"..cmd)
+ local msg = core.colorize("#00ffff", "/"..cmd)
if def.params and def.params ~= "" then
msg = msg .. " " .. def.params
end
diff --git a/builtin/game/misc.lua b/builtin/game/misc.lua
index 8d5c80216..918315656 100644
--- a/builtin/game/misc.lua
+++ b/builtin/game/misc.lua
@@ -198,19 +198,34 @@ function core.http_add_fetch(httpenv)
return httpenv
end
-function core.get_color_escape_sequence(color)
- --if string.len(color) == 3 then
- -- local r = string.sub(color, 1, 1)
- -- local g = string.sub(color, 2, 2)
- -- local b = string.sub(color, 3, 3)
- -- color = r .. r .. g .. g .. b .. b
- --end
-
- --assert(#color == 6, "Color must be six characters in length.")
- --return "\v" .. color
- return "\v(color;" .. color .. ")"
-end
+if minetest.setting_getbool("disable_escape_sequences") then
+
+ function core.get_color_escape_sequence(color)
+ return ""
+ end
+
+ function core.get_background_escape_sequence(color)
+ return ""
+ end
+
+ function core.colorize(color, message)
+ return message
+ end
+
+else
+
+ local ESCAPE_CHAR = string.char(0x1b)
+ function core.get_color_escape_sequence(color)
+ return ESCAPE_CHAR .. "(c@" .. color .. ")"
+ end
+
+ function core.get_background_escape_sequence(color)
+ return ESCAPE_CHAR .. "(b@" .. color .. ")"
+ end
+
+ function core.colorize(color, message)
+ return core.get_color_escape_sequence(color) .. message .. core.get_color_escape_sequence("#ffffff")
+ end
-function core.colorize(color, message)
- return core.get_color_escape_sequence(color) .. message .. core.get_color_escape_sequence("ffffff")
end
+
diff --git a/builtin/settingtypes.txt b/builtin/settingtypes.txt
index 93fb8e952..538a04f33 100644
--- a/builtin/settingtypes.txt
+++ b/builtin/settingtypes.txt
@@ -615,6 +615,11 @@ server_announce (Announce server) bool false
# If you want to announce your ipv6 address, use serverlist_url = v6.servers.minetest.net.
serverlist_url (Serverlist URL) string servers.minetest.net
+# Disable escape sequences, e.g. chat coloring.
+# Use this if you want to run a server with pre-0.4.14 clients and you want to disable
+# the escape sequences generated by mods.
+disable_escape_sequences (Disable escape sequences) bool false
+
[*Network]
# Network port to listen (UDP).