erdos/src/os.lua

57 lines
1.1 KiB
Lua
Raw Normal View History

2022-02-16 18:53:37 +00:00
VER = '0.1'
return function(con)
love.keyboard.setKeyRepeat(true)
require 'src.mouse' (con)
require 'src.fs' ()
require 'src.async'
2022-02-21 18:29:51 +00:00
local w, h, f
2022-02-16 18:53:37 +00:00
function love.resize(x, y)
w, h = math.max(32, x), math.max(32, y)
2022-02-21 18:29:51 +00:00
f = love.graphics.setNewFont('src/hack.ttf', math.min(w, h) / 32)
local cw, ch = f:getWidth 'A', f:getHeight 'A'
2022-02-16 18:53:37 +00:00
collectgarbage 'collect'
2022-02-21 18:29:51 +00:00
con.resz(w, h, cw, ch)
2022-02-16 18:53:37 +00:00
end
love.resize(love.graphics.getDimensions())
love.window.setMode(w, h, {
resizable = true,
minwidth = 32,
minheight = 32
})
love.textinput = con.type
love.keypressed = con.keydown
2022-02-21 18:29:51 +00:00
local sf = (love.getVersion() or love._version_major)
== 0 and 1 or 255
2022-02-16 18:53:37 +00:00
function love.draw()
2022-02-21 18:29:51 +00:00
love.graphics.setColor(100 / sf, 255 / sf, 0)
2022-02-16 18:53:37 +00:00
con.forText(function(l, x, y)
if not (
l == '\n'
or l == '\r'
or l == '\v'
or l == '\t'
)
2022-02-21 18:29:51 +00:00
then love.graphics.print(l, x * con.cw, y * con.ch + con.oy)
2022-02-16 18:53:37 +00:00
end
end)
end
function loadapp(name, ...)
2022-02-21 18:29:51 +00:00
local succ, msg = pcall(require, 'A.'.. name)
2022-02-16 18:53:37 +00:00
if not succ then
con.println('ERROR: '.. msg)
print(msg)
else
msg({...}, con)
end
end
end