Computer: allow output buffer to be editable

master
octacian 2017-01-30 22:29:52 -08:00
parent a4e0a2c875
commit f805b6b1e0
2 changed files with 27 additions and 5 deletions

View File

@ -34,6 +34,11 @@ Returns the value of the output buffer. Shorthand for `get_attr("output")`.
Set the output buffer to any string. This is the write method for the output attribute. Set the output buffer to any string. This is the write method for the output attribute.
#### `set_output_editable(bool)`
**Usage:** `set_output_editable(<true/false (bool)>)`
Makes the output buffer editable. Useful for programs that would like a larger input field. However, it can be used in any way wanted as `get_output` and `set_output` are still functional.
#### `get_input()` #### `get_input()`
**Usage:** `get_input()` **Usage:** `get_input()`

View File

@ -116,18 +116,27 @@ digicompute.c.forms = {
local meta = minetest.get_meta(pos) local meta = minetest.get_meta(pos)
local input = minetest.formspec_escape(meta:get_string("input")) local input = minetest.formspec_escape(meta:get_string("input"))
local help = minetest.formspec_escape(meta:get_string("help")) local help = minetest.formspec_escape(meta:get_string("help"))
local output = meta:get_string("output"):split("\n", true) local output = meta:get_string("output")
for i, line in ipairs(output) do if meta:get_string("output_editable") == "true" then
output[i] = minetest.formspec_escape(line) output = minetest.formspec_escape(output)
output =
"textarea[-0.03,-0.4;10.62,13.03;output;;"..output.."]"
else
output = output:split("\n", true)
for i, line in ipairs(output) do
output[i] = minetest.formspec_escape(line)
end
output =
"tableoptions[background=#000000FF;highlight=#00000000;border=false]"..
"table[-0.25,-0.38;10.38,11.17;list_credits;"..table.concat(output, ",")..";"..#output.."]"
end end
return return
"size[10,11]".. "size[10,11]"..
"tabheader[0,0;tabs;Command Line,Settings;1]".. "tabheader[0,0;tabs;Command Line,Settings;1]"..
"bgcolor[#000000FF;]".. "bgcolor[#000000FF;]"..
"tableoptions[background=#000000FF;highlight=#00000000;border=false]".. output..
"table[-0.25,-0.38;10.38,11.17;list_credits;"..table.concat(output, ",")..";"..#output.."]"..
"button[9.56,10.22;0.8,2;help;?]".. "button[9.56,10.22;0.8,2;help;?]"..
"tooltip[help;"..help.."]".. "tooltip[help;"..help.."]"..
"field[-0.02,10.99;10.1,1;input;;"..input.."]".. "field[-0.02,10.99;10.1,1;input;;"..input.."]"..
@ -391,6 +400,14 @@ function digicompute.c:make_env(pos, player)
function main.set_output(value) function main.set_output(value)
return meta:set_string("output", value) return meta:set_string("output", value)
end end
-- [function] set whether output is writable
function main.set_output_editable(bool)
if bool == true then
meta:set_string("output_editable", "true")
else
meta:set_string("output_editable", "false")
end
end
-- [function] get input -- [function] get input
function main.get_input() function main.get_input()
return meta:get_string("input") or nil return meta:get_string("input") or nil