fixed fullscreen support

This commit is contained in:
2025-10-25 15:03:32 -07:00
parent 4194765119
commit 06bc628ecf

View File

@@ -1,5 +1,5 @@
local lib = {}
local threading = require("libs.threading")
local function add(t, v)
for i = 1, #t + 1 do
if t[i] == nil then
@@ -88,18 +88,32 @@ function lib.create(name, w, h, x, y, do_not_add)
}
local function init_col(xi)
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
if not t.buffer[xi] then
t.buffer[xi] = {}
for yy = 1, t.h do
for yy = 1, h do
t.buffer[xi][yy] = { char = " ", tc = t.textColor, bc = t.bgColor }
end
end
end
function t.clear()
for xi = 1, t.w do
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
for xi = 1, w do
init_col(xi)
for yy = 1, t.h do
for yy = 1, h do
local cell = t.buffer[xi][yy]
if not cell then cell = { char = " ", tc = t.textColor, bc = t.bgColor } end
cell.char, cell.tc, cell.bc = " ", t.textColor, t.bgColor
@@ -114,8 +128,15 @@ function lib.create(name, w, h, x, y, do_not_add)
function t.clearLine()
local y0 = t.cursorY
if y0 < 1 or y0 > t.h then return end
for xi = 1, t.w do
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
if y0 < 1 or y0 > h then return end
for xi = 1, w do
init_col(xi)
if not t.buffer[xi][y0] then t.buffer[xi][y0] = { char = " ", tc = t.textColor, bc = t.bgColor } end
local cell = t.buffer[xi][y0]
@@ -124,7 +145,13 @@ function lib.create(name, w, h, x, y, do_not_add)
-- base keeps cursorX unchanged
end
function t.getSize() return t.w, t.h end
function t.getSize()
if t.isFullscreen then
local sw,sh = term.getSize()
return sw,sh-2
end
return t.w, t.h
end
function t.setCursorPos(x0, y0)
-- do NOT clamp; let writers clip like base window
@@ -187,11 +214,18 @@ function lib.create(name, w, h, x, y, do_not_add)
-- write/blit: mutate buffer with clipping; let cursor run past width
function t.write(str)
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
str = tostring(str)
local y0 = t.cursorY
for i = 1, #str do
local x = t.cursorX + i - 1
if x >= 1 and x <= t.w and y0 >= 1 and y0 <= t.h then
if x >= 1 and x <= w and y0 >= 1 and y0 <= h then
init_col(x)
if not t.buffer[x][y0] then t.buffer[x][y0] = { char = " ", tc = t.textColor, bc = t.bgColor } end
local cell = t.buffer[x][y0]
@@ -208,7 +242,13 @@ function lib.create(name, w, h, x, y, do_not_add)
if bgColors and type(bgColors) ~= "string" then error("bad argument #3 (expected string)", 2) end
if textColors and #textColors ~= #text then error("Arguments must be the same length", 2) end
if bgColors and #bgColors ~= #text then error("Arguments must be the same length", 2) end
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
textColors = textColors and textColors:lower() or nil
bgColors = bgColors and bgColors:lower() or nil
@@ -216,7 +256,7 @@ function lib.create(name, w, h, x, y, do_not_add)
local n = #text
for i = 1, n do
local x = t.cursorX + i - 1
if x >= 1 and x <= t.w and y0 >= 1 and y0 <= t.h then
if x >= 1 and x <= w and y0 >= 1 and y0 <= h then
init_col(x)
local ch = text:sub(i, i)
local tch = textColors and textColors:sub(i, i) or nil
@@ -233,15 +273,22 @@ function lib.create(name, w, h, x, y, do_not_add)
-- scroll: supports positive (up) and negative (down)
function t.scroll(n)
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
n = math.floor(n or 1)
if n == 0 then return end
local absn = math.abs(n)
if absn >= t.h then
if absn >= h then
-- clear all rows to new empty lines with current colors
for xi = 1, t.w do
for xi = 1, w do
init_col(xi)
for yy = 1, t.h do
for yy = 1, h do
local cell = t.buffer[xi][yy] or { char = " ", tc = t.textColor, bc = t.bgColor }
cell.char, cell.tc, cell.bc = " ", t.textColor, t.bgColor
end
@@ -251,14 +298,14 @@ function lib.create(name, w, h, x, y, do_not_add)
if n > 0 then
-- move content up
for xi = 1, t.w do
for xi = 1, w do
init_col(xi)
for yy = 1, t.h - n do
for yy = 1, h - n do
if not t.buffer[xi][yy] then t.buffer[xi][yy] = { char = " ", tc = t.textColor, bc = t.bgColor } end
local dst, src = t.buffer[xi][yy], (t.buffer[xi][yy + n] or { char = " ", tc = t.textColor, bc = t.bgColor })
dst.char, dst.tc, dst.bc = src.char, src.tc, src.bc
end
for yy = t.h - n + 1, t.h do
for yy = h - n + 1, h do
local cell = t.buffer[xi][yy] or { char = " ", tc = t.textColor, bc = t.bgColor }
cell.char, cell.tc, cell.bc = " ", t.textColor, t.bgColor
end
@@ -266,9 +313,9 @@ function lib.create(name, w, h, x, y, do_not_add)
else
-- n < 0 : move content down
local k = -n
for xi = 1, t.w do
for xi = 1, w do
init_col(xi)
for yy = t.h, k + 1, -1 do
for yy = h, k + 1, -1 do
local dst, src = t.buffer[xi][yy], t.buffer[xi][yy - k]
dst.char, dst.tc, dst.bc = src.char, src.tc, src.bc
end
@@ -331,6 +378,16 @@ function lib.create(name, w, h, x, y, do_not_add)
end
end
function t.fullscreen(fullscreen)
if fullscreen == nil or fullscreen ~= t.isFullscreen then
local w = t.w
local h = t.h
if t.isFullscreen then
local sw,sh = term.getSize()
w = sw
h = sh-2
end
threading.addThread(function () t.resized(w,h) end)
end
t.isFullscreen = fullscreen or not t.isFullscreen
end
function t.redraw() end -- renderer handles this elsewhere