Proto terminal interface.

Still doesn't do much yet, but the terminal code is somewhat
working. Need to limit output to ~16-18 lines. Implement locking
with triggers unlocking, input of text files, file/folder structure?
This commit is contained in:
Auke Kok 2017-02-18 00:14:20 -08:00
parent 0444b889d4
commit 38a1f4e904
4 changed files with 275 additions and 0 deletions

125
mods/terminal/init.lua Normal file
View File

@ -0,0 +1,125 @@
--[[
terminal - an interactive terminal
]]--
local context = {}
local commands = {
cls = function(output, params)
return ""
end,
md = function(output, params)
return output .. "\n" .. "command not implemented"
end,
copycon = function(output, params)
return output .. "\n" .. "command not implemented"
end,
dir = function(output, params)
return output .. "\n" .. "command not implemented"
end,
cd = function(output, params)
return output .. "\n" .. "command not implemented"
end,
echo = function(output, params)
return output .. "\n" .. params
end,
type = function(output, params)
return output .. "\n" .. "command not implemented"
end,
lock = function(output, params)
--FIXME need pos to set meta lock value
return output .. "\n" .. "terminal locked"
end,
help = function(output, params)
return output .. "\n" ..
"cls md copycon dir cd echo type help"
end,
}
local function make_formspec(output, prompt)
local f =
"size[12,8]" ..
"textlist[0.4,0.5;11,6;output;"
for part in output:gmatch("[^\r\n]+") do
f = f .. minetest.formspec_escape(part) .. ","
end
f = f .. minetest.formspec_escape(prompt) .. "]field[0.7,7;11.2,1;input;;]"
return f
end
minetest.register_on_player_receive_fields(function(player, formname, fields)
if formname ~= "terminal:" then
return false
end
local input = fields.input
if input and input ~= "" then
local name = player:get_player_name()
local c = context[name]
local output = c.output or ""
output = output .. "\nc:" .. c.path .. "> " .. input
local cmd = ""
local params = ""
for w in input:gmatch("%w+") do
if cmd == "" then
cmd = w
elseif params == "" then
params = w
else
params = params .. " " .. w
end
end
local fn = commands[cmd]
if fn then
output = fn(output, params)
else
output = output .. "\n" .. "Syntax Error"
end
c.output = output
minetest.show_formspec(name, "terminal:", make_formspec(output, "c:\\> "))
end
return true
end)
local terminal_use = function(pos, node, clicker, itemstack, pointed_thing)
if not clicker then
return
end
local name = clicker:get_player_name()
context[name] = {
pos = pos,
rw = false,
path = "\\",
output = "",
}
if boxes.players_editing_boxes[name] or
(not boxes.players_in_boxes[name] and minetest.check_player_privs(clicker, "server")) then
-- allow rw access
context[name].rw = true
end
-- send formspec to player
minetest.show_formspec(name, "terminal:", make_formspec("", "c:\\> "))
end
minetest.register_node("terminal:terminal", {
description = "An interactive terminal console emulator access interface unit controller",
drawtype = "mesh",
mesh = "terminal.obj",
tiles = {
{name = "terminal_base.png"},
{name = "terminal_idle.png", animation = {type = "vertical_frames", aspect_w = 14, aspect_h = 13, length = 4.0}},
},
paramtype = "light",
paramtype2 = "facedir",
on_trigger = function(pos)
-- unlock terminal
-- a locked terminal replies "access denied" to every command
end,
on_untrigger = function(pos)
-- lock terminal
end,
on_rightclick = terminal_use,
})

View File

