fix client wrong res

This commit is contained in:
Matthieu Jolimaitre 2024-04-10 02:45:49 +02:00
parent 976a99baa1
commit f277a71087

View file

@ -80,15 +80,17 @@ class DisplayHandler {
async spin() { async spin() {
while (true) { while (true) {
await wait(100); await wait(100);
const [width, height] = await this.get_res(); const [width, height] = await DisplayHandler.get_res();
this.outputs.send({ kind: "request_display", content: { width, height } }); this.outputs.send({ kind: "request_display", content: { width, height } });
} }
} }
async get_res() { static async get_res() {
const width = parseInt(await run("tput", "cols")) / 2 - 2; // note : tiles are 2 char wide const output = await run("stty", "size");
const height = parseInt(await run("tput", "lines")) - 2; const [raw_height, raw_width] = output.split(" ");
return [width, height]; const width = Math.floor(parseInt(raw_width) / 2) - 2; // note : tiles are 2 char wide
const height = parseInt(raw_height) - 2;
return [width, height] as const;
} }
refresh(raw: string) { refresh(raw: string) {
@ -123,3 +125,13 @@ class ServerInterface {
} }
if (import.meta.main) await main(); if (import.meta.main) await main();
Deno.test("res_check", async () => {
const ENABLED = false; // note : toggle before running test to know current resolution.
while (ENABLED) {
await wait(100);
const res = await DisplayHandler.get_res();
console.clear();
console.log("res", res);
}
});