console history
This commit is contained in:
parent
e0e052ff1a
commit
5af58fc69d
@ -11,5 +11,12 @@
|
|||||||
gravity="bottom-left"
|
gravity="bottom-left"
|
||||||
></textbox>
|
></textbox>
|
||||||
</container>
|
</container>
|
||||||
<textbox id='prompt' consumer='submit' margin='0' gravity='bottom-left' size-func="gui.get_viewport()[1],40"></textbox>
|
<textbox id='prompt'
|
||||||
|
consumer='submit'
|
||||||
|
margin='0'
|
||||||
|
gravity='bottom-left'
|
||||||
|
size-func="gui.get_viewport()[1],40"
|
||||||
|
onup="on_history_up()"
|
||||||
|
ondown="on_history_down()">
|
||||||
|
</textbox>
|
||||||
</container>
|
</container>
|
||||||
|
|||||||
@ -1,3 +1,6 @@
|
|||||||
|
history = session.get_entry("console_history")
|
||||||
|
history_pointer = #history
|
||||||
|
|
||||||
function setup_variables()
|
function setup_variables()
|
||||||
local x,y,z = player.get_pos(hud.get_player())
|
local x,y,z = player.get_pos(hud.get_player())
|
||||||
console.set('pos.x', x)
|
console.set('pos.x', x)
|
||||||
@ -5,7 +8,29 @@ function setup_variables()
|
|||||||
console.set('pos.z', z)
|
console.set('pos.z', z)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function on_history_up()
|
||||||
|
if history_pointer == 0 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
document.prompt.text = history[history_pointer]
|
||||||
|
history_pointer = history_pointer - 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function on_history_down()
|
||||||
|
if history_pointer == #history-1 then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
history_pointer = history_pointer + 1
|
||||||
|
document.prompt.text = history[history_pointer + 1]
|
||||||
|
end
|
||||||
|
|
||||||
|
function add_to_history(text)
|
||||||
|
table.insert(history, text)
|
||||||
|
history_pointer = #history
|
||||||
|
end
|
||||||
|
|
||||||
function submit(text)
|
function submit(text)
|
||||||
|
add_to_history(text)
|
||||||
setup_variables()
|
setup_variables()
|
||||||
|
|
||||||
local status, result = pcall(function() return console.execute(text) end)
|
local status, result = pcall(function() return console.execute(text) end)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user