mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-18 11:48:02 -04:00
Hint function can now return tables and iterators
Returning table or iterator will display set of available completion options. When user will return table, he/she should also provide prompt function for (re)drawing prompt if one is used is his/her program
This commit is contained in:
parent
47c95a62d8
commit
62a507ed87
@ -101,7 +101,7 @@ function term.isAvailable()
|
||||
return component.isAvailable("gpu") and component.isAvailable("screen")
|
||||
end
|
||||
|
||||
function term.read(history, dobreak, hint)
|
||||
function term.read(history, dobreak, hint, prompt)
|
||||
checkArg(1, history, "table", "nil")
|
||||
history = history or {}
|
||||
table.insert(history, "")
|
||||
@ -109,6 +109,10 @@ function term.read(history, dobreak, hint)
|
||||
local scrollX, scrollY = 0, #history - 1
|
||||
local cursorX = 1
|
||||
|
||||
if type(prompt) == "function" then
|
||||
pcall(prompt)
|
||||
end
|
||||
|
||||
local function getCursor()
|
||||
return cursorX, 1 + scrollY
|
||||
end
|
||||
@ -252,8 +256,15 @@ function term.read(history, dobreak, hint)
|
||||
if type(after) == "string" then
|
||||
local _, cby = getCursor()
|
||||
history[cby] = after
|
||||
elseif type(after) == "table" or type(after) == "function" then
|
||||
term.write("\n")
|
||||
for _, v in type(after) == "table" and pairs(after) or (function()return _,after end) do
|
||||
term.write(name .. " ", true)
|
||||
end
|
||||
term.write("\n")
|
||||
if type(prompt) == "function" then pcall(prompt)end
|
||||
end
|
||||
redraw() --hint might have printed sth
|
||||
redraw()
|
||||
ende()
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user