erdos/src/term/loop.lua

26 lines
458 B
Lua
Raw Normal View History

2022-02-16 18:53:37 +00:00
return function(con)
function con.forLine(l, fn, oy)
local x, y = 0, 0
2022-02-21 18:29:51 +00:00
for j, l in utf8.codes(con.out[l]) do
2022-02-16 18:53:37 +00:00
l = utf8.char(l)
if fn then fn(l, x, y + oy) end
if l == '\t' then x = x + 8 - (x % 8)
elseif l == '\v' then y = y + 1
elseif l == '\r' then x = 0
else x = x + 1
end
end
return y
end
function con.forText(fn)
local y = 0
2022-02-21 18:29:51 +00:00
for i = 1, #con.out do
2022-02-16 18:53:37 +00:00
y = y + 1 + con.forLine(i, fn, y)
end
return y
end
end