mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-14 09:46:53 -04:00
term crash guard for writes before binding, and resize support
This commit is contained in:
parent
cfe97d8327
commit
c7715382fd
@ -27,3 +27,10 @@ event.listen("component_unavailable", function(_,type)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
event.listen("screen_resized", function(_,addr,w,h)
|
||||||
|
local window = term.internal.window()
|
||||||
|
if term.isAvailable(window) and window.screen.address == addr and window.fullscreen then
|
||||||
|
window.w,window.h = w,h
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
@ -86,10 +86,10 @@ function process.load(path, env, init, name)
|
|||||||
-- msg can be a custom error object
|
-- msg can be a custom error object
|
||||||
local msg = result[2]
|
local msg = result[2]
|
||||||
if type(msg) == 'table' then
|
if type(msg) == 'table' then
|
||||||
assert(msg.reason=="terminated",msg.reason)
|
if msg.reason~="terminated" then error(msg.reason,2) end
|
||||||
result={0,msg.code}
|
result={0,msg.code}
|
||||||
else
|
else
|
||||||
assert(false, msg)
|
error(msg,2)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return select(2,table.unpack(result))
|
return select(2,table.unpack(result))
|
||||||
|
@ -15,8 +15,9 @@ local W = term.internal.window
|
|||||||
|
|
||||||
local local_env = {unicode=unicode,event=event,process=process,W=W,kb=kb}
|
local local_env = {unicode=unicode,event=event,process=process,W=W,kb=kb}
|
||||||
|
|
||||||
function term.internal.open(dx, dy, w, h)
|
function term.internal.open(...)
|
||||||
local window = {x=1,y=1,dx=dx or 0,dy=dy or 0,w=w,h=h,blink=true}
|
local dx, dy, w, h = ...
|
||||||
|
local window = {x=1,y=1,fullscreen=select("#",...)==0,dx=dx or 0,dy=dy or 0,w=w,h=h,blink=true}
|
||||||
return window
|
return window
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -25,6 +26,16 @@ function term.getViewport(window)
|
|||||||
return window.w, window.h, window.dx, window.dy, window.x, window.y
|
return window.w, window.h, window.dx, window.dy, window.x, window.y
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function term.setViewport(w,h,dx,dy,x,y,window)
|
||||||
|
window = window or W()
|
||||||
|
|
||||||
|
local gw,gh = window.gpu.getViewport()
|
||||||
|
w,h,dx,dy,x,y = w or gw,h or gh,dx or 0,dy or 0,x or 1,y or 1
|
||||||
|
|
||||||
|
window.w,window.h,window.dx,window.dy,window.x,window.y,window.gw,window.gh=
|
||||||
|
w,h,dx,dy,x,y, gw, gh
|
||||||
|
end
|
||||||
|
|
||||||
function term.gpu(window)
|
function term.gpu(window)
|
||||||
window = window or W()
|
window = window or W()
|
||||||
return window.gpu
|
return window.gpu
|
||||||
@ -40,7 +51,7 @@ end
|
|||||||
|
|
||||||
function term.isAvailable(w)
|
function term.isAvailable(w)
|
||||||
w = w or W()
|
w = w or W()
|
||||||
return not not (w.gpu and w.screen)
|
return w and not not (w.gpu and w.screen)
|
||||||
end
|
end
|
||||||
|
|
||||||
function term.internal.pull(input, c, off, p, ...)
|
function term.internal.pull(input, c, off, p, ...)
|
||||||
@ -263,6 +274,7 @@ end
|
|||||||
|
|
||||||
function term.drawText(value, wrap, window)
|
function term.drawText(value, wrap, window)
|
||||||
window = window or W()
|
window = window or W()
|
||||||
|
if not window then return end
|
||||||
local gpu = window.gpu
|
local gpu = window.gpu
|
||||||
if not gpu then return end
|
if not gpu then return end
|
||||||
local w,h,dx,dy,x,y = term.getViewport(window)
|
local w,h,dx,dy,x,y = term.getViewport(window)
|
||||||
@ -339,17 +351,13 @@ function term.setCursorBlink(enabled)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function term.bind(gpu, screen, kb, window)
|
function term.bind(gpu, screen, kb, window)
|
||||||
checkArg(1,gpu,"table")
|
|
||||||
checkArg(2,screen,"table")
|
|
||||||
checkArg(3,kb,"table","nil")
|
|
||||||
checkArg(4,window,"table","nil")
|
|
||||||
window = window or W()
|
window = window or W()
|
||||||
window.gpu = gpu
|
window.gpu = gpu or window.gpu
|
||||||
window.screen = screen
|
window.screen = screen or window.screen
|
||||||
window.keyboard = kb
|
window.keyboard = kb or window.keyboard
|
||||||
window.gw,window.gh = gpu.getViewport()
|
if window.fullscreen then
|
||||||
window.w = math.min(window.gw - window.dx, window.w or window.gw)
|
term.setViewport(nil,nil,nil,nil,window.x,window.y,window)
|
||||||
window.h = math.min(window.gh - window.dy, window.h or window.gh)
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function --[[@delayloaded-start@]] term.internal.ctrl_movement(input, dir)
|
function --[[@delayloaded-start@]] term.internal.ctrl_movement(input, dir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user