aboutsummaryrefslogtreecommitdiff
path: root/builtin/misc_helpers.lua
diff options
context:
space:
mode:
authorsapier <Sapier at GMX dot net>2013-11-10 19:37:45 +0100
committersapier <Sapier at GMX dot net>2013-11-10 19:37:45 +0100
commit0f9440fa61fbfd95b0c06217d08b07c81c897ee0 (patch)
tree2e1845fe07af64c1b6f4b6b533ccdb50a8b399ec /builtin/misc_helpers.lua
parentd75b1718f8768cca1390c463215e65c4ec9ef6c4 (diff)
downloadminetest-0f9440fa61fbfd95b0c06217d08b07c81c897ee0.tar.gz
minetest-0f9440fa61fbfd95b0c06217d08b07c81c897ee0.tar.bz2
minetest-0f9440fa61fbfd95b0c06217d08b07c81c897ee0.zip
Fix "TODO read modinfo" in modmanager to improve ui usability
Diffstat (limited to 'builtin/misc_helpers.lua')
-rw-r--r--builtin/misc_helpers.lua56
1 files changed, 56 insertions, 0 deletions
diff --git a/builtin/misc_helpers.lua b/builtin/misc_helpers.lua
index 38909ec1d..55c5798d7 100644
--- a/builtin/misc_helpers.lua
+++ b/builtin/misc_helpers.lua
@@ -205,6 +205,62 @@ function tbl.formspec_escape(text)
return text
end
+
+function tbl.splittext(text,charlimit)
+ local retval = {}
+
+ local current_idx = 1
+
+ local start,stop = string.find(text," ",current_idx)
+ local nl_start,nl_stop = string.find(text,"\n",current_idx)
+ local gotnewline = false
+ if nl_start ~= nil and (start == nil or nl_start < start) then
+ start = nl_start
+ stop = nl_stop
+ gotnewline = true
+ end
+ local last_line = ""
+ while start ~= nil do
+ if string.len(last_line) + (stop-start) > charlimit then
+ table.insert(retval,last_line)
+ last_line = ""
+ end
+
+ if last_line ~= "" then
+ last_line = last_line .. " "
+ end
+
+ last_line = last_line .. string.sub(text,current_idx,stop -1)
+
+ if gotnewline then
+ table.insert(retval,last_line)
+ last_line = ""
+ gotnewline = false
+ end
+ current_idx = stop+1
+
+ start,stop = string.find(text," ",current_idx)
+ nl_start,nl_stop = string.find(text,"\n",current_idx)
+
+ if nl_start ~= nil and (start == nil or nl_start < start) then
+ start = nl_start
+ stop = nl_stop
+ gotnewline = true
+ end
+ end
+
+ --add last part of text
+ if string.len(last_line) + (string.len(text) - current_idx) > charlimit then
+ table.insert(retval,last_line)
+ table.insert(retval,string.sub(text,current_idx))
+ else
+ last_line = last_line .. " " .. string.sub(text,current_idx)
+ table.insert(retval,last_line)
+ end
+
+ return retval
+end
+
--------------------------------------------------------------------------------
if minetest then