Add one element per line option
parent
a14b2bcf80
commit
38361c220a
|
@ -3,10 +3,10 @@ allow_defined_top = true
|
|||
|
||||
read_globals = {
|
||||
formspec_ast = {
|
||||
fields = {"_raw_parse", "_raw_unparse", "apply_offset", "find",
|
||||
"flatten", "formspec_escape", "get_element_by_name",
|
||||
"get_elements_by_name", "interpret", "parse", "register_element",
|
||||
"safe_interpret", "safe_parse", "show_formspec", "unparse", "walk"}
|
||||
fields = {"apply_offset", "find", "flatten", "formspec_escape",
|
||||
"get_element_by_name", "get_elements_by_name", "interpret",
|
||||
"parse", "register_element", "safe_interpret", "safe_parse",
|
||||
"show_formspec", "unparse", "walk"}
|
||||
},
|
||||
fs51 = {
|
||||
fields = {"backport", "backport_string"}
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<script src="https://unpkg.com/fengari-web/dist/fengari-web.js" async></script>
|
||||
<script src="https://unpkg.com/interactjs/dist/interact.min.js" async></script>
|
||||
<script src="index.js" async></script>
|
||||
<script type="application/lua" src="index.lua?rev=6" async defer></script>
|
||||
<script type="application/lua" src="index.lua?rev=7" async defer></script>
|
||||
<style>
|
||||
body {
|
||||
background: #8CBAFA;
|
||||
|
|
14
index.lua
14
index.lua
|
@ -18,7 +18,7 @@
|
|||
--
|
||||
|
||||
-- Load the renderer
|
||||
dofile('renderer.lua?rev=6')
|
||||
dofile('renderer.lua?rev=7')
|
||||
local formspec_escape = formspec_ast.formspec_escape
|
||||
|
||||
local _, digistuff_ts_export = dofile('digistuff_ts.lua?rev=4')
|
||||
|
@ -460,7 +460,7 @@ local load_save_opts = {}
|
|||
local function show_load_save_dialog()
|
||||
local callbacks = {}
|
||||
local formspec = [[
|
||||
formspec_version[2]size[6,11.25]button[0,0;1,0.6;back;←]
|
||||
formspec_version[4]size[6,12]button[0,0;1,0.6;back;←]
|
||||
label[1.25,0.3;Load / save formspec]
|
||||
checkbox[0.25,1.3;use_v1;Use formspec version 1;]] ..
|
||||
(load_save_opts.use_v1 and 'true' or 'false') .. [[]
|
||||
|
@ -473,10 +473,12 @@ local function show_load_save_dialog()
|
|||
label[0.75,5;expressions can be used inside]
|
||||
label[0.75,5.4;${...}. Formspec escaping is]
|
||||
label[0.75,5.8;handled automatically.]
|
||||
button[0.25,7;5.5,1;load;Load formspec]
|
||||
button[0.25,8.25;5.5,1;save;Save formspec]
|
||||
box[0,9.619;6,0.02;#aaa]
|
||||
button[0.25,10;5.5,1;digistuff_ts;WIP]] .. '\n' ..
|
||||
checkbox[0.25,6.8;multiline;One element per line;]] ..
|
||||
(load_save_opts.multiline and 'true' or 'false') .. [[]
|
||||
button[0.25,7.75;5.5,1;load;Load formspec]
|
||||
button[0.25,9;5.5,1;save;Save formspec]
|
||||
box[0,10.369;6,0.02;#aaa]
|
||||
button[0.25,10.75;5.5,1;digistuff_ts;WIP]] .. '\n' ..
|
||||
[[Export to digistuff touchscreen]
|
||||
]]
|
||||
local function get_options()
|
||||
|
|
15
renderer.lua
15
renderer.lua
|
@ -487,6 +487,21 @@ function renderer.export(tree, opts)
|
|||
|
||||
local fs, err = formspec_ast.unparse(tree)
|
||||
if not fs then return nil, err end
|
||||
|
||||
if opts.multiline then
|
||||
-- Make sure escapes are properly handled
|
||||
fs = fs:gsub('\\*%]', function(data)
|
||||
if #data % 2 == 1 then
|
||||
data = data .. "\n"
|
||||
end
|
||||
return data
|
||||
end)
|
||||
|
||||
if fs:sub(-1) == "\n" then
|
||||
fs = fs:sub(1, -2)
|
||||
end
|
||||
end
|
||||
|
||||
if opts.format then
|
||||
fs = ('%q'):format(fs):gsub('\\\n', '\\n')
|
||||
local ok, msg = true, ''
|
||||
|
|
Loading…
Reference in New Issue