forked from izaya/LuPPC
Compare commits
No commits in common. "b4fefd4c0f8ae9b99dde79314bf2769e9ed4d673" and "b9747364d7187632af82443273da187a241c713e" have entirely different histories.
b4fefd4c0f
...
b9747364d7
@ -45,36 +45,23 @@ local fg = 256
|
|||||||
local bg = 1
|
local bg = 1
|
||||||
local w, h = 1, 1
|
local w, h = 1, 1
|
||||||
|
|
||||||
local function rgb(i)
|
local unsub
|
||||||
return i>>16&0xFF, i>>8&0xFF, i&0xFF
|
local function set(x, y, text, f, b)
|
||||||
end
|
|
||||||
|
|
||||||
local unsub, fullRefresh
|
|
||||||
local function set(x, y, text, f, b, safe)
|
|
||||||
if x > w or x < 1 or y > h or y < 1 or not tbuffer[y] then
|
if x > w or x < 1 or y > h or y < 1 or not tbuffer[y] then
|
||||||
if safe then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
error("index out of bounds: " .. y, 3)
|
error("index out of bounds: " .. y, 3)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
if not text then return end
|
|
||||||
f = f or fg
|
f = f or fg
|
||||||
b = b or bg
|
b = b or bg
|
||||||
local len = utf8.len(text)
|
local len = utf8.len(text)
|
||||||
if x + len > w then
|
if x + len > w then
|
||||||
--len = (x + len) - w
|
text = unsub(text, 1, -1 - ((x + len) - w))
|
||||||
--text = unsub(text, 1, len)
|
|
||||||
end
|
end
|
||||||
tbuffer[y] = unsub(tbuffer[y], 1, x - 1) ..
|
tbuffer[y] = tbuffer[y]:sub(1, x - 1) ..
|
||||||
text .. unsub(tbuffer[y], x + len)
|
text .. tbuffer[y]:sub(x + len)
|
||||||
if type(f) == "string" then
|
if type(f) == "string" then
|
||||||
fbuffer[y] = fbuffer[y]:sub(1, x - 1) ..
|
fbuffer[y] = fbuffer[y]:sub(1, x - 1) ..
|
||||||
f .. fbuffer[y]:sub(x + len)
|
f .. fbuffer[y]:sub(x + len)
|
||||||
else
|
else
|
||||||
local F = mapping[f]
|
|
||||||
local r, g, _b = rgb(F)
|
|
||||||
write("\27[38;2;", r, ";", g, ";", _b, "m")
|
|
||||||
fbuffer[y] = fbuffer[y]:sub(1, x - 1) ..
|
fbuffer[y] = fbuffer[y]:sub(1, x - 1) ..
|
||||||
string.rep(string.char(f - 1), len) .. fbuffer[y]:sub(x + len)
|
string.rep(string.char(f - 1), len) .. fbuffer[y]:sub(x + len)
|
||||||
end
|
end
|
||||||
@ -82,17 +69,16 @@ local function set(x, y, text, f, b, safe)
|
|||||||
bbuffer[y] = bbuffer[y]:sub(1, x - 1) ..
|
bbuffer[y] = bbuffer[y]:sub(1, x - 1) ..
|
||||||
b .. bbuffer[y]:sub(x + len)
|
b .. bbuffer[y]:sub(x + len)
|
||||||
else
|
else
|
||||||
local B = mapping[b]
|
bbuffer[y] = fbuffer[y]:sub(1, x - 1) ..
|
||||||
local r, g, _b = rgb(B)
|
|
||||||
write("\27[48;2;", r, ";", g, ";", _b, "m")
|
|
||||||
bbuffer[y] = bbuffer[y]:sub(1, x - 1) ..
|
|
||||||
string.rep(string.char(b - 1), len) .. bbuffer[y]:sub(x + len)
|
string.rep(string.char(b - 1), len) .. bbuffer[y]:sub(x + len)
|
||||||
end
|
end
|
||||||
write("\27[", y, ";", x, "H", text)
|
local F, B = mapping[f], mapping[b]
|
||||||
flush()
|
write("\27[38;2;", F&0xFF0000, ";", F&0x00FF00, ";", F&0x0000FF, "m")
|
||||||
|
write("\27[48;2;", B&0xFF0000, ";", B&0x00FF00, ";", B&0x0000FF, "m")
|
||||||
|
write("\27[", x, ";", y, "H", text)
|
||||||
end
|
end
|
||||||
|
|
||||||
fullRefresh = function()
|
local function fullRefresh()
|
||||||
for i=1, h, 1 do
|
for i=1, h, 1 do
|
||||||
local text = tbuffer[i]
|
local text = tbuffer[i]
|
||||||
local fgt = fbuffer[i]
|
local fgt = fbuffer[i]
|
||||||
@ -103,37 +89,30 @@ fullRefresh = function()
|
|||||||
local str = ""
|
local str = ""
|
||||||
if bc ~= pb then
|
if bc ~= pb then
|
||||||
pb = bc
|
pb = bc
|
||||||
local B = mapping[bc:byte() + 1]
|
local B = mapping[bc]
|
||||||
str = str .. string.format("\27[48;2;%d;%d;%dm",
|
str = str .. string.format("\27[48;2;%d;%d;%dm",
|
||||||
rgb(B))
|
B&0xFF0000, B&0x00FF00, B&0x0000FF)
|
||||||
end
|
end
|
||||||
if fc ~= pf then
|
if fc ~= pf then
|
||||||
pf = fc
|
pf = fc
|
||||||
local F = mapping[fc:byte() + 1]
|
local F = mapping[fc]
|
||||||
str = str .. string.format("\27[38;2;%d;%d;%dm",
|
str = str .. string.format("\27[38;2;%d;%d;%dm",
|
||||||
rgb(F))
|
F&0xFF0000, F&0x00FF00, F&0x0000FF)
|
||||||
end
|
end
|
||||||
str = str .. tc
|
str = str .. tc
|
||||||
return str
|
return str
|
||||||
end)
|
end)
|
||||||
write("\27[", i, ";1H", fgt)
|
write("\27[", h, ";1H", fgt)
|
||||||
end
|
|
||||||
flush()
|
flush()
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function get(x, y, len, safe)
|
local function get(x, y, len)
|
||||||
if x < 1 or x > w or y < 1 or y > h then
|
if x < 1 or x > w or y < 1 or y > h then
|
||||||
if safe then
|
|
||||||
return
|
|
||||||
else
|
|
||||||
error("index out of bounds: " .. y, 3)
|
error("index out of bounds: " .. y, 3)
|
||||||
end
|
end
|
||||||
end
|
|
||||||
len = (len or 1) - 1
|
len = (len or 1) - 1
|
||||||
if x + len > w then
|
local txt = unsub(tbuffer[y], x, x + len)
|
||||||
len = (x + len) - w
|
|
||||||
end
|
|
||||||
local text = unsub(tbuffer[y], x, x + len)
|
|
||||||
if len == 0 then
|
if len == 0 then
|
||||||
return text,
|
return text,
|
||||||
mapping[fbuffer[y]:sub(x, x):byte() + 1],
|
mapping[fbuffer[y]:sub(x, x):byte() + 1],
|
||||||
@ -229,7 +208,6 @@ function textgpu.start()
|
|||||||
checkArg(2, y, "number")
|
checkArg(2, y, "number")
|
||||||
checkArg(3, text, "string")
|
checkArg(3, text, "string")
|
||||||
checkArg(4, vert, "boolean", "nil")
|
checkArg(4, vert, "boolean", "nil")
|
||||||
vert = false
|
|
||||||
if vert then
|
if vert then
|
||||||
local i = 1
|
local i = 1
|
||||||
local len = utf8.len(text)
|
local len = utf8.len(text)
|
||||||
@ -240,7 +218,6 @@ function textgpu.start()
|
|||||||
return true
|
return true
|
||||||
else
|
else
|
||||||
set(x, y, text)
|
set(x, y, text)
|
||||||
return true
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -259,8 +236,8 @@ function textgpu.start()
|
|||||||
c = unsub(c, 1, 1)
|
c = unsub(c, 1, 1)
|
||||||
if #c == 0 then return true end
|
if #c == 0 then return true end
|
||||||
local str = c:rep(W)
|
local str = c:rep(W)
|
||||||
for i=1, H, 1 do
|
for i=1, h, 1 do
|
||||||
set(x, y + i - 1, str, nil, nil, true)
|
set(x, y + i - 1, str)
|
||||||
end
|
end
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
@ -272,18 +249,15 @@ function textgpu.start()
|
|||||||
checkArg(4, H, "number")
|
checkArg(4, H, "number")
|
||||||
checkArg(5, xd, "number")
|
checkArg(5, xd, "number")
|
||||||
checkArg(6, yd, "number")
|
checkArg(6, yd, "number")
|
||||||
if xd == 0 and yd == 0 then return true end -- hah
|
|
||||||
local start, stop, step
|
local start, stop, step
|
||||||
if yd < 0 then -- moving up - copy from the top down
|
if yd > 0 then -- moving up - copy from the top down
|
||||||
start, stop, step = y, y + H, 1
|
start, stop, step = y, y + H, 1
|
||||||
else -- moving down - copy from the bottom up
|
else -- moving down - copy from the bottom up
|
||||||
start, stop, step = y + H, y, -1
|
start, stop, step = y + H, y, -1
|
||||||
end
|
end
|
||||||
for i=start, stop, step do
|
for i=start, stop, step do
|
||||||
local str, fstr, bstr = get(x, i, W, true)
|
local str, fstr, bstr = get(x, i, W)
|
||||||
if str and fstr and bstr then
|
set(x + xd, i + yd, str, fstr, bstr)
|
||||||
set(x + xd, i + yd, str, fstr, bstr, true)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
fullRefresh()
|
fullRefresh()
|
||||||
return true
|
return true
|
||||||
@ -294,7 +268,7 @@ function textgpu.start()
|
|||||||
return screenAddr
|
return screenAddr
|
||||||
end
|
end
|
||||||
|
|
||||||
function gpu.bind() --[[STUB]] end
|
function gpu.bind() end
|
||||||
|
|
||||||
if not termutils.init() then
|
if not termutils.init() then
|
||||||
return nil, "Cannot initialize terminal based gpu"
|
return nil, "Cannot initialize terminal based gpu"
|
||||||
@ -303,7 +277,6 @@ function textgpu.start()
|
|||||||
|
|
||||||
w, h = gpu.getResolution()
|
w, h = gpu.getResolution()
|
||||||
prep(w, h)
|
prep(w, h)
|
||||||
fullRefresh()
|
|
||||||
|
|
||||||
gpu.setForeground(0xFFFFFF)
|
gpu.setForeground(0xFFFFFF)
|
||||||
gpu.setBackground(0x000000)
|
gpu.setBackground(0x000000)
|
||||||
|
Loading…
Reference in New Issue
Block a user