ableos/sysdata/programs/sunset_server/src/main.hb
2024-11-10 18:57:48 +00:00

36 lines
1.3 KiB
Plaintext

.{log} := @use("../../../libraries/stn/src/lib.hb")
render := @use("../../../libraries/render/src/lib.hb");
.{server, message, WindowWrapper, WindowProps} := @use("../../../libraries/sunset_proto/src/lib.hb")
psf := @embed("../../../assets/consolefonts/tamsyn/10x20r.psf")
main := fn(): void {
screen := render.init(false)
font := render.text.font_from_psf2(@bitcast(&psf), false)
if font == null {
return
}
if server.init() == false {
log.error("Failed to create server\0")
return
}
loop if server.should_shutdown() break else {
recv := server.recieve()
if recv == null {
continue
} else if recv.kind == message.new {
props := *@as(^WindowProps, @bitcast(recv.data_ptr));
*@as(^?WindowWrapper, @bitcast(recv.callback)) = WindowWrapper.(0, props)
render.put_rect(screen, props.position, props.dimensions, render.white)
render.put_text(screen, font, props.position + .(1, 1), render.white, props.title)
render.put_hline(screen, props.position.y + font.height + 2, props.position.x, props.position.x + props.dimensions.x, render.white)
log.info("server: made a new window\0")
} else if recv.kind == message.shutdown {
*@as(^?u8, @bitcast(recv.callback)) = 255
break
}
}
render.put_text(screen, font, .(0, 0), render.white, "Shutdown triggered\0")
log.info("Server shutdown\0")
}