@ -0,0 +1,150 @@
# Blender v2.78 (sub 0) OBJ File: 'terminal.blend'
# www.blender.org
mtllib terminal.mtl
o Cube
v -0.499416 -0.499997 0.500427
v -0.499417 -0.499997 -0.499573
v 0.500584 -0.499997 -0.499573
v 0.500584 -0.499997 0.500427
v -0.499417 0.500003 0.500427
v 0.500584 0.500003 0.500427
v -0.499416 0.500003 -0.187073
v 0.438084 -0.371872 -0.187073
v 0.438084 0.434378 -0.187073
v 0.500584 0.500003 -0.187073
v -0.499416 -0.437497 -0.499573
v -0.436916 -0.371872 -0.187073
v 0.500584 -0.437497 -0.499573
v -0.499416 -0.437497 -0.187073
v 0.500584 -0.437497 -0.187073
v -0.436916 0.434378 -0.187073
v -0.436916 0.434378 -0.124573
v -0.436916 -0.371872 -0.124573
v 0.438084 -0.371872 -0.124573
v 0.438084 0.434378 -0.124573
v -0.436916 -0.437497 -0.437073
v -0.436916 -0.437497 -0.249573
v 0.438084 -0.437497 -0.437073
v 0.438084 -0.437497 -0.249573
v -0.436916 -0.374997 -0.249573
v -0.436916 -0.374997 -0.437073
v 0.438084 -0.374997 -0.249573
v 0.438084 -0.374997 -0.437073
vt 0.0000 1.0000
vt 0.0000 0.0000
vt 1.0000 0.0000
vt 1.0000 1.0000
vt 1.0000 1.0000
vt 0.3125 1.0000
vt 0.3125 0.0000
vt 1.0000 0.0000
vt 0.3125 0.0000
vt 0.3125 1.0000
vt 0.2500 0.9375
vt 0.2500 0.0625
vt 0.0625 0.0625
vt 0.0625 0.9375
vt 0.0000 1.0000
vt 0.0000 0.0000
vt 0.0000 0.0000
vt 1.0000 0.0000
vt 0.0000 1.0000
vt 0.3750 0.0625
vt 0.3750 0.9375
vt 0.3125 0.9375
vt 0.3125 0.0625
vt 0.6875 0.0625
vt 0.6875 1.0000
vt 0.0000 1.0000
vt 0.6875 0.1250
vt 0.6875 0.9375
vt 0.6250 0.9375
vt 0.6250 0.1250
vt 0.7500 0.0625
vt 0.9375 0.0625
vt 0.9375 0.1250
vt 0.7500 0.1250
vt 0.0000 0.0000
vt 1.0000 0.0000
vt 1.0000 0.0625
vt 0.0000 0.0625
vt 0.3125 0.9375
vt 0.3125 0.1250
vt 0.3750 0.1250
vt 0.3750 0.9375
vt 0.2500 0.0625
vt 0.2500 0.9375
vt 0.0625 0.9375
vt 0.0625 0.0625
vt 0.0625 0.0625
vt 0.0625 0.1250
vt 0.9375 0.1250
vt 0.9375 0.0625
vt 0.9375 0.0625
vt 0.9375 0.1250
vt 0.0625 0.1250
vt 0.0625 0.0625
vt 0.2500 0.1250
vt 0.0625 0.1250
vt 1.0000 1.0000
vt 0.9375 0.9344
vt 0.9375 0.1281
vt 1.0000 0.0625
vt 1.0000 1.0000
vt 0.3125 1.0000
vt 0.3125 0.0625
vt 0.6875 0.9375
vt 0.6250 0.9375
vt 0.6250 0.0625
vt 0.6875 0.0625
vt 0.0000 0.0000
vt 0.0000 0.0625
vt 1.0000 0.0000
vt 1.0000 0.0625
vt 0.0625 0.9344
vt 0.0000 1.0000
vt 0.0000 0.0625
vt 0.0625 0.1281
vt 1.0000 1.0000
vt 0.0000 1.0000
vt 0.0000 0.0000
vt 1.0000 0.0000
vn 0.0000 -1.0000 -0.0000
vn 0.0000 1.0000 -0.0000
vn -0.0000 0.0000 1.0000
vn 1.0000 -0.0000 0.0000
vn -0.0000 0.0000 -1.0000
vn -1.0000 0.0000 0.0000
g Cube_Cube_frame
usemtl frame
s off
f 3/1/1 4/2/1 1/3/1 2/4/1
f 6/5/2 10/6/2 7/7/2 5/8/2
f 14/9/2 15/10/2 24/11/2 22/12/2 21/13/2 23/14/2 13/15/2 11/16/2
f 1/17/3 4/18/3 6/5/3 5/19/3
f 18/20/2 19/21/2 8/22/2 12/23/2
f 15/24/4 10/25/4 6/26/4
f 12/27/4 16/28/4 17/29/4 18/30/4
f 24/31/4 23/32/4 28/33/4 27/34/4
f 3/35/5 2/36/5 11/37/5 13/38/5
f 9/39/6 8/40/6 19/41/6 20/42/6
f 25/43/2 27/44/2 28/45/2 26/46/2
f 24/47/3 27/48/3 25/49/3 22/50/3
f 21/51/5 26/52/5 28/53/5 23/54/5
f 22/12/6 25/55/6 26/56/6 21/13/6
f 7/57/5 16/58/5 12/59/5 14/60/5
f 13/15/2 23/14/2 24/11/2 15/10/2
f 5/61/6 7/62/6 14/63/6
f 17/64/1 16/65/1 9/66/1 20/67/1
f 14/63/6 2/68/6 1/3/6
f 1/3/6 5/61/6 14/63/6
f 14/63/6 11/69/6 2/68/6
f 15/24/4 6/26/4 4/2/4
f 3/70/4 13/71/4 15/24/4
f 4/2/4 3/70/4 15/24/4
f 9/72/5 10/73/5 15/74/5 8/75/5
f 12/59/5 8/75/5 15/74/5 14/60/5
f 7/57/5 10/73/5 9/72/5 16/58/5
g Cube_Cube_screen
usemtl screen
f 17/76/5 20/77/5 19/78/5 18/79/5

Binary file not shown.

After

Width:  |  Height:  |  Size: 349 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 109 B