Skip to content

Commit

Permalink
Update 3 files
Browse files Browse the repository at this point in the history
  • Loading branch information
ionarevamp committed Nov 9, 2023
1 parent 85db6c5 commit 244b091
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 6 deletions.
46 changes: 46 additions & 0 deletions src/lib/buffer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,52 @@ mvdirs = { -- mvdirs.r can be used to represent a space
u = "\027[1A",
d = "\027[1B"
}

function initscreen(width,height)
local screen = {}
for y = 1, height do
screen[y] = {}
for x = 1, width do
screen[y][x] = {
text = "",
fgcolor = FGCOLOR,
bgcolor = BGCOLOR
}
end
end
return screen
end
function tobuffer(x, y, str, fgcolor, bgcolor, screen)
screen = screen or SCREEN[1]
fgcolor = fgcolor or FGCOLOR
bgcolor = bgcolor or BGCOLOR
for i = 1, #str-(btoi[#str+x>#screen[1]]*(#str+x-#screen[1])) do
local str = str:sub(i, i) or str
screen[y][x+i] = {
text = str,
fgcolor = fgcolor,
bgcolor = bgcolor
}
end
end
function clearbuffline(y,screen) -- y coordinate is equivalent to row from top
screen = screen or SCREEN[1]
for x = 1, #screen[y] do
screen[y][x].text = ""
screen[y][x].fgcolor = FGCOLOR
screen[y][x].bgcolor = BGCOLOR
end
end
function clearbuff(screen)
screen = screen or SCREEN[1]
for y = 1, #screen do
clearbuffline(y,screen)
end
end
function clearbuffer(...)
clearbuff(...)
end

-- DEBUG
function showcmd(t)
local lines = {}
Expand Down
31 changes: 31 additions & 0 deletions src/lib/gfx.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,34 @@
checkflush = {"return ;",
"io.flush();"}
;

function printscreenbuf(screen,fgcolor,bgcolor,mode,btoi)
screen = screen or SCREEN[1]
mode = mode or "all";
btoi = btoi or {[true]=2,[false]=1}
for y = 1, #screen do
for x = 1, #screen[y] do
mvcursor(x,y)
rgbbg(screen[y][x].bgcolor)
rgbwr(screen[y][x].text,screen[y][x].fgcolor)
load(checkflush[(btoi[mode == "char"])])()
end
load(checkflush[(btoi[mode == "line"])])()
end
local checkflush = checkflush
load(checkflush[(btoi[mode == "all"])])()
end
function printlinebuf(y,screen)
screen = screen or SCREEN[1]
y = y or #screen
for x = 1, #screen[y] do
mvcursor(x,y)
rgbbg(screen[y][x].bgcolor)
rgbwr(screen[y][x].text, screen[y][x].fgcolor)
end
io.flush()
end

function drawline(x1,y1,x2,y2,char)
local char = char or "*"
local ceil = math.ceil
Expand Down
24 changes: 18 additions & 6 deletions src/main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ function rgbwr(text,rgb)
-- (scalar-ize data?)
dll.rgbwr(text,r,g,b)
end
function rgbbg(rgb)
local r,g,b = unpack(rgb)
dll.rgbbg(r,g,b)
end
function rgbset(rgb,BGrgb)
FGCOLOR = rgb
local BGrgb = BGrgb or BGCOLOR
rgbwr("",FGCOLOR)
rgbbg(BGrgb)
end
function rgbbg(rgb)
local r,g,b = unpack(rgb)
dll.rgbbg(r,g,b)
end
function rgbprint(text,bgrgb,fgrgb)
rgbbg(bgrgb) -- set background
rgbwr(text,fgrgb) -- set foreground
Expand Down Expand Up @@ -97,7 +97,7 @@ function getms() return tonumber(dll.getns()) end

maxnum = 2^(53)-(2^8)
math.randomseed(maxnum-os.time())
btoi={[true]=1,[false]=0}; -- stands for 'b.ool c.heck'
btoi={[true]=1,[false]=0}; -- boolean to integer
gc={[true]=load([[collectgarbage("collect");
collectgarbage("collect")]]),
[false]=load("return ;")} -- stands for 'g.arbage c.ollect'
Expand Down Expand Up @@ -130,6 +130,11 @@ flags = table.concat(flags," ")
os.execute("stty "..flags) -- put TTY in raw mode

keymaps = dofile("src/lib/keymap.lua")
SCREEN = {}
SCREEN[1] = initscreen(WIDTH,HEIGHT)
mainbuf = SCREEN[1]
-- statsbuf = ... ; (etc.)


function memcount()
local kbmem = string.match(collectgarbage("count"),"%d+%.?%d*")
Expand Down Expand Up @@ -184,7 +189,14 @@ function main()
for i=0,HEIGHT do io.write() end
clr()
savecursor()
-- dofile("src/intro.lua")
slp()
tobuffer(40,10,"Print test 1",CLR.red)
print("Print test 2")
printscreenbuf()
tobuffer(40,11,"Print test 2",CLR.blue)
printlinebuf(11)
slp()
dofile("src/intro.lua")
c_print("Press Enter key to start",CENTER[2])
memcount()
mcr(CENTER[2]);io.flush();
Expand Down

0 comments on commit 244b091

Please sign in to comment.